xenia/src/poly/ui/ui_event.h

90 lines
2 KiB
C
Raw Normal View History

/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
2014-12-20 22:54:55 +01:00
#ifndef POLY_UI_UI_EVENT_H_
#define POLY_UI_UI_EVENT_H_
2014-12-20 22:54:55 +01:00
namespace poly {
namespace ui {
2014-12-20 22:54:55 +01:00
class Control;
class UIEvent {
2014-08-22 08:10:08 +02:00
public:
2014-12-20 22:54:55 +01:00
UIEvent(Control* control = nullptr) : control_(control) {}
2014-08-22 08:10:08 +02:00
virtual ~UIEvent() = default;
2014-12-20 22:54:55 +01:00
Control* control() const { return control_; }
2014-08-22 08:10:08 +02:00
private:
2014-12-20 22:54:55 +01:00
Control* control_;
};
2014-05-28 22:59:43 +02:00
class KeyEvent : public UIEvent {
2014-08-22 08:10:08 +02:00
public:
2014-12-20 22:54:55 +01:00
KeyEvent(Control* control, int key_code)
2015-01-03 02:26:02 +01:00
: UIEvent(control), handled_(false), key_code_(key_code) {}
2014-08-22 08:10:08 +02:00
~KeyEvent() override = default;
2014-05-28 22:59:43 +02:00
2015-01-03 02:26:02 +01:00
bool is_handled() const { return handled_; }
void set_handled(bool value) { handled_ = value; }
2014-05-28 22:59:43 +02:00
int key_code() const { return key_code_; }
2014-08-22 08:10:08 +02:00
private:
2015-01-03 02:26:02 +01:00
bool handled_;
2014-05-28 22:59:43 +02:00
int key_code_;
};
class MouseEvent : public UIEvent {
2014-08-22 08:10:08 +02:00
public:
2014-12-20 22:54:55 +01:00
enum class Button {
kNone = 0,
kLeft,
kRight,
kMiddle,
kX1,
kX2,
};
2014-08-22 08:10:08 +02:00
public:
2014-12-20 22:54:55 +01:00
MouseEvent(Control* control, Button button, int32_t x, int32_t y,
2014-08-22 08:10:08 +02:00
int32_t dx = 0, int32_t dy = 0)
2015-01-03 02:26:02 +01:00
: UIEvent(control),
handled_(false),
button_(button),
x_(x),
y_(y),
dx_(dx),
dy_(dy) {}
2014-08-22 08:10:08 +02:00
~MouseEvent() override = default;
2015-01-03 02:26:02 +01:00
bool is_handled() const { return handled_; }
void set_handled(bool value) { handled_ = value; }
Button button() const { return button_; }
int32_t x() const { return x_; }
int32_t y() const { return y_; }
int32_t dx() const { return dx_; }
int32_t dy() const { return dy_; }
2014-08-22 08:10:08 +02:00
private:
2015-01-03 02:26:02 +01:00
bool handled_;
2014-08-22 08:10:08 +02:00
Button button_;
int32_t x_;
int32_t y_;
int32_t dx_;
int32_t dy_;
};
} // namespace ui
2014-12-20 22:54:55 +01:00
} // namespace poly
2014-12-20 22:54:55 +01:00
#endif // POLY_UI_UI_EVENT_H_