--- /dev/null
+/**
+ * \file
+ * Copyright 2004, 2008 Develer S.r.l. (http://www.develer.com/)
+ * All Rights Reserved.
+ *
+ * \version $Id$
+ *
+ * \author Stefano Fedrigo <aleph@develer.com>
+ * \author Francesco Sacchi <batt@develer.com>
+ *
+ * \brief Graphics Menu bar widget
+ */
+
+#include "menubar.h"
+
+#include <gfx/gfx.h>
+#include <gfx/text.h>
+#include <gfx/font.h>
+#include <cfg/compiler.h>
+
+#if CPU_AVR
+ #include <avr/pgmspace.h> /* strlen_P() */
+#else
+ #define strlen_P(s) strlen(s)
+ #define text_puts_P(s, b) text_puts(s, b)
+ #define pgm_read_uint16_t(addr) (*(addr))
+#endif
+
+#include <string.h> /* strlen, memcpy */
+
+
+/** Predefined labels */
+static const pgm_char lab_1[] = "";
+static const pgm_char lab_2[] = "mute";
+static const pgm_char lab_3[] = "menu";
+static const pgm_char lab_4[] = "back";
+static const pgm_char lab_5[] = " ok ";
+static const pgm_char lab_6[] = "Ch 1";
+static const pgm_char lab_7[] = "Ch 2";
+static const pgm_char lab_8[] = "C1+2";
+static const pgm_char lab_9[] = " "UP_ARROW" ";
+static const pgm_char lab_10[] = " "DOWN_ARROW" ";
+static const pgm_char lab_11[] = " - ";
+static const pgm_char lab_12[] = " + ";
+static const pgm_char lab_13[] = "sel ";
+#if OEM_BRAND == OEM_CLAIRBROS
+static const pgm_char lab_14[] = "gain";
+#else
+static const pgm_char lab_14[] = "lock";
+#endif
+static const pgm_char lab_15[] = "unlock";
+static const pgm_char lab_16[] = "more";
+static const pgm_char lab_17[] = "edit";
+static const pgm_char lab_18[] = "fast";
+static const pgm_char lab_19[] = LEFT_ARROW" ";
+static const pgm_char lab_20[] = " "RIGHT_ARROW;
+static const pgm_char lab_21[] = "slow";
+static const pgm_char lab_22[] = "yes";
+static const pgm_char lab_23[] = "no";
+
+
+static const pgm_char * PROGMEM label_strings[LABEL_CNT] = {
+ lab_1, lab_2, lab_3, lab_4, lab_5, lab_6, lab_7, lab_8, lab_9,
+ lab_10, lab_11, lab_12, lab_13, lab_14, lab_15, lab_16, lab_17,
+ lab_18, lab_19, lab_20, lab_21, lab_22, lab_23
+};
+
+/**
+ * Macro to access a label iptr_t: if a char pointer get the string pointed to
+ * in program memory, otherwise return the corrispondent predefined string
+ * (see label_strings in menubar.c)
+ */
+#define PTRLBL(x) ((unsigned int)(x) < 256 ? \
+ (const pgm_char *)pgm_read_uint16_t(label_strings + (unsigned int)(x)) \
+ : (const pgm_char *)(x))
+
+
+/**
+ * Initialize the MenuBar widget with the bitmap associated,
+ * the label names and the number of labels.
+ */
+void mbar_init(
+ struct MenuBar *mb,
+ struct Bitmap *bmp,
+ const_iptr_t labels[],
+ int num_labels)
+{
+ mb->bitmap = bmp;
+ mb->labels = labels;
+ mb->num_labels = num_labels;
+}
+
+
+/**
+ * Render the MenuBar on the bitmap.
+ */
+void mbar_draw(const struct MenuBar *mb)
+{
+ uint8_t oldstyle;
+ int i;
+ size_t maxlen = 0; /* Length of the longest label */
+ coord_t x1, x2, y1, y2, label_padding;
+
+ /* Maximum space available for a label */
+ coord_t slot_width = mb->bitmap->width / mb->num_labels;
+
+ /* Find longest label */
+ for (i = 0; i < mb->num_labels; i++)
+ if (strlen_P(PTRLBL(mb->labels[i])) > maxlen)
+ maxlen = strlen_P(PTRLBL(mb->labels[i]));
+
+ oldstyle = text_style(mb->bitmap, STYLEF_INVERT, STYLEF_MASK);
+
+ /* y coords for menubar: bottom of the bitmap */
+ y1 = mb->bitmap->height - FONT_HEIGHT;
+ y2 = mb->bitmap->height;
+
+ /* Clear menubar area */
+ gfx_rectClear(mb->bitmap, 0, y1, mb->bitmap->width, y2);
+
+ for (i = 0; i < mb->num_labels; i++)
+ {
+ size_t lablen = strlen_P(PTRLBL(mb->labels[i]));
+
+ /* Don't draw empty labels */
+ if (mb->labels[i] == (const_iptr_t)LABEL_EMPTY)
+ continue;
+
+ /* x coords: magic formula for equal distribution of the
+ * labels along bitmap
+ */
+ label_padding = slot_width - (FONT_WIDTH * lablen + 2);
+ x1 = i * (slot_width + (label_padding / (mb->num_labels - 1)));
+ x2 = x1 + lablen * FONT_WIDTH + 1;
+
+ /* Draw vertical line before.
+ * Uncomment +1 for "rounded" menubars */
+ gfx_line(mb->bitmap, x1, y1 /* + 1 */, x1, y2);
+
+ /* Draw text */
+ text_setCoord(mb->bitmap, x1 + 1, y1);
+ text_puts_P(PTRLBL(mb->labels[i]), mb->bitmap);
+
+ /* Draw vertical line after
+ * Uncomment +1 for "rounded" menubars */
+ gfx_line(mb->bitmap, x2, y1 /* + 1 */, x2, y2);
+ }
+
+ text_style(mb->bitmap, oldstyle, STYLEF_MASK);
+}
--- /dev/null
+/**
+ * \file
+ * Copyright 2004, 2005 Develer S.r.l. (http://www.develer.com/)
+ * All Rights Reserved.
+ *
+ * \version $Id$
+ *
+ * \author Stefano Fedrigo <aleph@develer.com>
+ *
+ * \brief Graphic menu bar widget.
+ */
+
+/*#*
+ *#* $Log: menubar.h,v $
+ *#* Revision 1.17 2006/06/16 16:18:49 batt
+ *#* Fix doxygen docs.
+ *#*
+ *#* Revision 1.16 2005/11/16 18:10:19 bernie
+ *#* Move top-level headers to cfg/ as in DevLib.
+ *#*
+ *#* Revision 1.15 2005/02/17 03:49:21 bernie
+ *#* Update to new PGM api.
+ *#*
+ *#* Revision 1.14 2004/10/31 11:02:15 aleph
+ *#* Rename functions with correct codying conventions; Simplify version display
+ *#*
+ *#* Revision 1.13 2004/09/27 12:05:46 powersoft
+ *#* Use sel label for toggle menus and remove it
+ *#*
+ *#* Revision 1.12 2004/09/27 10:05:33 powersoft
+ *#* Menu cosmetic fixes
+ *#*/
+#ifndef MWARE_MENUBAR_H
+#define MWARE_MENUBAR_H
+
+#include <appconfig.h>
+#include <cfg/compiler.h>
+#include <brand.h>
+
+/** Predefined labels ids */
+enum LabelId
+{
+ LABEL_EMPTY, /* empty label */
+ LABEL_MUTE,
+ LABEL_MENU,
+ LABEL_BACK,
+ LABEL_OK,
+ LABEL_CH_1,
+ LABEL_CH_2,
+ LABEL_C1PLUS2,
+ LABEL_UPARROW,
+ LABEL_DOWNARROW,
+ LABEL_MINUS,
+ LABEL_PLUS,
+ LABEL_SEL,
+ #if OEM_BRAND == OEM_CLAIRBROS
+ LABEL_GAIN,
+ #else
+ LABEL_LOCK,
+ #endif
+ LABEL_UNLOCK,
+ LABEL_MORE,
+ LABEL_EDIT,
+ LABEL_FAST,
+ LABEL_PREV,
+ LABEL_NEXT,
+ LABEL_SLOW,
+ LABEL_YES,
+ LABEL_NO,
+
+
+ LABEL_CNT
+};
+
+#define UP_ARROW "\x18"
+#define DOWN_ARROW "\x19"
+#define RIGHT_ARROW "\xC4\x1A"
+#define LEFT_ARROW "\x10\xC4"
+
+/* Forward decl */
+struct Bitmap;
+
+typedef struct MenuBar
+{
+ struct Bitmap *bitmap;
+ const_iptr_t *labels;
+ int num_labels;
+} MenuBar;
+
+void mbar_init(
+ struct MenuBar *mb,
+ struct Bitmap *bmp,
+ const_iptr_t *labels,
+ int num_labels);
+void mbar_draw(const struct MenuBar *mb);
+
+#endif /* MWARE_MENUBAR_H */