pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r2490 - in trunk: . src src/editor


From: jave27
Subject: [Pingus-CVS] r2490 - in trunk: . src src/editor
Date: Wed, 9 Nov 2005 23:07:03 +0100

Author: jave27
Date: 2005-11-09 23:06:55 +0100 (Wed, 09 Nov 2005)
New Revision: 2490

Added:
   trunk/src/editor/editor_viewport.cxx
   trunk/src/editor/editor_viewport.hxx
Modified:
   trunk/Pingus.vcproj
   trunk/src/editor/Makefile.am
   trunk/src/editor/editor_screen.cxx
   trunk/src/editor/editor_screen.hxx
   trunk/src/playfield.cxx
Log:
Managed to break the display of the editor, but more is completed.
Also cleaned up old unused playfield.cxx code.

Modified: trunk/Pingus.vcproj
===================================================================
--- trunk/Pingus.vcproj 2005-11-09 18:38:29 UTC (rev 2489)
+++ trunk/Pingus.vcproj 2005-11-09 22:06:55 UTC (rev 2490)
@@ -1768,6 +1768,12 @@
                                        
RelativePath=".\src\editor\editor_screen.hxx">
                                </File>
                                <File
+                                       
RelativePath=".\src\editor\editor_viewport.cxx">
+                               </File>
+                               <File
+                                       
RelativePath=".\src\editor\editor_viewport.hxx">
+                               </File>
+                               <File
                                        
RelativePath=".\src\editor\panel_buttons.cxx">
                                </File>
                                <File

Modified: trunk/src/editor/Makefile.am
===================================================================
--- trunk/src/editor/Makefile.am        2005-11-09 18:38:29 UTC (rev 2489)
+++ trunk/src/editor/Makefile.am        2005-11-09 22:06:55 UTC (rev 2490)
@@ -24,6 +24,7 @@
 libpingus_editor_a_SOURCES =       \
         editor_screen.cxx      editor_screen.hxx       \
                editor_panel.cxx        editor_panel.hxx        \
-               panel_button.cxx        panel_button.hxx
+               panel_button.cxx        panel_button.hxx        \
+               editor_viewport.cxx     editor_viewport.hxx
 
 # EOF #
\ No newline at end of file

Modified: trunk/src/editor/editor_screen.cxx
===================================================================
--- trunk/src/editor/editor_screen.cxx  2005-11-09 18:38:29 UTC (rev 2489)
+++ trunk/src/editor/editor_screen.cxx  2005-11-09 22:06:55 UTC (rev 2490)
@@ -30,6 +30,7 @@
 #include "../xml_pingus_level.hxx"
 #include "editor_screen.hxx"
 #include "editor_panel.hxx"
