Preliminary support for mixed percent and linear declarations

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-01-05 19:38:11 +01:00
parent 9a17588459
commit b9da170080
4 changed files with 117 additions and 165 deletions

View File

@ -93,7 +93,7 @@ layout_horizontally (grub_gui_box_t self, int modify_layout,
struct component_node *cur; struct component_node *cur;
unsigned w = 0, mwfrac = 0, h = 0, x = 0; unsigned w = 0, mwfrac = 0, h = 0, x = 0;
grub_fixed_unsigned_t wfrac = 0; grub_fixed_signed_t wfrac = 0;
int bogus_frac = 0; int bogus_frac = 0;
for (cur = self->chead.next; cur != &self->ctail; cur = cur->next) for (cur = self->chead.next; cur != &self->ctail; cur = cur->next)
@ -104,17 +104,14 @@ layout_horizontally (grub_gui_box_t self, int modify_layout,
if (c->ops->get_minimal_size) if (c->ops->get_minimal_size)
c->ops->get_minimal_size (c, &mw, &mh); c->ops->get_minimal_size (c, &mw, &mh);
if (!c->ishfrac && c->h > h) if (c->h > (signed) h)
h = c->h; h = c->h;
if (mh > h) if (mh > h)
h = mh; h = mh;
if (!c->iswfrac) wfrac += c->wfrac;
w += mw > c->w ? mw : c->w; w += c->w;
if (c->iswfrac) if (mw - c->w > 0)
{ mwfrac += mw - c->w;
wfrac += c->wfrac;
mwfrac += mw;
}
} }
if (wfrac > GRUB_FIXED_1 || (w > 0 && wfrac == GRUB_FIXED_1)) if (wfrac > GRUB_FIXED_1 || (w > 0 && wfrac == GRUB_FIXED_1))
bogus_frac = 1; bogus_frac = 1;
@ -122,7 +119,7 @@ layout_horizontally (grub_gui_box_t self, int modify_layout,
if (min_width) if (min_width)
{ {
if (wfrac < GRUB_FIXED_1) if (wfrac < GRUB_FIXED_1)
*min_width = grub_fixed_ufu_divide (w, GRUB_FIXED_1 - wfrac); *min_width = grub_fixed_sfs_divide (w, GRUB_FIXED_1 - wfrac);
else else
*min_width = w; *min_width = w;
if (*min_width < w + mwfrac) if (*min_width < w + mwfrac)
@ -142,16 +139,14 @@ layout_horizontally (grub_gui_box_t self, int modify_layout,
r.x = x; r.x = x;
r.y = 0; r.y = 0;
r.width = 32;
r.height = h; r.height = h;
if (c->ops->get_minimal_size) if (c->ops->get_minimal_size)
c->ops->get_minimal_size (c, &mw, &mh); c->ops->get_minimal_size (c, &mw, &mh);
if (!c->iswfrac) r.width = c->w;
r.width = c->w; if (!bogus_frac)
if (c->iswfrac && !bogus_frac) r.width += grub_fixed_sfs_multiply (self->bounds.width, c->wfrac);
r.width = grub_fixed_ufu_multiply (self->bounds.width, c->wfrac);
if (r.width < mw) if (r.width < mw)
r.width = mw; r.width = mw;
@ -171,7 +166,7 @@ layout_vertically (grub_gui_box_t self, int modify_layout,
struct component_node *cur; struct component_node *cur;
unsigned h = 0, mhfrac = 0, w = 0, y = 0; unsigned h = 0, mhfrac = 0, w = 0, y = 0;
grub_fixed_unsigned_t hfrac = 0; grub_fixed_signed_t hfrac = 0;
int bogus_frac = 0; int bogus_frac = 0;
for (cur = self->chead.next; cur != &self->ctail; cur = cur->next) for (cur = self->chead.next; cur != &self->ctail; cur = cur->next)
@ -182,17 +177,14 @@ layout_vertically (grub_gui_box_t self, int modify_layout,
if (c->ops->get_minimal_size) if (c->ops->get_minimal_size)
c->ops->get_minimal_size (c, &mw, &mh); c->ops->get_minimal_size (c, &mw, &mh);
if (!c->iswfrac && c->w > w) if (c->w > (signed) w)
w = c->w; w = c->w;
if (mw > w) if (mw > w)
w = mw; w = mw;
if (!c->ishfrac) hfrac += c->hfrac;
h += mh > c->h ? mh : c->h; h += c->h;
if (c->ishfrac) if (mh - c->h > 0)
{ mhfrac += mh - c->h;
hfrac += c->hfrac;
mhfrac += mh;
}
} }
if (hfrac > GRUB_FIXED_1 || (h > 0 && hfrac == GRUB_FIXED_1)) if (hfrac > GRUB_FIXED_1 || (h > 0 && hfrac == GRUB_FIXED_1))
bogus_frac = 1; bogus_frac = 1;
@ -200,7 +192,7 @@ layout_vertically (grub_gui_box_t self, int modify_layout,
if (min_height) if (min_height)
{ {
if (hfrac < GRUB_FIXED_1) if (hfrac < GRUB_FIXED_1)
*min_height = grub_fixed_ufu_divide (h, GRUB_FIXED_1 - hfrac); *min_height = grub_fixed_sfs_divide (h, GRUB_FIXED_1 - hfrac);
else else
*min_height = h; *min_height = h;
if (*min_height < h + mhfrac) if (*min_height < h + mhfrac)
@ -221,15 +213,13 @@ layout_vertically (grub_gui_box_t self, int modify_layout,
r.x = 0; r.x = 0;
r.y = y; r.y = y;
r.width = w; r.width = w;
r.height = 32;
if (c->ops->get_minimal_size) if (c->ops->get_minimal_size)
c->ops->get_minimal_size (c, &mw, &mh); c->ops->get_minimal_size (c, &mw, &mh);
if (!c->ishfrac) r.height = c->h;
r.height = c->h; if (!bogus_frac)
if (c->ishfrac) r.height += grub_fixed_sfs_multiply (self->bounds.height, c->hfrac);
r.height = grub_fixed_ufu_multiply (self->bounds.height, c->hfrac);
if (r.height < mh) if (r.height < mh)
r.height = mh; r.height = mh;

View File

@ -88,49 +88,51 @@ canvas_paint (void *vself, const grub_video_rect_t *region)
{ {
grub_video_rect_t r; grub_video_rect_t r;
grub_gui_component_t comp; grub_gui_component_t comp;
signed x, y, w, h;
comp = cur->component; comp = cur->component;
r.x = 0; w = grub_fixed_sfs_multiply (self->bounds.width, comp->wfrac) + comp->w;
r.y = 0; h = grub_fixed_sfs_multiply (self->bounds.height, comp->hfrac) + comp->h;
r.width = 32; x = grub_fixed_sfs_multiply (self->bounds.width, comp->xfrac) + comp->x;
r.height = 32; y = grub_fixed_sfs_multiply (self->bounds.height, comp->yfrac) + comp->y;
if (!comp->iswfrac && comp->w)
r.width = comp->w;
if (!comp->ishfrac && comp->h)
r.height = comp->h;
if (!comp->isxfrac && comp->x)
r.x = comp->x;
if (!comp->isyfrac && comp->y)
r.y = comp->y;
if (comp->ishfrac && comp->hfrac)
r.height = grub_fixed_ufu_multiply (self->bounds.height, comp->hfrac);
if (comp->iswfrac && comp->wfrac)
r.width = grub_fixed_ufu_multiply (self->bounds.width, comp->wfrac);
if (comp->isxfrac && comp->xfrac)
r.x = grub_fixed_ufu_multiply (self->bounds.width, comp->xfrac);
if (comp->isyfrac && comp->yfrac)
r.y = grub_fixed_ufu_multiply (self->bounds.height, comp->yfrac);
if (comp->ops->get_minimal_size) if (comp->ops->get_minimal_size)
{ {
unsigned mw; unsigned mw;
unsigned mh; unsigned mh;
comp->ops->get_minimal_size (comp, &mw, &mh); comp->ops->get_minimal_size (comp, &mw, &mh);
if (r.width < mw) if (w < (signed) mw)
r.width = mw; w = mw;
if (r.height < mh) if (h < (signed) mh)
r.height = mh; h = mh;
} }
/* Sanity checks. */
if (w <= 0)
w = 32;
if (h <= 0)
h = 32;
if (x >= (signed) self->bounds.width)
x = self->bounds.width - 32;
if (y >= (signed) self->bounds.height)
y = self->bounds.height - 32;
if (x < 0)
x = 0;
if (y < 0)
y = 0;
if (x + w >= (signed) self->bounds.width)
w = self->bounds.width - x;
if (y + h >= (signed) self->bounds.height)
h = self->bounds.height - y;
r.x = x;
r.y = y;
r.width = w;
r.height = h;
comp->ops->set_bounds (comp, &r); comp->ops->set_bounds (comp, &r);
/* Paint the child. */ /* Paint the child. */

View File

@ -361,6 +361,40 @@ read_expression (struct parsebuf *p)
return grub_new_substring (p->buf, start, end); return grub_new_substring (p->buf, start, end);
} }
static grub_err_t
parse_proportional_spec (char *value, signed *abs, grub_fixed_signed_t *prop)
{
signed num;
char *ptr;
int sig = 0;
*abs = 0;
*prop = 0;
ptr = value;
while (*ptr)
{
sig = 0;
while (*ptr == '-' || *ptr == '+')
{
if (*ptr == '-')
sig = !sig;
ptr++;
}
num = grub_strtoul (ptr, &ptr, 0);
if (grub_errno)
return grub_errno;
if (sig)
num = -num;
if (*ptr == '%')
*prop += grub_fixed_fsf_divide (grub_signed_to_fixed (num), 100);
else
*abs += num;
}
return GRUB_ERR_NONE;
}
/* Read a GUI object specification from the theme file. /* Read a GUI object specification from the theme file.
Any components created will be added to the GUI container PARENT. */ Any components created will be added to the GUI container PARENT. */
static grub_err_t static grub_err_t
@ -511,78 +545,16 @@ read_object (struct parsebuf *p, grub_gui_container_t parent)
/* Handle the property value. */ /* Handle the property value. */
if (grub_strcmp (property, "left") == 0) if (grub_strcmp (property, "left") == 0)
{ parse_proportional_spec (value, &component->x, &component->xfrac);
unsigned num;
char *ptr;
num = grub_strtoul (value, &ptr, 0);
if (*ptr == '%')
{
component->isxfrac = 1;
component->xfrac
= grub_fixed_fuf_divide (grub_unsigned_to_fixed (num), 100);
}
else
{
component->isxfrac = 0;
component->x = num;
}
}
else if (grub_strcmp (property, "top") == 0) else if (grub_strcmp (property, "top") == 0)
{ parse_proportional_spec (value, &component->y, &component->yfrac);
unsigned num;
char *ptr;
num = grub_strtoul (value, &ptr, 0);
if (*ptr == '%')
{
component->isyfrac = 1;
component->yfrac
= grub_fixed_fuf_divide (grub_unsigned_to_fixed (num), 100);
}
else
{
component->isyfrac = 0;
component->y = num;
}
}
else if (grub_strcmp (property, "width") == 0) else if (grub_strcmp (property, "width") == 0)
{ parse_proportional_spec (value, &component->w, &component->wfrac);
unsigned num;
char *ptr;
num = grub_strtoul (value, &ptr, 0);
if (*ptr == '%')
{
component->iswfrac = 1;
component->wfrac
= grub_fixed_fuf_divide (grub_unsigned_to_fixed (num), 100);
}
else
{
component->iswfrac = 0;
component->w = num;
}
}
else if (grub_strcmp (property, "height") == 0) else if (grub_strcmp (property, "height") == 0)
{ parse_proportional_spec (value, &component->h, &component->hfrac);
unsigned num;
char *ptr;
num = grub_strtoul (value, &ptr, 0);
if (*ptr == '%')
{
component->ishfrac = 1;
component->hfrac
= grub_fixed_fuf_divide (grub_unsigned_to_fixed (num), 100);
}
else
{
component->ishfrac = 0;
component->h = num;
}
}
else else
{ /* General property handling. */
/* General property handling. */ component->ops->set_property (component, property, value);
component->ops->set_property (component, property, value);
}
grub_free (value); grub_free (value);
grub_free (property); grub_free (property);

View File

@ -75,62 +75,50 @@ struct grub_gui_list_ops
grub_gfxmenu_model_t menu); grub_gfxmenu_model_t menu);
}; };
typedef grub_uint32_t grub_fixed_unsigned_t; typedef signed grub_fixed_signed_t;
#define GRUB_FIXED_1 0x10000 #define GRUB_FIXED_1 0x10000
static inline unsigned static inline signed
grub_fixed_ufu_divide (grub_uint32_t a, grub_fixed_unsigned_t b) grub_fixed_sfs_divide (signed a, grub_fixed_signed_t b)
{ {
return (a << 16) / b; return (a * GRUB_FIXED_1) / b;
} }
static inline grub_fixed_unsigned_t static inline grub_fixed_signed_t
grub_fixed_fuf_divide (grub_fixed_unsigned_t a, grub_uint32_t b) grub_fixed_fsf_divide (grub_fixed_signed_t a, signed b)
{ {
return a / b; return a / b;
} }
static inline unsigned static inline signed
grub_fixed_ufu_multiply (grub_uint32_t a, grub_fixed_unsigned_t b) grub_fixed_sfs_multiply (signed a, grub_fixed_signed_t b)
{ {
return (a * b) >> 16; return (a * b) / GRUB_FIXED_1;
} }
static inline unsigned static inline signed
grub_fixed_to_unsigned (grub_fixed_unsigned_t in) grub_fixed_to_signed (grub_fixed_signed_t in)
{ {
return in >> 16; return in / GRUB_FIXED_1;
} }
static inline grub_fixed_unsigned_t static inline grub_fixed_signed_t
grub_unsigned_to_fixed (unsigned in) grub_signed_to_fixed (signed in)
{ {
return in << 16; return in * GRUB_FIXED_1;
} }
struct grub_gui_component struct grub_gui_component
{ {
struct grub_gui_component_ops *ops; struct grub_gui_component_ops *ops;
int isxfrac:1; signed x;
int isyfrac:1; grub_fixed_signed_t xfrac;
int iswfrac:1; signed y;
int ishfrac:1; grub_fixed_signed_t yfrac;
union { signed w;
unsigned x; grub_fixed_signed_t wfrac;
grub_fixed_unsigned_t xfrac; signed h;
}; grub_fixed_signed_t hfrac;
union {
unsigned y;
grub_fixed_unsigned_t yfrac;
};
union {
unsigned w;
grub_fixed_unsigned_t wfrac;
};
union {
unsigned h;
grub_fixed_unsigned_t hfrac;
};
}; };
struct grub_gui_container struct grub_gui_container