(svn r9091) [cpp_gui] -Codechange: Widgets now use container's coordinate space instead of window's space
/* $Id$ */
#include "../stdafx.h"
#include <stdarg.h>
#include "../openttd.h"
#include "../debug.h"
#include "../functions.h"
#include "../map.h"
#include "../player.h"
#include "../window.h"
#include "../gfx.h"
#include "../viewport.h"
#include "../console.h"
#include "../variables.h"
#include "../table/sprites.h"
#include "../genworld.h"
#include "../helpers.hpp"
#include "window_events.hpp"
#include "widget_types.h"
namespace gui {
/*virtual*/ void CaptionBar::CreateWidgets()
{
BaseWindow *w = GetWindow();
assert(w != NULL);
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 = GetLocalRect();
/* add close box */
if (make_close_box) {
CloseBox *close_box = new CloseBox(this);
AddWidget(close_box);
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 */
Caption *caption = new Caption(this, -100, FF_NONE, m_color, rc_caption, 0x84, STR_018C_WINDOW_TITLE_DRAG_THIS, w->m_caption_text);
caption->SetAnchors(PIN_LEFT | PIN_TOP | PIN_RIGHT);
AddWidget(caption);
}
/*virtual*/ void Caption::DrawBackground(EvtPaint &ev)
{
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(m_color, FR_BORDERONLY);
DrawFrameRect(1, 1, Width() - 2, Height() - 2, m_color, (caption_color == 0xFF) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY);
if (caption_color != 0xFF) {
GfxFillRect(2, 2, Width() - 3, Height() - 3, _colour_gradient[_player_colors[caption_color]][4]);
}
}
/*virtual*/ void Caption::OnPaint(EvtPaint &ev)
{
BaseWindow *w = GetWindow();
assert(w != NULL);
DrawBackground(ev);
DrawStringCenteredTruncated(2, Width() - 3, 2, w->m_caption_text, 0x84);
ev.SetHandled();
}
/*virtual*/ void Caption::OnLeftButtonDown(EvtLeftButtonDown &ev)
{
BaseWindow *w = GetWindow();
assert(w != NULL);
/* if window is unmovable, do nothing */
if ((w->m_feature_flags & FF_UNMOVABLE) != FF_NONE) {
super::OnLeftButtonDown(ev);
return;
}
m_moving_offset = ev.m_pt;
ev.SetHandled();
m_ticket_moving = CaptureEventsT(this, &Caption::OnCaptureMoving);
Invalidate();
}
void Caption::OnCaptureMoving(EvtMouseOver &e)
{
if (!_left_button_down) {
m_ticket_moving.Release();
EvtLeftClick ev(Point(0, 0));
ev.m_widget = this;
CallHandlers(ev);
return;
}
GetWindow()->SetTopLeft(e.m_pt - m_moving_offset);
e.SetHandled();
Invalidate();
}
}; // namespace gui