[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2492 - in trunk: . src/editor src/gui src/worldobjs
From: |
jave27 |
Subject: |
[Pingus-CVS] r2492 - in trunk: . src/editor src/gui src/worldobjs |
Date: |
Thu, 10 Nov 2005 17:38:25 +0100 |
Author: jave27
Date: 2005-11-10 17:38:16 +0100 (Thu, 10 Nov 2005)
New Revision: 2492
Added:
trunk/src/gui/combobox.cxx
trunk/src/gui/combobox.hxx
Modified:
trunk/Pingus.vcproj
trunk/src/editor/editor_panel.cxx
trunk/src/editor/editor_panel.hxx
trunk/src/editor/editor_screen.cxx
trunk/src/gui/Makefile.am
trunk/src/worldobjs/surface_background.cxx
Log:
Implemented a rudimentary GUI::Combobox widget, and tested it on the editor.
Also, hacked the surface_background.cxx again to try to remove the dividing
line that's caused by scrolling backgrounds which are blitter scaled.
Modified: trunk/Pingus.vcproj
===================================================================
--- trunk/Pingus.vcproj 2005-11-10 01:52:16 UTC (rev 2491)
+++ trunk/Pingus.vcproj 2005-11-10 16:38:16 UTC (rev 2492)
@@ -277,6 +277,12 @@
RelativePath=".\src\gui\button.hxx">
</File>
<File
+ RelativePath=".\src\gui\combobox.cxx">
+ </File>
+ <File
+ RelativePath=".\src\gui\combobox.hxx">
+ </File>
+ <File
RelativePath=".\src\gui\component.hxx">
</File>
<File
Modified: trunk/src/editor/editor_panel.cxx
===================================================================
--- trunk/src/editor/editor_panel.cxx 2005-11-10 01:52:16 UTC (rev 2491)
+++ trunk/src/editor/editor_panel.cxx 2005-11-10 16:38:16 UTC (rev 2492)
@@ -23,6 +23,8 @@
#include "../vector.hxx"
#include "../display/drawing_context.hxx"
#include "../gui/gui_manager.hxx"
+#include "../gui/combobox.hxx"
+#include "../fonts.hxx"
#include "editor_panel.hxx"
#include "editor_screen.hxx"
#include "panel_buttons.hxx"
@@ -43,7 +45,7 @@
// Destructor
EditorPanel::~EditorPanel()
{
-
+ delete combo_groundpieces;
}
// Wait to run this until after the panel has been added to the gui_manager
@@ -54,14 +56,27 @@
{
// Create exit button
add((PanelButton*)(new PanelButtonExit(this)));
+
+ // Create groundpiece Combobox (FIXME: Temporary testing)
+ combo_groundpieces = new GUI::Combobox(Vector(500, 30));
+ combo_groundpieces->add(new GUI::ComboItem(0, "Test 1"));
+ combo_groundpieces->add(new GUI::ComboItem(0, "Test 2"));
+ combo_groundpieces->add(new GUI::ComboItem(0, "Test 3"));
+ combo_groundpieces->add(new GUI::ComboItem(0, "Test 4"));
+ combo_groundpieces->add(new GUI::ComboItem(0, "Test 5"));
+ get_screen()->get_gui_manager()->add(combo_groundpieces);
}
// Draw the panel
void
EditorPanel::draw (DrawingContext& gc)
{
+ // Draw the panel
gc.draw_fillrect(0, 0, (float)CL_Display::get_width(),
50.0f, CL_Color::lightgray, -50);
+
+ // Draw any labels for comboboxes that might be needed
+ gc.print_left(Fonts::smallfont, 390, 30, "Groundpieces");
}
// Add the button to the vector, set it's position, and add to the gui_manager
Modified: trunk/src/editor/editor_panel.hxx
===================================================================
--- trunk/src/editor/editor_panel.hxx 2005-11-10 01:52:16 UTC (rev 2491)
+++ trunk/src/editor/editor_panel.hxx 2005-11-10 16:38:16 UTC (rev 2492)
@@ -23,6 +23,7 @@
#include <vector>
#include <iostream>
#include "../gui/component.hxx"
+#include "../gui/combobox.hxx"
namespace Pingus {
@@ -43,6 +44,8 @@
/** Collection of buttons on this panel */
std::vector<PanelButton*> panel_buttons;
+ GUI::Combobox* combo_groundpieces;
+
public:
/** Constructor
@param es The EditorScreen to which this panel belongs */
Modified: trunk/src/editor/editor_screen.cxx
===================================================================
--- trunk/src/editor/editor_screen.cxx 2005-11-10 01:52:16 UTC (rev 2491)
+++ trunk/src/editor/editor_screen.cxx 2005-11-10 16:38:16 UTC (rev 2492)
@@ -55,14 +55,15 @@
void
EditorScreen::on_startup()
{
+ // Create the viewport for the images and data
+ viewport = new EditorViewport(this);
+ gui_manager->add(viewport);
+
// Create the panel for the buttons
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
Modified: trunk/src/gui/Makefile.am
===================================================================
--- trunk/src/gui/Makefile.am 2005-11-10 01:52:16 UTC (rev 2491)
+++ trunk/src/gui/Makefile.am 2005-11-10 16:38:16 UTC (rev 2492)
@@ -40,6 +40,8 @@
screen_ptr.hxx \
component.hxx \
surface_button.cxx \
- surface_button.hxx
+ surface_button.hxx \
+ combobox.cxx \
+ combobox.hxx
# EOF #
\ No newline at end of file
Added: trunk/src/gui/combobox.cxx
===================================================================
--- trunk/src/gui/combobox.cxx 2005-11-10 01:52:16 UTC (rev 2491)
+++ trunk/src/gui/combobox.cxx 2005-11-10 16:38:16 UTC (rev 2492)
@@ -0,0 +1,150 @@
+// $Id: combobox.cxx,v 1.16 2005/11/10 21:37:06 Jave27 Exp $
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2005 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/font.h>
+#include <vector>
+#include <string>
+#include "combobox.hxx"
+#include "../fonts.hxx"
+
+namespace Pingus {
+namespace GUI {
+
+// Constructor
+Combobox::Combobox (Vector p) :
+ current_item(0),
+ drop_down(false),
+ pos(p)
+{
+ // Default to 20 characters wide.
+ width = Fonts::smallfont.get_width('O') * 20.0f;
+ height = (float)Fonts::smallfont.get_height();
+}
+
+// Destructor
+Combobox::~Combobox ()
+{
+ for (std::vector<ComboItem*>::iterator i = item_list.begin();
+ i != item_list.end(); i++)
+ {
+ if ((*i)->delete_it())
+ delete (*i);
+ }
+}
+
+// Add an item to the combobox
+void
+Combobox::add(ComboItem* item)
+{
+ item_list.push_back(item);
+}
+
+// Remove an item from the combobox. Delete it if necessary
+void
+Combobox::remove(ComboItem* item)
+{
+ for (std::vector<ComboItem*>::iterator i = item_list.begin();
+ i != item_list.end(); i++)
+ {
+ if ((*i) == item)
+ {
+ item_list.erase(i);
+ if (item->delete_it())
+ delete item;
+ }
+ }
+}
+
+// Returns whether or not the combobox is at this location
+bool
+Combobox::is_at(int x, int y)
+{
+ return ((float)x > pos.x && (float)x < pos.x + get_width() &&
+ (float)y > pos.y && (float)y < pos.y + get_height());
+}
+
+// Returns the width of the box
+float
+Combobox::get_width()
+{
+ return width;
+}
+
+// Returns the height of the box
+float
+Combobox::get_height()
+{
+ if (drop_down)
+ return height * ((float)item_list.size() + 1.0f);
+ else
+ return height;
+}
+
+// action taken when the primary mouse button is clicked
+void
+Combobox::on_primary_button_click(int x, int y)
+{
+ if (drop_down)
+ {
+ // Determine which item was selected, if any, and set the
current item to it.
+ if (y > pos.y + height)
+ current_item = item_list[static_cast<int>((y - pos.y -
height) / height)];
+ drop_down = false;
+ }
+ else
+ {
+ drop_down = true;
+ }
+}
+
+// Draws the Combobox on the screen at it's location
+void
+Combobox::draw(DrawingContext &gc)
+{
+ // First off, Draw the rectangle
+ gc.draw_fillrect(pos.x, pos.y, pos.x + get_width(), pos.y +
get_height(),
+ CL_Color::white);
+ // Next, draw the rectangle border
+ gc.draw_rect(pos.x, pos.y, pos.x + get_width(), pos.y + get_height(),
+ CL_Color::black);
+
+ if (drop_down && item_list.size() > 0)
+ {
+ // FIXME: Implement - Draw the "highlighted" rectangle.
+ // FIXME: Need to have the mouse pointer x,y coordinates for
this function.
+
+ // Draw all of the items
+ for (unsigned i = 0; i < item_list.size(); i++)
+ {
+ gc.print_left(Fonts::smallfont, pos.x + 5.0f, pos.y +
((i + 1) * height),
+ item_list[i]->get_string(), 5000);
+ }
+ }
+
+ if (current_item)
+ {
+ // Print the currently selected item
+ gc.print_left(Fonts::smallfont, pos.x + 3.0f, pos.y,
current_item->get_string());
+ }
+}
+
+} // GUI namespace
+} // Pingus namespace
+
+/* EOF */
\ No newline at end of file
Added: trunk/src/gui/combobox.hxx
===================================================================
--- trunk/src/gui/combobox.hxx 2005-11-10 01:52:16 UTC (rev 2491)
+++ trunk/src/gui/combobox.hxx 2005-11-10 16:38:16 UTC (rev 2492)
@@ -0,0 +1,155 @@
+// $Id: combobox.hxx,v 1.16 2005/11/10 21:37:06 Jave27 Exp $
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2005 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_GUI_COMBOBOX_HXX
+#define HEADER_PINGUS_GUI_COMBOBOX_HXX
+
+#include <vector>
+#include <string>
+#include "component.hxx"
+#include "../vector.hxx"
+
+namespace Pingus {
+
+namespace GUI {
+
+/** A ComboItems holds a specific item in a Combobox (string, id, etc.) */
+class ComboItem
+{
+protected:
+ /* The item's hidden ID field */
+ int id;
+
+ /** string that displays when printed on the Combobox */
+ std::string str;
+
+ /** Should this item be deleted when the Combobox dies? */
+ bool delete_item;
+
+public:
+ /** Constructors */
+ ComboItem () { delete_item = true; }
+ ComboItem (int i, std::string s, bool d = true)
+ {
+ id = i;
+ str =s;
+ delete_item = d;
+ }
+
+ virtual ~ComboItem () { }
+
+ /** Returns this item's ID */
+ int get_id() { return id; }
+
+ /** Returns this item's string */
+ std::string get_string() { return str; }
+
+ /** Returns the value of del_item */
+ bool delete_it() { return delete_item; }
+
+ /** Set this item's ID */
+ void set_id(int i) { id = i; }
+
+ /** Set this item's string */
+ void set_string(std::string s) { str = s; }
+
+private:
+ ComboItem (const ComboItem&);
+ ComboItem& operator= (const ComboItem&);
+}; // ComboItem class
+
+
+
+/** The Combobox class gives you a drop-down list of items to choose from. */
+class Combobox : public Component
+{
+protected:
+ /** List of items in this Combobox */
+ std::vector<ComboItem*> item_list;
+
+ /** The currently selected item in the list */
+ ComboItem* current_item;
+
+ /** Whether or not the list is showing right now */
+ bool drop_down;
+
+ /** Width of the Combobox */
+ float width;
+
+ /** Height of EACH ITEM in the Combobox. So, when drop_down is false,
this
+ should be the height of the entire widget/component. When
drop_down is
+ true, the entire widget's height should be this height times
the number of
+ items */
+ float height;
+
+ /** Location of the Combobox */
+ Vector pos;
+
+public:
+ /** Constructor */
+ Combobox (Vector p);
+
+ /** Destructor */
+ virtual ~Combobox ();
+
+ /** Add an item to the list.
+ @param del_item Set to true if you want this Combobox to delete
the
+ ComboItem when it's destroyed */
+ virtual void add(ComboItem* item);
+
+ /** Remove an item from the list */
+ virtual void remove(ComboItem* item);
+
+ /** Return a pointer to the selected item. Returns 0 if nothing is
selected */
+ ComboItem* get_selected_item() { return current_item; }
+
+ /** Sets the selected item to the given ComboItem. Returns false if
that item
+ doesn't exist */
+ bool set_selected_item(ComboItem*);
+
+ /** Draw this Combobox and all of it's items if selected */
+ virtual void draw (DrawingContext& gc);
+
+ /** Tells the gui_manager if the mouse is on top of the Combobox */
+ virtual bool is_at (int x, int y);
+
+ /** Returns the height of the Combobox at this given moment. Will be
tall if
+ drop_down = true, and short if drop_down = false */
+ virtual float get_height();
+
+ /** Returns the width of the Combobox */
+ virtual float get_width();
+
+ /** Gets emmited when a button is pressed and released over the
+ same component */
+ virtual void on_primary_button_click (int x, int y);
+
+private:
+ Combobox();
+ Combobox (const Combobox&);
+ Combobox& operator= (const Combobox&);
+
+}; // Combobox class
+
+} // GUI namespace
+} // Pingus namespace
+
+#endif
+
+/* EOF */
Modified: trunk/src/worldobjs/surface_background.cxx
===================================================================
--- trunk/src/worldobjs/surface_background.cxx 2005-11-10 01:52:16 UTC (rev
2491)
+++ trunk/src/worldobjs/surface_background.cxx 2005-11-10 16:38:16 UTC (rev
2492)
@@ -182,21 +182,23 @@
start_x = static_cast<int>((x_of * para_x) + scroll_ox);
start_y = static_cast<int>((y_of * para_y) + scroll_oy);
- while (start_x >= 0)
+ while (start_x > 0)
start_x = start_x - bg_surface.get_width();
- while (start_y >= 0)
+ while (start_y > 0)
start_y -= bg_surface.get_height();
- while (start_y < 0 -
static_cast<int>(bg_surface.get_height()))
- start_y += bg_surface.get_height();
+ // FIXME: The part (y += bg_surface.get_height() -1) is
an ugly hack
+ // to correct some issues with the Blitter scaling that
put lines down
+ // the screen between background tiles. There should
be a better way
+ // to handle this.
for(int y = start_y;
y < world->get_height();
- y += bg_surface.get_height())
+ y += bg_surface.get_height() -1)
{
for(int x = start_x;
x < world->get_width();
- x += bg_surface.get_width())
+ x += bg_surface.get_width() -1)
{
gc.color().draw(bg_surface,
Vector(static_cast<float>(x),
static_cast<float>(y)));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2492 - in trunk: . src/editor src/gui src/worldobjs,
jave27 <=