+uint16 mousePic[] = {
+ 6, 8,
+
+ 0x03E0,0x0000,0x0000,0x0000,0x0000,0x0000, // +
+ 0x0300,0x03E0,0x0000,0x0000,0x0000,0x0000, // @+
+ 0x0300,0x03E0,0x03E0,0x0000,0x0000,0x0000, // @++
+ 0x0300,0x0300,0x03E0,0x03E0,0x0000,0x0000, // @@++
+ 0x0300,0x0300,0x03E0,0x03E0,0x03E0,0x0000, // @@+++
+ 0x0300,0x0300,0x0300,0x03E0,0x03E0,0x03E0, // @@@+++
+ 0x0300,0x0300,0x0300,0x0000,0x0000,0x0000, // @@@
+ 0x0300,0x0000,0x0000,0x0000,0x0000,0x0000 // @
+/*
+ 0xFFFF,0x0000,0x0000,0x0000,0x0000,0x0000, // +
+ 0xE318,0xFFFF,0x0000,0x0000,0x0000,0x0000, // @+
+ 0xE318,0xFFFF,0xFFFF,0x0000,0x0000,0x0000, // @++
+ 0xE318,0xE318,0xFFFF,0xFFFF,0x0000,0x0000, // @@++
+ 0xE318,0xE318,0xFFFF,0xFFFF,0xFFFF,0x0000, // @@+++
+ 0xE318,0xE318,0xE318,0xFFFF,0xFFFF,0xFFFF, // @@@+++
+ 0xE318,0xE318,0xE318,0x0000,0x0000,0x0000, // @@@
+ 0xE318,0x0000,0x0000,0x0000,0x0000,0x0000 // @
+*/
+};
+// 1 111 00 11 100 1 1100 -> F39C
+// 1 100 00 10 000 1 0000 -> C210
+// 1 110 00 11 000 1 1000 -> E318
+// 0 000 00 11 111 0 0000 -> 03E0
+// 0 000 00 11 000 0 0000 -> 0300
+
+#define NUM_MENU_ITEMS 3
+char * menu[NUM_MENU_ITEMS] = { "File", "Settings", "Options" };
+
+char * menu1[4] = { "Load...", "Reset", "Run", "Quit" };
+char * menu2[3] = { "Video...", "Audio...", "Misc..." };
+char * menu3[1] = { "About..." };
+
+char ** subMenu[NUM_MENU_ITEMS] = { menu1, menu2, menu3 };
+uint8 subMenuNumItems[NUM_MENU_ITEMS] = { 4, 3, 1 };
+
+void (* menu1Action[4])(void) = { LoadROM, NULL, RunEmu, Quit };
+void (* menu2Action[3])(void) = { NULL, NULL, NULL };
+void (* menu3Action[1])(void) = { About };
+void (** subMenuAction[NUM_MENU_ITEMS])(void) = { menu1Action, menu2Action, menu3Action };
+
+//
+// Local GUI classes
+//
+
+class Element
+{
+ public:
+ virtual void HandleKey(SDLKey key) = 0;
+ virtual void HandleMouseMove(uint32 x, uint32 y) = 0;
+ virtual void HandleMouseButton(uint32 x, uint32 y, bool mouseDown) = 0;
+ virtual void Draw(uint32, uint32) = 0;
+//Needed? virtual ~Element() = 0;
+//We're not allocating anything in the base class, so the answer would be NO.
+ bool Inside(uint32 x, uint32 y);
+ // Class method
+ static void SetScreenAndPitch(int16 * s, uint32 p) { screenBuffer = s, pitch = p; }
+
+ protected:
+ SDL_Rect extents;
+ // Class variables...
+ static int16 * screenBuffer;
+ static uint32 pitch;
+};
+
+int16 * Element::screenBuffer = NULL;
+uint32 Element::pitch = 0;
+
+bool Element::Inside(uint32 x, uint32 y)
+{
+ return (x >= (uint32)extents.x && x < (uint32)(extents.x + extents.w)
+ && y >= (uint32)extents.y && y < (uint32)(extents.y + extents.h) ? true : false);
+}
+
+class Button: public Element
+{
+ public:
+ Button(uint32 x = 0, uint32 y = 0, uint32 w = 0, uint32 h = 0): clicked(false),
+ inside(false), fgColor(0xFFFF), bgColor(0x03E0)
+ { extents.x = x, extents.y = y, extents.w = w, extents.h = h; }
+ virtual void HandleKey(SDLKey key) {}
+ virtual void HandleMouseMove(uint32 x, uint32 y);
+ virtual void HandleMouseButton(uint32 x, uint32 y, bool mouseDown);
+ virtual void Draw(uint32 offsetX = 0, uint32 offsetY = 0);
+
+ protected:
+ bool clicked, inside;
+ uint16 fgColor, bgColor;
+};
+
+void Button::HandleMouseMove(uint32 x, uint32 y)
+{
+ inside = Inside(x, y);
+}
+
+void Button::HandleMouseButton(uint32 x, uint32 y, bool mouseDown)
+{
+ if (inside && mouseDown)
+ clicked = true;
+ else
+ clicked = false;
+}
+
+void Button::Draw(uint32 offsetX/*= 0*/, uint32 offsetY/*= 0*/)
+{
+ uint32 addr = (extents.x + offsetX) + ((extents.y + offsetY) * pitch);
+
+ for(uint32 y=0; y<extents.h; y++)
+ {
+ for(uint32 x=0; x<extents.w; x++)
+ {
+ // Doesn't clip in y axis! !!! FIX !!!
+ if (extents.x + x < pitch)
+ screenBuffer[addr + x + (y * pitch)]
+ = (clicked ? fgColor : (inside ? 0x43F0 : bgColor));
+ }
+ }
+}
+
+class Window: public Element
+{
+ public:
+ Window(uint32 x = 0, uint32 y = 0, uint32 w = 0, uint32 h = 0): /*clicked(false),
+ inside(false),*/ fgColor(0x4FF0), bgColor(0xFE10)
+ { extents.x = x, extents.y = y, extents.w = w, extents.h = h; }
+ virtual void HandleKey(SDLKey key) {}
+ virtual void HandleMouseMove(uint32 x, uint32 y);
+ virtual void HandleMouseButton(uint32 x, uint32 y, bool mouseDown);
+ virtual void Draw(uint32 offsetX = 0, uint32 offsetY = 0);
+ void AddElement(Element * e);
+
+ protected:
+// bool clicked, inside;
+ uint16 fgColor, bgColor;
+ vector<Element *> list;
+};
+
+void Window::HandleMouseMove(uint32 x, uint32 y)
+{
+ // Handle the items this window contains...
+ for(uint32 i=0; i<list.size(); i++)
+ // Make coords relative to upper right corner of this window...
+ list[i]->HandleMouseMove(x - extents.x, y - extents.y);
+}
+
+void Window::HandleMouseButton(uint32 x, uint32 y, bool mouseDown)
+{
+ // Handle the items this window contains...
+ for(uint32 i=0; i<list.size(); i++)
+ // Make coords relative to upper right corner of this window...
+ list[i]->HandleMouseButton(x - extents.x, y - extents.y, mouseDown);
+}
+
+void Window::Draw(uint32 offsetX/*= 0*/, uint32 offsetY/*= 0*/)
+{
+ uint32 addr = (extents.x + offsetX) + ((extents.y + offsetY) * pitch);
+
+ for(uint32 y=0; y<extents.h; y++)
+ {
+ for(uint32 x=0; x<extents.w; x++)
+ {
+ // Doesn't clip in y axis! !!! FIX !!!
+ if (extents.x + x < pitch)
+ screenBuffer[addr + x + (y * pitch)] = bgColor;
+ }
+ }
+
+ // Handle the items this window contains...
+ for(uint32 i=0; i<list.size(); i++)
+ list[i]->Draw(extents.x, extents.y);
+}
+
+void Window::AddElement(Element * e)
+{
+ list.push_back(e);
+}
+
+struct NameAction
+{
+ string name;
+ void (* action)(void);
+ bool isWindow;
+
+ NameAction(string n, void (* a)(void) = NULL, bool w = false): name(n), action(a),
+ isWindow(w) {}
+};
+
+class MenuItems
+{
+ public:
+ MenuItems(): charLength(0) {}
+
+ string title;
+ vector<NameAction> item;
+ uint32 charLength;
+ SDL_Rect extents;
+};
+
+class Menu: public Element
+{
+ public:
+ Menu(uint32 x = 0, uint32 y = 0, uint32 w = 0, uint32 h = 8,
+ uint16 fgc = 0x1CFF, uint16 bgc = 0x000F, uint16 fgch = 0x421F,
+ uint16 bgch = 0x1CFF): clicked(false), inside(0), fgColor(fgc), bgColor(bgc),
+ fgColorHL(fgch), bgColorHL(bgch), menuChosen(-1), menuItemChosen(-1)
+ { extents.x = x, extents.y = y, extents.w = w, extents.h = h; }
+ virtual void HandleKey(SDLKey key);
+ virtual void HandleMouseMove(uint32 x, uint32 y);
+ virtual void HandleMouseButton(uint32 x, uint32 y, bool mouseDown);
+ virtual void Draw(uint32 offsetX = 0, uint32 offsetY = 0);
+ void Add(MenuItems mi);
+
+ protected:
+ bool clicked;
+ uint32 inside;
+ uint16 fgColor, bgColor, fgColorHL, bgColorHL;
+ int menuChosen, menuItemChosen;
+
+ private:
+ vector<MenuItems> itemList;
+};
+
+void Menu::HandleKey(SDLKey Key)
+{
+}
+
+void Menu::HandleMouseMove(uint32 x, uint32 y)
+{
+ if (!Inside(x, y))
+ inside = 0;
+ else
+ {
+ // Find out *where* we are inside the menu bar
+ uint32 xpos = extents.x;
+
+ for(uint32 i=0; i<itemList.size(); i++)
+ {
+ uint32 width = (itemList[i].title.length() + 2) * 8;
+
+ if (x >= xpos && x < xpos + width)
+ {
+ inside = i + 1;
+ break;
+ }
+
+ xpos += width;
+ }
+ }
+}
+
+void Menu::HandleMouseButton(uint32 x, uint32 y, bool mouseDown)
+{
+ if (inside && mouseDown)
+ clicked = true, menuChosen = inside - 1;
+// else
+ if (!inside && mouseDown)
+ clicked = false, menuChosen = -1;
+}
+
+void Menu::Draw(uint32 offsetX/*= 0*/, uint32 offsetY/*= 0*/)
+{
+ uint32 xpos = extents.x + offsetX;
+
+ for(uint32 i=0; i<itemList.size(); i++)
+ {
+ uint16 color1 = fgColor, color2 = bgColor;
+ if (inside == (i + 1) || (menuChosen != -1 && (uint32)menuChosen == i))
+ color1 = fgColorHL, color2 = bgColorHL;
+
+ DrawStringOpaque(screenBuffer, xpos, extents.y + offsetY, color1, color2,
+ " %s ", itemList[i].title.c_str());
+ xpos += (itemList[i].title.length() + 2) * 8;
+ }
+
+ // Draw sub menu
+ if (clicked)
+ {
+// menuItemChosen = -1;
+ uint32 ypos = extents.y + 9;
+
+ for(uint32 i=0; i<itemList[menuChosen].item.size(); i++)
+ {
+ uint16 color1 = fgColor, color2 = bgColor;
+
+//This won't work...
+// if (((uint32)mouseX >= menuXPos && (uint32)mouseX < menuXPos + (length + 2) * 8)
+// && mouseY >= (extents.y + 9 + i * 8) && mouseY < (extents.y + 9 + (i + 1) * 8))
+// color1 = fgColorHL, color2 = bgColorHL, menuItemChosen = i;
+
+ DrawStringOpaque(screenBuffer, itemList[menuChosen].extents.x, ypos,
+ color1, color2, " %-*.*s ", itemList[menuChosen].charLength,
+ itemList[menuChosen].charLength, itemList[menuChosen].item[i].name.c_str());
+ ypos += 8;
+ }
+ }
+}
+
+void Menu::Add(MenuItems mi)
+{
+ for(uint32 i=0; i<mi.item.size(); i++)
+ if (mi.item[i].name.length() > mi.charLength)
+ mi.charLength = mi.item[i].name.length();
+
+ // Set extents here as well...
+ mi.extents.x = extents.x + extents.w, mi.extents.y = extents.y + 9;
+ mi.extents.w = (mi.charLength + 2) * 8, mi.extents.h = mi.item.size() * 8;
+
+ itemList.push_back(mi);
+ extents.w += (mi.title.length() + 2) * 8;
+}
+
+class RootWindow: public Window
+{
+ public:
+ RootWindow(Menu * m, Window * w = NULL): menu(m), window(w) {}
+//Do we even need to care about this crap?
+// { extents.x = extents.y = 0, extents.w = 320, extents.h = 240; }
+ virtual void HandleKey(SDLKey key) {}
+ virtual void HandleMouseMove(uint32 x, uint32 y) {}
+ virtual void HandleMouseButton(uint32 x, uint32 y, bool mouseDown) {}
+ virtual void Draw(uint32 offsetX = 0, uint32 offsetY = 0) {}
+
+ private:
+ Menu * menu;
+ Window * window;
+ int16 * rootImage[1280 * 240 * 2];
+};
+
+
+
+//
+// GUI stuff--it's not crunchy, it's GUI! ;-)
+//