src/widget/widget_button.cpp
author KUDr
Thu, 01 Mar 2007 22:48:46 +0000
branchcpp_gui
changeset 6271 0ad100a98853
parent 6264 9fc3b5467396
child 6282 c5b92f2d924f
permissions -rw-r--r--
(svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
-Codechange: Button now releases itself and generates EvtClick event when mouse button is released
/* $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"

namespace gui {

void Button::OnCapturePressed(EvtMouseOver &e)
{
	if (_left_button_down) {
		e.SetHandled();
		return;
	}
	m_pushed = false;
	m_ticket_pressed.Release();

	EvtClick ev(Point(0, 0));
	ev.m_widget = this;
	CallHandlers(ev);
}

/*virtual*/ void Button::DrawBackground(EvtPaint &ev)
{
	DrawFrameRect(m_color, m_pushed ? FR_LOWERED : FR_NONE);
}

/*virtual*/ void Button::OnLeftClick(EvtClick &ev)
{
	m_pushed = true;
	ev.SetHandled();
	m_ticket_pressed = CaptureEventsT(this, &Button::OnCapturePressed);
	Invalidate();
}


}; // namespace gui