The-Powder-Toy/includes/interface/Component.h

205 lines
5.3 KiB
C
Raw Normal View History

2012-01-14 12:51:24 -06:00
#pragma once
2012-01-08 11:39:03 -06:00
2012-01-14 12:51:24 -06:00
#include "Point.h"
#include "State.h"
#include "Platform.h"
2012-01-08 11:39:03 -06:00
namespace ui
{
2012-01-14 12:51:24 -06:00
class State;
class Panel;
/* class Component
*
* An interactive UI component that can be added to a state or an XComponent*.
* *See sys::XComponent
*/
class Component
2012-01-08 11:39:03 -06:00
{
public:
2012-01-14 12:51:24 -06:00
Component(State* parent_state);
Component(Point position, Point size);
Component();
2012-01-08 11:39:03 -06:00
virtual ~Component();
2012-01-14 12:51:24 -06:00
void* UserData;
inline State* const GetParentState() const { return parentstate_; }
bool IsFocused() const;
2012-01-08 11:39:03 -06:00
2012-01-14 12:51:24 -06:00
Point Position;
Point Size;
bool Locked;
2012-01-08 11:39:03 -06:00
bool Visible;
2012-01-14 12:51:24 -06:00
/* See the parent of this component.
* If new_parent is NULL, this component will have no parent. (THIS DOES NOT delete THE COMPONENT. See XComponent::RemoveChild)
*/
void SetParentState(State* state);
void SetParent(Panel* new_parent);
//Get the parent component.
inline Panel* const GetParent() const { return _parent; }
//UI functions:
/*
void Tick(float dt);
void Draw(const Point& screenPos);
void OnMouseHover(int localx, int localy);
void OnMouseMoved(int localx, int localy, int dx, int dy);
void OnMouseMovedInside(int localx, int localy, int dx, int dy);
void OnMouseEnter(int localx, int localy);
void OnMouseLeave(int localx, int localy);
void OnMouseDown(int x, int y, unsigned int button);
void OnMouseUp(int x, int y, unsigned int button);
void OnMouseClick(int localx, int localy, unsigned int button);
void OnMouseUnclick(int localx, int localy, unsigned int button);
void OnMouseWheel(int localx, int localy, int d);
void OnMouseWheelInside(int localx, int localy, int d);
void OnKeyPress(int key, bool shift, bool ctrl, bool alt);
void OnKeyRelease(int key, bool shift, bool ctrl, bool alt);
*/
2012-01-08 11:39:03 -06:00
2012-01-14 12:51:24 -06:00
///
// Called: Every tick.
// Params:
// dt: The change in time.
///
virtual void Tick(float dt);
///
// Called: When ready to draw.
// Params:
// None
///
virtual void Draw(const Point& screenPos);
///
// Called: When the mouse is currently hovering over the item. (Called every tick)
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
///
virtual void OnMouseHover(int localx, int localy);
///
// Called: When the mouse moves.
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
// dx: Mouse X delta.
// dy: Mouse Y delta.
///
2012-01-08 11:39:03 -06:00
virtual void OnMouseMoved(int localx, int localy, int dx, int dy);
2012-01-14 12:51:24 -06:00
///
// Called: When the mouse moves.
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
// dx: Mouse X delta.
// dy: Mouse Y delta.
///
2012-01-08 11:39:03 -06:00
virtual void OnMouseMovedInside(int localx, int localy, int dx, int dy);
2012-01-14 12:51:24 -06:00
///
// Called: When the mouse moves on top of the item.
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
// dx: Mouse X delta.
// dy: Mouse Y delta.
///
virtual void OnMouseEnter(int localx, int localy);
///
// Called: When the mouse leaves the item.
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
///
virtual void OnMouseLeave(int localx, int localy);
///
// Called: When a mouse button is pressed.
// Params:
// x: X position of the mouse.
// y: Y position of the mouse.
// button: The button that is being held down.
///
virtual void OnMouseDown(int x, int y, unsigned button);
///
// Called: When a mouse button is released.
// Params:
// x: X position of the mouse.
// y: Y position of the mouse.
// button: The button that is being released.
///
virtual void OnMouseUp(int x, int y, unsigned button);
///
// Called: When a mouse button is pressed on top of the item.
// Params:
// x: X position of the mouse.
// y: Y position of the mouse.
// button: The button that is being held down.
///
virtual void OnMouseClick(int localx, int localy, unsigned button);
///
// Called: When a mouse button is released on top of the item.
// Params:
// x: X position of the mouse.
// y: Y position of the mouse.
// button: The button that is being released.
///
virtual void OnMouseUnclick(int localx, int localy, unsigned button);
///
// Called: When the mouse wheel moves/changes.
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
// d: The mouse wheel movement value.
///
2012-01-08 11:39:03 -06:00
virtual void OnMouseWheel(int localx, int localy, int d);
2012-01-14 12:51:24 -06:00
///
// Called: When the mouse wheel moves/changes on top of the item.
// Params:
// localx: Local mouse X position.
// localy: Local mouse Y position.
// d: The mouse wheel movement value.
///
2012-01-08 11:39:03 -06:00
virtual void OnMouseWheelInside(int localx, int localy, int d);
2012-01-14 12:51:24 -06:00
///
// Called: When a key is pressed.
// Params:
// key: The value of the key that is being pressed.
// shift: Shift key is down.
// ctrl: Control key is down.
// alt: Alternate key is down.
///
2012-01-08 11:39:03 -06:00
virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt);
2012-01-14 12:51:24 -06:00
///
// Called: When a key is released.
// Params:
// key: The value of the key that is being released.
// shift: Shift key is released.
// ctrl: Control key is released.
// alt: Alternate key is released.
///
2012-01-08 11:39:03 -06:00
virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt);
2012-01-14 12:51:24 -06:00
private:
State* parentstate_;
Panel* _parent;
2012-01-08 11:39:03 -06:00
};
}