[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Windstille-devel] rev 350 - trunk/src
From: |
Ingo Ruhnke |
Subject: |
[Windstille-devel] rev 350 - trunk/src |
Date: |
Thu, 27 May 2004 00:42:08 +0200 |
Author: grumbel
Date: 2004-05-27 00:42:08 +0200 (Thu, 27 May 2004)
New Revision: 350
Added:
trunk/src/titlebar.cxx
trunk/src/titlebar.hxx
Modified:
trunk/src/SConstruct
trunk/src/directory_view.cxx
trunk/src/editor.py
trunk/src/flexlay.i
trunk/src/menu.cxx
trunk/src/menu.hxx
trunk/src/window.cxx
Log:
- added titlebar
Modified: trunk/src/SConstruct
===================================================================
--- trunk/src/SConstruct 2004-05-22 18:10:43 UTC (rev 349)
+++ trunk/src/SConstruct 2004-05-26 22:42:08 UTC (rev 350)
@@ -97,6 +97,7 @@
'popup_menu.cxx',
'lispreader.cxx',
'tile.cxx',
+ 'titlebar.cxx',
'tile_brush.cxx',
'tile_editor.cxx',
'tile_selection.cxx',
Modified: trunk/src/directory_view.cxx
===================================================================
--- trunk/src/directory_view.cxx 2004-05-22 18:10:43 UTC (rev 349)
+++ trunk/src/directory_view.cxx 2004-05-26 22:42:08 UTC (rev 350)
@@ -196,7 +196,7 @@
CL_Font font = Fonts::verdana11;
- column_width = 0;
+ column_width = 60; // min_colum_width
for(Items::iterator i = items.begin(); i != items.end(); ++i)
{
CL_Rect rect = font.bounding_rect(0, 0, i->name + "[]");
Modified: trunk/src/editor.py
===================================================================
--- trunk/src/editor.py 2004-05-22 18:10:43 UTC (rev 349)
+++ trunk/src/editor.py 2004-05-26 22:42:08 UTC (rev 350)
@@ -126,14 +126,16 @@
a = menu.add_item("File/Save As...", menu_file_save_as)
a = menu.add_item("File/Quit", do_quit)
+mysprite = make_sprite("../data/images/icons16/stock_paste-16.png")
+
mymenu = Menu(CL_Point(100, 100), gui.get_component())
-mymenu.add_item("Foobar")
-mymenu.add_item("blub")
-mymenu.add_item("bla")
+mymenu.add_item(mysprite, "Foobar aeuaeu")
+mymenu.add_item(mysprite, "blub")
+mymenu.add_item(mysprite, "bla")
mymenu.add_seperator()
-mymenu.add_item("Foobar")
-mymenu.add_item("blub")
-mymenu.add_item("bla")
+mymenu.add_item(mysprite, "Foobar")
+mymenu.add_item(mysprite, "blubaoeuau aueau aeu")
+mymenu.add_item(mysprite, "bla")
def show_menu():
mymenu.run()
Modified: trunk/src/flexlay.i
===================================================================
--- trunk/src/flexlay.i 2004-05-22 18:10:43 UTC (rev 349)
+++ trunk/src/flexlay.i 2004-05-26 22:42:08 UTC (rev 350)
@@ -78,5 +78,4 @@
%include "menu.hxx"
%include "menubar.hxx"
-
/* EOF */
Modified: trunk/src/menu.cxx
===================================================================
--- trunk/src/menu.cxx 2004-05-22 18:10:43 UTC (rev 349)
+++ trunk/src/menu.cxx 2004-05-26 22:42:08 UTC (rev 350)
@@ -20,13 +20,43 @@
#include <iostream>
#include <string>
#include <ClanLib/Display/display.h>
+#include <ClanLib/Display/sprite.h>
#include "fonts.hxx"
#include "box.hxx"
#include "menu.hxx"
+class MenuItem;
+
+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);
+};
+
class MenuItem
{
+protected:
+ MenuImpl* parent;
public:
+ MenuItem(MenuImpl* parent_)
+ : parent(parent_) {}
virtual void draw(int x, int y, bool active) =0;
virtual int get_width() =0;
virtual int get_height() =0;
@@ -35,13 +65,17 @@
class SeperatorMenuItem : public MenuItem
{
public:
- SeperatorMenuItem() {}
+ SeperatorMenuItem(MenuImpl* parent_)
+ : MenuItem(parent_)
+ {}
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));
+ CL_Display::fill_rect(CL_Rect(CL_Point(x, y),
CL_Size(parent->get_width()-7, 2)),
+ CL_Color(150, 150, 150));
+ CL_Display::fill_rect(CL_Rect(CL_Point(x, y+1),
CL_Size(parent->get_width()-7, 1)),
+ CL_Color(255, 255, 255));
}
int get_width() { return 10; }
@@ -51,46 +85,33 @@
class TextMenuItem : public MenuItem
{
private:
+ CL_Sprite sprite;
std::string text;
public:
- TextMenuItem(const std::string& text_)
- : text(text_) {}
+ TextMenuItem(const CL_Sprite& sprite_, const std::string& text_, MenuImpl*
parent_)
+ : MenuItem(parent_),
+ sprite(sprite_),
+ text(text_)
+ {
+ sprite.set_alignment(origin_center);
+ }
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_Display::fill_rect(CL_Rect(CL_Point(x, y-2),
CL_Size(parent->get_width() - 7, 18)),
CL_Color(255, 255, 255));
+ if (sprite)
+ {
+ sprite.draw(x+10, y+7);
+ }
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())
@@ -110,15 +131,15 @@
MenuItemHandle
Menu::add_seperator()
{
- impl->items.push_back(new SeperatorMenuItem());
+ impl->items.push_back(new SeperatorMenuItem(impl.get()));
impl->recalc_size();
return impl->items.size();
}
MenuItemHandle
-Menu::add_item(const std::string& name)
+Menu::add_item(const CL_Sprite& sprite, const std::string& name)
{
- impl->items.push_back(new TextMenuItem(name));
+ impl->items.push_back(new TextMenuItem(sprite, name, impl.get()));
impl->recalc_size();
return impl->items.size();
}
@@ -133,8 +154,8 @@
void
MenuImpl::recalc_size()
{
- int height = 0;
- int width = 0;
+ height = 0;
+ width = 0;
for(Items::iterator i = items.begin(); i != items.end(); ++i)
width = std::max(width, (*i)->get_width());
Modified: trunk/src/menu.hxx
===================================================================
--- trunk/src/menu.hxx 2004-05-22 18:10:43 UTC (rev 349)
+++ trunk/src/menu.hxx 2004-05-26 22:42:08 UTC (rev 350)
@@ -26,6 +26,7 @@
#include "shared_ptr.hxx"
class MenuImpl;
+class CL_Sprite;
typedef int MenuItemHandle;
@@ -35,7 +36,7 @@
public:
Menu(const CL_Point& pos, CL_Component* parent);
- MenuItemHandle add_item(const std::string& name);
+ MenuItemHandle add_item(const CL_Sprite& sprite, const std::string& name);
MenuItemHandle add_submenu(const std::string& name, const Menu& submenu);
MenuItemHandle add_seperator();
Added: trunk/src/titlebar.cxx
===================================================================
--- trunk/src/titlebar.cxx 2004-05-22 18:10:43 UTC (rev 349)
+++ trunk/src/titlebar.cxx 2004-05-26 22:42:08 UTC (rev 350)
@@ -0,0 +1,108 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2002 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 <iostream>
+#include <ClanLib/Display/display.h>
+#include <ClanLib/Display/keys.h>
+#include "fonts.hxx"
+#include "titlebar.hxx"
+
+class TitlebarImpl
+{
+public:
+ CL_Component* window;
+ Titlebar* parent;
+ CL_Point click_pos;
+ CL_Rect old_pos;
+ std::string title;
+ std::vector<CL_Slot> slots;
+ bool pressed;
+
+ TitlebarImpl(Titlebar* parent_) : parent(parent_) {}
+
+ void on_mouse_move(const CL_InputEvent& event);
+ void on_mouse_down(const CL_InputEvent& event);
+ void on_mouse_up(const CL_InputEvent& event);
+ void draw();
+};
+
+Titlebar::Titlebar(const CL_Rect& rect, const std::string& title,
CL_Component* parent)
+ : CL_Component(rect, parent),
+ impl(new TitlebarImpl(this))
+{
+ impl->title = title;
+ impl->pressed = false;
+ impl->window = parent;
+
+ impl->slots.push_back(sig_mouse_down().connect(impl.get(),
&TitlebarImpl::on_mouse_down));
+ impl->slots.push_back(sig_mouse_move().connect(impl.get(),
&TitlebarImpl::on_mouse_move));
+ impl->slots.push_back(sig_mouse_up().connect(impl.get(),
&TitlebarImpl::on_mouse_up));
+ impl->slots.push_back(sig_paint().connect(impl.get(), &TitlebarImpl::draw));
+}
+
+void
+TitlebarImpl::on_mouse_up(const CL_InputEvent& event)
+{
+ if (event.id == CL_MOUSE_LEFT)
+ {
+ pressed = false;
+ parent->release_mouse();
+ }
+}
+
+void
+TitlebarImpl::on_mouse_down(const CL_InputEvent& event)
+{
+ if (event.id == CL_MOUSE_LEFT)
+ {
+ pressed = true;
+ click_pos = event.mouse_pos;
+ parent->capture_mouse();
+ window->raise();
+
+ old_pos = window->get_position();
+ click_pos.x += old_pos.left;
+ click_pos.y += old_pos.top;
+ }
+}
+
+void
+TitlebarImpl::on_mouse_move(const CL_InputEvent& event)
+{
+ if(pressed)
+ {
+ CL_Rect rect = window->get_position();
+
+ CL_Point move(old_pos.left - (click_pos.x - (rect.left +
event.mouse_pos.x)),
+ old_pos.top - (click_pos.y - (rect.top +
event.mouse_pos.y)));
+
+ window->set_position(move.x, move.y);
+ }
+}
+
+void
+TitlebarImpl::draw()
+{
+ CL_Display::fill_rect(CL_Rect(CL_Point(0, 0),
+ CL_Size(parent->get_width()-1,
parent->get_height())),
+ CL_Color(250, 250, 250));
+ Fonts::verdana11.draw(4, 0, title);
+}
+
+/* EOF */
Added: trunk/src/titlebar.hxx
===================================================================
--- trunk/src/titlebar.hxx 2004-05-22 18:10:43 UTC (rev 349)
+++ trunk/src/titlebar.hxx 2004-05-26 22:42:08 UTC (rev 350)
@@ -0,0 +1,41 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2002 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_TITLEBAR_HXX
+#define HEADER_TITLEBAR_HXX
+
+#include <ClanLib/GUI/component.h>
+#include <ClanLib/Core/Math/rect.h>
+#include "shared_ptr.hxx"
+
+class TitlebarImpl;
+
+/** */
+class Titlebar : public CL_Component
+{
+public:
+ Titlebar(const CL_Rect& rect, const std::string& title, CL_Component*
parent);
+
+private:
+ SharedPtr<TitlebarImpl> impl;
+};
+
+#endif
+
+/* EOF */
Modified: trunk/src/window.cxx
===================================================================
--- trunk/src/window.cxx 2004-05-22 18:10:43 UTC (rev 349)
+++ trunk/src/window.cxx 2004-05-26 22:42:08 UTC (rev 350)
@@ -27,6 +27,7 @@
#include "box.hxx"
#include "fonts.hxx"
#include "icon.hxx"
+#include "titlebar.hxx"
#include "window.hxx"
CL_Sprite
@@ -43,25 +44,24 @@
CL_Component* client_area;
CL_Component* parent;
+ Titlebar* titlebar;
CL_Component* close;
CL_Component* minimize;
CL_Component* maximize;
std::vector<CL_Slot> slots;
- CL_Point click_pos;
- CL_Rect old_pos;
- bool pressed;
- std::string title;
void draw();
- void mouse_down(const CL_InputEvent& event);
- void mouse_up(const CL_InputEvent& event);
- void mouse_move(const CL_InputEvent& event);
};
Window::Window(const CL_Rect& rect, const std::string& title, CL_Component*
parent)
: CL_Component(rect, parent), impl(new WindowImpl())
{
+ impl->titlebar = new Titlebar(CL_Rect(CL_Point(3+16,3),
+ CL_Size(get_width()-6-18-18-18,
12+3)), title,
+ this);
+ //Fonts::verdana11.draw(8+15, 3, title);
+
impl->close = new Icon(CL_Rect(CL_Point(3, 3), CL_Size(18,18)),
make_sprite("../data/images/window/close.png"),
"", this);
@@ -75,14 +75,9 @@
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;
+ impl->parent = this;
impl->slots.push_back(sig_paint().connect(impl.get(),
&WindowImpl::draw));
- impl->slots.push_back(sig_mouse_down().connect(impl.get(),
&WindowImpl::mouse_down));
- impl->slots.push_back(sig_mouse_up().connect(impl.get(),
&WindowImpl::mouse_up));
- impl->slots.push_back(sig_mouse_move().connect(impl.get(),
&WindowImpl::mouse_move));
}
Window::~Window()
@@ -99,10 +94,6 @@
CL_Rect rect = parent->get_position() ;
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);
-
Box::draw_panel_down(client_area->get_position());
/*
@@ -121,47 +112,6 @@
*/
}
-void
-WindowImpl::mouse_down(const CL_InputEvent& event)
-{
- if (event.id == CL_MOUSE_MIDDLE)
- {
- pressed = true;
- click_pos = event.mouse_pos;
- parent->capture_mouse();
-
- old_pos = parent->get_position();
- click_pos.x += old_pos.left;
- click_pos.y += old_pos.top;
- }
-}
-
-void
-WindowImpl::mouse_up(const CL_InputEvent& event)
-{
- if (event.id == CL_MOUSE_MIDDLE)
- {
- pressed = false;
- parent->release_mouse();
-
- parent->raise();
- }
-}
-
-void
-WindowImpl::mouse_move(const CL_InputEvent& event)
-{
- if(pressed)
- {
- CL_Rect rect = parent->get_position();
-
- CL_Point move(old_pos.left - (click_pos.x - (rect.left +
event.mouse_pos.x)),
- old_pos.top - (click_pos.y - (rect.top +
event.mouse_pos.y)));
-
- parent->set_position(move.x, move.y);
- }
-}
-
CL_Component*
Window::get_client_area()
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Windstille-devel] rev 350 - trunk/src,
Ingo Ruhnke <=