/* $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)
{
BaseWindow *w = GetWindow();
assert(w != NULL);
if (_left_button_down) {
/* translate the global coordinates to our window space */
Point16 pt_local = e.m_pt - w->TopLeft();
/* determine the new button push state (is cursor inside button?) */
bool pushed = (WidgetFromPt(pt_local) != NULL);
/* did the push state change */
if (pushed != m_pushed) {
/* update button push state */
m_pushed = pushed;
Invalidate();
}
e.SetHandled();
return;
}
/* stop capturing mouse move events */
m_ticket_pressed.Release();
/* Issue OnLeftClick() event only if the button was pushed */
if (m_pushed) {
/* release button */
m_pushed = false;
Invalidate();
/* issue click event */
EvtLeftClick ev(e.m_pt - w->TopLeft());
ev.m_widget = this;
OnLeftClick(ev);
}
}
/*virtual*/ void Button::DrawBackground(EvtPaint &ev)
{
DrawFrameRect(m_color, m_pushed ? FR_LOWERED : FR_NONE);
}
/*virtual*/ void Button::OnLeftButtonDown(EvtLeftButtonDown &ev)
{
/* start capturing mouse move events */
m_ticket_pressed = CaptureEventsT(this, &Button::OnCapturePressed);
/* push the button */
m_pushed = true;
Invalidate();
ev.SetHandled();
}
}; // namespace gui