1 // $Id: gui_buttons.cxx,v 1.16 2003/07/26 16:34:57 grumbel Exp $
3 // Construo - A wire-frame construction game
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "graphic_context.hxx"
22 #include "controller.hxx"
24 #include "world_gui_manager.hxx"
25 #include "gui_buttons.hxx"
26 #include "screen_manager.hxx"
27 #include "worldview_component.hxx"
29 #define BUTTON_POS(n) (80 + n * 30)
30 #define BUTTON_WIDTH 75
31 #define BUTTON_HEIGHT 25
33 GUIButton::GUIButton (const std::string
& title_
,
34 int x_pos_
, int y_pos_
, int width_
, int height_
)
35 : GUIComponent (x_pos_
, y_pos_
, width_
, height_
),
43 GUIButton::on_mouse_enter ()
49 GUIButton::on_mouse_leave ()
55 GUIButton::on_primary_button_press (int x
, int y
)
57 WorldGUIManager::instance()->grab_mouse (this);
62 GUIButton::on_primary_button_release (int x
, int y
)
64 WorldGUIManager::instance()->ungrab_mouse (this);
71 GUIButton::draw (GraphicContext
* gc
)
73 if (pressed
&& mouse_over
)
75 gc
->draw_fill_rect (x_pos
, y_pos
, x_pos
+ width
, y_pos
+ height
, Colors::button_bg_pressed
);
79 gc
->draw_fill_rect (x_pos
, y_pos
, x_pos
+ width
, y_pos
+ height
, Colors::button_bg_hover
);
83 gc
->draw_fill_rect (x_pos
, y_pos
, x_pos
+ width
, y_pos
+ height
, Colors::button_bg_passive
);
88 if (pressed
&& mouse_over
)
90 draw_border_pressed (gc
);
94 draw_border_hover (gc
);
98 draw_border_normal (gc
);
103 GUIButton::draw_content (GraphicContext
* gc
)
105 gc
->draw_string_centered (x_pos
+ width
/2, y_pos
+ 16, title
);
109 GUIButton::draw_border_hover(GraphicContext
* gc
)
111 gc
->draw_rect (x_pos
, y_pos
,
112 x_pos
+ width
, y_pos
+ height
, Colors::button_fg_hover
);
116 GUIButton::draw_border_pressed(GraphicContext
* gc
)
118 gc
->draw_rect (x_pos
, y_pos
,
119 x_pos
+ width
, y_pos
+ height
, Colors::button_fg_pressed
);
123 GUIButton::draw_border_normal(GraphicContext
* gc
)
125 gc
->draw_rect (x_pos
, y_pos
,
126 x_pos
+ width
, y_pos
+ height
, Colors::button_fg_passive
);
129 GUIRunButton::GUIRunButton ()
130 : GUIButton ("Run", 10, BUTTON_POS(0), BUTTON_WIDTH
, BUTTON_HEIGHT
)
135 GUIButton::on_click()
137 std::cout
<< "GUIButton: cliked (implement me)" << std::endl
;
141 GUIRunButton::draw_content (GraphicContext
* gc
)
143 if ((!pressed
|| !mouse_over
) && Controller::instance()->is_running ())
144 gc
->draw_fill_rect (x_pos
, y_pos
,
145 x_pos
+ width
, y_pos
+ height
, Colors::button_bg_active
) ;
147 gc->draw_line (x_pos, y_pos,
148 x_pos + width, y_pos + height,
151 gc->draw_line (x_pos + width, y_pos,
152 x_pos, y_pos + height,
155 GUIButton::draw_content (gc
);
159 GUIRunButton::on_click()
161 std::cout
<< "Button pressed" << std::endl
;
162 Controller::instance()->start_simulation ();
165 GUISlowMoButton::GUISlowMoButton ()
166 : GUIButton ("SlowMotion", 10, BUTTON_POS(1), BUTTON_WIDTH
, BUTTON_HEIGHT
)
172 GUISlowMoButton::on_click()
174 Controller::instance()->set_slow_down (!Controller::instance()->slow_down_active ());
178 GUISlowMoButton::draw_content (GraphicContext
* gc
)
180 if (Controller::instance()->slow_down_active())
181 gc
->draw_fill_rect (x_pos
, y_pos
,
182 x_pos
+ width
, y_pos
+ height
, Colors::button_bg_active
);
184 GUIButton::draw_content (gc
);
187 GUIZoomInButton::GUIZoomInButton ()
188 : GUIButton ("Zoom In", 10, BUTTON_POS(2), BUTTON_WIDTH
, BUTTON_HEIGHT
)
193 GUIZoomInButton::on_click()
195 WorldViewComponent::instance()->wheel_up (400,300);
199 GUIZoomOutButton::GUIZoomOutButton ()
200 : GUIButton ("Zoom Out", 10, BUTTON_POS(3), BUTTON_WIDTH
, BUTTON_HEIGHT
)
205 GUIZoomOutButton::on_click()
207 WorldViewComponent::instance()->wheel_down (400,300);
210 GUIQuitButton::GUIQuitButton ()
211 : GUIButton ("Quit", 10, BUTTON_POS(12), BUTTON_WIDTH
, BUTTON_HEIGHT
)
216 GUIQuitButton::on_click()
218 ScreenManager::instance()->quit();
222 GUILoadButton::GUILoadButton ()
223 : GUIButton ("Load", 10, BUTTON_POS(9), BUTTON_WIDTH
, BUTTON_HEIGHT
)
228 GUILoadButton::on_click()
230 ScreenManager::instance()->set_gui(ScreenManager::LOAD_GUI
);