windstille-devel
[Top][All Lists]
Advanced

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

[Windstille-devel] rev 348 - trunk/src


From: Ingo Ruhnke
Subject: [Windstille-devel] rev 348 - trunk/src
Date: Sat, 22 May 2004 18:42:28 +0200

Author: grumbel
Date: 2004-05-22 18:42:27 +0200 (Sat, 22 May 2004)
New Revision: 348

Modified:
   trunk/src/SConstruct
   trunk/src/box.cxx
   trunk/src/box.hxx
   trunk/src/editor.py
   trunk/src/flexlay.i
   trunk/src/menu.cxx
   trunk/src/menu.hxx
   trunk/src/window.cxx
Log:
- made menu a bit more useable

Modified: trunk/src/SConstruct
===================================================================
--- trunk/src/SConstruct        2004-05-22 12:25:16 UTC (rev 347)
+++ trunk/src/SConstruct        2004-05-22 16:42:27 UTC (rev 348)
@@ -91,7 +91,8 @@
     'objmap_select_tool.cxx',
     'objmap_sprite_object.cxx',
     'paint_command.cxx',
-    'panel.cxx', 
+    'panel.cxx',
+    'menu.cxx',
     'popup_menu.cxx',
     'lispreader.cxx',
     'tile.cxx',

Modified: trunk/src/box.cxx
===================================================================
--- trunk/src/box.cxx   2004-05-22 12:25:16 UTC (rev 347)
+++ trunk/src/box.cxx   2004-05-22 16:42:27 UTC (rev 348)
@@ -21,7 +21,7 @@
 #include <ClanLib/Display/display.h>
 #include "box.hxx"
 
-CL_Color background   (220, 220, 220);
+CL_Color background   (210, 210, 210);
 CL_Color background_hl(240, 240, 240);
 CL_Color background_sw(200, 200, 200);
 CL_Color highlight    (255, 255, 255);
@@ -95,4 +95,11 @@
                         rect.right, rect.bottom, highlight);
 }
 
+void
+Box::draw_window(const CL_Rect& rect)
+{
+  draw_panel(CL_Rect(rect.left+1, rect.top+1, rect.right-2, rect.bottom-2));
+  CL_Display::draw_rect(rect, CL_Color(0, 0, 0));
+}
+
 /* EOF */

Modified: trunk/src/box.hxx
===================================================================
--- trunk/src/box.hxx   2004-05-22 12:25:16 UTC (rev 347)
+++ trunk/src/box.hxx   2004-05-22 16:42:27 UTC (rev 348)
@@ -31,6 +31,7 @@
   static void draw_button_neutral(const CL_Rect& rect);
   static void draw_panel(const CL_Rect& rect);
   static void draw_panel_down(const CL_Rect& rect);
+  static void draw_window(const CL_Rect& rect);
 };
 
 #endif

Modified: trunk/src/editor.py
===================================================================
--- trunk/src/editor.py 2004-05-22 12:25:16 UTC (rev 347)
+++ trunk/src/editor.py 2004-05-22 16:42:27 UTC (rev 348)
@@ -64,12 +64,12 @@
 dirview = DirectoryView(CL_Rect(CL_Point(3, 40), CL_Size(300, 200)), 
gui.get_component())
 dirview.set_directory("/");
 
-load_icon    = Icon(CL_Point(34*0+2, 2), 
make_sprite("../data/images/icons/stock_open.png"), "Some tooltip", 
gui.get_component());
-save_icon    = Icon(CL_Point(34*1+2, 2), 
make_sprite("../data/images/icons/stock_save.png"), "Some tooltip", 
gui.get_component());
-save_as_icon = Icon(CL_Point(34*2+2, 2), 
make_sprite("../data/images/icons/stock_save_as.png"), "Some tooltip", 
gui.get_component());
+load_icon    = Icon(CL_Point(34*0+2, 2), 
make_sprite("../data/images/icons24/stock_open.png"), "Some tooltip", 
gui.get_component());
+save_icon    = Icon(CL_Point(34*1+2, 2), 
make_sprite("../data/images/icons24/stock_save.png"), "Some tooltip", 
gui.get_component());
+save_as_icon = Icon(CL_Point(34*2+2, 2), 
make_sprite("../data/images/icons24/stock_save_as.png"), "Some tooltip", 
gui.get_component());
 
