Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

messagebox_generic.cpp

Go to the documentation of this file.
00001 /*
00002         ClanGUI, copyrights by various people. Have a look in the CREDITS file.
00003         
00004         This sourcecode is distributed using the Library GNU Public Licence,
00005         version 2 or (at your option) any later version. Please read LICENSE
00006         for details.
00007 */
00008 
00009 #include "precomp.h"
00010 #include "messagebox_generic.h"
00011 #include "API/GUI/component_options.h"
00012 #include "API/Display/Display/display.h"
00013 
00014 CL_ComponentOptions CL_MessageBox_Generic::create_options(
00015         const std::string &title,
00016         const std::string &text,
00017         const std::string &button1,
00018         const std::string &button2,
00019         const std::string &button3)
00020 {
00021         CL_ComponentOptions options;
00022 
00023         // TODO: Calculate proper size
00024         int width = 300;
00025         int height = 150;
00026         int x = (CL_Display::get_width() - width) / 2;
00027         int y = (CL_Display::get_height() - height) / 2;
00028 
00029         options.add_option_as_int("x", x);
00030         options.add_option_as_int("y", y);
00031         options.add_option_as_int("width", width);
00032         options.add_option_as_int("height", height);
00033         options.add_option("title", title);
00034         options.add_option("text", text);
00035         options.add_option("button1", button1);
00036         options.add_option("button2", button2);
00037         options.add_option("button3", button3);
00038 
00039         return options;
00040 }
00041 
00042 CL_MessageBox_Generic::CL_MessageBox_Generic(CL_MessageBox *self, const CL_ComponentOptions &options, CL_StyleManager *style)
00043 :
00044         messagebox(self)
00045 {
00046         if(options.exists("text"))
00047                 text = options.get_value("text");
00048 
00049         CL_Rect pos = messagebox->get_client_area()->get_position();
00050         int width = pos.get_width();
00051         int height = pos.get_height();
00052 
00053         // Add the text
00054         CL_Rect rect(0, 10, width, 0);
00055         label_text = new CL_Label(rect, text, messagebox->get_client_area(), style);
00056         messagebox->get_client_area()->add_child(label_text, true);
00057         label_text->set_alignment(1);
00058 
00059         result_button = -1;
00060 
00061         // Button size
00062         int button_width = 75;
00063         int button_height = 25;
00064 
00065         int buttons = 0;
00066         std::string button_text[3];
00067 
00068         // Get button texts
00069         if(options.exists("button1"))
00070                 button_text[0] = options.get_value("button1");
00071         if(options.exists("button2"))
00072                 button_text[1] = options.get_value("button2");
00073         if(options.exists("button3"))
00074                 button_text[2] = options.get_value("button3");
00075 
00076         // Find out total numbers of button
00077         if(button_text[2].size())
00078                 buttons = 3;
00079         else if(button_text[1].size())
00080                 buttons = 2;
00081         else if(button_text[0].size())
00082                 buttons = 1;
00083 
00084         // Center buttons
00085         int cur_pos_x = (width - ((button_width * buttons) + (10 * (buttons - 1)))) / 2;
00086         int cur_pos_y = height - button_height - 5;
00087 
00088         // Create and position all the buttons
00089         for(int i = 0; i < buttons; i++)
00090         {
00091                 rect = CL_Rect(cur_pos_x, cur_pos_y, cur_pos_x + button_width, cur_pos_y + button_height);
00092                 button[i] = new CL_Button(
00093                         rect,
00094                         button_text[i],
00095                         messagebox->get_client_area());
00096 
00097                 slot_on_button[i] = button[i]->sig_clicked().connect(CL_CreateSlot(this, &CL_MessageBox_Generic::on_button, i));
00098 
00099                 cur_pos_x += button_width + 10;
00100         }
00101 }
00102 
00103 void CL_MessageBox_Generic::on_button(int button)
00104 {
00105         result_button = button;
00106         sig_button[button]();
00107         messagebox->quit();
00108 }

Generated at Wed Apr 4 19:54:01 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001