12 /*#define DEBUG_TIME_DRAW*/
14 static screen_t
*currentScreen
;
15 static screen_t
*futureScreen
;
17 static list_t
*listScreen
;
19 static bool_t isScreenInit
= FALSE
;
21 bool_t
screen_is_inicialized()
26 screen_t
*screen_new(char *name
, void (*fce_start
) (), void (*fce_event
) (),
27 void (*fce_draw
) (), void (*fce_stop
) ())
32 assert(fce_start
!= NULL
);
33 assert(fce_event
!= NULL
);
34 assert(fce_draw
!= NULL
);
35 assert(fce_stop
!= NULL
);
37 new = malloc(sizeof(screen_t
));
38 new->name
= strdup(name
);
39 new->fce_start
= fce_start
;
40 new->fce_event
= fce_event
;
41 new->fce_draw
= fce_draw
;
42 new->fce_stop
= fce_stop
;
47 void screen_destroy(screen_t
*p
)
55 void screen_register(screen_t
*p
)
59 debug("Registering screen [%s]", p
->name
);
61 list_add(listScreen
, p
);
66 listScreen
= list_new();
74 static screen_t
*findScreen(char *name
)
79 for (i
= 0; i
< listScreen
->count
; i
++) {
80 this = (screen_t
*) listScreen
->list
[i
];
83 if (strcmp(name
, this->name
) == 0) {
91 void screen_set(char *name
)
93 futureScreen
= findScreen(name
);
94 assert(futureScreen
!= NULL
);
99 if (futureScreen
== NULL
) {
105 if (currentScreen
!= NULL
) {
106 debug("Stopping screen [%s]", currentScreen
->name
);
107 currentScreen
->fce_stop();
110 currentScreen
= futureScreen
;
113 debug("Starting screen [%s]", currentScreen
->name
);
115 currentScreen
->fce_start();
118 void screen_start(char *name
)
126 assert(currentScreen
!= NULL
);
127 return currentScreen
->name
;
132 static int count
= 0;
139 assert(currentScreen
!= NULL
);
141 #ifdef DEBUG_TIME_DRAW
144 prev
= timer_get_current_timeMicro();
145 #endif /* DEBUG_TIME_DRAW */
147 currentScreen
->fce_draw();
151 #ifdef DEBUG_TIME_DRAW
152 printf("c draw time = %d\n", timer_get_current_timeMicro() - prev
);
153 #endif /* DEBUG_TIME_DRAW */
160 assert(currentScreen
!= NULL
);
162 currentScreen
->fce_event();
164 #ifdef DEBUG_TIME_EVENT
165 printf("c event time = %d\n", timer_get_current_timeMicro() - prev
);
166 #endif /* DEBUG_TIME_EVENT */
171 assert(listScreen
!= NULL
);
173 list_destroy_item(listScreen
, screen_destroy
);
174 isScreenInit
= FALSE
;