-copy_icon    = Icon(CL_Point(34*3.1+2, 2), 
make_sprite("../data/images/icons/stock_copy.png"), "Some tooltip", 
gui.get_component());
-paste_icon   = Icon(CL_Point(34*4.1+2, 2), 
make_sprite("../data/images/icons/stock_paste.png"), "Some tooltip", 
gui.get_component());
+copy_icon    = Icon(CL_Point(34*3.1+2, 2), 
make_sprite("../data/images/icons24/stock_copy.png"), "Some tooltip", 
gui.get_component());
+paste_icon   = Icon(CL_Point(34*4.1+2, 2), 
make_sprite("../data/images/icons24/stock_paste.png"), "Some tooltip", 
gui.get_component());
 
 
 def foo():
@@ -81,12 +81,12 @@
 
 willow = Panel(CL_Rect(CL_Point(0, 23), CL_Size(800, 33)), gui.get_component())
 
-load_icon    = Icon(CL_Point(32*0+2, 2), 
make_sprite("../data/images/icons/stock_open.png"), "Some tooltip", willow);
-save_icon    = Icon(CL_Point(32*1+2, 2), 
make_sprite("../data/images/icons/stock_save.png"), "Some tooltip", willow);
-save_as_icon = Icon(CL_Point(32*2+2, 2), 
make_sprite("../data/images/icons/stock_save_as.png"), "Some tooltip", willow);
+load_icon    = Icon(CL_Point(32*0+2, 2), 
make_sprite("../data/images/icons24/stock_open.png"), "Some tooltip", willow);
+save_icon    = Icon(CL_Point(32*1+2, 2), 
make_sprite("../data/images/icons24/stock_save.png"), "Some tooltip", willow);
+save_as_icon = Icon(CL_Point(32*2+2, 2), 
make_sprite("../data/images/icons24/stock_save_as.png"), "Some tooltip", 
willow);
 
-copy_icon    = Icon(CL_Point(32*3.1+2, 2), 
make_sprite("../data/images/icons/stock_copy.png"), "Some tooltip", willow);
-paste_icon   = Icon(CL_Point(32*4.1+2, 2), 
make_sprite("../data/images/icons/stock_paste.png"), "Some tooltip", willow);
+copy_icon    = Icon(CL_Point(32*3.1+2, 2), 
make_sprite("../data/images/icons24/stock_copy.png"), "Some tooltip", willow);
+paste_icon   = Icon(CL_Point(32*4.1+2, 2), 
make_sprite("../data/images/icons24/stock_paste.png"), "Some tooltip", willow);
 
 
 toolbar = Panel(CL_Rect(CL_Point(0, 23+33), CL_Size(33, 256)), 
gui.get_component())
@@ -98,7 +98,7 @@
 
 supertux = SuperTuxGUI(tileset, gui)
 
-class Menu(CL_Menu):
+class MMenu(CL_Menu):
     def __init__(self):
         CL_Menu.__init__(self, gui.get_component())
 
@@ -120,12 +120,21 @@
 def menu_file_save_as():
     print "File/Save As"
 
-menu = Menu()
+menu = MMenu()
 a = menu.add_item("File/Open...", menu_file_open)
 a = menu.add_item("File/Save...", menu_file_save)
 a = menu.add_item("File/Save As...", menu_file_save_as)
 a = menu.add_item("File/Quit",  do_quit)
 
+mymenu = Menu(CL_Point(100, 100), gui.get_component())
+mymenu.add_item("Foobar")
+mymenu.add_item("blub")
+mymenu.add_item("bla")
+mymenu.add_seperator()
+mymenu.add_item("Foobar")
+mymenu.add_item("blub")
+mymenu.add_item("bla")
+
 minimap_panel = Panel(CL_Rect(CL_Point(0, 600-56), CL_Size(800-134, 56)), 
gui.get_component())
 minimap = Minimap(editor_map, CL_Rect(CL_Point(3, 3), CL_Size(794-134, 50)), 
minimap_panel)
 

Modified: trunk/src/flexlay.i
===================================================================
--- trunk/src/flexlay.i 2004-05-22 12:25:16 UTC (rev 347)
+++ trunk/src/flexlay.i 2004-05-22 16:42:27 UTC (rev 348)
@@ -37,6 +37,7 @@
 #include "window.hxx"
 #include "panel.hxx"
 #include "directory_view.hxx"
