1 // $Id: world_gui_manager.cxx,v 1.13 2003/07/29 15:10:07 grumbel Exp $
3 // Construo - A wire-frame construction gamee
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 "controller.hxx"
22 #include "construo.hxx"
23 #include "graphic_context.hxx"
24 #include "worldview_component.hxx"
25 #include "string_utils.hxx"
26 #include "worldview_insert_tool.hxx"
27 #include "gui_buttons.hxx"
28 #include "gui_window.hxx"
29 #include "gui_label.hxx"
30 #include "globals.hxx"
31 #include "screen_manager.hxx"
32 #include "root_graphic_context.hxx"
33 #include "world_gui_manager.hxx"
35 using namespace StringUtils
;
37 WorldGUIManager
* WorldGUIManager::instance_
= 0;
40 void increase_particle_mass() {
41 WorldViewInsertTool
& wc
= *WorldViewComponent::instance()->get_insert_tool();
42 wc
.set_particle_mass(wc
.get_particle_mass() + 1.0f
);
45 void decrease_particle_mass() {
46 WorldViewInsertTool
& wc
= *WorldViewComponent::instance()->get_insert_tool();
47 wc
.set_particle_mass(wc
.get_particle_mass() - 1.0f
);
50 void switch_to_insert_mode() {
51 WorldViewComponent::instance()->set_mode (WorldViewComponent::INSERT_MODE
);
54 bool insert_mode_hfunc() {
55 return WorldViewComponent::instance()->get_mode() == WorldViewComponent::INSERT_MODE
;
58 bool zoom_mode_hfunc() {
59 return WorldViewComponent::instance()->get_mode() == WorldViewComponent::ZOOM_MODE
;
62 bool select_mode_hfunc() {
63 return WorldViewComponent::instance()->get_mode() == WorldViewComponent::SELECT_MODE
;
66 bool collider_mode_hfunc() {
67 return WorldViewComponent::instance()->get_mode() == WorldViewComponent::COLLIDER_MODE
;
70 void switch_to_zoom_mode() {
71 WorldViewComponent::instance()->set_mode (WorldViewComponent::ZOOM_MODE
);
74 void switch_to_collider_mode() {
75 WorldViewComponent::instance()->set_mode (WorldViewComponent::COLLIDER_MODE
);
78 void switch_to_select_mode() {
79 WorldViewComponent::instance()->set_mode (WorldViewComponent::SELECT_MODE
);
82 void save_button_callback() {
83 ScreenManager::instance()->set_gui(ScreenManager::SAVE_GUI
);
86 void action_cam_callback() {
87 Controller::instance()->set_action_cam(!Controller::instance()->get_action_cam());
90 void zoom_in_callback() {
91 WorldViewComponent::instance()->wheel_up (graphic_context
->get_width()/2,
92 graphic_context
->get_height()/2);
95 void zoom_out_callback() {
96 WorldViewComponent::instance()->wheel_down (graphic_context
->get_width()/2,
97 graphic_context
->get_height()/2);
101 void hide_dots_callback() {
102 Controller
& c
= *Controller::instance();
103 c
.set_hide_dots(!c
.get_hide_dots());
106 bool hide_dots_hfunc ()
108 return Controller::instance()->get_hide_dots();
111 bool action_cam_hfunc ()
113 return Controller::instance()->get_action_cam();
116 bool show_grid_hfunc()
118 return WorldViewComponent::instance()->uses_grid();
121 void show_grid_callback()
123 WorldViewComponent::instance()->on_grid_press(0, 0);
126 void redo_callback ()
128 return Controller::instance()->redo();
131 void undo_callback ()
133 return Controller::instance()->undo();
136 #define BUTTON_POS(n) (80 + n * 30)
137 #define BUTTON_RPOS(n) (50 + n * 30)
138 #define BUTTON_WIDTH 75
139 #define BUTTON_HEIGHT 25
140 #define BUTTON_LX_POS (graphic_context->get_width() - BUTTON_WIDTH - 10)
142 WorldGUIManager::WorldGUIManager ()
146 add(new WorldViewComponent ());
147 //add(new GUILabel ("Sim:", 10, 50, 10, 10));
148 add(new GUIRunButton ());
149 add(new GUISlowMoButton ());
150 //add(new GUIZoomInButton ());
151 //add(new GUIZoomOutButton ());
152 add(new GUILoadButton ());
153 add(new GUIGenericButton ("Save", 10, BUTTON_POS(10), BUTTON_WIDTH
, BUTTON_HEIGHT
, save_button_callback
));
155 add(new GUIGenericButton ("Undo", 10, BUTTON_POS(6), BUTTON_WIDTH
, BUTTON_HEIGHT
, undo_callback
));
156 add(new GUIGenericButton ("Redo", 10, BUTTON_POS(7), BUTTON_WIDTH
, BUTTON_HEIGHT
, redo_callback
));
158 add(new GUIGenericButton ("ActionCam", 10, BUTTON_POS(2), BUTTON_WIDTH
, BUTTON_HEIGHT
, action_cam_callback
, action_cam_hfunc
));
159 add(new GUIGenericButton ("Hide Dots", 10, BUTTON_POS(3), BUTTON_WIDTH
, BUTTON_HEIGHT
, hide_dots_callback
, hide_dots_hfunc
));
160 add(new GUIGenericButton ("Use Grid", 10, BUTTON_POS(4), BUTTON_WIDTH
, BUTTON_HEIGHT
, show_grid_callback
, show_grid_hfunc
));
161 add(new GUIQuitButton ());
163 //add(new GUILabel ("Tools", BUTTON_LX_POS, BUTTON_POS(3)+5, BUTTON_WIDTH, BUTTON_HEIGHT));
165 add(new GUIGenericButton ("Insert", BUTTON_LX_POS
, BUTTON_RPOS(4), BUTTON_WIDTH
, BUTTON_HEIGHT
, switch_to_insert_mode
, insert_mode_hfunc
));
166 add(new GUIGenericButton ("Select", BUTTON_LX_POS
, BUTTON_RPOS(5), BUTTON_WIDTH
, BUTTON_HEIGHT
, switch_to_select_mode
, select_mode_hfunc
));
167 add(new GUIGenericButton ("Collider", BUTTON_LX_POS
, BUTTON_RPOS(6), BUTTON_WIDTH
, BUTTON_HEIGHT
, switch_to_collider_mode
, collider_mode_hfunc
));
168 add(new GUIGenericButton ("Zoom", BUTTON_LX_POS
, BUTTON_RPOS(7), BUTTON_WIDTH
, BUTTON_HEIGHT
, switch_to_zoom_mode
, zoom_mode_hfunc
));
170 add(new GUIGenericButton ("-", BUTTON_LX_POS
+ 38, BUTTON_RPOS(8), 25, 25, zoom_out_callback
));
171 add(new GUIGenericButton ("+", BUTTON_LX_POS
+ 6, BUTTON_RPOS(8), 25, 25, zoom_in_callback
));
173 // FIXME: Stuff for particle mass and Co. must be implemented in another way
176 add(new GUIGenericButton ("Increase ParticleMass", 650, 220, 140, 25, increase_particle_mass
));
177 add(new GUIGenericButton ("Decrease ParticleMass", 650, 250, 140, 25, decrease_particle_mass
));
179 add(new GUILabel ("Stiffness", 550, 280, 75, 25));
181 add(new GUIGenericButton ("+", BUTTON_LX_POS
, 280, 25, 25, increase_particle_mass
));
182 add(new GUIGenericButton ("-", 680, 280, 25, 25, decrease_particle_mass
));
184 add(new GUIGenericButton ("+", 650, 280, 25, 25, increase_particle_mass
));
185 add(new GUIGenericButton ("-", 680, 280, 25, 25, decrease_particle_mass
));
187 //add(new GUIWindow ("Test Window", 200, 100, 200, 90));
190 GUIWindow* window = new GUIWindow ("Window Title", 300, 100, 300, 400);
191 window->add (new GUIButton ("Testbutton", 10, 10, 100, 25));
196 WorldGUIManager::~WorldGUIManager ()
201 WorldGUIManager::update()
203 Controller::instance()->update ();
207 WorldGUIManager::draw_overlay ()
209 graphic_context
->draw_string (10, 20, " [1-9] - quick save");
210 graphic_context
->draw_string (10, 32, "[shift 1-9] - quick load");
211 graphic_context
->draw_string (10, 44, " [space] - run simulation");
212 graphic_context
->draw_string (10, 56, " [tab] - toggle slow motion");
213 graphic_context
->draw_string (10, 68, " [F11] - toggle fullscreen");
215 graphic_context
->draw_string (200, 20, " [c] - clear scene");
216 graphic_context
->draw_string (200, 32, " [u] - undo to last state");
217 graphic_context
->draw_string (200, 44, " [r] - redo (undo an undo)");
218 graphic_context
->draw_string (200, 56, " [+/-] - zoom in/out");
219 graphic_context
->draw_string (200, 68, " [g] - toggle grid");
221 graphic_context
->draw_string (600, 32, "[middle] - scroll");
223 switch (WorldViewComponent::instance()->get_mode())
225 case WorldViewComponent::INSERT_MODE
:
226 graphic_context
->draw_string (600, 20, " [left] - insert/connect spots");
227 graphic_context
->draw_string (600, 44, " [right] - remove spot");
228 graphic_context
->draw_string (400, 20, " [f] - fix current dot");
231 case WorldViewComponent::SELECT_MODE
:
232 graphic_context
->draw_string (600, 20, " [left] - create/move selection");
233 graphic_context
->draw_string (600, 44, " [right] - rotate selection");
235 graphic_context
->draw_string (400, 20, " [v] - set velocity");
236 graphic_context
->draw_string (400, 32, " [d] - duplicate selection");
237 graphic_context
->draw_string (400, 44, " [h] - flip selection");
238 graphic_context
->draw_string (400, 56, " [f] - fix selection");
239 graphic_context
->draw_string (400, 68, " [j] - join dots");
240 graphic_context
->draw_string (400, 80, " [s] - scale selection");
243 case WorldViewComponent::ZOOM_MODE
:
244 graphic_context
->draw_string (600, 20, " [left] - zoom into region");
245 graphic_context
->draw_string (600, 44, " [right] - zoom out");
248 case WorldViewComponent::COLLIDER_MODE
:
249 graphic_context
->draw_string (600, 20, " [left] - create/move collider");
250 graphic_context
->draw_string (600, 44, " [right] - remove collider");
257 World
& world
= *Controller::instance()->get_world ();
259 /*graphic_context->draw_string (600, 430, "Particles Mass: ");
260 graphic_context->draw_string (BUTTON_LX_POS, 430,
261 to_string(WorldViewComponent::instance()->get_insert_tool()->get_particle_mass ()));
263 int bottom_line
= graphic_context
->get_height() - 10;
264 graphic_context
->draw_string (10, bottom_line
-20, "FPS: ");
265 graphic_context
->draw_string (80, bottom_line
-20, to_string(current_fps
));
267 graphic_context
->draw_string (10, bottom_line
, "Pos: ");
268 graphic_context
->draw_string (80, bottom_line
,
269 to_string(WorldViewComponent::instance()->get_gc()->screen_to_world(input_context
->get_mouse_pos())));
271 graphic_context
->draw_string (210, bottom_line
-20, "Particles: ");
272 graphic_context
->draw_string (280, bottom_line
-20, to_string(world
.get_num_particles()));
274 graphic_context
->draw_string (210, bottom_line
, "Springs: ");
275 graphic_context
->draw_string (280, bottom_line
, to_string(world
.get_num_springs()));
277 graphic_context
->draw_string (410, bottom_line
, "Zoom: ");
278 graphic_context
->draw_string (480, bottom_line
, to_string(WorldViewComponent::instance()->get_zoom()));
280 graphic_context
->draw_string (610, bottom_line
, "..:: Construo V"VERSION
" ::..");
281 //graphic_context->draw_string (680, bottom_line, to_string(WorldViewComponent::instance()->get_zoom()));