BeRTOS
|
00001 00040 #include "menubar.h" 00041 00042 #include <gfx/gfx.h> 00043 #include <gfx/text.h> 00044 #include <gfx/font.h> 00045 #include <cfg/compiler.h> 00046 00047 #warning FIXME:This module is obsolete, you must refactor it! 00048 00049 #if 0 00050 #if CPU_AVR 00051 #include <avr/pgmspace.h> /* strlen_P() */ 00052 #else 00053 #define strlen_P(s) strlen(s) 00054 #define text_puts_P(s, b) text_puts(s, b) 00055 #define pgm_read_uint16_t(addr) (*(addr)) 00056 #endif 00057 00058 #include <string.h> /* strlen, memcpy */ 00059 00060 00062 static const pgm_char lab_1[] = ""; 00063 static const pgm_char lab_2[] = "mute"; 00064 static const pgm_char lab_3[] = "menu"; 00065 static const pgm_char lab_4[] = "back"; 00066 static const pgm_char lab_5[] = " ok "; 00067 static const pgm_char lab_6[] = "Ch 1"; 00068 static const pgm_char lab_7[] = "Ch 2"; 00069 static const pgm_char lab_8[] = "C1+2"; 00070 static const pgm_char lab_9[] = " "UP_ARROW" "; 00071 static const pgm_char lab_10[] = " "DOWN_ARROW" "; 00072 static const pgm_char lab_11[] = " - "; 00073 static const pgm_char lab_12[] = " + "; 00074 static const pgm_char lab_13[] = "sel "; 00075 static const pgm_char lab_14[] = "lock"; 00076 static const pgm_char lab_15[] = "unlock"; 00077 static const pgm_char lab_16[] = "more"; 00078 static const pgm_char lab_17[] = "edit"; 00079 static const pgm_char lab_18[] = "fast"; 00080 static const pgm_char lab_19[] = LEFT_ARROW" "; 00081 static const pgm_char lab_20[] = " "RIGHT_ARROW; 00082 static const pgm_char lab_21[] = "slow"; 00083 static const pgm_char lab_22[] = "yes"; 00084 static const pgm_char lab_23[] = "no"; 00085 00086 00087 static const pgm_char * PROGMEM label_strings[LABEL_CNT] = { 00088 lab_1, lab_2, lab_3, lab_4, lab_5, lab_6, lab_7, lab_8, lab_9, 00089 lab_10, lab_11, lab_12, lab_13, lab_14, lab_15, lab_16, lab_17, 00090 lab_18, lab_19, lab_20, lab_21, lab_22, lab_23 00091 }; 00092 00098 #define PTRLBL(x) ((unsigned int)(x) < 256 ? \ 00099 (const pgm_char *)pgm_read_uint16_t(label_strings + (unsigned int)(x)) \ 00100 : (const pgm_char *)(x)) 00101 00102 00107 void mbar_init( 00108 struct MenuBar *mb, 00109 struct Bitmap *bmp, 00110 const_iptr_t labels[], 00111 int num_labels) 00112 { 00113 mb->bitmap = bmp; 00114 mb->labels = labels; 00115 mb->num_labels = num_labels; 00116 } 00117 00118 00122 void mbar_draw(const struct MenuBar *mb) 00123 { 00124 uint8_t oldstyle; 00125 int i; 00126 size_t maxlen = 0; /* Length of the longest label */ 00127 coord_t x1, x2, y1, y2, label_padding; 00128 00129 /* Maximum space available for a label */ 00130 coord_t slot_width = mb->bitmap->width / mb->num_labels; 00131 00132 /* Find longest label */ 00133 for (i = 0; i < mb->num_labels; i++) 00134 if (strlen_P(PTRLBL(mb->labels[i])) > maxlen) 00135 maxlen = strlen_P(PTRLBL(mb->labels[i])); 00136 00137 oldstyle = text_style(mb->bitmap, STYLEF_INVERT, STYLEF_MASK); 00138 00139 /* y coords for menubar: bottom of the bitmap */ 00140 y1 = mb->bitmap->height - FONT_HEIGHT; 00141 y2 = mb->bitmap->height; 00142 00143 /* Clear menubar area */ 00144 gfx_rectClear(mb->bitmap, 0, y1, mb->bitmap->width, y2); 00145 00146 for (i = 0; i < mb->num_labels; i++) 00147 { 00148 size_t lablen = strlen_P(PTRLBL(mb->labels[i])); 00149 00150 /* Don't draw empty labels */ 00151 if (mb->labels[i] == (const_iptr_t)LABEL_EMPTY) 00152 continue; 00153 00154 /* x coords: magic formula for equal distribution of the 00155 * labels along bitmap 00156 */ 00157 label_padding = slot_width - (FONT_WIDTH * lablen + 2); 00158 x1 = i * (slot_width + (label_padding / (mb->num_labels - 1))); 00159 x2 = x1 + lablen * FONT_WIDTH + 1; 00160 00161 /* Draw vertical line before. 00162 * Uncomment +1 for "rounded" menubars */ 00163 gfx_line(mb->bitmap, x1, y1 /* + 1 */, x1, y2); 00164 00165 /* Draw text */ 00166 text_setCoord(mb->bitmap, x1 + 1, y1); 00167 text_puts_P(PTRLBL(mb->labels[i]), mb->bitmap); 00168 00169 /* Draw vertical line after 00170 * Uncomment +1 for "rounded" menubars */ 00171 gfx_line(mb->bitmap, x2, y1 /* + 1 */, x2, y2); 00172 } 00173 00174 text_style(mb->bitmap, oldstyle, STYLEF_MASK); 00175 } 00176 #endif 00177