Mercurial > MadButterfly
changeset 294:2ca0773cd48d
* Add MBAF files
* Change begin_index to be start_index
* fix the color setting.
author | wycc |
---|---|
date | Sun, 01 Feb 2009 09:51:12 +0800 |
parents | a171b94582ae |
children | 2469f8d23658 |
files | include/mbapp.h include/mbbutton.h src/Makefile.am src/mbaf/mbapp.c src/mbaf/mbbutton.c src/shape_text.c |
diffstat | 6 files changed, 216 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/mbapp.h Sun Feb 01 09:51:12 2009 +0800 @@ -0,0 +1,19 @@ +#ifndef __APP_H +#define __APP_H +typedef struct _mbapp MBApp; +struct _mbapp { + void *rt; + redraw_man_t *rdman; + mb_sprite_t *rootsprite; + mb_obj_t *root; + void *private; +}; +MBApp *MBApp_Init(char *module); +void MBApp_setData(MBApp *app,void *data); +mb_tman_t *MBApp_getTimer(MBApp *app); +void MBApp_loop(MBApp *en); +#define MBAPP_DATA(app,type) ((type *) ((app)->private)) +#define MBAPP_RDMAN(app) (((MBApp *) app)->rdman) + +#include "mbbutton.h" +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/mbbutton.h Sun Feb 01 09:51:12 2009 +0800 @@ -0,0 +1,19 @@ +#ifndef __MBBUTTON_H +#define __MBBUTTON_H +typedef struct _mb_button { + mb_obj_t obj; + redraw_man_t *rdman; + int state; + coord_t *root; + coord_t *active; + coord_t *normal; + coord_t *click; + void (*press)(); + void *arg; + observer_t *obs_move,*obs_out,*obs_press; + mb_progm_t *progm; +} mb_button_t; +mb_button_t *mb_button_new(redraw_man_t *rdman,mb_sprite_t *sp, char *name); +void mb_button_add_onClick(mb_button_t *b, void (*h)(void *arg), void *arg); +#endif +
--- a/src/Makefile.am Sun Feb 01 02:34:24 2009 +0800 +++ b/src/Makefile.am Sun Feb 01 09:51:12 2009 +0800 @@ -3,12 +3,12 @@ lib_LTLIBRARIES = libmbfly.la noinst_PROGRAMS = X_main - +MBAF_SOURCES=mbaf/mbapp.c mbaf/mbbutton.c libmbfly_la_SOURCES = animate.c chgcolor.c coord.c event.c geo.c \ observer.c paint.c redraw_man.c rotate.c shape_path.c \ shape_rect.c shape_text.c shift.c subtree_free.c timer.c \ timertool.c tools.c visibility.c X_supp.c prop.c sprite.c \ - mouse.c shape_image.c img_ldr.c + mouse.c shape_image.c img_ldr.c $(MBAF_SOURCES) libmbfly_la_CPPFLAGS = @cairo_CFLAGS@ `pkg-config --cflags pangocairo` libmbfly_la_LDFLAGS = @cairo_LIBS@ `pkg-config --libs pangocairo`
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mbaf/mbapp.c Sun Feb 01 09:51:12 2009 +0800 @@ -0,0 +1,41 @@ +#include <mb.h> +#include <mbapp.h> +MBApp *MBApp_Init(char *module) +{ + MBApp *app = (MBApp *) malloc(sizeof(MBApp)); + X_MB_runtime_t *rt; + + rt = X_MB_new(":0.0", 800, 600); + + app->rt = rt; + app->rdman = X_MB_rdman(rt); + app->rootsprite= sprite_load(module,app->rdman, app->rdman->root_coord); + rdman_attach_backend(app->rdman, rt); + MB_SPRITE_GOTO_SCENE(app->rootsprite, 1); + return app; +} + +void MBApp_setData(MBApp *app,void *data) +{ + app->private = (void *) data; +} + +mb_tman_t *MBApp_getTimer(MBApp *app) +{ + return X_MB_tman(app->rt); +} + +void MBApp_loop(MBApp *en) +{ + /* + * Start handle connections, includes one to X server. + * User start to interact with the application. + */ + X_MB_handle_connection(en->rt); + + /* + * Clean + */ + X_MB_free(en->rt); + free(en); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mbaf/mbbutton.c Sun Feb 01 09:51:12 2009 +0800 @@ -0,0 +1,129 @@ + +#include <stdio.h> +#include <mb.h> +#include <string.h> +#include "mbapp.h" + + + +#define CMOUSE(e) (coord_get_mouse_event(e)) + + +static void mb_button_pressed(event_t *evt, void *arg); +static void mb_button_out(event_t *evt, void *arg); + +void mb_button_add_onClick(mb_button_t *b, void (*h)(void *arg), void *arg) +{ + b->press = h; + b->arg = arg; +} + +void mb_button_refresh(mb_button_t *btn) +{ + rdman_coord_changed(btn->rdman,btn->root); + rdman_redraw_changed(btn->rdman); +} + +static void mb_button_move(event_t *evt, void *arg) +{ + mb_button_t *btn = (mb_button_t *) arg; + + + printf("Mouse move\n"); + coord_show(btn->active); + mb_button_refresh(btn); +} +static void mb_button_out(event_t *evt, void *arg) +{ + mb_button_t *btn = (mb_button_t *) arg; + + if (btn->progm) { + mb_progm_abort(btn->progm); + btn->progm = NULL; + } + printf("mouse out\n"); + coord_hide(btn->click); + coord_hide(btn->active); + coord_show(btn->normal); + mb_button_refresh(btn); +} + +static void mb_button_show_active(event_t *evt, void *arg) +{ + mb_button_t *btn = (mb_button_t *) arg; + + coord_show(btn->active); + mb_button_refresh(btn); +} + +static void mb_button_pressed(event_t *evt, void *arg) +{ + mb_button_t *btn = (mb_button_t *) arg; + mb_timeval_t start, playing, now; + mb_progm_t *progm; + mb_word_t *word; + + printf("Pressed\n"); + if (btn->progm) { + mb_progm_abort(btn->progm); + btn->progm = NULL; + } + coord_show(btn->click); + coord_hide(btn->active); + rdman_coord_changed(btn->rdman,btn->root); + rdman_redraw_changed(btn->rdman); + + btn->progm = progm = mb_progm_new(1, btn->rdman); + MB_TIMEVAL_SET(&start, 0, 500000); + MB_TIMEVAL_SET(&playing, 0, 0); + word = mb_progm_next_word(progm, &start, &playing); + mb_visibility_new(VIS_HIDDEN, btn->click, word); + mb_visibility_new(VIS_VISIBLE, btn->active, word); + mb_progm_free_completed(progm); + get_now(&now); + printf("rt = %x\n", btn->rdman->rt); + mb_progm_start(progm, X_MB_tman(btn->rdman->rt), &now); + if (btn->press) + btn->press(btn->arg); +} +mb_button_t *mb_button_new(redraw_man_t *rdman,mb_sprite_t *sp, char *name) +{ + mb_button_t *btn = (mb_button_t *) malloc(sizeof(mb_button_t)); + char *buf = (char *) malloc(strlen(name)+5); + + btn->root = (coord_t *) MB_SPRITE_GET_OBJ(sp, name); + sprintf(buf, "%s_normal", name); + btn->normal = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf); + if (btn->normal == NULL) { + printf("Missing normal button, this is not a correct button\n"); + } + sprintf(buf, "%s_active", name); + btn->active = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf); + if (btn->active == NULL) { + printf("Missing click button, this is not a correct button\n"); + } + sprintf(buf, "%s_click", name); + btn->click = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf); + if (btn->active == NULL) { + printf("Missing click button, this is not a correct button\n"); + } + btn->press = NULL; + // Show only the normal button + coord_hide(btn->active); + coord_hide(btn->click); + coord_show(btn->normal); + // Move to the same position + btn->active->matrix[2] = 200; + btn->active->matrix[5] = 200; + btn->normal->matrix[2] = 200; + btn->normal->matrix[5] = 200; + btn->click->matrix[2] = 200; + btn->click->matrix[5] = 200; + btn->rdman = rdman; + btn->obs_move = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_MOVE, mb_button_move,btn); + btn->obs_press = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_BUT_PRESS, mb_button_pressed,btn); + btn->obs_out = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_OUT, mb_button_out,btn); + btn->progm = NULL; + rdman_redraw_changed(rdman); + return btn; +}
--- a/src/shape_text.c Sun Feb 01 02:34:24 2009 +0800 +++ b/src/shape_text.c Sun Feb 01 09:51:12 2009 +0800 @@ -83,9 +83,9 @@ void sh_text_set_color(shape_t *shape, unsigned int color) { - PangoAttribute *attr = pango_attr_color_new(color); + PangoAttribute *attr = pango_attr_foreground_new(TEXTCOLOR_RED(color)<<8,TEXTCOLOR_GREEN(color)<<8,TEXTCOLOR_BLUE(color)<<8); sh_text_t *text = (sh_text_t *)shape; - attr->begin_index = 0; + attr->start_index = 0; attr->end_index = -1; pango_attr_list_change(text->attrs, attr); } @@ -93,7 +93,7 @@ { PangoAttribute *attr = pango_attr_weight_new(bold? PANGO_WEIGHT_BOLD:PANGO_WEIGHT_NORMAL); sh_text_t *text = (sh_text_t *)shape; - attr->begin_index = 0; + attr->start_index = 0; attr->end_index = -1; pango_attr_list_change(text->attrs, attr); } @@ -101,7 +101,7 @@ { PangoAttribute *attr = pango_attr_style_new(italic? PANGO_STYLE_ITALIC:PANGO_STYLE_NORMAL); sh_text_t *text = (sh_text_t *)shape; - attr->begin_index = 0; + attr->start_index = 0; attr->end_index = -1; pango_attr_list_change(text->attrs, attr); } @@ -109,7 +109,7 @@ { PangoAttribute *attr = pango_attr_underline_new(underline? PANGO_UNDERLINE_SINGLE:PANGO_UNDERLINE_NONE); sh_text_t *text = (sh_text_t *)shape; - attr->begin_index = 0; + attr->start_index = 0; attr->end_index = -1; pango_attr_list_change(text->attrs, attr); } @@ -117,7 +117,7 @@ { PangoAttribute *attr = pango_attr_family_new(family); sh_text_t *text = (sh_text_t *)shape; - attr->begin_index = 0; + attr->start_index = 0; attr->end_index = -1; pango_attr_list_change(text->attrs, attr); }