Welcome to the NetCologne GmbH open source mirroring service!

This machine mirrors various open-source projects. 20 Gbit/s uplink.

If there are any issues or you want another project mirrored, please contact mirror-service -=AT=- netcologne DOT de !

world_gui_manager.cxx Source File
Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

world_gui_manager.cxx

Go to the documentation of this file.
00001 //  $Id: world_gui_manager.cxx,v 1.6 2003/01/11 19:07:48 grumbel Exp $
00002 //
00003 //  Construo - A wire-frame construction gamee
00004 //  Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #include <config.h>
00021 #include "controller.hxx"
00022 #include "construo.hxx"
00023 #include "graphic_context.hxx"
00024 #include "worldview_component.hxx"
00025 #include "string_utils.hxx"
00026 #include "worldview_insert_tool.hxx"
00027 #include "gui_buttons.hxx"
00028 #include "gui_window.hxx"
00029 #include "gui_label.hxx"
00030 #include "globals.hxx"
00031 #include "screen_manager.hxx"
00032 #include "world_gui_manager.hxx"
00033 
00034 using namespace StringUtils;
00035 
00036 WorldGUIManager* WorldGUIManager::instance_ = 0;
00037 
00038 
00039 void increase_particle_mass() {
00040   WorldViewInsertTool& wc = *WorldViewComponent::instance()->get_insert_tool();
00041   wc.set_particle_mass(wc.get_particle_mass() + 1.0f);
00042 }
00043 
00044 void decrease_particle_mass() {
00045   WorldViewInsertTool& wc = *WorldViewComponent::instance()->get_insert_tool();
00046   wc.set_particle_mass(wc.get_particle_mass() - 1.0f);
00047 }
00048 
00049 void switch_to_insert_mode() {
00050   WorldViewComponent::instance()->set_mode (WorldViewComponent::INSERT_MODE);
00051 }
00052 
00053 bool insert_mode_hfunc() {
00054   return WorldViewComponent::instance()->get_mode() == WorldViewComponent::INSERT_MODE;
00055 }
00056 
00057 bool zoom_mode_hfunc() {
00058   return WorldViewComponent::instance()->get_mode() == WorldViewComponent::ZOOM_MODE;
00059 }
00060 
00061 bool select_mode_hfunc() {
00062   return WorldViewComponent::instance()->get_mode() == WorldViewComponent::SELECT_MODE;
00063 }
00064 
00065 bool collider_mode_hfunc() {
00066   return WorldViewComponent::instance()->get_mode() == WorldViewComponent::COLLIDER_MODE;
00067 }
00068 
00069 void switch_to_zoom_mode() {
00070   WorldViewComponent::instance()->set_mode (WorldViewComponent::ZOOM_MODE);
00071 }
00072 
00073 void switch_to_collider_mode() {
00074   WorldViewComponent::instance()->set_mode (WorldViewComponent::COLLIDER_MODE);
00075 }
00076 
00077 void switch_to_select_mode() {
00078   WorldViewComponent::instance()->set_mode (WorldViewComponent::SELECT_MODE);
00079 }
00080 
00081 void save_button_callback() {
00082   ScreenManager::instance()->set_gui(ScreenManager::SAVE_GUI);
00083 }
00084 
00085 void action_cam_callback() {
00086   Controller::instance()->set_action_cam(!Controller::instance()->get_action_cam());
00087 }
00088 
00089 void zoom_in_callback() {
00090   WorldViewComponent::instance()->wheel_up (graphic_context->get_width()/2,
00091                                             graphic_context->get_height()/2);
00092 }
00093 
00094 void zoom_out_callback() {
00095   WorldViewComponent::instance()->wheel_down (graphic_context->get_width()/2,
00096                                               graphic_context->get_height()/2);
00097 
00098 }
00099 
00100 void hide_dots_callback() {
00101   Controller& c = *Controller::instance();
00102   c.set_hide_dots(!c.get_hide_dots());
00103 }
00104 
00105 bool hide_dots_hfunc ()
00106 {
00107   return Controller::instance()->get_hide_dots();
00108 }
00109 
00110 bool action_cam_hfunc ()
00111 {
00112   return Controller::instance()->get_action_cam();
00113 }
00114 
00115 void redo_callback ()
00116 {
00117   return Controller::instance()->redo();
00118 }
00119 
00120 void undo_callback ()
00121 {
00122   return Controller::instance()->undo();
00123 }
00124 
00125 #define BUTTON_POS(n) (75 + n * 30)
00126 #define BUTTON_RPOS(n) (50 + n * 30)
00127 #define BUTTON_WIDTH  75
00128 #define BUTTON_HEIGHT 25
00129 #define BUTTON_LX_POS (graphic_context->get_width() - BUTTON_WIDTH - 10)
00130 
00131 WorldGUIManager::WorldGUIManager ()
00132 {
00133   instance_  = this;
00134 
00135   add(new WorldViewComponent ());
00136   //add(new GUILabel ("Sim:", 10, 50, 10, 10));
00137   add(new GUIRunButton ());
00138   add(new GUISlowMoButton  ());
00139   //add(new GUIZoomInButton ());
00140   //add(new GUIZoomOutButton ());
00141   add(new GUILoadButton ());
00142   add(new GUIGenericButton ("Save", 10, BUTTON_POS(9), BUTTON_WIDTH, BUTTON_HEIGHT, save_button_callback));
00143 
00144   add(new GUIGenericButton ("Undo", 10, BUTTON_POS(5), BUTTON_WIDTH, BUTTON_HEIGHT, undo_callback));
00145   add(new GUIGenericButton ("Redo", 10, BUTTON_POS(6), BUTTON_WIDTH, BUTTON_HEIGHT, redo_callback));
00146 
00147   add(new GUIGenericButton ("ActionCam", 10, BUTTON_POS(2), BUTTON_WIDTH, BUTTON_HEIGHT, action_cam_callback, action_cam_hfunc));
00148   add(new GUIGenericButton ("Hide Dots", 10, BUTTON_POS(3), BUTTON_WIDTH, BUTTON_HEIGHT, hide_dots_callback, hide_dots_hfunc));
00149   add(new GUIQuitButton ());
00150 
00151   //add(new GUILabel ("Tools", BUTTON_LX_POS, BUTTON_POS(3)+5, BUTTON_WIDTH, BUTTON_HEIGHT));
00152 
00153   add(new GUIGenericButton ("Insert", BUTTON_LX_POS, BUTTON_RPOS(4), BUTTON_WIDTH, BUTTON_HEIGHT, switch_to_insert_mode, insert_mode_hfunc));
00154   add(new GUIGenericButton ("Select", BUTTON_LX_POS, BUTTON_RPOS(5), BUTTON_WIDTH, BUTTON_HEIGHT, switch_to_select_mode, select_mode_hfunc));
00155   add(new GUIGenericButton ("Collider",   BUTTON_LX_POS, BUTTON_RPOS(6), BUTTON_WIDTH, BUTTON_HEIGHT, switch_to_collider_mode, collider_mode_hfunc));
00156   add(new GUIGenericButton ("Zoom",   BUTTON_LX_POS, BUTTON_RPOS(7), BUTTON_WIDTH, BUTTON_HEIGHT, switch_to_zoom_mode, zoom_mode_hfunc));
00157 
00158   add(new GUIGenericButton ("-", BUTTON_LX_POS + 38, BUTTON_RPOS(8), 25, 25, zoom_out_callback));
00159   add(new GUIGenericButton ("+", BUTTON_LX_POS +  6, BUTTON_RPOS(8), 25, 25, zoom_in_callback));
00160 
00161   if(0)
00162     {
00163   add(new GUIGenericButton ("Increase ParticleMass",   650, 220, 140, 25, increase_particle_mass));
00164   add(new GUIGenericButton ("Decrease ParticleMass",   650, 250, 140, 25, decrease_particle_mass));
00165 
00166   add(new GUILabel ("Stiffness",   550, 280, 75, 25));
00167 
00168   add(new GUIGenericButton ("+",   BUTTON_LX_POS, 280, 25, 25, increase_particle_mass));
00169   add(new GUIGenericButton ("-",   680, 280, 25, 25, decrease_particle_mass));
00170 
00171   add(new GUIGenericButton ("+",   650, 280, 25, 25, increase_particle_mass));
00172   add(new GUIGenericButton ("-",   680, 280, 25, 25, decrease_particle_mass));
00173     }
00174   //add(new GUIWindow ("Test Window",   200, 100, 200, 90));
00175  
00176   /*
00177     GUIWindow* window = new GUIWindow ("Window Title", 300, 100, 300, 400);
00178     window->add (new GUIButton ("Testbutton", 10, 10, 100, 25));
00179     add (window);
00180   */
00181 }
00182 
00183 WorldGUIManager::~WorldGUIManager ()
00184 {
00185 }
00186 
00187 void
00188 WorldGUIManager::update()
00189 {
00190   Controller::instance()->update ();
00191 }
00192 
00193 void
00194 WorldGUIManager::draw_overlay ()
00195 {
00196   graphic_context->draw_string (10, 20, "      [1-9] - quick save");
00197   graphic_context->draw_string (10, 32, "[shift 1-9] - quick load");
00198   graphic_context->draw_string (10, 44, "    [space] - run simulation");
00199   graphic_context->draw_string (10, 56, "      [tab] - toggle slow motion");
00200 
00201   graphic_context->draw_string (200,  20, "     [c] - clear scene");
00202   graphic_context->draw_string (200,  32, "     [u] - undo to last state");
00203   graphic_context->draw_string (200,  44, "     [r] - redo (undo an undo)");
00204   graphic_context->draw_string (200,  56, "   [+/-] - zoom in/out");
00205 
00206 
00207   graphic_context->draw_string (600,  32, "[middle] - scroll");
00208 
00209   switch (WorldViewComponent::instance()->get_mode())
00210     {
00211     case WorldViewComponent::INSERT_MODE:
00212       graphic_context->draw_string (600,  20, "  [left] - insert/connect spots");
00213       graphic_context->draw_string (600,  44, " [right] - remove spot");
00214       graphic_context->draw_string (400,  20, "     [f] - fix current dot");
00215       break;
00216 
00217     case WorldViewComponent::SELECT_MODE:
00218       graphic_context->draw_string (600,  20, "  [left] - create/move selection");
00219       graphic_context->draw_string (600,  44, " [right] - rotate selection");
00220       graphic_context->draw_string (400,  20, "     [v] - set velocity");
00221       graphic_context->draw_string (400,  32, "     [d] - duplicate selection");
00222       graphic_context->draw_string (400,  44, "     [h] - flip selection");
00223       graphic_context->draw_string (400,  56, "     [f] - fix selection");
00224       break;
00225       
00226     case WorldViewComponent::ZOOM_MODE:
00227       graphic_context->draw_string (600,  20, "  [left] - zoom into region");
00228       break;
00229 
00230     case WorldViewComponent::COLLIDER_MODE:
00231       graphic_context->draw_string (600,  20, "  [left] - create/move collider");
00232       graphic_context->draw_string (600,  44, " [right] - remove collider");
00233       break;
00234 
00235     default:
00236       break;
00237     }
00238 
00239   World& world = *Controller::instance()->get_world ();
00240 
00241   /*graphic_context->draw_string (600,  430, "Particles Mass: ");
00242   graphic_context->draw_string (BUTTON_LX_POS,  430, 
00243                                 to_string(WorldViewComponent::instance()->get_insert_tool()->get_particle_mass ()));
00244   */
00245   int bottom_line = graphic_context->get_height() - 10;
00246   graphic_context->draw_string (10, bottom_line-20, "FPS: ");
00247   graphic_context->draw_string (80, bottom_line-20, to_string(current_fps));
00248 
00249   graphic_context->draw_string (10, bottom_line, "Pos: ");
00250   graphic_context->draw_string (80, bottom_line, 
00251                                 to_string(WorldViewComponent::instance()->get_gc()->screen_to_world(input_context->get_mouse_pos())));
00252 
00253   graphic_context->draw_string (210, bottom_line-20, "Particles: ");
00254   graphic_context->draw_string (280, bottom_line-20, to_string(world.get_num_particles()));
00255 
00256   graphic_context->draw_string (210, bottom_line, "Springs: ");
00257   graphic_context->draw_string (280, bottom_line, to_string(world.get_num_springs()));
00258 
00259   graphic_context->draw_string (410, bottom_line, "Zoom: ");
00260   graphic_context->draw_string (480, bottom_line, to_string(WorldViewComponent::instance()->get_zoom()));
00261 
00262   graphic_context->draw_string (610, bottom_line, "..:: Construo V"VERSION" ::..");
00263   //graphic_context->draw_string (680, bottom_line, to_string(WorldViewComponent::instance()->get_zoom()));
00264 }
00265 
00266 /* EOF */

Generated on Thu Jul 24 10:24:31 2003 for Construo by doxygen1.3-rc3