+#include "editor_viewport.hxx"
 
 namespace Pingus {
 
@@ -55,11 +56,13 @@
 EditorScreen::on_startup()
 {
        // Create the panel for the buttons
-       {
-               panel = new EditorPanel(this);
-               gui_manager->add(panel);
-               panel->init();
-       } // end panel setup
+       panel = new EditorPanel(this);
+       gui_manager->add(panel);
+       panel->init();
+
+       // Create the viewport for the images and data
+       viewport = new EditorViewport(this);
+       gui_manager->add(viewport);
 }
 
 // Close the current screen
@@ -108,7 +111,8 @@
 EditorScreen::draw(Pingus::DrawingContext &gc)
 {
        // Black out screen
-       gc.fill_screen(CL_Color(0, 0, 0, 255));
+       gc.draw_fillrect(0, 0, CL_Display::get_width(), 
CL_Display::get_height(),
+               CL_Color(0, 0, 0, 255), -10000);
        gui_manager->draw(gc);
        return true;
 }

Modified: trunk/src/editor/editor_screen.hxx
===================================================================
--- trunk/src/editor/editor_screen.hxx  2005-11-09 18:38:29 UTC (rev 2489)
+++ trunk/src/editor/editor_screen.hxx  2005-11-09 22:06:55 UTC (rev 2490)
@@ -31,6 +31,7 @@
 namespace Editor {
 
 class EditorPanel;
+class EditorViewport;
 
 /** This class is the screen that contains all of the
        editor objects */
@@ -43,6 +44,9 @@
        /* Panel which contains all of the buttons for each action */
        EditorPanel* panel;
 
+       /* Viewport which holds all of the level images and data */
+       EditorViewport* viewport;
+
 public:
        /** Default constructor */
   EditorScreen(PingusLevel* level = 0);

Added: trunk/src/editor/editor_viewport.cxx
===================================================================
--- trunk/src/editor/editor_viewport.cxx        2005-11-09 18:38:29 UTC (rev 
2489)
+++ trunk/src/editor/editor_viewport.cxx        2005-11-09 22:06:55 UTC (rev 
2490)
@@ -0,0 +1,118 @@
+//  $Id: editor_viewport.cxx,v 1.00 2005/11/09 23:41:12 Jave27 Exp $
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 1999 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 <ClanLib/display.h>
+#include <vector>
+#include <string>
+#include <iostream>
+#include "../vector.hxx"
+#include "../display/drawing_context.hxx"
+#include "../graphic_context_state.hxx"
+#include "editor_viewport.hxx"
+
+namespace Pingus {
+namespace Editor {
+
+// Constructor
+EditorViewport::EditorViewport(EditorScreen* e) :
+       editor(e),
+       bg_surface(0),
+       start_pos(Vector(10.0f, 60.0f)),
+       end_pos(Vector((float)(CL_Display::get_width() - 10), 
+                                                               
(float)(CL_Display::get_height() - 10))),
+  scene_context(new SceneContext()),
+       autoscroll(true),
+       state((int)(end_pos.x - start_pos.x), (int)(end_pos.y - start_pos.y))
+{
+       state.set_limit(CL_Rect((int)start_pos.x, (int)start_pos.y, 
+               (int)end_pos.x, (int)end_pos.y));
+       state.set_pos(CL_Pointf((float)(state.get_width() / 2), 
+               (float)(state.get_height() / 2)));
+}
+
+// Destructor
+EditorViewport::~EditorViewport ()
+{
+       if (bg_surface) delete bg_surface;
+}
+
+// When someone right-clicks inside the viewport
+void
+EditorViewport::on_secondary_button_click(int x, int y)
+{
+       std::cout << "Right-click at " << x - start_pos.x << ", " 
+               << y - start_pos.y << std::endl;
+}
+
+// Draws all of the objects in the viewport and the background (if any)
+void
+EditorViewport::draw(DrawingContext &gc)
+{
+       scene_context->clear();
+
+       state.push(*scene_context);
+
+       // Now, draw all of the objects
+
+       // FIXME: Should draw the background over the whole viewport (stretched 
or tiled)
+       if (bg_surface)
+               scene_context->color().draw(*bg_surface, start_pos);
+       else
+               scene_context->color().draw_fillrect(start_pos.x, start_pos.y, 
end_pos.x, end_pos.y, CL_Color::darkgray);
+
+
+       scene_context->color().draw_circle(25, 25, 10, CL_Color::white);
+
+       state.pop(*scene_context);
+
+       gc.draw(new SceneContextDrawingRequest(scene_context, 0));
+}
+
+// Returns true if the viewport is at the x,y coordinate
+bool
+EditorViewport::is_at(int x, int y)
+{
+  return (x > start_pos.x && x < end_pos.x
+         && y > start_pos.y && y < end_pos.y);
+}
+
+// 
+void
+EditorViewport::on_pointer_move(int x, int y)
+{
+       const int autoscroll_border = 10;
+       if (is_at(x, y))
+       {
+               // Autoscroll if necessary
+               if (x - start_pos.x < autoscroll_border)
+                       std::cout << "AutoScroll left" << std::endl;
+               else if (end_pos.x - x < autoscroll_border)
+                       std::cout << "AutoScroll right" << std::endl;
+               else if (y - start_pos.y < autoscroll_border)
+                       state.set_pos(state.get_pos() - CL_Pointf(0, 5.0f));
+               else if (end_pos.y - y < autoscroll_border)
+                       state.set_pos(state.get_pos() + CL_Pointf(0, 5.0f));
+                       //std::cout << "AutoScroll down" << std::endl;
+       }
+}
+
+} // Editor namespace
+} // Pingus namespace
+
+/* EOF */
\ No newline at end of file

Added: trunk/src/editor/editor_viewport.hxx
===================================================================
--- trunk/src/editor/editor_viewport.hxx        2005-11-09 18:38:29 UTC (rev 
2489)
+++ trunk/src/editor/editor_viewport.hxx        2005-11-09 22:06:55 UTC (rev 
2490)
@@ -0,0 +1,100 @@
+//  $Id: editor_viewport.hxx,v 1.00 2005/11/09 23:41:12 Jave27 Exp $
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 1999 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 <ClanLib/Display/sprite.h>
+#include "../gui/component.hxx"
+#include "../graphic_context_state.hxx"
+#include <vector>
+#include <string>
+
+namespace Pingus {
+
+       class Vector;
+       class DrawingContext;
+       class SceneContext;
+
+namespace Editor {
+
+       class EditorScreen;
+
+/** 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::Component {
+
+public:
+       /** Constructor
+               @param e The EditorScreen to which this viewport belongs */
+       EditorViewport (EditorScreen* e);
+
+       /** Destructor */
+       ~EditorViewport ();
+
+       /** Returns the list of objects inside the viewport */
+       std::vector<std::string> get_objects() { return objs; }
+
+       /** When someone right-clicks inside the viewport */
+       void on_secondary_button_click(int x, int y);
+
+       /** Draws all of the objects in the viewport */
+       void draw(DrawingContext &gc);
+
+       /** 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);
+
+private:
+       EditorViewport();
+       EditorViewport (const EditorViewport&);
+  EditorViewport& operator= (const EditorViewport&);
+       
+       GraphicContextState state;
+       SceneContext* scene_context;
+
+       /** The EditorScreen to which this viewport belongs */
+       EditorScreen* editor;
+
+       /** Collection of objects inside the viewport (groundpieces, traps, 
etc.) */
+       std::vector<std::string> objs;
+
+       /** Background image - if null, will display dark gray background */
+       CL_Surface* bg_surface;
+
+       /** Vector where this Viewport starts */
+       Vector start_pos;
+
+       /** Vector where this Viewport ends */
+       Vector end_pos;
+
+       /** Whether or not Autoscrolling is turned on */
+       bool autoscroll;
+};
+
+} // Editor namespace
+} // Pingus namespace
+
+#endif
+
+/* EOF */
\ No newline at end of file

