diff options
author | Mateusz Kaduk <mateusz.kaduk@gmail.com> | 2004-12-12 17:51:50 +0000 |
---|---|---|
committer | Mateusz Kaduk <mateusz.kaduk@gmail.com> | 2004-12-12 17:51:50 +0000 |
commit | 812e679c9befbfe98cc311723b8296df0384515e (patch) | |
tree | fe349e783efc0ee70ab60bcce866bdc4f9b67752 /src/gui/setup.cpp | |
parent | 197b684831c9701635fd140bbb06a6c2b3f0fcc7 (diff) | |
download | mana-812e679c9befbfe98cc311723b8296df0384515e.tar.gz mana-812e679c9befbfe98cc311723b8296df0384515e.tar.bz2 mana-812e679c9befbfe98cc311723b8296df0384515e.tar.xz mana-812e679c9befbfe98cc311723b8296df0384515e.zip |
Created setup class and changed to use guichan
Diffstat (limited to 'src/gui/setup.cpp')
-rw-r--r-- | src/gui/setup.cpp | 162 |
1 files changed, 49 insertions, 113 deletions
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index b88fc8cd..c8b677db 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -5,133 +5,69 @@ * setup dialog. */ -#include <allegro.h> -#include "gui.h" +#include "setup.h" -#define CONFIG_FILE "tmw.ini" - -extern unsigned int screen_mode; - -DIALOG_PLAYER *player_setup; /* Pointer to player's dialog */ -bool show_player_setup; /* Switch for setup dialog */ - -typedef struct { - int width, height; - char* desc; -} LIST; /* New type for holding video modes */ - -int apply_setup(int msg, DIALOG *d, int c); /* Need this here in order to access dialog directly */ - -/* - * Hard coded list cuz get_gfx_mode_list fails with AUTODETECT - */ -const LIST mode_list[] = { - { 1024,768, "1024x768" }, - { 800,600, "800x600" }, - { 640,480, "640x480"} -}; +extern bool show_setup; /* - * Get video modes list for setup + * Setup action listener */ -char *get_listbox_video_modes(int index, int *list_size) -{ - if (index < 0 & index < 4) { - *list_size = 3; - return NULL; - } else - return mode_list[index].desc; -} - -/* - * Calls orginal tmw_button_proc and If D_O_K was cliked calls function in dp3 - */ -int tmw_ok_button_proc(int msg, DIALOG *d, int c) -{ - int ret; - - ret = tmw_button_proc(msg, d, c); // returns D_CLOSE when D_O_K was clicked otherwise D_O_K - - if(ret == D_CLOSE && d->dp3 != NULL) - return ((int(*)(void))d->dp3)(); - - return ret; +void SetupActionListener::action(const std::string& eventId) { + if(eventId == "apply") { + puts("apply"); + show_setup = false; + } else if (eventId == "cancel") { + puts("calncel"); + show_setup = false; + } } /* - * Array for dialog objects and callbacks - */ -DIALOG setup_dialog[] = - { - /* Dialog proc*/ - { tmw_dialog_proc, 300, 300, 300, 200, 0, 0, 0, 0, 0, 0, (char *)"Setup", NULL, NULL }, - - /* Descriptions */ - { tmw_text_proc, 305, 320, 0, 0, 0, 0, 0, 0, 0, 0, (char *)"Display", NULL, NULL }, - { tmw_text_proc, 435, 320, 0, 0, 0, 0, 0, 0, 0, 0, (char *)"Strech modes", NULL, NULL }, - - /* List */ - { tmw_list_proc, 305, 345, 100, 100, 0, 0, 0, 0, 0, 0, (char *)get_listbox_video_modes, NULL, NULL }, - - /* Radio buttons */ - //{ tmw_radio_proc, 435, 339, 160, 19, 0, 0, 0, 0, 0, 0, (char *)"Normal", NULL, NULL }, - //{ tmw_radio_proc, 435, 358, 160, 19, 0, 0, 0, 0, 0, 0, (char *)"2xSaI", NULL, NULL }, - //{ tmw_radio_proc, 435, 377, 160, 19, 0, 0, 0, 0, 0, 0, (char *)"SuperEagle", NULL, NULL }, - - /* Buttons */ - { tmw_ok_button_proc, 315, 470, 40, 20, 0, 0, 0, D_EXIT, 0, 0, (char *)"&Ok", NULL, (int*)apply_setup }, - { tmw_ok_button_proc, 535, 470, 40, 20, 0, 0, 0, D_EXIT, 0, 0, (char *)"&Cancel", NULL, NULL }, - { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } - }; - -/* - * Apply setup settings + * Display setup dialog */ -int apply_setup(int msg, DIALOG *d, int c) { +Setup::Setup() { + visible = false; + setupDialog = new gcn::Container(); + displayLabel = new gcn::Label("Display"); + applyButton = new gcn::Button("Apply"); + cancelButton = new gcn::Button("Cancel"); - int index = 0; - int index_loaded = 0, value; + /* Set dialog elements */ + setupDialog->setDimension(gcn::Rectangle(300,300,200,200)); + displayLabel->setPosition(4,14); + applyButton->setPosition(30,162); + cancelButton->setPosition(146,162); - /* Load settings from file */ - if(get_config_int("[settings]","selected_vmode",value) == 1) - index_loaded = value; + /* Set events */ + applyButton->setEventId("apply"); + cancelButton->setEventId("cancel"); - /* Check if settings changed if so use and save them */ - if((index = setup_dialog[3].d1) != index_loaded) { - set_config_int("[settings]","selected_vmode",index); - flush_config_file(); - } + /* Listen for actions */ + SetupActionListener *setupActionListener = new SetupActionListener(); + applyButton->addActionListener(setupActionListener); + cancelButton->addActionListener(setupActionListener); - /* - if(set_gfx_mode(screen_mode, list[index].width, list[index].height, 0, 0)) - error(allegro_error); - */ - return D_CLOSE; // closes the dialog + /* Assemble dialog */ + setupDialog->add(displayLabel); + setupDialog->add(applyButton); + setupDialog->add(cancelButton); + + setupDialog->setVisible(visible); + guiTop->add(setupDialog); } -/* - * Initialize setup dialog - */ -void init_setup(void) { - int value = 0; - - show_player_setup = false; // setup starts as hidden - - /* Initialize */ - player_setup = init_dialog(setup_dialog, -1); - position_dialog(setup_dialog, 300, 200); - set_config_file(CONFIG_FILE); - - /* Set previous selections */ - value = get_config_int("[settings]","selected_vmode",0); - setup_dialog[3].d1 = value; +Setup::~Setup() { + delete setupDialog; + delete displayLabel; + delete applyButton; + delete cancelButton; } -/* - * Update setup dialog - */ -void update_setup(void) { - if(show_player_setup) { - if(gui_update(player_setup) == 0) show_player_setup = false; - } +void Setup::toggleVisible(bool toggle) { + if(visible == false && toggle == true) + visible == true; + else + if(visible == true && toggle == false) visible == false; + + setupDialog->setVisible(visible); } |