1 // -----------------------------------------------
3 // -----------------------------------------------
4 // Quick menu system for my games/etc
5 // -----------------------------------------------
6 // Developed By Kronoman - Copyright (c) 2004
7 // In loving memory of my father
8 // -----------------------------------------------
10 // From hell they came!! arghhhh!!
18 #include <vector> // STL container for the menu items
22 #include "control.h" // I use my generic controller to control the menu system ;^D
24 // how many beats by second should the menu manager handle ? (default = 30)
25 // this is used for double buffer stuff mainly, and also for timing the calls to the optional callback routine
26 #define BPS_OF_MENU_MANAGER 30
28 // This class models a quick menu system
35 void clear_menu_list(); // resets menu list to empty
37 int add_item_to_menu(string item
); // adds a selectable item to the menu, returns the index of the item added, or -1 on error (menu full)
38 int add_item_to_menu(char *item
) { return add_item_to_menu(string(item
)); };
40 int do_the_menu(int selected
); // starts the menu loop until the user selects one, will return the index of the item selected by the user (starts at 0).
41 int do_the_menu(void) { return do_the_menu(0); } // overload
44 void set_font_s(FONT
*f
); // sets font to render (selected)
45 void set_font_ns(FONT
*f
); // sets font to render (not selected)
47 void set_fg_color_ns(int fg
); // sets fg color (not selected)
48 void set_bg_color_ns(int bg
); // sets bg color (not selected)
49 void set_fg_color_s(int fg
); // sets fg color (selected)
50 void set_bg_color_s(int bg
); // sets bg color (selected)
51 void set_xywh(int x
, int y
, int w
, int h
); // set pos of the menu
52 void set_to_bitmap(BITMAP
*b
);
53 void set_back_bitmap(BITMAP
*b
);
54 void set_callback_drawer(void (*c
)(CQMenu
&d
, bool do_logic
));
59 int get_fg_color_ns();
60 int get_bg_color_ns();
63 int get_menu_item_count();
68 BITMAP
*get_to_bitmap();
69 BITMAP
*get_back_bitmap();
70 string
get_menu_item_text(int item_index
); // will return string of item
72 // timing helpers (global timer)
73 int get_time_counter();
74 unsigned long int get_big_timer_counter();
76 // the controller object is public so you can control it directly to suit your needs
77 CController control
; // controller for menu control
79 // some public values that control the display of the menu itself
80 int item_y_separation
; // pixels to separate each item in 'Y'
81 int text_align
; // alignment of text of items: default = left (normal), 1 = right, 2 = center around mx, 3 = justify in mw space
83 FONT
*menu_font_s
; // pointer to font to render the menu items (selected)
84 FONT
*menu_font_ns
; // pointer to font to render the menu items (not selected)
86 int menu_fg_color_ns
; // color of foreground of the text (item NOT selected)
87 int menu_bg_color_ns
; // color of background of the text (-1 for transparent) (item NOT selected)
89 int menu_fg_color_s
; // color of foreground of the text (item SELECTED)
90 int menu_bg_color_s
; // color of background of the text (-1 for transparent) (item SELECTED)
92 int mx
, my
, mw
, mh
; // x,y,w,h of the menu (position for drawing)
94 BITMAP
*to_bitmap
; // bitmap where the menu must be drawn in each draw update (usually 'screen')
95 BITMAP
*back_bitmap
; // background bitmap of the menu, will be put at 0,0 of "to_bitmap" on each redraw
97 // this is a callback function that can be called in each logic and draw update
98 // will be pased a reference to the caller object (to get bitmap, etc)
99 // do_logic will have TRUE if you need to update the logic
100 // do_logic will have FALSE if you need to render the graphics
101 // this scheme lets you keep a constant rate of animations
102 void (*callback
)(CQMenu
&d
, bool do_logic
);
105 vector
<string
> menu_item_text
; // item menu container