Imported kball_final_src_16dec2004.tar.gz
[kball.git] / include / qmenu.h
bloba97b5ad5511142c25a3755752f0e82f4d0f5c8e9
1 // -----------------------------------------------
2 // qmenu.h
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!!
12 #ifndef QMENU_H
13 #define QMENU_H
15 #include <allegro.h>
17 #include <string>
18 #include <vector> // STL container for the menu items
19 #include <iterator>
20 using namespace std;
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
29 class CQMenu
31 public:
32 CQMenu();
33 ~CQMenu();
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
43 // set functions
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));
56 // get functions
57 FONT *get_font_s();
58 FONT *get_font_ns();
59 int get_fg_color_ns();
60 int get_bg_color_ns();
61 int get_fg_color_s();
62 int get_bg_color_s();
63 int get_menu_item_count();
64 int get_x();
65 int get_y();
66 int get_w();
67 int get_h();
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
82 private:
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);
104 // data contained
105 vector <string> menu_item_text; // item menu container
110 #endif