--- a/source.list Sun Mar 04 13:13:24 2007 +0000
+++ b/source.list Sun Mar 04 22:36:22 2007 +0000
@@ -334,6 +334,7 @@
widget/widget_resizebox.cpp
widget/widget_scrollbar.cpp
widget/widget_stickybox.cpp
+widget/widget_types.h
widget/window_event.cpp
widget/window_event_base.h
widget/window_events.hpp
--- a/src/intro_gui.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/intro_gui.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -4,7 +4,6 @@
#include "stdafx.h"
#include "openttd.h"
-#include "table/strings.h"
#include "table/sprites.h"
#include "functions.h"
#include "window.h"
@@ -18,6 +17,7 @@
#include "genworld.h"
#include "network/network_gui.h"
#include "newgrf.h"
+#include "widget/widget_types.h"
static const OldWidget _select_game_widgets[] = {
{ WWT_CAPTION, RESIZE_NONE, 13, 0, 335, 0, 13, STR_0307_OPENTTD, STR_NULL},
--- a/src/widget/widget.h Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget.h Sun Mar 04 22:36:22 2007 +0000
@@ -47,6 +47,8 @@
FF_NO_RESIZE_BOX = (1 << 3),
FF_UNMOVABLE = (1 << 4),
FF_TRANSPARENT = (1 << 5),
+ FF_TOGGLE_BUTTON = (1 << 6),
+ FF_STICKED = (1 << 7),
};
DECLARE_ENUM_AS_BIT_SET(FeatureFlags);
@@ -223,163 +225,6 @@
/*virtual*/ void OnResize(EvtResize &ev);
};
-struct Label : public Widget {
- typedef Widget super;
-
-protected:
- StringID m_text;
-
-public:
- Label()
- : Widget()
- {}
-
- Label(CompositeWidget *container, WidgetId id, FeatureFlags feature_flags, const Rect16 &rect, StringID text, StringID tooltip = 0, int color = COLOUR_NONE)
- : Widget(container, id, feature_flags, (byte)color, rect, tooltip)
- , m_text(text)
- {
- /* make the label transparent (no background) if color not provided */
- if (color == COLOUR_NONE) m_feature_flags |= FF_TRANSPARENT;
- }
-
- /*virtual*/ void DrawBackground(EvtPaint &ev);
-
- /*virtual*/ void OnPaint(EvtPaint &ev);
-};
-
-struct Button : public Widget {
- typedef Widget super;
-
-protected:
- bool m_pushed;
- CaptureTicket m_ticket_pressed;
-
-public:
- Button()
- : Widget()
- , m_pushed(false)
- {}
-
- Button(CompositeWidget *container, WidgetId id, FeatureFlags feature_flags, byte color, const Rect16 &rect, StringID tooltips)
- : Widget(container, id, feature_flags, color, rect, tooltips)
- , m_pushed(false)
- {}
-
- void OnCapturePressed(EvtMouseOver &e);
-
- /*virtual*/ void DrawBackground(EvtPaint &ev);
-
- /*virtual*/ void OnLeftButtonDown(EvtLeftButtonDown &ev);
-};
-
-struct TextButton : public Button {
- typedef Button super;
-
-protected:
- StringID m_text;
-
-public:
- TextButton()
- : Button()
- {}
-
- TextButton(CompositeWidget *container, WidgetId id, FeatureFlags feature_flags, byte color, const Rect16 &rect, StringID tooltips, StringID text)
- : Button(container, id, feature_flags, color, rect, tooltips)
- , m_text(text)
- {}
-
- /*virtual*/ void OnPaint(EvtPaint &ev);
-};
-
-struct CloseBox : public Button {
- typedef Button super;
-
- static const int16 DEFAULT_WIDTH = 11;
- static const int16 DEFAULT_HEIGHT = 14;
-
-public:
- CloseBox()
- : Button()
- {}
-
- CloseBox(CompositeWidget *container)
- : Button(container, -102, FF_NONE, container->m_color, Rect16(), 0)
- {}
-
- /*virtual*/ void OnCreate(EvtCreate &ev);
- /*virtual*/ void OnPaint(EvtPaint &ev);
- /*virtual*/ void OnLeftClick(EvtLeftClick &ev);
-};
-
-struct Caption : public Widget {
- typedef Widget super;
-
-protected:
- Point16 m_moving_offset;
- CaptureTicket m_ticket_moving;
-
-public:
- Caption()
- : Widget()
- {}
-
- Caption(CompositeWidget *container, WidgetId id, FeatureFlags feature_flags, byte color, const Rect16 rect, byte text_color, StringID tooltips, StringID text)
- : Widget(container, id, feature_flags, color, rect, tooltips)
- {}
-
- /*virtual*/ void DrawBackground(EvtPaint &ev);
-
- /*virtual*/ void OnPaint(EvtPaint &ev);
- /*virtual*/ void OnLeftButtonDown(EvtLeftButtonDown &ev);
- void OnCaptureMoving(EvtMouseOver &e);
-};
-
-struct CaptionBar : public CompositeWidget {
- typedef CompositeWidget super;
-
- static const int16 DEFAULT_HEIGHT = 14;
-
-public:
- CaptionBar()
- : CompositeWidget()
- {}
-
- CaptionBar(CompositeWidget *container, WidgetId id, FeatureFlags feature_flags, byte color)
- : CompositeWidget(container, id, feature_flags, color, Rect16(0, 0, container->Right(), DEFAULT_HEIGHT - 1), 0)
- {}
-
- /*virtual*/ void CreateWidgets();
-};
-
-
-struct ResizeBox : public Widget {
- typedef Widget super;
-
- static const int16 DEFAULT_WIDTH = 11;
- static const int16 DEFAULT_HEIGHT = 11;
-
-protected:
- Point16 m_sizing_offset;
- CaptureTicket m_ticket_sizing;
-
-public:
- ResizeBox()
- : Widget()
- {}
-
- ResizeBox(CompositeWidget *container)
- : Widget(container, -101, FF_NONE, container->m_color, Rect16(), 0)
- {}
-
- /*virtual*/ void DrawBackground(EvtPaint &ev);
- void OnCaptureSizing(EvtMouseOver &e);
-
- /*virtual*/ void OnCreate(EvtCreate &ev);
- /*virtual*/ void OnPaint(EvtPaint &ev);
- /*virtual*/ void OnLeftButtonDown(EvtLeftButtonDown &ev);
- /*virtual*/ void OnResizeParent(EvtResizeParent &ev);
-
-};
}; // namespace gui
--- a/src/widget/widget_button.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_button.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -16,6 +16,7 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
namespace gui {
@@ -59,16 +60,25 @@
DrawFrameRect(m_color, m_pushed ? FR_LOWERED : FR_NONE);
}
-/*virtual*/ void Button::OnLeftButtonDown(EvtLeftButtonDown &ev)
+/*virtual*/ void Button::OnLeftButtonDown(EvtLeftButtonDown &e)
{
- /* start capturing mouse move events */
- m_ticket_pressed = CaptureEventsT(this, &Button::OnCapturePressed);
+ if ((m_feature_flags & FF_TOGGLE_BUTTON) != FF_NONE) {
+ /* toggle button */
+ m_pushed = !m_pushed;
- /* push the button */
- m_pushed = true;
+ /* issue click event */
+ EvtLeftClick ev(e.m_pt);
+ ev.m_widget = this;
+ OnLeftClick(ev);
+ } else {
+ /* push button */
+ m_pushed = true;
+
+ /* start capturing mouse move events */
+ m_ticket_pressed = CaptureEventsT(this, &Button::OnCapturePressed);
+ }
Invalidate();
-
- ev.SetHandled();
+ e.SetHandled();
}
--- a/src/widget/widget_button_img.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_button_img.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -16,5 +16,6 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
--- a/src/widget/widget_button_img2.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_button_img2.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -16,5 +16,6 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
--- a/src/widget/widget_button_txt.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_button_txt.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -16,6 +16,7 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
namespace gui {
--- a/src/widget/widget_caption.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_caption.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -3,7 +3,6 @@
#include "../stdafx.h"
#include <stdarg.h>
#include "../openttd.h"
-#include "table/strings.h"
#include "../debug.h"
#include "../functions.h"
#include "../map.h"
@@ -17,6 +16,7 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
namespace gui {
@@ -26,14 +26,23 @@
BaseWindow *w = GetWindow();
assert(w != NULL);
- bool make_close_box = ((m_feature_flags & FF_NO_CLOSE_BOX) == FF_NONE);
+ bool make_close_box = ((m_feature_flags & FF_NO_CLOSE_BOX ) == FF_NONE);
+ bool make_sticky_box = ((m_feature_flags & FF_NO_STICKY_BOX) == FF_NONE);
+
Rect16 rc_caption = GetRect();
/* add close box */
if (make_close_box) {
CloseBox *close_box = new CloseBox(this);
AddWidget(close_box);
- rc_caption.SetLeft(rc_caption.Left() + 11);
+ rc_caption.SetLeft(rc_caption.Left() + CloseBox::DEFAULT_WIDTH);
+ }
+
+ /* add sticky box */
+ if (make_sticky_box) {
+ StickyBox *sticky_box = new StickyBox(this);
+ AddWidget(sticky_box);
+ rc_caption.SetRight(rc_caption.Right() - StickyBox::DEFAULT_WIDTH);
}
/* add caption */
--- a/src/widget/widget_closebox.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_closebox.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -3,7 +3,6 @@
#include "../stdafx.h"
#include <stdarg.h>
#include "../openttd.h"
-#include "table/strings.h"
#include "../debug.h"
#include "../functions.h"
#include "../map.h"
@@ -17,6 +16,7 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
namespace gui {
@@ -27,8 +27,6 @@
SetTopLeft(m_container->TopLeft());
SetBottomRight(TopLeft() + size - Point16(1, 1));
- m_tooltips = STR_018B_CLOSE_WINDOW;
-
SetAnchors(PIN_LEFT | PIN_TOP);
super::OnCreate(ev);
}
--- a/src/widget/widget_frame.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_frame.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -16,5 +16,6 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
--- a/src/widget/widget_hscrollbar.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_hscrollbar.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -16,5 +16,6 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
--- a/src/widget/widget_inset.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_inset.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -16,5 +16,6 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
--- a/src/widget/widget_label.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_label.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -16,6 +16,7 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
namespace gui {
--- a/src/widget/widget_list.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_list.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -16,5 +16,6 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
--- a/src/widget/widget_panel.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_panel.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -16,5 +16,6 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
--- a/src/widget/widget_resizebox.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_resizebox.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -3,7 +3,6 @@
#include "../stdafx.h"
#include <stdarg.h>
#include "../openttd.h"
-#include "table/strings.h"
#include "../debug.h"
#include "../functions.h"
#include "../map.h"
@@ -17,6 +16,7 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
namespace gui {
@@ -49,8 +49,6 @@
SetTopLeft(m_container->BottomRight() - size + Point16(1, 1));
SetBottomRight(m_container->BottomRight());
- m_tooltips = STR_RESIZE_BUTTON;
-
SetAnchors(PIN_RIGHT | PIN_BOTTOM);
super::OnCreate(ev);
}
--- a/src/widget/widget_scrollbar.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_scrollbar.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -16,5 +16,6 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
--- a/src/widget/widget_stickybox.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/widget/widget_stickybox.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -1,5 +1,4 @@
/* $Id$ */
-
#include "../stdafx.h"
#include <stdarg.h>
#include "../openttd.h"
@@ -16,5 +15,37 @@
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
+#include "widget_types.h"
+namespace gui {
+/*virtual*/ void StickyBox::OnCreate(EvtCreate &ev)
+{
+ // move itself to the right side of the parent
+ Rect16 rc = m_container->GetRect();
+ rc.SetLeft(rc.Right() - (DEFAULT_WIDTH - 1));
+ rc.SetBottom(rc.Top() + (DEFAULT_HEIGHT - 1));
+ SetRect(rc);
+
+ SetAnchors(PIN_TOP | PIN_RIGHT);
+ super::OnCreate(ev);
+}
+
+/*virtual*/ void StickyBox::OnPaint(EvtPaint &ev)
+{
+ assert(Size() == Point16(DEFAULT_WIDTH, DEFAULT_HEIGHT));
+
+ DrawBackground(ev);
+ DrawSprite(m_pushed ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, Left() + 2 + m_pushed, Top() + 3 + m_pushed);
+}
+
+/*virtual*/ void StickyBox::OnLeftClick(EvtLeftClick &ev)
+{
+ BaseWindow *w = GetWindow();
+ assert(w != NULL);
+
+ w->m_feature_flags = (w->m_feature_flags & ~FF_STICKED) | (m_pushed ? FF_STICKED : FF_NONE);
+}
+
+}; // namespace gui
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/widget/widget_types.h Sun Mar 04 22:36:22 2007 +0000
@@ -0,0 +1,191 @@
+/* $Id$ */
+
+#ifndef WIDGET_TYPES_H
+#define WIDGET_TYPES_H
+
+#include "widget.h"
+#include "table/strings.h"
+
+namespace gui {
+
+struct Label : public Widget {
+ typedef Widget super;
+
+protected:
+ StringID m_text;
+
+public:
+ Label()
+ : Widget()
+ {}
+
+ Label(CompositeWidget *container, WidgetId id, FeatureFlags feature_flags, const Rect16 &rect, StringID text, StringID tooltip = 0, int color = COLOUR_NONE)
+ : Widget(container, id, feature_flags, (byte)color, rect, tooltip)
+ , m_text(text)
+ {
+ /* make the label transparent (no background) if color not provided */
+ if (color == COLOUR_NONE) m_feature_flags |= FF_TRANSPARENT;
+ }
+
+ /*virtual*/ void DrawBackground(EvtPaint &ev);
+
+ /*virtual*/ void OnPaint(EvtPaint &ev);
+};
+
+struct Button : public Widget {
+ typedef Widget super;
+
+protected:
+ bool m_pushed;
+ CaptureTicket m_ticket_pressed;
+
+public:
+ Button()
+ : Widget()
+ , m_pushed(false)
+ {}
+
+ Button(CompositeWidget *container, WidgetId id, FeatureFlags feature_flags, byte color, const Rect16 &rect, StringID tooltips)
+ : Widget(container, id, feature_flags, color, rect, tooltips)
+ , m_pushed(false)
+ {}
+
+ void OnCapturePressed(EvtMouseOver &e);
+
+ /*virtual*/ void DrawBackground(EvtPaint &ev);
+
+ /*virtual*/ void OnLeftButtonDown(EvtLeftButtonDown &ev);
+};
+
+struct TextButton : public Button {
+ typedef Button super;
+
+protected:
+ StringID m_text;
+
+public:
+ TextButton()
+ : Button()
+ {}
+
+ TextButton(CompositeWidget *container, WidgetId id, FeatureFlags feature_flags, byte color, const Rect16 &rect, StringID tooltips, StringID text)
+ : Button(container, id, feature_flags, color, rect, tooltips)
+ , m_text(text)
+ {}
+
+ /*virtual*/ void OnPaint(EvtPaint &ev);
+};
+
+struct CloseBox : public Button {
+ typedef Button super;
+
+ static const int16 DEFAULT_WIDTH = 11;
+ static const int16 DEFAULT_HEIGHT = 14;
+
+public:
+ CloseBox()
+ : Button()
+ {}
+
+ CloseBox(CompositeWidget *container)
+ : Button(container, -102, FF_NONE, container->m_color, Rect16(), STR_018B_CLOSE_WINDOW)
+ {}
+
+ /*virtual*/ void OnCreate(EvtCreate &ev);
+ /*virtual*/ void OnPaint(EvtPaint &ev);
+ /*virtual*/ void OnLeftClick(EvtLeftClick &ev);
+};
+
+struct StickyBox : public Button {
+ typedef Button super;
+
+ static const int16 DEFAULT_WIDTH = 12;
+ static const int16 DEFAULT_HEIGHT = 14;
+
+public:
+ StickyBox()
+ : Button()
+ {}
+
+ StickyBox(CompositeWidget *container)
+ : Button(container, -103, FF_TOGGLE_BUTTON, container->m_color, Rect16(), STR_STICKY_BUTTON)
+ {}
+
+ /*virtual*/ void OnCreate(EvtCreate &ev);
+ /*virtual*/ void OnPaint(EvtPaint &ev);
+ /*virtual*/ void OnLeftClick(EvtLeftClick &ev);
+};
+
+struct Caption : public Widget {
+ typedef Widget super;
+
+protected:
+ Point16 m_moving_offset;
+ CaptureTicket m_ticket_moving;
+
+public:
+ Caption()
+ : Widget()
+ {}
+
+ Caption(CompositeWidget *container, WidgetId id, FeatureFlags feature_flags, byte color, const Rect16 rect, byte text_color, StringID tooltips, StringID text)
+ : Widget(container, id, feature_flags, color, rect, tooltips)
+ {}
+
+ /*virtual*/ void DrawBackground(EvtPaint &ev);
+
+ /*virtual*/ void OnPaint(EvtPaint &ev);
+ /*virtual*/ void OnLeftButtonDown(EvtLeftButtonDown &ev);
+ void OnCaptureMoving(EvtMouseOver &e);
+};
+
+struct CaptionBar : public CompositeWidget {
+ typedef CompositeWidget super;
+
+ static const int16 DEFAULT_HEIGHT = 14;
+
+public:
+ CaptionBar()
+ : CompositeWidget()
+ {}
+
+ CaptionBar(CompositeWidget *container, WidgetId id, FeatureFlags feature_flags, byte color)
+ : CompositeWidget(container, id, feature_flags, color, Rect16(0, 0, container->Right(), DEFAULT_HEIGHT - 1), 0)
+ {}
+
+ /*virtual*/ void CreateWidgets();
+};
+
+
+struct ResizeBox : public Widget {
+ typedef Widget super;
+
+ static const int16 DEFAULT_WIDTH = 11;
+ static const int16 DEFAULT_HEIGHT = 11;
+
+protected:
+ Point16 m_sizing_offset;
+ CaptureTicket m_ticket_sizing;
+
+public:
+ ResizeBox()
+ : Widget()
+ {}
+
+ ResizeBox(CompositeWidget *container)
+ : Widget(container, -101, FF_NONE, container->m_color, Rect16(), STR_RESIZE_BUTTON)
+ {}
+
+ /*virtual*/ void DrawBackground(EvtPaint &ev);
+ void OnCaptureSizing(EvtMouseOver &e);
+
+ /*virtual*/ void OnCreate(EvtCreate &ev);
+ /*virtual*/ void OnPaint(EvtPaint &ev);
+ /*virtual*/ void OnLeftButtonDown(EvtLeftButtonDown &ev);
+ /*virtual*/ void OnResizeParent(EvtResizeParent &ev);
+
+};
+
+}; // namespace gui
+
+#endif /* WIDGET_TYPES_H */
--- a/src/window.cpp Sun Mar 04 13:13:24 2007 +0000
+++ b/src/window.cpp Sun Mar 04 22:36:22 2007 +0000
@@ -5,7 +5,6 @@
#include "stdafx.h"
#include <stdarg.h>
#include "openttd.h"
-#include "table/strings.h"
#include "debug.h"
#include "functions.h"
#include "map.h"
@@ -19,6 +18,7 @@
#include "genworld.h"
#include "helpers.hpp"
#include "widget/window_events.hpp"
+#include "widget/widget_types.h"
// delta between mouse cursor and upper left corner of dragged window
static Point _drag_delta;