+#include "menu.hxx"
 %}
 
 %include "std_string.i"
@@ -73,5 +74,7 @@
 %include "panel.hxx"
 %include "minimap.hxx"
 %include "directory_view.hxx"
+%include "menu.hxx"
 
+
 /* EOF */

Modified: trunk/src/menu.cxx
===================================================================
--- trunk/src/menu.cxx  2004-05-22 12:25:16 UTC (rev 347)
+++ trunk/src/menu.cxx  2004-05-22 16:42:27 UTC (rev 348)
@@ -17,8 +17,184 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include <iostream>
+#include <string>
+#include <ClanLib/Display/display.h>
+#include "fonts.hxx"
+#include "box.hxx"
 #include "menu.hxx"
 
+class MenuItem
+{
+public:
+  virtual void draw(int x, int y, bool active) =0;
+  virtual int get_width() =0;
+  virtual int get_height() =0;
+};
 
+class SeperatorMenuItem : public MenuItem
+{
+public:
+  SeperatorMenuItem() {}
+  virtual ~SeperatorMenuItem() {}
 
+  void draw(int x, int y, bool active) 
+  {
+    CL_Display::fill_rect(CL_Rect(CL_Point(x, y), CL_Size(80-4, 2)), 
CL_Color(150, 150, 150));
+    CL_Display::fill_rect(CL_Rect(CL_Point(x, y+1), CL_Size(80-4, 1)), 
CL_Color(255, 255, 255));
+  }
+
+  int get_width()  { return 10; }
+  int get_height() { return 4; }
+};
+
+class TextMenuItem : public MenuItem
+{
+private:
+  std::string text;
+public:
+  TextMenuItem(const std::string& text_)
+    : text(text_) {}
+
+  virtual ~TextMenuItem() {}
+
+  void draw(int x, int y, bool active) {
+    if (active)
+      CL_Display::fill_rect(CL_Rect(CL_Point(x, y-2), CL_Size(70, 18)), 
+                            CL_Color(255, 255, 255));
+    Fonts::verdana11.draw(x+24, y, text);
+  }
+  int get_width()  { return Fonts::verdana11.bounding_rect(0, 0, 
text).get_width() + 16; }
+  int get_height() { return Fonts::verdana11.get_height(); }
+};
+
+class MenuImpl
+{
+public:
+  Menu* parent;
+  std::vector<CL_Slot> slots;
+
+  typedef std::vector<MenuItem*> Items;
+  Items items;
+  
+  int current_item;
+
+  int width;
+  int height;
+
+  void draw();
+  void recalc_size();
+  int  get_width();
+  int  get_height();
+
+  void on_mouse_move(const CL_InputEvent& event);
+  void on_mouse_down(const CL_InputEvent& event);
+};
+
+Menu::Menu(const CL_Point& pos, CL_Component* parent)
+  : CL_Component(CL_Rect(pos, CL_Size(1,1)), parent),
+    impl(new MenuImpl())
+{
+  impl->parent = this;
+
+  impl->width  = 1;
+  impl->height = 1;
+
+  impl->slots.push_back(sig_paint().connect(impl.get(), &MenuImpl::draw));
+  impl->slots.push_back(sig_mouse_move().connect(impl.get(), 
&MenuImpl::on_mouse_move));
+  impl->slots.push_back(sig_mouse_down().connect(impl.get(), 
&MenuImpl::on_mouse_down));
+}
+
+MenuItemHandle
+Menu::add_seperator()
+{
+  impl->items.push_back(new SeperatorMenuItem());
+  impl->recalc_size();
+  return impl->items.size();
+}
+
+MenuItemHandle
+Menu::add_item(const std::string& name)
+{
+  impl->items.push_back(new TextMenuItem(name));
+  impl->recalc_size();
+  return impl->items.size();
+}
+
+MenuItemHandle
+Menu::add_submenu(const std::string& name, const Menu& submenu)
+{
+  impl->recalc_size();
+  return -1;
+}
+
+void
+MenuImpl::recalc_size()
+{
+  int height = 0;
+  int width = 0;
+
+  for(Items::iterator i = items.begin(); i != items.end(); ++i)
+    width = std::max(width, (*i)->get_width());
+
+  for(Items::iterator i = items.begin(); i != items.end(); ++i)
+    height += (*i)->get_height() + 6;
+  
+  width  += 12 + 24;
+  height += 8;
+
+  parent->set_size(width, height);
+}
+
+void
+MenuImpl::draw()
+{
+  Box::draw_window(CL_Rect(CL_Point(0, 0), 
+                           CL_Size(parent->get_width(),
+                                   parent->get_height())));
+  int x_pos = 3;
+  int y_pos = 6;
+
+  for(int i = 0; i < int(items.size()); ++i)
+    {
+      items[i]->draw(x_pos, y_pos, i == current_item);
+      y_pos += items[i]->get_height() + 6;
+    }
+}
+
+int
+MenuImpl::get_width()
+{
+  return width;
+}
+
+int
+MenuImpl::get_height()
+{
+  return height;
+}
+
+void
+MenuImpl::on_mouse_down(const CL_InputEvent& event)
+{
+  std::cout << "Click on item: " << current_item << std::endl;
+}
+
+void
+MenuImpl::on_mouse_move(const CL_InputEvent& event)
+{
+  int y_pos = 6;
+
+  for(int i = 0; i < int(items.size()); ++i)
+    {
+      y_pos += items[i]->get_height() + 6;      
+      if (y_pos > event.mouse_pos.y)
+        {
+          current_item = i;
+          return;
+        }
+    }
+  current_item = -1;
+}
+
 /* EOF */

