/* $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 ResizeBox::DrawBackground(EvtPaint &ev)
{
bool sizing = m_ticket_sizing.IsActive();
DrawFrameRect(GetBkColor(), sizing ? FR_LOWERED : FR_NONE);
}
void ResizeBox::OnCaptureSizing(EvtMouseOver &e)
{
if (!_left_button_down) {
m_ticket_sizing.Release();
EvtLeftClick ev(Point(0, 0));
ev.m_widget = this;
CallHandlers(ev);
return;
}
BaseWindow *w = GetWindow();
w->SetDirty();
Point16 size = e.m_pt - w->TopLeft() + m_sizing_offset;
size.x = max(size.x, w->m_min_size.x);
size.y = max(size.y, w->m_min_size.y);
w->SetSize(size);
e.SetHandled();
w->SetDirty();
}
/*virtual*/ void ResizeBox::OnCreate(EvtCreate &ev)
{
Point16 size(DEFAULT_WIDTH, DEFAULT_HEIGHT);
SetTopLeft(m_container->BottomRight() - size + Point16(1, 1));
SetBottomRight(m_container->BottomRight());
SetAnchors(PIN_RIGHT | PIN_BOTTOM);
super::OnCreate(ev);
}
/*virtual*/ void ResizeBox::OnPaint(EvtPaint &ev)
{
// assert(GetSize() == Point16(DEFAULT_WIDTH, DEFAULT_HEIGHT));
DrawBackground(ev);
bool sizing = m_ticket_sizing.IsActive();
DrawSprite(SPR_WINDOW_RESIZE, PAL_NONE, sizing ? Point16(4, 4) : Point16(3, 3));
ev.SetHandled();
}
/*virtual*/ void ResizeBox::OnLeftButtonDown(EvtLeftButtonDown &ev)
{
BaseWindow *w = GetWindow();
m_sizing_offset = w->GetSize() - (GetTopLeftInWindow() + ev.m_pt);
m_ticket_sizing = CaptureEventsT(this, &ResizeBox::OnCaptureSizing);
Invalidate();
ev.SetHandled();
}
/*virtual*/ void ResizeBox::OnResizeParent(EvtResizeParent &ev)
{
//SetTopLeft(TopLeft() + ev.m_change);
//ev.SetHandled();
super::OnResizeParent(ev);
}
}; // namespace gui