Rebuild autotool system
[construo.git] / gui_buttons.cxx
blob1ee1234a728ede68dd4f37fa0f8ecad93e3ffea6
1 // $Id: gui_buttons.cxx,v 1.16 2003/07/26 16:34:57 grumbel Exp $
2 //
3 // Construo - A wire-frame construction game
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
5 //
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.
20 #include <iostream>
21 #include "graphic_context.hxx"
22 #include "controller.hxx"
23 #include "colors.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_),
36 title (title_)
38 mouse_over = false;
39 pressed = false;
42 void
43 GUIButton::on_mouse_enter ()
45 mouse_over = true;
48 void
49 GUIButton::on_mouse_leave ()
51 mouse_over = false;
54 void
55 GUIButton::on_primary_button_press (int x, int y)
57 WorldGUIManager::instance()->grab_mouse (this);
58 pressed = true;
61 void
62 GUIButton::on_primary_button_release (int x, int y)
64 WorldGUIManager::instance()->ungrab_mouse (this);
65 if (is_at (x, y))
66 on_click ();
67 pressed = false;
70 void
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);
77 else if (mouse_over)
79 gc->draw_fill_rect (x_pos, y_pos, x_pos + width, y_pos + height, Colors::button_bg_hover);
81 else
83 gc->draw_fill_rect (x_pos, y_pos, x_pos + width, y_pos + height, Colors::button_bg_passive);
86 draw_content (gc);
88 if (pressed && mouse_over)
90 draw_border_pressed (gc);
92 else if (mouse_over)
94 draw_border_hover (gc);
96 else
98 draw_border_normal (gc);
102 void
103 GUIButton::draw_content (GraphicContext* gc)
105 gc->draw_string_centered (x_pos + width/2, y_pos + 16, title);
108 void
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);
115 void
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);
122 void
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)
134 void
135 GUIButton::on_click()
137 std::cout << "GUIButton: cliked (implement me)" << std::endl;
140 void
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,
149 Color (0x0000FFFF));
151 gc->draw_line (x_pos + width, y_pos,
152 x_pos, y_pos + height,
153 Color (0x0000FFFF));
155 GUIButton::draw_content (gc);
158 void
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)
171 void
172 GUISlowMoButton::on_click()
174 Controller::instance()->set_slow_down (!Controller::instance()->slow_down_active ());
177 void
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)
192 void
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)
204 void
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)
215 void
216 GUIQuitButton::on_click()
218 ScreenManager::instance()->quit();
222 GUILoadButton::GUILoadButton ()
223 : GUIButton ("Load", 10, BUTTON_POS(9), BUTTON_WIDTH, BUTTON_HEIGHT)
227 void
228 GUILoadButton::on_click()
230 ScreenManager::instance()->set_gui(ScreenManager::LOAD_GUI);
233 /* EOF */