Modified: trunk/src/playfield.cxx
===================================================================
--- trunk/src/playfield.cxx     2005-11-09 18:38:29 UTC (rev 2489)
+++ trunk/src/playfield.cxx     2005-11-09 22:06:55 UTC (rev 2490)
@@ -50,39 +50,6 @@
   needs_clear_screen = false;
 
   state.set_limit(CL_Rect(CL_Point(0, 0), CL_Size(world->get_width(), 
world->get_height())));
-
-  if (0)
-    { // FIXME: Fix this
-      // Special handling for levels smaller than the screen
-      int x1, x2, y1, y2;
-
-      x1 = (CL_Display::get_width() - world->get_width()) / 2;
-      x2 = x1 + world->get_width() - 1;
-
-      y1 = (CL_Display::get_height() - world->get_height()) / 2;
-      y2 = y1 + world->get_height() - 1;
-
-      if (x1 < 0)
-        x1 = 0;
-      if (x2 >= CL_Display::get_width())
-        x2 = CL_Display::get_width() - 1;
-      if (y1 < 0)
-        y1 = 0;
-      if (y2 >= CL_Display::get_height())
-        y2 = CL_Display::get_height() - 1;
-
-      if (x1 > 0 || x2 < (CL_Display::get_width() - 1)
-          || y1 > 0 || y2 < (CL_Display::get_height() - 1))
-        {
-          std::cout << "Playfield:: Activating clear screen" << std::endl;
-          needs_clear_screen = true;
-          generate_clipping_rects(x1, y1, x2, y2);
-        }
-      else
-        {
-          needs_clear_screen = false;
-        }
-    }
 }
 
 Playfield::~Playfield()





reply via email to

[Prev in Thread] Current Thread [Next in Thread]