src/widget/widget_resizebox.cpp
author KUDr
Sat, 10 Mar 2007 02:39:51 +0000
branchcpp_gui
changeset 6293 59b7305f9a8b
parent 6290 8078f7a3c8a0
child 6295 a88d8c2cff6e
permissions -rw-r--r--
(svn r9087) [cpp_gui] -Codechange: Window is now clipping its widgets in OnPaint()
-Add: ClipDrawContext class to simplify draw clipping
-Fix: ResizeBox now can't resize window to negative width/height
/* $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(Left(), Top(), Right(), Bottom(), m_color, 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, DEFAULT_WIDTH);
	size.y = max(size.y, DEFAULT_HEIGHT);
	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(Size() == 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->Size() - 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