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