remove important functions from main.c
authorDerek Foreman <foremande@gmail.com>
Thu, 20 May 2010 22:54:22 +0000 (18:54 -0400)
committerDerek Foreman <foremande@gmail.com>
Thu, 20 May 2010 22:54:22 +0000 (18:54 -0400)
Makefile
main.c
obtheme.c [new file with mode: 0644]
obtheme.h

index 29e9aa5..8b79f4e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,8 +12,8 @@ CFLAGS=-g -Wall -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include \
 
 all: obtheme
 
-obtheme: main.o obtheme.tab.o obtheme.lex.o obtheme.tab.h
-       $(CC) $(CFLAGS) -o obtheme main.o obtheme.tab.o obtheme.lex.o -lm -lglib-2.0
+obtheme: main.o obtheme.tab.o obtheme.lex.o obtheme.tab.h obtheme.o
+       $(CC) $(CFLAGS) -o obtheme main.o obtheme.o obtheme.tab.o obtheme.lex.o -lm -lglib-2.0
 
 clean:
        rm -f obtheme *.lex.* *.tab.* *.o obtheme.c
diff --git a/main.c b/main.c
index 3846dd8..438166c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -10,165 +10,6 @@ struct boundrect {
        double x2, y2;
 };
 
-double variable_lookup(struct variable *in)
-{
-       if (strcmp("client", in->base) == 0) {
-               if (strcmp("width", in->member) == 0) {
-                       return 640;
-               } else
-                       return 480;
-       }
-       if (strcmp("font", in->base) == 0) {
-               return 15.0;
-       }
-       return 0.0;
-}
-
-double expression_eval(struct expression *in)
-{
-       switch (in->op) {
-               case OB_THEME_INV:
-                       return - expression_eval(in->a);
-                       break;
-               case OB_THEME_MUL:
-                       return expression_eval(in->a) * expression_eval(in->b);
-                       break;
-               case OB_THEME_DIV:
-                       return expression_eval(in->a) / expression_eval(in->b);
-                       break;
-               case OB_THEME_ADD:
-                       return expression_eval(in->a) + expression_eval(in->b);
-                       break;
-               case OB_THEME_SUB:
-                       return expression_eval(in->a) - expression_eval(in->b);
-                       break;
-               case OB_THEME_EQL:
-                       if (in->v.base == NULL) {
-                               return in->v.number;
-                       } else return variable_lookup(&in->v);
-                       break;
-               default:
-                       assert(!!!"OH NOES!!!");
-       }
-       return 0;
-}
-
-static void decor_print(gpointer data, gpointer user_data)
-{
-       double out;
-       struct decor *decor = data;
-       printf("    decor id %s\n", decor->name);
-printf("   anchor.x = %f\n", expression_eval(&decor->space.anchor.x));
-       if (decor->texture.present) {
-               if (decor->texture.internal)
-                       printf("    texture internal: %s\n", decor->texture.name);
-               else
-                       printf("    texture file: %s\n", decor->texture.name);
-       }
-//     printf("      anchor (%d %d %d)\n", decor->space.anchor.x, decor->space.anchor.y, decor->space.anchor.z);
-//     printf("      up     (%d %d %d)\n", decor->space.up.x, decor->space.up.y, decor->space.up.z);
-       if (decor->children)
-               g_slist_foreach(decor->children, decor_print, NULL);
-}
-
-static void style_print(gpointer key, gpointer value, gpointer user_data)
-{
-       char *stylename = key;
-       struct style *style = value;
-
-       printf("  style %s\n", stylename);
-       g_slist_foreach(style->tree, decor_print, NULL);
-}
-
-static void theme_print(gpointer key, gpointer value, gpointer user_data)
-{
-       char *name = key;
-       struct theme *thm = value;
-       printf("name = %s\n", name);
-       g_hash_table_foreach(thm->styles, style_print, NULL);
-}
-
-static void material_print(gpointer key, gpointer value, gpointer user_data)
-{
-       char *name = key;
-       struct material *mat = value;
-       printf("name = %s\n", name);
-       printf(" opacity = %f\n", mat->opacity);
-}
-
-static void decor_render(gpointer data, gpointer user_data)
-{
-       struct decor *decor = data;
-       struct box *box = &decor->geometry.box;
-       struct vector *a = &decor->space.anchor;
-       double x, y;
-
-       printf("%s:", decor->name);
-       x = expression_eval(&a->x);
-       y = expression_eval(&a->y);
-       printf("rectangle(%f %f) - (%f %f)\n", x + expression_eval(&box->start.x), y + expression_eval(&box->start.y),
-                                   x + expression_eval(&box->end.x), y + expression_eval(&box->end.y));
-       if (decor->children)
-               g_slist_foreach(decor->children, decor_render, NULL);
-}
-
-static void decor_bound(gpointer data, gpointer user_data)
-{
-       struct boundrect *br = user_data;
-       struct decor *decor = data;
-       struct box *box = &decor->geometry.box;
-       struct vector *a = &decor->space.anchor;
-       double x1, y1, x2, y2;
-       x1 = expression_eval(&a->x);
-       y1 = expression_eval(&a->y);
-       x2 = x1;
-       y2 = y1;
-       x1 += expression_eval(&box->start.x);
-       y1 += expression_eval(&box->start.y);
-       x2 += expression_eval(&box->end.x);
-       y2 += expression_eval(&box->end.y);
-       if (x1 < br->x1)
-               br->x1 = x1;
-       if (x2 < br->x1)
-               br->x1 = x2;
-       if (x1 > br->x2)
-               br->x2 = x1;
-       if (x2 > br->x2)
-               br->x2 = x2;
-
-       if (y1 < br->y1)
-               br->y1 = y1;
-       if (y2 < br->y1)
-               br->y1 = y2;
-       if (y1 > br->y2)
-               br->y2 = y1;
-       if (y2 > br->y2)
-               br->y2 = y2;
-printf("%f %f %f %f\n", br->x1, br->y1, br->x2, br->y2);
-       if (decor->children)
-               g_slist_foreach(decor->children, decor_bound, br);
-}
-
-void bound(struct theme *thm, char *name, struct boundrect *br)
-{
-       struct style *sty;
-
-       br->x1 = 0.0;
-       br->y1 = 0.0;
-       br->x2 = 0.0;
-       br->y2 = 0.0;
-       sty = g_hash_table_lookup(thm->styles, name);
-       assert(sty);
-       g_slist_foreach(sty->tree, decor_bound, br);
-}
-
-void draw(struct theme *thm, char *name)
-{
-       struct style *sty;
-       sty = g_hash_table_lookup(thm->styles, name);
-       g_slist_foreach(sty->tree, decor_render, NULL);
-}
-
 int main(int argc, char **argv)
 {
        int err;
@@ -188,8 +29,8 @@ int main(int argc, char **argv)
 //     g_hash_table_foreach(themedata.themes, theme_print, NULL);
 
        thm = g_hash_table_lookup(themedata.themes, "awesome");
-       draw(thm, "regular_window");
-       bound(thm, "regular_window", &br);
+       obtheme_decorate_window(thm, "regular_window");
+       obtheme_calc_bound(thm, "regular_window", &br);
        printf("bounding rectangle: (%f %f) - (%f %f)\n", br.x1, br.y1, br.x2, br.y2);
 
        return 0;
diff --git a/obtheme.c b/obtheme.c
new file mode 100644 (file)
index 0000000..56734a0
--- /dev/null
+++ b/obtheme.c
@@ -0,0 +1,165 @@
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+#include "obtheme.h"
+#include "geom.h"
+
+static double variable_lookup(struct variable *in)
+{
+       if (strcmp("client", in->base) == 0) {
+               if (strcmp("width", in->member) == 0) {
+                       return 640;
+               } else
+                       return 480;
+       }
+       if (strcmp("font", in->base) == 0) {
+               return 15.0;
+       }
+       return 0.0;
+}
+
+static double expression_eval(struct expression *in)
+{
+       switch (in->op) {
+               case OB_THEME_INV:
+                       return - expression_eval(in->a);
+                       break;
+               case OB_THEME_MUL:
+                       return expression_eval(in->a) * expression_eval(in->b);
+                       break;
+               case OB_THEME_DIV:
+                       return expression_eval(in->a) / expression_eval(in->b);
+                       break;
+               case OB_THEME_ADD:
+                       return expression_eval(in->a) + expression_eval(in->b);
+                       break;
+               case OB_THEME_SUB:
+                       return expression_eval(in->a) - expression_eval(in->b);
+                       break;
+               case OB_THEME_EQL:
+                       if (in->v.base == NULL) {
+                               return in->v.number;
+                       } else return variable_lookup(&in->v);
+                       break;
+               default:
+                       assert(!!!"OH NOES!!!");
+       }
+       return 0;
+}
+
+static void decor_print(gpointer data, gpointer user_data)
+{
+       struct decor *decor = data;
+       printf("    decor id %s\n", decor->name);
+printf("   anchor.x = %f\n", expression_eval(&decor->space.anchor.x));
+       if (decor->texture.present) {
+               if (decor->texture.internal)
+                       printf("    texture internal: %s\n", decor->texture.name);
+               else
+                       printf("    texture file: %s\n", decor->texture.name);
+       }
+//     printf("      anchor (%d %d %d)\n", decor->space.anchor.x, decor->space.anchor.y, decor->space.anchor.z);
+//     printf("      up     (%d %d %d)\n", decor->space.up.x, decor->space.up.y, decor->space.up.z);
+       if (decor->children)
+               g_slist_foreach(decor->children, decor_print, NULL);
+}
+
+static void style_print(gpointer key, gpointer value, gpointer user_data)
+{
+       char *stylename = key;
+       struct style *style = value;
+
+       printf("  style %s\n", stylename);
+       g_slist_foreach(style->tree, decor_print, NULL);
+}
+
+static void theme_print(gpointer key, gpointer value, gpointer user_data)
+{
+       char *name = key;
+       struct theme *thm = value;
+       printf("name = %s\n", name);
+       g_hash_table_foreach(thm->styles, style_print, NULL);
+}
+
+static void material_print(gpointer key, gpointer value, gpointer user_data)
+{
+       char *name = key;
+       struct material *mat = value;
+       printf("name = %s\n", name);
+       printf(" opacity = %f\n", mat->opacity);
+}
+
+static void decor_render(gpointer data, gpointer user_data)
+{
+       struct decor *decor = data;
+       struct box *box = &decor->geometry.box;
+       struct vector *a = &decor->space.anchor;
+       double x, y;
+
+       printf("%s:", decor->name);
+       x = expression_eval(&a->x);
+       y = expression_eval(&a->y);
+       printf("rectangle(%f %f) - (%f %f)\n", x + expression_eval(&box->start.x), y + expression_eval(&box->start.y),
+                                   x + expression_eval(&box->end.x), y + expression_eval(&box->end.y));
+       if (decor->children)
+               g_slist_foreach(decor->children, decor_render, NULL);
+}
+
+static void decor_bound(gpointer data, gpointer user_data)
+{
+       struct boundrect *br = user_data;
+       struct decor *decor = data;
+       struct box *box = &decor->geometry.box;
+       struct vector *a = &decor->space.anchor;
+       Rect newrect;
+       double x1, y1, x2, y2;
+
+       x1 = expression_eval(&a->x);
+       y1 = expression_eval(&a->y);
+       x2 = x1;
+       y2 = y1;
+       x1 += expression_eval(&box->start.x);
+       y1 += expression_eval(&box->start.y);
+       x2 += expression_eval(&box->end.x);
+       y2 += expression_eval(&box->end.y);
+       if (x1 < br->x1)
+               br->x1 = x1;
+       if (x2 < br->x1)
+               br->x1 = x2;
+       if (x1 > br->x2)
+               br->x2 = x1;
+       if (x2 > br->x2)
+               br->x2 = x2;
+
+       if (y1 < br->y1)
+               br->y1 = y1;
+       if (y2 < br->y1)
+               br->y1 = y2;
+       if (y1 > br->y2)
+               br->y2 = y1;
+       if (y2 > br->y2)
+               br->y2 = y2;
+       if (decor->children)
+               g_slist_foreach(decor->children, decor_bound, br);
+}
+
+void obtheme_calc_bound(struct theme *thm, char *name, struct boundrect *br)
+{
+       struct style *sty;
+
+       br->x1 = 0.0;
+       br->y1 = 0.0;
+       br->x2 = 0.0;
+       br->y2 = 0.0;
+       sty = g_hash_table_lookup(thm->styles, name);
+       assert(sty);
+       g_slist_foreach(sty->tree, decor_bound, br);
+}
+
+void obtheme_decorate_window(struct theme *thm, char *name)
+{
+       struct style *sty;
+       sty = g_hash_table_lookup(thm->styles, name);
+       g_slist_foreach(sty->tree, decor_render, NULL);
+}
index c9aaa51..63c52a6 100644 (file)
--- a/obtheme.h
+++ b/obtheme.h
 
 extern int themedebug;
 
+struct boundrect {
+       double x1, y1, x2, y2;
+};
+
 typedef enum {
        OB_THEME_INV,
        OB_THEME_ADD,
@@ -108,5 +112,7 @@ int obtheme_parse(struct obthemedata *td, const char *filename);
 struct parser_control *parser_init(struct obthemedata *td);
 int obthemeparse(struct parser_control *);
 void parser_finish(struct parser_control *);
+void obtheme_calc_bound(struct theme *thm, char *name, struct boundrect *br);
+void obtheme_decorate_window(struct theme *thm, char *name);
 
 #endif /* __THEME_PARSE_H__ */