[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r3446 - in trunk/pingus: . src/editor
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r3446 - in trunk/pingus: . src/editor |
Date: |
Thu, 1 Nov 2007 09:18:06 +0100 |
Author: grumbel
Date: 2007-11-01 09:18:05 +0100 (Thu, 01 Nov 2007)
New Revision: 3446
Added:
trunk/pingus/src/editor/viewport.cpp
trunk/pingus/src/editor/viewport.hpp
Removed:
trunk/pingus/src/editor/editor_viewport.cpp
trunk/pingus/src/editor/editor_viewport.hpp
Modified:
trunk/pingus/SConstruct
trunk/pingus/src/editor/context_menu.cpp
trunk/pingus/src/editor/context_menu.hpp
trunk/pingus/src/editor/editor_screen.cpp
trunk/pingus/src/editor/editor_screen.hpp
Log:
- renamed EditorViewport to Viewport
Modified: trunk/pingus/SConstruct
===================================================================
--- trunk/pingus/SConstruct 2007-11-01 08:15:27 UTC (rev 3445)
+++ trunk/pingus/SConstruct 2007-11-01 08:18:05 UTC (rev 3446)
@@ -82,7 +82,6 @@
'src/editor/button.cpp',
'src/editor/gui_style.cpp',
-'src/editor/context_menu.cpp',
'src/editor/checkbox.cpp',
'src/editor/editor_level.cpp',
'src/editor/panel.cpp',
@@ -92,7 +91,7 @@
'src/editor/editor_screen.cpp',
'src/editor/combobox.cpp',
'src/editor/minimap.cpp',
-'src/editor/editor_viewport.cpp',
+'src/editor/viewport.cpp',
'src/editor/level_objs.cpp',
'src/editor/inputbox.cpp',
'src/editor/object_selector.cpp',
Modified: trunk/pingus/src/editor/context_menu.cpp
===================================================================
--- trunk/pingus/src/editor/context_menu.cpp 2007-11-01 08:15:27 UTC (rev
3445)
+++ trunk/pingus/src/editor/context_menu.cpp 2007-11-01 08:18:05 UTC (rev
3446)
@@ -29,7 +29,7 @@
namespace Editor {
// Determine which actions are available for these objects
-ContextMenu::ContextMenu(std::vector<LevelObj*> o, Vector2i p, EditorViewport*
vp, bool base_menu)
+ContextMenu::ContextMenu(std::vector<LevelObj*> o, Vector2i p, Viewport* vp,
bool base_menu)
: objs(o),
viewport(vp),
pos(p),
Modified: trunk/pingus/src/editor/context_menu.hpp
===================================================================
--- trunk/pingus/src/editor/context_menu.hpp 2007-11-01 08:15:27 UTC (rev
3445)
+++ trunk/pingus/src/editor/context_menu.hpp 2007-11-01 08:18:05 UTC (rev
3446)
@@ -29,7 +29,7 @@
namespace Editor {
class LevelObj;
-class EditorViewport;
+class Viewport;
class ContextMenu;
typedef enum ItemModifier { REMOVE, ROTATE, SET_OWNER, SET_DIRECTION,
@@ -61,7 +61,7 @@
std::vector<LevelObj*> objs;
/** Viewport to which this menu belongs */
- EditorViewport* viewport;
+ Viewport* viewport;
/** List of actions available in this menu */
std::vector<ContextItem> actions;
@@ -92,7 +92,7 @@
public:
// Constructor
- ContextMenu (std::vector<LevelObj*>, Vector2i p, EditorViewport* v, bool
base_menu = true);
+ ContextMenu (std::vector<LevelObj*>, Vector2i p, Viewport* v, bool base_menu
= true);
// Desctructor
~ContextMenu ();
Modified: trunk/pingus/src/editor/editor_screen.cpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.cpp 2007-11-01 08:15:27 UTC (rev
3445)
+++ trunk/pingus/src/editor/editor_screen.cpp 2007-11-01 08:18:05 UTC (rev
3446)
@@ -57,7 +57,7 @@
show_help(false)
{
// Create the viewport for the images and data
- viewport = new EditorViewport(this, Rect(0, 38,
+ viewport = new Viewport(this, Rect(0, 38,
Display::get_width() - 244,
Display::get_height()));
gui_manager->add(viewport, true);
Modified: trunk/pingus/src/editor/editor_screen.hpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.hpp 2007-11-01 08:15:27 UTC (rev
3445)
+++ trunk/pingus/src/editor/editor_screen.hpp 2007-11-01 08:18:05 UTC (rev
3446)
@@ -35,7 +35,7 @@
class EditorLevel;
class LevelObj;
class Panel;
-class EditorViewport;
+class Viewport;
class ObjectSelector;
class ObjectProperties;
class ActionProperties;
@@ -51,7 +51,7 @@
Pathname level_pathname;
Panel* panel;
- EditorViewport* viewport;
+ Viewport* viewport;
ObjectSelector* object_selector;
Minimap* minimap;
ObjectProperties* object_properties;
@@ -86,12 +86,12 @@
GUI::GUIManager* get_gui_manager() const { return gui_manager; }
/** Return the viewport */
- EditorViewport* get_viewport() const { return viewport; }
+ Viewport* get_viewport() const { return viewport; }
/** Return a pointer to the current level */
EditorLevel* get_level() const { return plf; }
- /** Add an object to both the EditorLevel and the EditorViewport */
+ /** Add an object to both the EditorLevel and the Viewport */
void add_object(LevelObj* obj);
void add_objects(std::vector<LevelObj*> objs);
Deleted: trunk/pingus/src/editor/editor_viewport.cpp
===================================================================
--- trunk/pingus/src/editor/editor_viewport.cpp 2007-11-01 08:15:27 UTC (rev
3445)
+++ trunk/pingus/src/editor/editor_viewport.cpp 2007-11-01 08:18:05 UTC (rev
3446)
@@ -1,546 +0,0 @@
-// $Id$
-//
-// Pingus - A free Lemmings clone
-// Copyright (C) 2007 Jason Green <address@hidden>,
-// Ingo Ruhnke <address@hidden>
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-#include <vector>
-#include <string>
-#include <iostream>
-#include "../gui/gui_manager.hpp"
-#include "../display/display.hpp"
-#include "../display/drawing_context.hpp"
-#include "../math/vector3f.hpp"
-#include "../graphic_context_state.hpp"
-#include "editor_level.hpp"
-#include "editor_screen.hpp"
-#include "editor_viewport.hpp"
-#include "level_objs.hpp"
-
-namespace Editor {
-
-// Constructor
-EditorViewport::EditorViewport(EditorScreen* e, const Rect& rect_)
- : RectComponent(rect_),
- state(rect.get_width(), rect.get_height()),
- drawing_context(new DrawingContext(rect)),
- editor(e),
- autoscroll(false),
- highlighted_area(0,0,0,0),
- snap_to(false),
- current_action(NOTHING)
-{
-}
-
-// Destructor
-EditorViewport::~EditorViewport ()
-{
- delete drawing_context;
-}
-
-void
-EditorViewport::on_secondary_button_press(int x_, int y_)
-{
- mouse_world_pos = screen2world(x_, y_);
- mouse_screen_pos = Vector2i(x_, y_);
-
- if (current_action == NOTHING)
- {
- drag_screen_pos = mouse_screen_pos;
- current_action = SCROLLING;
- }
-}
-
-void
-EditorViewport::on_secondary_button_release(int x_, int y_)
-{
- mouse_world_pos = screen2world(x_, y_);
- mouse_screen_pos = Vector2i(x_, y_);
-
- if (current_action == SCROLLING)
- current_action = NOTHING;
-}
-
-// When someone right-clicks inside the viewport
-void
-EditorViewport::on_secondary_button_click(int x_, int y_)
-{
- mouse_world_pos = screen2world(x_, y_);
- mouse_screen_pos = Vector2i(x_, y_);
-}
-
-// Select 1 or more LevelObjs, or drag them.
-void
-EditorViewport::on_primary_button_press(int x_, int y_)
-{
- mouse_world_pos = screen2world(x_, y_);
- mouse_screen_pos = Vector2i(x_, y_);
-
- if (current_action == NOTHING)
- {
- LevelObj* obj = editor->get_level()->object_at(mouse_world_pos.x,
mouse_world_pos.y);
-
- if (obj)
- {
- // If the currently selected object isn't selected, select it and
deselect the rest
- if (!obj->is_selected())
- {
- clear_selection();
- obj->select();
- selected_objs.push_back(obj);
-
- selection_changed(selected_objs);
- }
-
- for (unsigned i = 0; i < selected_objs.size(); i++)
- selected_objs[i]->set_orig_pos(selected_objs[i]->get_pos());
-
- // Allow dragging of the currently selected objects
- current_action = DRAGGING;
- drag_world_pos = mouse_world_pos;
- }
- else
- {
- current_action = HIGHLIGHTING;
- highlighted_area.left = highlighted_area.right = mouse_world_pos.x;
- highlighted_area.top = highlighted_area.bottom = mouse_world_pos.y;
-
- clear_selection();
-
- selection_changed(selected_objs);
- }
- }
-}
-
-void
-EditorViewport::on_primary_button_release(int x_, int y_)
-{
- mouse_world_pos = screen2world(x_, y_);
- mouse_screen_pos = Vector2i(x_, y_);
-
- if (current_action == HIGHLIGHTING)
- {
- highlighted_area.normalize();
- for (unsigned i = 0; i < get_objects()->size(); i++)
- {
- if
(highlighted_area.is_inside(Vector2i(int((*get_objects())[i]->get_pos().x),
-
int((*get_objects())[i]->get_pos().y))))
- {
- selected_objs.push_back((*get_objects())[i]);
- (*get_objects())[i]->select();
- }
- else
- (*get_objects())[i]->unselect();
- }
-
- selection_changed(selected_objs);
- }
- else if (current_action == DRAGGING)
- {
- // Set the objects' positions for good
- for (unsigned i = 0; i < (*get_objects()).size(); i++)
- (*get_objects())[i]->set_orig_pos((*get_objects())[i]->get_pos());
- }
- current_action = NOTHING;
-}
-
-void
-EditorViewport::on_pointer_move(int x_, int y_)
-{
- mouse_world_pos = screen2world(x_, y_);
- mouse_screen_pos = Vector2i(x_, y_);
-
- switch(current_action)
- {
- case HIGHLIGHTING:
- highlighted_area.right = mouse_world_pos.x;
- highlighted_area.bottom = mouse_world_pos.y;
- break;
-
- case DRAGGING:
- {
- float new_x, new_y;
-
- for (unsigned i = 0; i < selected_objs.size(); i++)
- {
- Vector3f orig_pos(selected_objs[i]->get_orig_pos());
- float x_offset = (float)(mouse_world_pos.x - drag_world_pos.x);
- float y_offset = (float)(mouse_world_pos.y - drag_world_pos.y);
-
- if (snap_to)
- {
- // FIXME: May need to adjust the snap-to offset here.
- new_x = (float)((int)((x_offset + orig_pos.x) / 10) * 10);
- new_y = (float)((int)((y_offset + orig_pos.y) / 10) * 10);
- }
- else
- {
- new_x = x_offset + orig_pos.x;
- new_y = y_offset + orig_pos.y;
- }
- selected_objs[i]->set_pos(Vector3f(new_x, new_y, orig_pos.z));
- }
- }
- break;
-
- case SCROLLING:
- break;
-
- case NOTHING:
- break;
- }
-}
-
-void
-EditorViewport::on_key_pressed(const unsigned short c)
-{
- if (c < 256)
- {
- switch(c)
- {
- case 'A':
- clear_selection();
- selection_changed(selected_objs);
- break;
-
- case 'a':
- if (selected_objs == (*get_objects()))
- {
- clear_selection();
- }
- else
- {
- clear_selection();
- selected_objs = (*get_objects());
- for (unsigned i = 0; i < selected_objs.size(); i++)
- selected_objs[i]->select();
- }
- selection_changed(selected_objs);
- break;
-
- case ']':
- case 'w':
- raise_objects();
- break;
-
- case '}':
- case 'W':
- raise_objects_to_top();
- break;
-
- case '{':
- case 'S':
- lower_objects_to_bottom();
- break;
-
- case '[':
- case 's':
- lower_objects();
- break;
-
- case 'r':
- rotate_90_selected_objects();
- break;
-
- case 'R':
- rotate_270_selected_objects();
- break;
-
- case 8: // backspace
- case 127: // delete
- delete_selected_objects();
- break;
-
- case 'd':
- duplicate_selected_objects();
- break;
-
- case 'V':
- case 'f':
- hflip_selected_objects();
- break;
-
- case 'F':
- case 'v':
- vflip_selected_objects();
- break;
-
- case 'c': // dvorak-up
- case 'i': // up
- move_objects(Vector2i(0,-1));
- break;
-
- case 't': // dvorak-down
- case 'k': // down
- move_objects(Vector2i(0,1));
- break;
-
- case 'h': // dvorak-left
- case 'j': // left
- move_objects(Vector2i(-1,0));
- break;
-
- case 'n': // dvorak-right
- case 'l': // right
- move_objects(Vector2i(1,0));
- break;
-
- default:
- std::cout << "EditorViewport::on_key_pressed: " << int(c) << " "
<< (char)c << std::endl;
- break;
- }
- }
-}
-
-// Draws all of the objects in the viewport and the background (if any)
-void
-EditorViewport::draw(DrawingContext &gc)
-{
- drawing_context->clear();
- drawing_context->fill_screen(Color(155,0,155));
- state.push(*drawing_context);
-
- // Level border
- drawing_context->draw_rect(Rect(Vector2i(0,0),
editor->get_level()->get_size()), Color(255,255,255), 5000.0f);
- drawing_context->draw_rect(Rect(Vector2i(0,0),
editor->get_level()->get_size()).grow(1), Color(0,0,0), 5000.0f);
-
- // Safe area
- drawing_context->draw_rect(Rect(Vector2i(0,0),
editor->get_level()->get_size()).grow(-100), Color(155,155,155), 5000.0f);
-
- // Draw the level objects
- for (unsigned i = 0; i < (*get_objects()).size(); i++)
- (*get_objects())[i]->draw(*drawing_context);
-
- if (current_action == HIGHLIGHTING)
- {
- drawing_context->draw_fillrect(highlighted_area, Color(155,200,255,
100), 1000.0f);
- drawing_context->draw_rect(highlighted_area, Color(155,200,255),
1000.0f);
- }
-
- state.pop(*drawing_context);
- gc.draw(*drawing_context, -150);
-}
-
-// Returns true if the viewport is at the x,y coordinate
-bool
-EditorViewport::is_at(int x, int y)
-{
- return drawing_context->get_rect().is_inside(Vector2i(x,y));
-}
-
-void
-EditorViewport::update(float delta)
-{
- UNUSED_ARG(delta);
-
- if (current_action == SCROLLING)
- state.set_pos(state.get_pos() + Vector2f(mouse_screen_pos -
drag_screen_pos) * delta * 5.0f);
-
- // Autoscroll if necessary
- if (autoscroll)
- {
- const int autoscroll_border = 10;
- if (autoscroll)
- {
- if (mouse_screen_pos.x < autoscroll_border)
- state.set_pos(state.get_pos() - Vector2f(5, 0));
- else if (Display::get_width() - mouse_screen_pos.x <
autoscroll_border)
- state.set_pos(state.get_pos() + Vector2f(5, 0));
- else if (mouse_screen_pos.y < autoscroll_border)
- state.set_pos(state.get_pos() - Vector2f(0, 5));
- else if (Display::get_height() - mouse_screen_pos.y <
autoscroll_border)
- state.set_pos(state.get_pos() + Vector2f(0, 5));
- }
- }
-}
-
-void
-EditorViewport::refresh()
-{
- state.set_limit(Rect(Vector2i(0,0),
editor->get_level()->get_size()).grow(256));
- //std::cout << editor->get_level()->get_size().width << ", "
- //<< editor->get_level()->get_size().height
- // << std::endl;
-}
-
-void
-EditorViewport::duplicate_selected_objects()
-{
- std::vector<LevelObj*> new_objs;
- for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
- {
- LevelObj* clone = (*i)->duplicate(Vector2i(32, 32));
- if (clone)
- {
- new_objs.push_back(clone);
- (*get_objects()).push_back(clone);
- clone->select();
- }
- }
-
- clear_selection();
- selected_objs = new_objs;
- selection_changed(selected_objs);
-}
-
-void
-EditorViewport::delete_selected_objects()
-{
- for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
- (*i)->remove();
-
- (*get_objects()).erase(std::remove_if((*get_objects()).begin(),
(*get_objects()).end(), boost::mem_fn(&LevelObj::is_removed)),
- (*get_objects()).end());
-
- for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
- delete (*i);
-
- selected_objs.clear();
- selection_changed(selected_objs);
-}
-
-void
-EditorViewport::hflip_selected_objects()
-{
- for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
- {
-
(*i)->set_modifier(ResourceModifierNS::horizontal_flip((*i)->get_modifier()));
- }
-}
-
-void
-EditorViewport::vflip_selected_objects()
-{
- for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
- {
-
(*i)->set_modifier(ResourceModifierNS::vertical_flip((*i)->get_modifier()));
- }
-}
-
-void
-EditorViewport::rotate_90_selected_objects()
-{
- for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
- {
- (*i)->set_modifier(ResourceModifierNS::rotate_90((*i)->get_modifier()));
- }
-}
-
-void
-EditorViewport::rotate_270_selected_objects()
-{
- for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
- {
- (*i)->set_modifier(ResourceModifierNS::rotate_270((*i)->get_modifier()));
- }
-}
-
-Vector2i
-EditorViewport::screen2world(int x, int y) const
-{
- return
Vector2i(state.screen2world(drawing_context->screen_to_world(Vector2i(x, y))));
-}
-
-void
-EditorViewport::raise_objects()
-{
- for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
- {
- editor->get_level()->raise_object(*i);
- }
-}
-
-void
-EditorViewport::lower_objects()
-{
- for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
- {
- editor->get_level()->lower_object(*i);
- }
-}
-
-void
-EditorViewport::raise_objects_to_top()
-{
- for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
- editor->get_level()->raise_object_to_top(*i);
-}
-
-void
-EditorViewport::lower_objects_to_bottom()
-{
- for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
- editor->get_level()->lower_object_to_bottom(*i);
-}
-
-void
-EditorViewport::update_layout()
-{
- state.set_size(rect.get_width(), rect.get_height());
- drawing_context->set_rect(rect);
-}
-
-void
-EditorViewport::clear_selection()
-{
- for (unsigned i = 0; i < selected_objs.size(); i++)
- selected_objs[i]->unselect();
-
- selected_objs.clear();
-}
-
-void
-EditorViewport::move_objects(const Vector2i& offset)
-{
- for (unsigned i = 0; i < selected_objs.size(); i++)
- {
- Vector3f p = selected_objs[i]->get_pos();
- selected_objs[i]->set_pos(Vector3f(p.x + offset.x, p.y + offset.y, p.z));
- }
-}
-
-void
-EditorViewport::clear()
-{
- selected_objs.clear();
- for(std::vector<LevelObj*>::iterator i = (*get_objects()).begin(); i !=
(*get_objects()).end(); ++i)
- delete *i;
- (*get_objects()).clear();
- selection_changed(selected_objs);
-}
-
-Vector2f
-EditorViewport::get_scroll_pos() const
-{
- return state.get_pos();
-}
-
-void
-EditorViewport::set_scroll_pos(const Vector2f& pos)
-{
- state.set_pos(pos);
-}
-
-std::vector<LevelObj*>*
-EditorViewport::get_objects()
-{
- return editor->get_level()->get_objects();
-}
-
-} // namespace Editor
-
-/* EOF */
Deleted: trunk/pingus/src/editor/editor_viewport.hpp
===================================================================
--- trunk/pingus/src/editor/editor_viewport.hpp 2007-11-01 08:15:27 UTC (rev
3445)
+++ trunk/pingus/src/editor/editor_viewport.hpp 2007-11-01 08:18:05 UTC (rev
3446)
@@ -1,160 +0,0 @@
-// $Id$
-//
-// Pingus - A free Lemmings clone
-// Copyright (C) 2007 Jason Green <address@hidden>,
-// Ingo Ruhnke <address@hidden>
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-#ifndef HEADER_PINGUS_EDITOR_VIEWPORT_HXX
-#define HEADER_PINGUS_EDITOR_VIEWPORT_HXX
-
-#include "../gui/rect_component.hpp"
-#include "../graphic_context_state.hpp"
-#include <boost/signal.hpp>
-#include <vector>
-#include <string>
-
-class Vector3f;
-class DrawingContext;
-class SceneContext;
-
-namespace Editor {
-
-class LevelObj;
-class EditorScreen;
-class ContextMenu;
-
-/** This class is where the actual level graphics will display in the
- level editor. Objects can be added, deleted, moved, modified, etc.
- inside of the EditorViewport */
-class EditorViewport : public GUI::RectComponent
-{
-private:
- GraphicContextState state;
- DrawingContext* drawing_context;
-
- /** The EditorScreen to which this viewport belongs */
- EditorScreen* editor;
-
-
- /** Whether or not Autoscrolling is turned on */
- bool autoscroll;
-
- /** Where the mouse is right now - used for autoscrolling */
- Vector2i mouse_world_pos;
- Vector2i mouse_screen_pos;
-
- /** Where the mouse started dragging from */
- Vector2i drag_world_pos;
- Vector2i drag_screen_pos;
-
- /** The currently selected LevelObjs */
- std::vector<LevelObj*> selected_objs;
-
- /** The region that is currently highlighted */
- Rect highlighted_area;
-
- /** There should only be 0 or 1 context menus on the screen */
- ContextMenu* context_menu;
-
- /** Whether or not the "snap-to-grid" functionality is on. */
- bool snap_to;
-
- /** What is the currently selected action that the mouse is doing */
- enum ActionType { NOTHING, HIGHLIGHTING, DRAGGING, SCROLLING }
current_action;
-
-public:
- /** Constructor
- @param e The EditorScreen to which this viewport belongs */
- EditorViewport(EditorScreen* e, const Rect& rect);
-
- /** Destructor */
- ~EditorViewport ();
-
- /** Draws all of the objects in the viewport */
- void draw(DrawingContext &gc);
-
- /** Update information about scrolling, etc. */
- void update(float delta);
-
- /** Returns whether or not the mouse is inside the viewport */
- bool is_at(int x, int y);
-
- /** Emitted when the pointer moved, x and y are the new pointer
- coordinates */
- void on_pointer_move (int x, int y);
-
- /** Refresh the list of objects (do when loading or creating a new level) */
- void refresh();
-
- /** Turns the "snap-to-grid" option on or off */
- void set_snap_to(bool s) { snap_to = s; }
-
- /** Return a pointer to the EditorScreen object */
- EditorScreen* get_screen() { return editor; }
-
- Vector2f get_scroll_pos() const;
- void set_scroll_pos(const Vector2f& pos);
-
- /// Mouse actions
- void on_primary_button_press(int x, int y);
- void on_primary_button_release(int x, int y);
-
- void on_secondary_button_press(int x, int y);
- void on_secondary_button_release(int x, int y);
-
- void on_secondary_button_click(int x, int y);
-
- void on_key_pressed(const unsigned short c);
-
- void delete_selected_objects();
- void duplicate_selected_objects();
-
- void vflip_selected_objects();
- void hflip_selected_objects();
-
- void rotate_90_selected_objects();
- void rotate_270_selected_objects();
-
- void raise_objects();
- void lower_objects();
-
- void raise_objects_to_top();
- void lower_objects_to_bottom();
-
- void move_objects(const Vector2i& offset);
-
- Vector2i screen2world(int x, int y) const;
-
- void update_layout();
-
- std::vector<LevelObj*>* get_objects();
-
- void clear_selection();
- void clear();
-
- boost::signal<void (const std::vector<LevelObj*>&)> selection_changed;
-private:
- EditorViewport();
- EditorViewport (const EditorViewport&);
- EditorViewport& operator= (const EditorViewport&);
-};
-
-} // Editor namespace
-
-#endif
-
-/* EOF */
Copied: trunk/pingus/src/editor/viewport.cpp (from rev 3445,
trunk/pingus/src/editor/editor_viewport.cpp)
===================================================================
--- trunk/pingus/src/editor/editor_viewport.cpp 2007-11-01 08:15:27 UTC (rev
3445)
+++ trunk/pingus/src/editor/viewport.cpp 2007-11-01 08:18:05 UTC (rev
3446)
@@ -0,0 +1,546 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// Ingo Ruhnke <address@hidden>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#include <vector>
+#include <string>
+#include <iostream>
+#include "../gui/gui_manager.hpp"
+#include "../display/display.hpp"
+#include "../display/drawing_context.hpp"
+#include "../math/vector3f.hpp"
+#include "../graphic_context_state.hpp"
+#include "editor_level.hpp"
+#include "editor_screen.hpp"
+#include "editor_viewport.hpp"
+#include "level_objs.hpp"
+
+namespace Editor {
+
+// Constructor
+Viewport::Viewport(EditorScreen* e, const Rect& rect_)
+ : RectComponent(rect_),
+ state(rect.get_width(), rect.get_height()),
+ drawing_context(new DrawingContext(rect)),
+ editor(e),
+ autoscroll(false),
+ highlighted_area(0,0,0,0),
+ snap_to(false),
+ current_action(NOTHING)
+{
+}
+
+// Destructor
+Viewport::~Viewport ()
+{
+ delete drawing_context;
+}
+
+void
+Viewport::on_secondary_button_press(int x_, int y_)
+{
+ mouse_world_pos = screen2world(x_, y_);
+ mouse_screen_pos = Vector2i(x_, y_);
+
+ if (current_action == NOTHING)
+ {
+ drag_screen_pos = mouse_screen_pos;
+ current_action = SCROLLING;
+ }
+}
+
+void
+Viewport::on_secondary_button_release(int x_, int y_)
+{
+ mouse_world_pos = screen2world(x_, y_);
+ mouse_screen_pos = Vector2i(x_, y_);
+
+ if (current_action == SCROLLING)
+ current_action = NOTHING;
+}
+
+// When someone right-clicks inside the viewport
+void
+Viewport::on_secondary_button_click(int x_, int y_)
+{
+ mouse_world_pos = screen2world(x_, y_);
+ mouse_screen_pos = Vector2i(x_, y_);
+}
+
+// Select 1 or more LevelObjs, or drag them.
+void
+Viewport::on_primary_button_press(int x_, int y_)
+{
+ mouse_world_pos = screen2world(x_, y_);
+ mouse_screen_pos = Vector2i(x_, y_);
+
+ if (current_action == NOTHING)
+ {
+ LevelObj* obj = editor->get_level()->object_at(mouse_world_pos.x,
mouse_world_pos.y);
+
+ if (obj)
+ {
+ // If the currently selected object isn't selected, select it and
deselect the rest
+ if (!obj->is_selected())
+ {
+ clear_selection();
+ obj->select();
+ selected_objs.push_back(obj);
+
+ selection_changed(selected_objs);
+ }
+
+ for (unsigned i = 0; i < selected_objs.size(); i++)
+ selected_objs[i]->set_orig_pos(selected_objs[i]->get_pos());
+
+ // Allow dragging of the currently selected objects
+ current_action = DRAGGING;
+ drag_world_pos = mouse_world_pos;
+ }
+ else
+ {
+ current_action = HIGHLIGHTING;
+ highlighted_area.left = highlighted_area.right = mouse_world_pos.x;
+ highlighted_area.top = highlighted_area.bottom = mouse_world_pos.y;
+
+ clear_selection();
+
+ selection_changed(selected_objs);
+ }
+ }
+}
+
+void
+Viewport::on_primary_button_release(int x_, int y_)
+{
+ mouse_world_pos = screen2world(x_, y_);
+ mouse_screen_pos = Vector2i(x_, y_);
+
+ if (current_action == HIGHLIGHTING)
+ {
+ highlighted_area.normalize();
+ for (unsigned i = 0; i < get_objects()->size(); i++)
+ {
+ if
(highlighted_area.is_inside(Vector2i(int((*get_objects())[i]->get_pos().x),
+
int((*get_objects())[i]->get_pos().y))))
+ {
+ selected_objs.push_back((*get_objects())[i]);
+ (*get_objects())[i]->select();
+ }
+ else
+ (*get_objects())[i]->unselect();
+ }
+
+ selection_changed(selected_objs);
+ }
+ else if (current_action == DRAGGING)
+ {
+ // Set the objects' positions for good
+ for (unsigned i = 0; i < (*get_objects()).size(); i++)
+ (*get_objects())[i]->set_orig_pos((*get_objects())[i]->get_pos());
+ }
+ current_action = NOTHING;
+}
+
+void
+Viewport::on_pointer_move(int x_, int y_)
+{
+ mouse_world_pos = screen2world(x_, y_);
+ mouse_screen_pos = Vector2i(x_, y_);
+
+ switch(current_action)
+ {
+ case HIGHLIGHTING:
+ highlighted_area.right = mouse_world_pos.x;
+ highlighted_area.bottom = mouse_world_pos.y;
+ break;
+
+ case DRAGGING:
+ {
+ float new_x, new_y;
+
+ for (unsigned i = 0; i < selected_objs.size(); i++)
+ {
+ Vector3f orig_pos(selected_objs[i]->get_orig_pos());
+ float x_offset = (float)(mouse_world_pos.x - drag_world_pos.x);
+ float y_offset = (float)(mouse_world_pos.y - drag_world_pos.y);
+
+ if (snap_to)
+ {
+ // FIXME: May need to adjust the snap-to offset here.
+ new_x = (float)((int)((x_offset + orig_pos.x) / 10) * 10);
+ new_y = (float)((int)((y_offset + orig_pos.y) / 10) * 10);
+ }
+ else
+ {
+ new_x = x_offset + orig_pos.x;
+ new_y = y_offset + orig_pos.y;
+ }
+ selected_objs[i]->set_pos(Vector3f(new_x, new_y, orig_pos.z));
+ }
+ }
+ break;
+
+ case SCROLLING:
+ break;
+
+ case NOTHING:
+ break;
+ }
+}
+
+void
+Viewport::on_key_pressed(const unsigned short c)
+{
+ if (c < 256)
+ {
+ switch(c)
+ {
+ case 'A':
+ clear_selection();
+ selection_changed(selected_objs);
+ break;
+
+ case 'a':
+ if (selected_objs == (*get_objects()))
+ {
+ clear_selection();
+ }
+ else
+ {
+ clear_selection();
+ selected_objs = (*get_objects());
+ for (unsigned i = 0; i < selected_objs.size(); i++)
+ selected_objs[i]->select();
+ }
+ selection_changed(selected_objs);
+ break;
+
+ case ']':
+ case 'w':
+ raise_objects();
+ break;
+
+ case '}':
+ case 'W':
+ raise_objects_to_top();
+ break;
+
+ case '{':
+ case 'S':
+ lower_objects_to_bottom();
+ break;
+
+ case '[':
+ case 's':
+ lower_objects();
+ break;
+
+ case 'r':
+ rotate_90_selected_objects();
+ break;
+
+ case 'R':
+ rotate_270_selected_objects();
+ break;
+
+ case 8: // backspace
+ case 127: // delete
+ delete_selected_objects();
+ break;
+
+ case 'd':
+ duplicate_selected_objects();
+ break;
+
+ case 'V':
+ case 'f':
+ hflip_selected_objects();
+ break;
+
+ case 'F':
+ case 'v':
+ vflip_selected_objects();
+ break;
+
+ case 'c': // dvorak-up
+ case 'i': // up
+ move_objects(Vector2i(0,-1));
+ break;
+
+ case 't': // dvorak-down
+ case 'k': // down
+ move_objects(Vector2i(0,1));
+ break;
+
+ case 'h': // dvorak-left
+ case 'j': // left
+ move_objects(Vector2i(-1,0));
+ break;
+
+ case 'n': // dvorak-right
+ case 'l': // right
+ move_objects(Vector2i(1,0));
+ break;
+
+ default:
+ std::cout << "Viewport::on_key_pressed: " << int(c) << " " <<
(char)c << std::endl;
+ break;
+ }
+ }
+}
+
+// Draws all of the objects in the viewport and the background (if any)
+void
+Viewport::draw(DrawingContext &gc)
+{
+ drawing_context->clear();
+ drawing_context->fill_screen(Color(155,0,155));
+ state.push(*drawing_context);
+
+ // Level border
+ drawing_context->draw_rect(Rect(Vector2i(0,0),
editor->get_level()->get_size()), Color(255,255,255), 5000.0f);
+ drawing_context->draw_rect(Rect(Vector2i(0,0),
editor->get_level()->get_size()).grow(1), Color(0,0,0), 5000.0f);
+
+ // Safe area
+ drawing_context->draw_rect(Rect(Vector2i(0,0),
editor->get_level()->get_size()).grow(-100), Color(155,155,155), 5000.0f);
+
+ // Draw the level objects
+ for (unsigned i = 0; i < (*get_objects()).size(); i++)
+ (*get_objects())[i]->draw(*drawing_context);
+
+ if (current_action == HIGHLIGHTING)
+ {
+ drawing_context->draw_fillrect(highlighted_area, Color(155,200,255,
100), 1000.0f);
+ drawing_context->draw_rect(highlighted_area, Color(155,200,255),
1000.0f);
+ }
+
+ state.pop(*drawing_context);
+ gc.draw(*drawing_context, -150);
+}
+
+// Returns true if the viewport is at the x,y coordinate
+bool
+Viewport::is_at(int x, int y)
+{
+ return drawing_context->get_rect().is_inside(Vector2i(x,y));
+}
+
+void
+Viewport::update(float delta)
+{
+ UNUSED_ARG(delta);
+
+ if (current_action == SCROLLING)
+ state.set_pos(state.get_pos() + Vector2f(mouse_screen_pos -
drag_screen_pos) * delta * 5.0f);
+
+ // Autoscroll if necessary
+ if (autoscroll)
+ {
+ const int autoscroll_border = 10;
+ if (autoscroll)
+ {
+ if (mouse_screen_pos.x < autoscroll_border)
+ state.set_pos(state.get_pos() - Vector2f(5, 0));
+ else if (Display::get_width() - mouse_screen_pos.x <
autoscroll_border)
+ state.set_pos(state.get_pos() + Vector2f(5, 0));
+ else if (mouse_screen_pos.y < autoscroll_border)
+ state.set_pos(state.get_pos() - Vector2f(0, 5));
+ else if (Display::get_height() - mouse_screen_pos.y <
autoscroll_border)
+ state.set_pos(state.get_pos() + Vector2f(0, 5));
+ }
+ }
+}
+
+void
+Viewport::refresh()
+{
+ state.set_limit(Rect(Vector2i(0,0),
editor->get_level()->get_size()).grow(256));
+ //std::cout << editor->get_level()->get_size().width << ", "
+ //<< editor->get_level()->get_size().height
+ // << std::endl;
+}
+
+void
+Viewport::duplicate_selected_objects()
+{
+ std::vector<LevelObj*> new_objs;
+ for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
+ {
+ LevelObj* clone = (*i)->duplicate(Vector2i(32, 32));
+ if (clone)
+ {
+ new_objs.push_back(clone);
+ (*get_objects()).push_back(clone);
+ clone->select();
+ }
+ }
+
+ clear_selection();
+ selected_objs = new_objs;
+ selection_changed(selected_objs);
+}
+
+void
+Viewport::delete_selected_objects()
+{
+ for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
+ (*i)->remove();
+
+ (*get_objects()).erase(std::remove_if((*get_objects()).begin(),
(*get_objects()).end(), boost::mem_fn(&LevelObj::is_removed)),
+ (*get_objects()).end());
+
+ for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
+ delete (*i);
+
+ selected_objs.clear();
+ selection_changed(selected_objs);
+}
+
+void
+Viewport::hflip_selected_objects()
+{
+ for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
+ {
+
(*i)->set_modifier(ResourceModifierNS::horizontal_flip((*i)->get_modifier()));
+ }
+}
+
+void
+Viewport::vflip_selected_objects()
+{
+ for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
+ {
+
(*i)->set_modifier(ResourceModifierNS::vertical_flip((*i)->get_modifier()));
+ }
+}
+
+void
+Viewport::rotate_90_selected_objects()
+{
+ for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
+ {
+ (*i)->set_modifier(ResourceModifierNS::rotate_90((*i)->get_modifier()));
+ }
+}
+
+void
+Viewport::rotate_270_selected_objects()
+{
+ for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
+ {
+ (*i)->set_modifier(ResourceModifierNS::rotate_270((*i)->get_modifier()));
+ }
+}
+
+Vector2i
+Viewport::screen2world(int x, int y) const
+{
+ return
Vector2i(state.screen2world(drawing_context->screen_to_world(Vector2i(x, y))));
+}
+
+void
+Viewport::raise_objects()
+{
+ for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
+ {
+ editor->get_level()->raise_object(*i);
+ }
+}
+
+void
+Viewport::lower_objects()
+{
+ for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
+ {
+ editor->get_level()->lower_object(*i);
+ }
+}
+
+void
+Viewport::raise_objects_to_top()
+{
+ for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
+ editor->get_level()->raise_object_to_top(*i);
+}
+
+void
+Viewport::lower_objects_to_bottom()
+{
+ for(std::vector<LevelObj*>::iterator i = selected_objs.begin(); i !=
selected_objs.end(); ++i)
+ editor->get_level()->lower_object_to_bottom(*i);
+}
+
+void
+Viewport::update_layout()
+{
+ state.set_size(rect.get_width(), rect.get_height());
+ drawing_context->set_rect(rect);
+}
+
+void
+Viewport::clear_selection()
+{
+ for (unsigned i = 0; i < selected_objs.size(); i++)
+ selected_objs[i]->unselect();
+
+ selected_objs.clear();
+}
+
+void
+Viewport::move_objects(const Vector2i& offset)
+{
+ for (unsigned i = 0; i < selected_objs.size(); i++)
+ {
+ Vector3f p = selected_objs[i]->get_pos();
+ selected_objs[i]->set_pos(Vector3f(p.x + offset.x, p.y + offset.y, p.z));
+ }
+}
+
+void
+Viewport::clear()
+{
+ selected_objs.clear();
+ for(std::vector<LevelObj*>::iterator i = (*get_objects()).begin(); i !=
(*get_objects()).end(); ++i)
+ delete *i;
+ (*get_objects()).clear();
+ selection_changed(selected_objs);
+}
+
+Vector2f
+Viewport::get_scroll_pos() const
+{
+ return state.get_pos();
+}
+
+void
+Viewport::set_scroll_pos(const Vector2f& pos)
+{
+ state.set_pos(pos);
+}
+
+std::vector<LevelObj*>*
+Viewport::get_objects()
+{
+ return editor->get_level()->get_objects();
+}
+
+} // namespace Editor
+
+/* EOF */
Copied: trunk/pingus/src/editor/viewport.hpp (from rev 3445,
trunk/pingus/src/editor/editor_viewport.hpp)
===================================================================
--- trunk/pingus/src/editor/editor_viewport.hpp 2007-11-01 08:15:27 UTC (rev
3445)
+++ trunk/pingus/src/editor/viewport.hpp 2007-11-01 08:18:05 UTC (rev
3446)
@@ -0,0 +1,160 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// Ingo Ruhnke <address@hidden>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#ifndef HEADER_PINGUS_EDITOR_VIEWPORT_HXX
+#define HEADER_PINGUS_EDITOR_VIEWPORT_HXX
+
+#include "../gui/rect_component.hpp"
+#include "../graphic_context_state.hpp"
+#include <boost/signal.hpp>
+#include <vector>
+#include <string>
+
+class Vector3f;
+class DrawingContext;
+class SceneContext;
+
+namespace Editor {
+
+class LevelObj;
+class EditorScreen;
+class ContextMenu;
+
+/** This class is where the actual level graphics will display in the
+ level editor. Objects can be added, deleted, moved, modified, etc.
+ inside of the Viewport */
+class Viewport : public GUI::RectComponent
+{
+private:
+ GraphicContextState state;
+ DrawingContext* drawing_context;
+
+ /** The EditorScreen to which this viewport belongs */
+ EditorScreen* editor;
+
+
+ /** Whether or not Autoscrolling is turned on */
+ bool autoscroll;
+
+ /** Where the mouse is right now - used for autoscrolling */
+ Vector2i mouse_world_pos;
+ Vector2i mouse_screen_pos;
+
+ /** Where the mouse started dragging from */
+ Vector2i drag_world_pos;
+ Vector2i drag_screen_pos;
+
+ /** The currently selected LevelObjs */
+ std::vector<LevelObj*> selected_objs;
+
+ /** The region that is currently highlighted */
+ Rect highlighted_area;
+
+ /** There should only be 0 or 1 context menus on the screen */
+ ContextMenu* context_menu;
+
+ /** Whether or not the "snap-to-grid" functionality is on. */
+ bool snap_to;
+
+ /** What is the currently selected action that the mouse is doing */
+ enum ActionType { NOTHING, HIGHLIGHTING, DRAGGING, SCROLLING }
current_action;
+
+public:
+ /** Constructor
+ @param e The EditorScreen to which this viewport belongs */
+ Viewport(EditorScreen* e, const Rect& rect);
+
+ /** Destructor */
+ ~Viewport ();
+
+ /** Draws all of the objects in the viewport */
+ void draw(DrawingContext &gc);
+
+ /** Update information about scrolling, etc. */
+ void update(float delta);
+
+ /** Returns whether or not the mouse is inside the viewport */
+ bool is_at(int x, int y);
+
+ /** Emitted when the pointer moved, x and y are the new pointer
+ coordinates */
+ void on_pointer_move (int x, int y);
+
+ /** Refresh the list of objects (do when loading or creating a new level) */
+ void refresh();
+
+ /** Turns the "snap-to-grid" option on or off */
+ void set_snap_to(bool s) { snap_to = s; }
+
+ /** Return a pointer to the EditorScreen object */
+ EditorScreen* get_screen() { return editor; }
+
+ Vector2f get_scroll_pos() const;
+ void set_scroll_pos(const Vector2f& pos);
+
+ /// Mouse actions
+ void on_primary_button_press(int x, int y);
+ void on_primary_button_release(int x, int y);
+
+ void on_secondary_button_press(int x, int y);
+ void on_secondary_button_release(int x, int y);
+
+ void on_secondary_button_click(int x, int y);
+
+ void on_key_pressed(const unsigned short c);
+
+ void delete_selected_objects();
+ void duplicate_selected_objects();
+
+ void vflip_selected_objects();
+ void hflip_selected_objects();
+
+ void rotate_90_selected_objects();
+ void rotate_270_selected_objects();
+
+ void raise_objects();
+ void lower_objects();
+
+ void raise_objects_to_top();
+ void lower_objects_to_bottom();
+
+ void move_objects(const Vector2i& offset);
+
+ Vector2i screen2world(int x, int y) const;
+
+ void update_layout();
+
+ std::vector<LevelObj*>* get_objects();
+
+ void clear_selection();
+ void clear();
+
+ boost::signal<void (const std::vector<LevelObj*>&)> selection_changed;
+private:
+ Viewport();
+ Viewport (const Viewport&);
+ Viewport& operator= (const Viewport&);
+};
+
+} // Editor namespace
+
+#endif
+
+/* EOF */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r3446 - in trunk/pingus: . src/editor,
grumbel at BerliOS <=