79 lines
2.0 KiB
C++
79 lines
2.0 KiB
C++
/*
|
|
Copyright 2013 Peter Nelson
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
#ifndef WIDGET_H
|
|
#define WIDGET_H
|
|
|
|
#include <climits>
|
|
#include <list>
|
|
|
|
struct Rect {
|
|
int x;
|
|
int y;
|
|
int w;
|
|
int h;
|
|
|
|
Rect() : x(0), y(0), w(0), h(0) {}
|
|
|
|
inline bool Hit(int hitx, int hity)
|
|
{
|
|
return hitx >= x && hitx < x + w && hity >= y && hity < y + h;
|
|
}
|
|
};
|
|
|
|
struct Colour {
|
|
float r, g, b, a;
|
|
|
|
Colour() : r(0), g(0), b(0), a(0) {}
|
|
Colour(float r, float g, float b) : r(r), g(g), b(b), a(1.f) {}
|
|
Colour(float r, float g, float b, float a) : r(r), g(g), b(b), a(a) {}
|
|
};
|
|
|
|
/* Forward declaration of PUi for OnPaint() member */
|
|
struct PUi;
|
|
|
|
struct Widget : Rect {
|
|
uint32_t port;
|
|
float min;
|
|
float max;
|
|
float value;
|
|
char group[128];
|
|
char label[128];
|
|
char text[128];
|
|
|
|
bool active;
|
|
|
|
Widget() : port(UINT_MAX), min(0.f), max(1.f), value(0.f), active(false) {}
|
|
|
|
virtual ~Widget() {}
|
|
|
|
virtual Widget *GetWidget(int x, int y) { return this; }
|
|
virtual Widget *GetWidget(uint32_t port) { return this->port == port ? this : NULL; }
|
|
virtual float GetNewValue(int x, int y) { return this->value; }
|
|
virtual bool SetValue(float newvalue);
|
|
|
|
virtual void OnPaint(const PUi *pui) const;
|
|
|
|
void Pad(int xpad, int ypad);
|
|
};
|
|
|
|
struct Frame : Widget {
|
|
Colour colour;
|
|
|
|
/* virtual */ void OnPaint(const PUi *pui) const;
|
|
};
|
|
|
|
#endif /* WIDGET_H */
|