2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#ifndef HUD_H
|
|
|
|
#define HUD_H
|
2012-06-12 16:28:00 +00:00
|
|
|
|
2014-05-17 08:48:33 +00:00
|
|
|
#include <algorithm>
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <cstdarg>
|
2015-02-27 23:52:12 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2012-06-21 01:51:16 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#include "hud.h"
|
2012-06-12 16:28:00 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
class Hud
|
|
|
|
{
|
2012-06-12 16:28:00 +00:00
|
|
|
public:
|
2012-12-11 01:15:13 +00:00
|
|
|
typedef void (*RadioButtonCallback)(int c);
|
|
|
|
typedef void (*CheckBoxCallback)(bool checked, int data);
|
2013-09-21 01:19:34 +00:00
|
|
|
typedef void (*SliderCallback)(float value, int data);
|
2014-04-28 01:38:51 +00:00
|
|
|
typedef void (*PullDownCallback)(int value);
|
2012-06-12 23:28:17 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
Hud();
|
|
|
|
virtual ~Hud();
|
2013-09-21 01:19:34 +00:00
|
|
|
|
2014-05-23 20:24:31 +00:00
|
|
|
virtual void Init(int width, int height, int framebufferWidth, int framebufferHeight);
|
2012-06-12 23:28:17 +00:00
|
|
|
|
2014-05-23 20:24:31 +00:00
|
|
|
virtual void Rebuild(int width, int height,
|
|
|
|
int framebufferWidth, int framebufferHeight);
|
2012-06-12 16:28:00 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual bool Flush();
|
2012-06-12 23:28:17 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
bool IsVisible() const;
|
2012-06-21 01:51:16 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
void SetVisible(bool visible);
|
2012-06-12 23:28:17 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
void DrawString(int x, int y, const char *fmt, ...);
|
2012-06-12 23:28:17 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
void DrawString(int x, int y, float r, float g, float b, const char *fmt, ...);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
void Clear();
|
2012-06-12 16:28:00 +00:00
|
|
|
|
2013-09-21 01:19:34 +00:00
|
|
|
void AddLabel(const char *label, int x, int y);
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
void AddRadioButton(int group, const char *label, bool checked, int x, int y,
|
|
|
|
RadioButtonCallback callback=0, int data=0, int shortcut=0);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
void AddCheckBox(const char *label, bool checked, int x, int y,
|
|
|
|
CheckBoxCallback callback=0, int data=0, int shortcut=0);
|
2012-06-12 23:28:17 +00:00
|
|
|
|
2013-09-21 01:19:34 +00:00
|
|
|
void AddSlider(const char *label, float min, float max, float value,
|
|
|
|
int x, int y, int width, bool intStep,
|
|
|
|
SliderCallback callback=0, int data=0);
|
|
|
|
|
2014-04-28 01:38:51 +00:00
|
|
|
int AddPullDown(const char *label, int x, int y, int width,
|
|
|
|
PullDownCallback callback=0, int shortcut=0);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-04-28 23:36:39 +00:00
|
|
|
void AddPullDownButton(int handle, const char *label, int value, bool checked=false);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
bool KeyDown(int key);
|
2012-06-12 23:28:17 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
bool MouseClick(int x, int y);
|
2012-06-12 23:28:17 +00:00
|
|
|
|
2013-09-21 01:19:34 +00:00
|
|
|
bool MouseCapture() const;
|
|
|
|
|
|
|
|
void MouseRelease();
|
|
|
|
|
|
|
|
void MouseMotion(int x, int y);
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
int GetWidth() const;
|
2013-09-21 01:19:34 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
int GetHeight() const;
|
2012-06-12 16:28:00 +00:00
|
|
|
|
2012-06-12 23:28:17 +00:00
|
|
|
protected:
|
2014-04-28 01:38:51 +00:00
|
|
|
struct Item {
|
|
|
|
|
2013-09-21 01:19:34 +00:00
|
|
|
int x, y, w, h;
|
|
|
|
std::string label;
|
|
|
|
};
|
|
|
|
|
2014-04-28 01:38:51 +00:00
|
|
|
struct RadioButton : public Item {
|
|
|
|
|
2013-09-21 01:19:34 +00:00
|
|
|
int group;
|
|
|
|
int localIndex;
|
|
|
|
bool checked;
|
|
|
|
int shortcut;
|
|
|
|
bool sharedShortcut;
|
|
|
|
RadioButtonCallback callback;
|
|
|
|
int callbackData;
|
|
|
|
};
|
|
|
|
|
2014-04-28 01:38:51 +00:00
|
|
|
struct CheckBox : public Item {
|
|
|
|
|
2013-09-21 01:19:34 +00:00
|
|
|
bool checked;
|
|
|
|
CheckBoxCallback callback;
|
|
|
|
int callbackData;
|
|
|
|
int shortcut;
|
|
|
|
};
|
|
|
|
|
2014-04-28 01:38:51 +00:00
|
|
|
struct Slider : public Item {
|
|
|
|
|
2013-09-21 01:19:34 +00:00
|
|
|
float min, max;
|
|
|
|
float value;
|
|
|
|
SliderCallback callback;
|
|
|
|
int callbackData;
|
|
|
|
bool intStep;
|
|
|
|
|
|
|
|
void SetValue(float v) {
|
|
|
|
value = std::max(std::min(v, max), min);
|
2015-02-26 21:57:47 +00:00
|
|
|
if (intStep) {
|
2015-02-27 23:52:12 +00:00
|
|
|
// MSVC 2010 does not have std::round() or roundf()
|
|
|
|
value = v>0.0f ? floor(v+0.5f) : ceil(v-0.5f);
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
2013-09-21 01:19:34 +00:00
|
|
|
}
|
|
|
|
};
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-04-28 01:38:51 +00:00
|
|
|
struct PullDown : public Item {
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
bool open;
|
2014-04-28 01:38:51 +00:00
|
|
|
int selected;
|
|
|
|
std::vector<char const *> labels;
|
2014-04-28 06:05:18 +00:00
|
|
|
std::vector<int> values;
|
2014-04-28 01:38:51 +00:00
|
|
|
int shortcut;
|
|
|
|
PullDownCallback callback;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-04-28 01:38:51 +00:00
|
|
|
void SetSelected(int idx) {
|
|
|
|
if (idx>=0 and idx<(int)labels.size()) {
|
|
|
|
selected=idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2013-09-21 01:19:34 +00:00
|
|
|
|
2014-04-28 06:05:18 +00:00
|
|
|
static int drawString(std::vector<float> &vboSource, int x, int y,
|
|
|
|
float r, float g, float b, const char *c);
|
2013-09-21 01:19:34 +00:00
|
|
|
|
2014-04-28 06:05:18 +00:00
|
|
|
static int drawChar(std::vector<float> &vboSource, int x, int y,
|
|
|
|
float r, float g, float b, char ch);
|
2013-09-21 01:19:34 +00:00
|
|
|
|
|
|
|
bool hitTest(Item const &item, int x, int y) const {
|
|
|
|
int ix = item.x > 0 ? item.x : _windowWidth + item.x;
|
|
|
|
int iy = item.y > 0 ? item.y : _windowHeight + item.y;
|
|
|
|
return (x >= ix &&
|
|
|
|
y >= iy &&
|
|
|
|
x <= (ix + item.w) &&
|
|
|
|
y <= (iy + item.h));
|
|
|
|
}
|
|
|
|
|
|
|
|
void getWindowPos(Item const &item, int *x, int *y) const {
|
|
|
|
*x = item.x > 0 ? item.x : _windowWidth + item.x;
|
|
|
|
*y = item.y > 0 ? item.y : _windowHeight + item.y;
|
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
std::vector<float> & getVboSource();
|
2013-09-21 01:19:34 +00:00
|
|
|
std::vector<float> & getStaticVboSource();
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
private:
|
2014-04-28 01:38:51 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
bool _visible;
|
2013-09-21 01:19:34 +00:00
|
|
|
std::vector<float> _vboSource, _staticVboSource;
|
2012-12-11 01:15:13 +00:00
|
|
|
int _windowWidth, _windowHeight;
|
2014-05-23 20:24:31 +00:00
|
|
|
int _framebufferWidth, _framebufferHeight;
|
2012-12-11 01:15:13 +00:00
|
|
|
bool _requiresRebuildStatic;
|
2013-09-21 01:19:34 +00:00
|
|
|
std::vector<Item> _labels;
|
2012-12-11 01:15:13 +00:00
|
|
|
std::vector<RadioButton> _radioButtons;
|
|
|
|
std::vector<CheckBox> _checkBoxes;
|
2013-09-21 01:19:34 +00:00
|
|
|
std::vector<Slider> _sliders;
|
2014-04-28 01:38:51 +00:00
|
|
|
std::vector<PullDown> _pulldowns;
|
2013-09-21 01:19:34 +00:00
|
|
|
int _capturedSlider;
|
2012-06-12 16:28:00 +00:00
|
|
|
};
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif // HUD_H
|