(svn r8981) [cpp_gui] -Add: simple CaptionBar Widget cpp_gui
authorKUDr
Fri, 02 Mar 2007 21:21:41 +0000
branchcpp_gui
changeset 6273 d8a2c6844650
parent 6272 43637acd46b5
child 6274 35a9b459de19
(svn r8981) [cpp_gui] -Add: simple CaptionBar Widget
- no CloseButton and StickyButton yet
- no moving capability yet
src/intro_gui.cpp
src/widget/widget.h
src/widget/widget_caption.cpp
src/window.cpp
--- a/src/intro_gui.cpp	Thu Mar 01 23:34:28 2007 +0000
+++ b/src/intro_gui.cpp	Fri Mar 02 21:21:41 2007 +0000
@@ -174,6 +174,11 @@
 		SetTopLeft(Point16(140, 40));
 		SetSize(Point16(336, 195));
 		desc_flags = WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS;
+		m_color = COLOUR_BROWN;
+
+		/* add caption bar (later this will be done automatically by window core */
+		gui::CaptionBar *capt_bar = new gui::CaptionBar(this, -100, RESIZE_LR, COLOUR_BROWN, 0x84, STR_0282_CONSTRUCT_BUBBLE_GENERATOR, STR_015B_OPENTTD);
+		AddWidget(capt_bar);
 
 		/* add controls */
 		m_button1 = new gui::TextButton(this, 22, RESIZE_NONE, COLOUR_YELLOW, Rect16(104, 175, 231, 186), STR_0305_QUIT_OPENTTD, STR_0304_QUIT);
--- a/src/widget/widget.h	Thu Mar 01 23:34:28 2007 +0000
+++ b/src/widget/widget.h	Fri Mar 02 21:21:41 2007 +0000
@@ -231,6 +231,33 @@
 	/*virtual*/ void OnPaint(EvtPaint &ev);
 };
 
+struct CaptionBar : public CompositeWidget {
+	typedef CompositeWidget super;
+
+	static const int16 DEFAULT_HEIGHT = 14;
+
+protected:
+	StringID m_text;
+	byte     m_text_color;
+
+public:
+	CaptionBar()
+		: CompositeWidget()
+		, m_text(0)
+		, m_text_color(0xFF)
+	{}
+
+	CaptionBar(CompositeWidget *container, WidgetId id, byte display_flags, byte color, byte text_color, StringID tooltips, StringID text)
+		: CompositeWidget(container, id, display_flags, color, Rect16(0, 0, container->Width() - 1, DEFAULT_HEIGHT - 1), tooltips)
+		, m_text(text)
+		, m_text_color(text_color)
+	{}
+
+	/*virtual*/ void DrawBackground(EvtPaint &ev);
+
+	/*virtual*/ void OnPaint(EvtPaint &ev);
+};
+
 
 
 
--- a/src/widget/widget_caption.cpp	Thu Mar 01 23:34:28 2007 +0000
+++ b/src/widget/widget_caption.cpp	Fri Mar 02 21:21:41 2007 +0000
@@ -18,3 +18,37 @@
 #include "window_events.hpp"
 
 
+namespace gui {
+
+/*virtual*/ void CaptionBar::DrawBackground(EvtPaint &ev)
+{
+//	DrawFrameRect(m_color, FR_NONE);
+
+	BaseWindow *w = GetWindow();
+	assert(w != NULL);
+
+	byte caption_color = w->caption_color;
+	assert(Height() == 14); // XXX - to ensure the same sizes are used everywhere!
+	DrawFrameRect(Left(), Top(), Right(), Bottom(), m_color, FR_BORDERONLY);
+	DrawFrameRect(Left() + 1, Top() + 1, Right() - 1, Bottom() - 1, m_color, (caption_color == 0xFF) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY);
+	if (caption_color != 0xFF) {
+		GfxFillRect(Left() + 2, Top() + 2, Right() - 2, Bottom() - 2, _colour_gradient[_player_colors[caption_color]][4]);
+	}
+
+	//assert(r.bottom - r.top == 13); // XXX - to ensure the same sizes are used everywhere!
+	//DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_BORDERONLY);
+	//DrawFrameRect(r.left+1, r.top+1, r.right-1, r.bottom-1, wi->color, (caption_color == 0xFF) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY);
+
+	//if (caption_color != 0xFF) {
+	//	GfxFillRect(r.left+2, r.top+2, r.right-2, r.bottom-2, _colour_gradient[_player_colors[caption_color]][4]);
+	//}
+}
+
+/*virtual*/ void CaptionBar::OnPaint(EvtPaint &ev)
+{
+	DrawBackground(ev);
+	DrawStringCenteredTruncated(Left() + 2, Right() - 2, Top() + 2, m_text, m_text_color);
+	ev.SetHandled();
+}
+
+}; // namespace gui
--- a/src/window.cpp	Thu Mar 01 23:34:28 2007 +0000
+++ b/src/window.cpp	Fri Mar 02 21:21:41 2007 +0000
@@ -225,6 +225,7 @@
 {
 	window_number = num;
 	flash_timeout = 3; // just opened windows have a white border
+	caption_color = 0xFF;
 
 	/* add our new window into z-order list */
 	BaseWindow::s_list.Add(this);