Modified: trunk/src/menu.hxx
===================================================================
--- trunk/src/menu.hxx  2004-05-22 12:25:16 UTC (rev 347)
+++ trunk/src/menu.hxx  2004-05-22 16:42:27 UTC (rev 348)
@@ -20,14 +20,27 @@
 #ifndef HEADER_MENU_HXX
 #define HEADER_MENU_HXX
 
+#include <string>
+#include <ClanLib/GUI/component.h>
+#include <ClanLib/Core/Math/rect.h>
+#include "shared_ptr.hxx"
+
+class MenuImpl;
+
+typedef int MenuItemHandle;
+
 /** */
-class Menu
+class Menu : public CL_Component
 {
-private:
 public:
-  Menu(CL_Component* parent);
+  Menu(const CL_Point& pos, CL_Component* parent);
 
-  MenuItem add_item(const std::string& );
+  MenuItemHandle add_item(const std::string& name);
+  MenuItemHandle add_submenu(const std::string& name, const Menu& submenu);
+  MenuItemHandle add_seperator();
+  
+private:
+  SharedPtr<MenuImpl> impl;
 };
 
 #endif

Modified: trunk/src/window.cxx
===================================================================
--- trunk/src/window.cxx        2004-05-22 12:25:16 UTC (rev 347)
+++ trunk/src/window.cxx        2004-05-22 16:42:27 UTC (rev 348)
@@ -72,9 +72,9 @@
                             make_sprite("../data/images/window/maximize.png"),
                             "", this);
 
-  impl->client_area = new CL_Component(CL_Rect(CL_Point(3, 3+12+6), 
-                                               CL_Size(rect.get_width()-8,
-                                                       rect.get_height()-25)), 
this);
+  impl->client_area = new CL_Component(CL_Rect(CL_Point(4, 3+12+7), 
+                                               CL_Size(rect.get_width()-10,
+                                                       rect.get_height()-28)), 
this);
   impl->parent = this;
   impl->pressed = false;
   impl->title = title;
@@ -98,7 +98,7 @@
 
   CL_Rect rect = parent->get_position() ;
 
-  Box::draw_panel(CL_Rect(CL_Point(0, 0), CL_Size(rect.get_width()-1, 
rect.get_height()-1)));
+  Box::draw_window(CL_Rect(CL_Point(0, 0), CL_Size(rect.get_width()-1, 
rect.get_height()-1)));
 
   CL_Display::fill_rect(CL_Rect(CL_Point(3+16,3), 
CL_Size(parent->get_width()-6-18-18-18, 12+3)), CL_Color(250, 250, 250));
   Fonts::verdana11.draw(8+15, 3, title);





reply via email to

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