test % operator

2002-02-02  Havoc Pennington  <hp@pobox.com>

	* src/theme-viewer.c: test % operator

	* src/theme.c (pos_tokenize): add % to switch for operators

	* src/theme.c: rework theme stuff so we have
	MetaDrawOp/MetaDrawOpList instead of MetaTextureSpec/MetaShapeSpec
This commit is contained in:
Havoc Pennington 2002-02-02 05:09:19 +00:00 committed by Havoc Pennington
parent add8c23c13
commit 089eb7e6de
4 changed files with 1596 additions and 1910 deletions

View File

@ -1,3 +1,12 @@
2002-02-02 Havoc Pennington <hp@pobox.com>
* src/theme-viewer.c: test % operator
* src/theme.c (pos_tokenize): add % to switch for operators
* src/theme.c: rework theme stuff so we have
MetaDrawOp/MetaDrawOpList instead of MetaTextureSpec/MetaShapeSpec
2002-01-28 Havoc Pennington <hp@pobox.com> 2002-01-28 Havoc Pennington <hp@pobox.com>
* src/theme.c (meta_texture_spec_render): fix shadowed variable * src/theme.c (meta_texture_spec_render): fix shadowed variable

View File

@ -186,6 +186,8 @@ static const PositionExpressionTest position_expression_tests[] = {
"14 - 10", 14, 24, NO_ERROR }, "14 - 10", 14, 24, NO_ERROR },
{ { 10, 20, 40, 50 }, { { 10, 20, 40, 50 },
"8 / 2", 14, 24, NO_ERROR }, "8 / 2", 14, 24, NO_ERROR },
{ { 10, 20, 40, 50 },
"8 % 3", 12, 22, NO_ERROR },
/* Binary expressions with floats and mixed float/ints */ /* Binary expressions with floats and mixed float/ints */
{ { 10, 20, 40, 50 }, { { 10, 20, 40, 50 },
"7.0 / 3.5", 12, 22, NO_ERROR }, "7.0 / 3.5", 12, 22, NO_ERROR },
@ -293,6 +295,10 @@ static const PositionExpressionTest position_expression_tests[] = {
"2 *", 0, 0, META_POSITION_EXPR_ERROR_FAILED }, "2 *", 0, 0, META_POSITION_EXPR_ERROR_FAILED },
{ { 10, 20, 40, 50 }, { { 10, 20, 40, 50 },
"- width", 0, 0, META_POSITION_EXPR_ERROR_FAILED }, "- width", 0, 0, META_POSITION_EXPR_ERROR_FAILED },
{ { 10, 20, 40, 50 },
"5 % 1.0", 0, 0, META_POSITION_EXPR_ERROR_MOD_ON_FLOAT },
{ { 10, 20, 40, 50 },
"1.0 % 5", 0, 0, META_POSITION_EXPR_ERROR_MOD_ON_FLOAT },
{ { 10, 20, 40, 50 }, { { 10, 20, 40, 50 },
"! * 2", 0, 0, META_POSITION_EXPR_ERROR_BAD_CHARACTER }, "! * 2", 0, 0, META_POSITION_EXPR_ERROR_BAD_CHARACTER },
{ { 10, 20, 40, 50 }, { { 10, 20, 40, 50 },
@ -313,6 +319,7 @@ static void
run_position_expression_tests (void) run_position_expression_tests (void)
{ {
int i; int i;
MetaPositionExprEnv env;
i = 0; i = 0;
while (i < G_N_ELEMENTS (position_expression_tests)) while (i < G_N_ELEMENTS (position_expression_tests))
@ -330,11 +337,15 @@ run_position_expression_tests (void)
err = NULL; err = NULL;
env.x = test->rect.x;
env.y = test->rect.y;
env.width = test->rect.width;
env.height = test->rect.height;
env.object_width = -1;
env.object_height = -1;
retval = meta_parse_position_expression (test->expr, retval = meta_parse_position_expression (test->expr,
test->rect.x, &env,
test->rect.y,
test->rect.width,
test->rect.height,
&x, &y, &x, &y,
&err); &err);
@ -377,6 +388,7 @@ run_position_expression_timings (void)
int iters; int iters;
clock_t start; clock_t start;
clock_t end; clock_t end;
MetaPositionExprEnv env;
#define ITERATIONS 100000 #define ITERATIONS 100000
@ -391,11 +403,15 @@ run_position_expression_timings (void)
test = &position_expression_tests[i]; test = &position_expression_tests[i];
env.x = test->rect.x;
env.y = test->rect.y;
env.width = test->rect.width;
env.height = test->rect.height;
env.object_width = -1;
env.object_height = -1;
meta_parse_position_expression (test->expr, meta_parse_position_expression (test->expr,
test->rect.x, &env,
test->rect.y,
test->rect.width,
test->rect.height,
&x, &y, NULL); &x, &y, NULL);
++iters; ++iters;

File diff suppressed because it is too large Load Diff

View File

@ -28,21 +28,22 @@
typedef struct _MetaFrameStyle MetaFrameStyle; typedef struct _MetaFrameStyle MetaFrameStyle;
typedef struct _MetaFrameStyleSet MetaFrameStyleSet; typedef struct _MetaFrameStyleSet MetaFrameStyleSet;
typedef struct _MetaTextureSpec MetaTextureSpec; typedef struct _MetaDrawOp MetaDrawOp;
typedef struct _MetaDrawOpList MetaDrawOpList;
typedef struct _MetaGradientSpec MetaGradientSpec; typedef struct _MetaGradientSpec MetaGradientSpec;
typedef struct _MetaColorSpec MetaColorSpec; typedef struct _MetaColorSpec MetaColorSpec;
typedef struct _MetaShapeSpec MetaShapeSpec;
typedef struct _MetaFrameLayout MetaFrameLayout; typedef struct _MetaFrameLayout MetaFrameLayout;
typedef struct _MetaFrameGeometry MetaFrameGeometry; typedef struct _MetaFrameGeometry MetaFrameGeometry;
typedef struct _MetaTheme MetaTheme; typedef struct _MetaTheme MetaTheme;
typedef struct _MetaPositionExprEnv MetaPositionExprEnv;
typedef enum typedef enum
{ {
META_TEXTURE_DRAW_UNSCALED, META_SCALE_NONE,
META_TEXTURE_DRAW_SCALED_VERTICALLY, META_SCALE_VERTICALLY,
META_TEXTURE_DRAW_SCALED_HORIZONTALLY, META_SCALE_HORIZONTALLY,
META_TEXTURE_DRAW_SCALED_BOTH META_SCALE_BOTH
} MetaTextureDrawMode; } MetaScaleMode;
/* Parameters used to calculate the geometry of the frame */ /* Parameters used to calculate the geometry of the frame */
struct _MetaFrameLayout struct _MetaFrameLayout
@ -147,25 +148,33 @@ struct _MetaColorSpec
} data; } data;
}; };
struct _MetaGradientSpec
{
MetaGradientType type;
GSList *color_specs;
};
typedef enum typedef enum
{ {
/* Basic drawing */ /* Basic drawing */
META_SHAPE_LINE, META_DRAW_LINE,
META_SHAPE_RECTANGLE, META_DRAW_RECTANGLE,
META_SHAPE_ARC, META_DRAW_ARC,
/* Texture in a specific rectangle */ /* Texture thingies */
META_SHAPE_TEXTURE, META_DRAW_TINT, /* just a filled rectangle with alpha */
META_DRAW_GRADIENT,
META_DRAW_IMAGE,
/* GTK theme engine stuff */ /* GTK theme engine stuff */
META_SHAPE_GTK_ARROW, META_DRAW_GTK_ARROW,
META_SHAPE_GTK_BOX, META_DRAW_GTK_BOX,
META_SHAPE_GTK_VLINE META_DRAW_GTK_VLINE
} MetaShapeType; } MetaDrawType;
struct _MetaShapeSpec struct _MetaDrawOp
{ {
MetaShapeType type; MetaDrawType type;
/* Positions are strings because they can be expressions */ /* Positions are strings because they can be expressions */
union union
@ -202,15 +211,32 @@ struct _MetaShapeSpec
} arc; } arc;
struct { struct {
MetaTextureSpec *texture_spec; MetaColorSpec *color_spec;
MetaTextureDrawMode mode; double alpha;
double xalign;
double yalign;
char *x; char *x;
char *y; char *y;
char *width; char *width;
char *height; char *height;
} texture; } tint;
struct {
MetaGradientSpec *gradient_spec;
double alpha;
char *x;
char *y;
char *width;
char *height;
} gradient;
struct {
GdkPixbuf *pixbuf;
double alpha;
MetaScaleMode scale_mode;
char *x;
char *y;
char *width;
char *height;
} image;
struct { struct {
GtkStateType state; GtkStateType state;
@ -242,50 +268,12 @@ struct _MetaShapeSpec
} data; } data;
}; };
struct _MetaGradientSpec struct _MetaDrawOpList
{ {
MetaGradientType type; int refcount;
GSList *color_specs; MetaDrawOp **ops;
}; int n_ops;
int n_allocated;
typedef enum
{
META_TEXTURE_SOLID,
META_TEXTURE_GRADIENT,
META_TEXTURE_IMAGE,
META_TEXTURE_COMPOSITE,
META_TEXTURE_BLANK,
META_TEXTURE_SHAPE_LIST
} MetaTextureType;
struct _MetaTextureSpec
{
MetaTextureType type;
union
{
struct {
MetaColorSpec *color_spec;
} solid;
struct {
MetaGradientSpec *gradient_spec;
} gradient;
struct {
GdkPixbuf *pixbuf;
} image;
struct {
MetaTextureSpec *background;
MetaTextureSpec *foreground;
double alpha;
} composite;
struct {
int dummy;
} blank;
struct {
MetaShapeSpec **shape_specs;
int n_specs;
} shape_list;
} data;
}; };
typedef enum typedef enum
@ -320,58 +308,30 @@ typedef enum
* *
*/ */
/* place over entire frame, scaled both */ /* entire frame */
META_FRAME_PIECE_ENTIRE_BACKGROUND, META_FRAME_PIECE_ENTIRE_BACKGROUND,
/* place over entire titlebar background, scaled both */ /* entire titlebar background */
META_FRAME_PIECE_TITLEBAR_BACKGROUND, META_FRAME_PIECE_TITLEBAR_BACKGROUND,
/* place on left end of titlebar, scaled vert */ /* portion of the titlebar background inside the titlebar
* background edges
*/
META_FRAME_PIECE_TITLEBAR_MIDDLE,
/* left end of titlebar */
META_FRAME_PIECE_LEFT_TITLEBAR_EDGE, META_FRAME_PIECE_LEFT_TITLEBAR_EDGE,
/* place on right end of titlebar, scaled vert */ /* right end of titlebar */
META_FRAME_PIECE_RIGHT_TITLEBAR_EDGE, META_FRAME_PIECE_RIGHT_TITLEBAR_EDGE,
/* place on top edge of titlebar, scaled horiz */ /* top edge of titlebar */
META_FRAME_PIECE_TOP_TITLEBAR_EDGE, META_FRAME_PIECE_TOP_TITLEBAR_EDGE,
/* place on bottom edge of titlebar, scaled horiz */ /* bottom edge of titlebar */
META_FRAME_PIECE_BOTTOM_TITLEBAR_EDGE, META_FRAME_PIECE_BOTTOM_TITLEBAR_EDGE,
/* place on left end of top edge of titlebar, unscaled */ /* render over title background (text area) */
META_FRAME_PIECE_LEFT_END_OF_TOP_TITLEBAR_EDGE,
/* place on right end of top edge of titlebar, unscaled */
META_FRAME_PIECE_RIGHT_END_OF_TOP_TITLEBAR_EDGE,
/* place on left end of bottom edge of titlebar, unscaled */
META_FRAME_PIECE_LEFT_END_OF_BOTTOM_TITLEBAR_EDGE,
/* place on right end of bottom edge of titlebar, unscaled */
META_FRAME_PIECE_RIGHT_END_OF_BOTTOM_TITLEBAR_EDGE,
/* place on top end of left titlebar edge, unscaled */
META_FRAME_PIECE_TOP_END_OF_LEFT_TITLEBAR_EDGE,
/* place on bottom end of left titlebar edge, unscaled */
META_FRAME_PIECE_BOTTOM_END_OF_LEFT_TITLEBAR_EDGE,
/* place on top end of right titlebar edge, unscaled */
META_FRAME_PIECE_TOP_END_OF_RIGHT_TITLEBAR_EDGE,
/* place on bottom end of right titlebar edge, unscaled */
META_FRAME_PIECE_BOTTOM_END_OF_RIGHT_TITLEBAR_EDGE,
/* render over title background (text area), scaled both */
META_FRAME_PIECE_TITLE_BACKGROUND, META_FRAME_PIECE_TITLE_BACKGROUND,
/* render over left side of TITLE_BACKGROUND, scaled vert */ /* left edge of the frame */
META_FRAME_PIECE_LEFT_TITLE_BACKGROUND,
/* render over right side of TITLE_BACKGROUND, scaled vert */
META_FRAME_PIECE_RIGHT_TITLE_BACKGROUND,
/* place on left edge of the frame, scaled vert */
META_FRAME_PIECE_LEFT_EDGE, META_FRAME_PIECE_LEFT_EDGE,
/* place on right edge of the frame, scaled vert */ /* right edge of the frame */
META_FRAME_PIECE_RIGHT_EDGE, META_FRAME_PIECE_RIGHT_EDGE,
/* place on bottom edge of the frame, scaled horiz */ /* bottom edge of the frame */
META_FRAME_PIECE_BOTTOM_EDGE, META_FRAME_PIECE_BOTTOM_EDGE,
/* place on top end of left edge of the frame, unscaled */
META_FRAME_PIECE_TOP_END_OF_LEFT_EDGE,
/* place on bottom end of left edge of the frame, unscaled */
META_FRAME_PIECE_BOTTOM_END_OF_LEFT_EDGE,
/* place on top end of right edge of the frame, unscaled */
META_FRAME_PIECE_TOP_END_OF_RIGHT_EDGE,
/* place on bottom end of right edge of the frame, unscaled */
META_FRAME_PIECE_BOTTOM_END_OF_RIGHT_EDGE,
/* place on left end of bottom edge of the frame, unscaled */
META_FRAME_PIECE_LEFT_END_OF_BOTTOM_EDGE,
/* place on right end of bottom edge of the frame, unscaled */
META_FRAME_PIECE_RIGHT_END_OF_BOTTOM_EDGE,
/* place over entire frame, after drawing everything else */ /* place over entire frame, after drawing everything else */
META_FRAME_PIECE_OVERLAY, META_FRAME_PIECE_OVERLAY,
/* Used to get size of the enum */ /* Used to get size of the enum */
@ -382,9 +342,9 @@ struct _MetaFrameStyle
{ {
int refcount; int refcount;
MetaFrameStyle *parent; MetaFrameStyle *parent;
MetaTextureSpec *button_icons[META_BUTTON_TYPE_LAST][META_BUTTON_STATE_LAST]; MetaDrawOpList *button_icons[META_BUTTON_TYPE_LAST][META_BUTTON_STATE_LAST];
MetaTextureSpec *button_backgrounds[META_BUTTON_TYPE_LAST][META_BUTTON_STATE_LAST]; MetaDrawOpList *button_backgrounds[META_BUTTON_TYPE_LAST][META_BUTTON_STATE_LAST];
MetaTextureSpec *pieces[META_FRAME_PIECE_LAST]; MetaDrawOpList *pieces[META_FRAME_PIECE_LAST];
MetaFrameLayout *layout; MetaFrameLayout *layout;
}; };
@ -449,6 +409,28 @@ struct _MetaTheme
MetaFrameStyleSet *style_sets_by_type[META_FRAME_TYPE_LAST]; MetaFrameStyleSet *style_sets_by_type[META_FRAME_TYPE_LAST];
}; };
#define META_POSITION_EXPR_ERROR (g_quark_from_static_string ("meta-position-expr-error"))
typedef enum
{
META_POSITION_EXPR_ERROR_BAD_CHARACTER,
META_POSITION_EXPR_ERROR_BAD_PARENS,
META_POSITION_EXPR_ERROR_UNKNOWN_VARIABLE,
META_POSITION_EXPR_ERROR_DIVIDE_BY_ZERO,
META_POSITION_EXPR_ERROR_MOD_ON_FLOAT,
META_POSITION_EXPR_ERROR_FAILED
} MetaPositionExprError;
struct _MetaPositionExprEnv
{
int x;
int y;
int width;
int height;
/* size of an image or whatever */
int object_width;
int object_height;
};
MetaFrameLayout* meta_frame_layout_new (void); MetaFrameLayout* meta_frame_layout_new (void);
void meta_frame_layout_free (MetaFrameLayout *layout); void meta_frame_layout_free (MetaFrameLayout *layout);
void meta_frame_layout_get_borders (const MetaFrameLayout *layout, void meta_frame_layout_get_borders (const MetaFrameLayout *layout,
@ -467,31 +449,15 @@ void meta_frame_layout_calc_geometry (const MetaFrameLayout *layout,
int client_height, int client_height,
MetaFrameGeometry *fgeom); MetaFrameGeometry *fgeom);
#define META_POSITION_EXPR_ERROR (g_quark_from_static_string ("meta-position-expr-error")) gboolean meta_parse_position_expression (const char *expr,
typedef enum const MetaPositionExprEnv *env,
{ int *x_return,
META_POSITION_EXPR_ERROR_BAD_CHARACTER, int *y_return,
META_POSITION_EXPR_ERROR_BAD_PARENS, GError **err);
META_POSITION_EXPR_ERROR_UNKNOWN_VARIABLE, gboolean meta_parse_size_expression (const char *expr,
META_POSITION_EXPR_ERROR_DIVIDE_BY_ZERO, const MetaPositionExprEnv *env,
META_POSITION_EXPR_ERROR_MOD_ON_FLOAT, int *val_return,
META_POSITION_EXPR_ERROR_FAILED GError **err);
} MetaPositionExprError;
gboolean meta_parse_position_expression (const char *expr,
int x,
int y,
int width,
int height,
int *x_return,
int *y_return,
GError **err);
gboolean meta_parse_size_expression (const char *expr,
int width,
int height,
int *val_return,
GError **err);
MetaColorSpec* meta_color_spec_new (MetaColorSpecType type); MetaColorSpec* meta_color_spec_new (MetaColorSpecType type);
MetaColorSpec* meta_color_spec_new_from_string (const char *str, MetaColorSpec* meta_color_spec_new_from_string (const char *str,
@ -504,22 +470,32 @@ void meta_color_spec_render (MetaColorSpec *spec,
GdkColor *color); GdkColor *color);
MetaShapeSpec* meta_shape_spec_new (MetaShapeType type); MetaDrawOp* meta_draw_op_new (MetaDrawType type);
void meta_shape_spec_free (MetaShapeSpec *spec); void meta_draw_op_free (MetaDrawOp *op);
void meta_shape_spec_draw (const MetaShapeSpec *spec, void meta_draw_op_draw (const MetaDrawOp *op,
GtkWidget *widget, GtkWidget *widget,
GdkDrawable *drawable, GdkDrawable *drawable,
const GdkRectangle *clip, const GdkRectangle *clip,
/* logical region being drawn, /* logical region being drawn */
* shape coords are offset by int x,
* x,y and w/h variables are int y,
* available in shape coord int width,
* expressions. int height);
*/
int x,
int y, MetaDrawOpList* meta_draw_op_list_new (int n_preallocs);
int width, void meta_draw_op_list_ref (MetaDrawOpList *op_list);
int height); void meta_draw_op_list_unref (MetaDrawOpList *op_list);
void meta_draw_op_list_draw (const MetaDrawOpList *op_list,
GtkWidget *widget,
GdkDrawable *drawable,
const GdkRectangle *clip,
int x,
int y,
int width,
int height);
void meta_draw_op_list_append (MetaDrawOpList *op_list,
MetaDrawOp *op);
MetaGradientSpec* meta_gradient_spec_new (MetaGradientType type); MetaGradientSpec* meta_gradient_spec_new (MetaGradientType type);
void meta_gradient_spec_free (MetaGradientSpec *desc); void meta_gradient_spec_free (MetaGradientSpec *desc);
@ -528,26 +504,6 @@ GdkPixbuf* meta_gradient_spec_render (const MetaGradientSpec *desc,
int width, int width,
int height); int height);
MetaTextureSpec* meta_texture_spec_new (MetaTextureType type);
void meta_texture_spec_free (MetaTextureSpec *desc);
void meta_texture_spec_draw (const MetaTextureSpec *desc,
GtkWidget *widget,
GdkDrawable *drawable,
const GdkRectangle *clip,
MetaTextureDrawMode mode,
/* How to align a texture
* smaller than the given area
*/
double xalign,
double yalign,
/* logical region being drawn,
* scale to this area if in SCALED
* mode
*/
int x,
int y,
int width,
int height);
MetaFrameStyle* meta_frame_style_new (MetaFrameStyle *parent); MetaFrameStyle* meta_frame_style_new (MetaFrameStyle *parent);
void meta_frame_style_ref (MetaFrameStyle *style); void meta_frame_style_ref (MetaFrameStyle *style);