Optimized menu drawing code. Now the code
- is about 40 bytes shorter (with cc65)
- avoids gotoxy'ing past the screen width
diff --git a/contiki/ctk/ctk-conio-service.c b/contiki/ctk/ctk-conio-service.c
index 19b112d..f9a5e87 100644
--- a/contiki/ctk/ctk-conio-service.c
+++ b/contiki/ctk/ctk-conio-service.c
@@ -29,7 +29,7 @@
*
* This file is part of the "ctk" console GUI toolkit for cc65
*
- * $Id: ctk-conio-service.c,v 1.4 2004/12/27 22:03:04 oliverschmidt Exp $
+ * $Id: ctk-conio-service.c,v 1.5 2005/03/15 14:19:40 oliverschmidt Exp $
*
*/
@@ -289,6 +289,7 @@
}
h = window->y + 2 + window->h;
+
/* Clear window contents. */
for(i = window->y + 2; i < h; ++i) {
if(i >= clipy1 && i < clipy2) {
@@ -410,15 +411,12 @@
x = dialog->x;
y = dialog->y + 1;
-
x1 = x + 1;
y1 = y + 1;
x2 = x1 + dialog->w;
y2 = y1 + dialog->h;
-
/* Draw dialog frame. */
-
cvlinexy(x, y1,
dialog->h);
cvlinexy(x2, y1,
@@ -434,7 +432,6 @@
cputcxy(x2, y, CH_URCORNER);
cputcxy(x2, y2, CH_LRCORNER);
-
/* Clear dialog contents. */
for(i = y1; i < y2; ++i) {
cclearxy(x1, i, dialog->w);
@@ -456,40 +453,42 @@
}
/*-----------------------------------------------------------------------------------*/
static void
-draw_menu(struct ctk_menu *m)
+draw_menu(struct ctk_menu *m, unsigned char open)
{
unsigned char x, x2, y;
- textcolor(OPENMENUCOLOR);
- revers(0);
- x = wherex();
+
+ if(open) {
+ x = x2 = wherex();
+ if(x2 + CTK_CONF_MENUWIDTH > sizex) {
+ x2 = sizex - CTK_CONF_MENUWIDTH;
+ }
+
+ for(y = 0; y < m->nitems; ++y) {
+ if(y == m->active) {
+ textcolor(ACTIVEMENUITEMCOLOR);
+ revers(0);
+ } else {
+ textcolor(MENUCOLOR);
+ revers(1);
+ }
+ gotoxy(x2, y + 1);
+ if(m->items[y].title[0] == '-') {
+ chline(CTK_CONF_MENUWIDTH);
+ } else {
+ cputs(m->items[y].title);
+ }
+ if(x2 + CTK_CONF_MENUWIDTH > wherex()) {
+ cclear(x2 + CTK_CONF_MENUWIDTH - wherex());
+ }
+ }
+
+ gotoxy(x, 0);
+ textcolor(OPENMENUCOLOR);
+ revers(0);
+ }
+
cputs(m->title);
cputc(' ');
- x2 = wherex();
- if(x + CTK_CONF_MENUWIDTH > sizex) {
- x = sizex - CTK_CONF_MENUWIDTH;
- }
-
-
- for(y = 0; y < m->nitems; ++y) {
- if(y == m->active) {
- textcolor(ACTIVEMENUITEMCOLOR);
- revers(0);
- } else {
- textcolor(MENUCOLOR);
- revers(1);
- }
- gotoxy(x, y + 1);
- if(m->items[y].title[0] == '-') {
- chline(CTK_CONF_MENUWIDTH);
- } else {
- cputs(m->items[y].title);
- }
- if(x + CTK_CONF_MENUWIDTH > wherex()) {
- cclear(x + CTK_CONF_MENUWIDTH - wherex());
- }
-
- }
- gotoxy(x2, 0);
textcolor(MENUCOLOR);
revers(1);
}
@@ -497,7 +496,7 @@
static void
s_ctk_draw_menus(struct ctk_menus *menus)
{
- struct ctk_menu *m;
+ struct ctk_menu *m;
/* Draw menus */
textcolor(MENUCOLOR);
@@ -505,29 +504,17 @@
revers(1);
cputc(' ');
for(m = menus->menus->next; m != NULL; m = m->next) {
- if(m != menus->open) {
- cputs(m->title);
- cputc(' ');
- } else {
- draw_menu(m);
- }
+ draw_menu(m, m == menus->open);
}
-
- if(wherex() + strlen(menus->desktopmenu->title) + 1>= sizex) {
+ /* Draw desktopmenu */
+ if(wherex() + strlen(menus->desktopmenu->title) + 1 >= sizex) {
gotoxy(sizex - strlen(menus->desktopmenu->title) - 1, 0);
} else {
cclear(sizex - wherex() -
strlen(menus->desktopmenu->title) - 1);
}
-
- /* Draw desktopmenu */
- if(menus->desktopmenu != menus->open) {
- cputs(menus->desktopmenu->title);
- cputc(' ');
- } else {
- draw_menu(menus->desktopmenu);
- }
+ draw_menu(menus->desktopmenu, menus->desktopmenu == menus->open);
revers(0);
}