Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
View
2  gl.h
@@ -13,7 +13,7 @@
#ifdef PRINT_GL_ERRORS
#define glCheckError() { \
int gl_error = glGetError(); \
- if(gl_error != GL_NO_ERROR) fprintf(stderr, "GL error %s at %s:%d\n", gluErrorString(gl_error), __FILE__, __LINE__); \
+ if(gl_error != GL_NO_ERROR) warnLog("GL error %s at %s:%d", gluErrorString(gl_error), __FILE__, __LINE__); \
}
#else
#define glCheckError()
View
1  ui/action.h
@@ -6,6 +6,7 @@ class UIAction {
UIAction() {};
virtual void perform() {};
+ virtual void idle() {};
};
#endif
View
13 ui/label.cpp
@@ -4,7 +4,7 @@
//UILabel
-UILabel::UILabel(const std::string& text, bool editable, float width) : text(text), width(width), UIElement() {
+UILabel::UILabel(const std::string& text, bool editable, float width, UIAction* action) : text(text), width(width), action(action), UIElement() {
slider = 0;
text_colour = vec4(0.0f);
@@ -175,6 +175,10 @@ void UILabel::setTextColour(const vec4& text_colour) {
this->text_colour = text_colour;
}
+void UILabel::idle() {
+ if(action != 0) action->idle();
+}
+
void UILabel::drawContent() {
drawBackground();
@@ -232,7 +236,7 @@ void UILabel::drawContent() {
//UIIntLabel
-UIIntLabel::UIIntLabel(int* value, bool editable) : value(value), UILabel("", editable) {
+UIIntLabel::UIIntLabel(int* value, bool editable, UIAction* action) : value(value), UILabel("", editable, -1.0f, action) {
width = 80.0f;
edit_bgcolour = vec4(0.0f, 0.0f, 0.0f, 0.0f);
}
@@ -267,13 +271,13 @@ void UIIntLabel::updateContent() {
//UIFloatLabel
-UIFloatLabel::UIFloatLabel(UIFloatSlider* slider, bool editable) : value(slider->value), UILabel("", editable) {
+UIFloatLabel::UIFloatLabel(UIFloatSlider* slider, bool editable, UIAction* action) : value(slider->value), UILabel("", editable, -1.0f, action) {
this->slider = slider;
width = 80.0f;
edit_bgcolour = vec4(0.0f, 0.0f, 0.0f, 0.0f);
}
-UIFloatLabel::UIFloatLabel(float* value, bool editable) : value(value), UILabel("", editable) {
+UIFloatLabel::UIFloatLabel(float* value, bool editable, UIAction* action) : value(value), UILabel("", editable, -1.0f, action) {
width = 80.0f;
edit_bgcolour = vec4(0.0f, 0.0f, 0.0f, 0.0f);
}
@@ -297,6 +301,7 @@ bool UIFloatLabel::submit() {
((UIFloatSlider*)slider)->setValue(v);
} else {
*value = v;
+ if(action != 0) action->perform();
}
return true;
View
12 ui/label.h
@@ -2,6 +2,7 @@
#define UI_LABEL_H
#include "element.h"
+#include "action.h"
class UISlider;
class UIFloatSlider;
@@ -14,6 +15,7 @@ class UILabel : public UIElement {
bool text_changed;
+ UIAction* action;
void drawBackground();
public:
@@ -26,7 +28,7 @@ class UILabel : public UIElement {
std::string text;
std::string display_text;
- UILabel(const std::string& text, bool editable = false, float width = -1.0f);
+ UILabel(const std::string& text, bool editable = false, float width = -1.0f, UIAction* action = 0);
float width;
@@ -51,12 +53,14 @@ class UILabel : public UIElement {
void updateRect();
void drawContent();
+
+ void idle();
};
class UIIntLabel : public UILabel {
int* value;
public:
- UIIntLabel(int* value, bool editable);
+ UIIntLabel(int* value, bool editable, UIAction* action = 0);
bool keyPress(SDL_KeyboardEvent *e, char c);
bool submit();
@@ -68,8 +72,8 @@ class UIFloatLabel : public UILabel {
protected:
float* value;
public:
- UIFloatLabel(float* value, bool editable);
- UIFloatLabel(UIFloatSlider* slider, bool editable);
+ UIFloatLabel(float* value, bool editable, UIAction* action = 0);
+ UIFloatLabel(UIFloatSlider* slider, bool editable, UIAction* action = 0);
void setValue(float* value);
View
29 ui/slider.cpp
@@ -2,7 +2,7 @@
//UISlider
-UISlider::UISlider(const std::string& slider_texture, float width) : slider_width(width), UIElement() {
+UISlider::UISlider(const std::string& slider_texture, float width, UIAction* action) : slider_width(width), action(action), UIElement() {
slidertex = texturemanager.grab(slider_texture);
rect = vec2(slider_width, 16.0f);
background = true;
@@ -80,10 +80,15 @@ bool UISlider::keyPress(SDL_KeyboardEvent *e, char c) {
return false;
}
+void UISlider::idle() {
+ if(action != 0) action->idle();
+}
+
+
//UIFloatSlider
-UIFloatSlider::UIFloatSlider(float* value, float min, float max) :
- min(min), max(max), value(value), UISlider("ui/slider.png", 128.0f) {
+UIFloatSlider::UIFloatSlider(float* value, float min, float max, UIAction* action) :
+ min(min), max(max), value(value), UISlider("ui/slider.png", 128.0f, action) {
}
void UIFloatSlider::scroll(bool up) {
@@ -139,6 +144,7 @@ void UIFloatSlider::setValue(float v) {
if(!value) return;
*value = std::max(std::min(max,v), min);
+ if(action != 0) action->perform();
}
void UIFloatSlider::drawContent() {
@@ -150,8 +156,8 @@ void UIFloatSlider::drawContent() {
//UIIntSlider
-UIIntSlider::UIIntSlider(int* value, int min, int max) :
- min(min), max(max), value(value), UISlider("ui/slider.png", 128.0f) {
+UIIntSlider::UIIntSlider(int* value, int min, int max, UIAction* action) :
+ min(min), max(max), value(value), UISlider("ui/slider.png", 128.0f, action) {
}
void UIIntSlider::scroll(bool up) {
@@ -176,6 +182,7 @@ void UIIntSlider::drag(const vec2& pos) {
void UIIntSlider::setValue(int v) {
*value = std::max(std::min(max,v), min);
+ if(action != 0) action->perform();
}
void UIIntSlider::drawContent() {
@@ -187,11 +194,11 @@ void UIIntSlider::drawContent() {
// UILabelFloatSlider
-UILabelFloatSlider::UILabelFloatSlider(const std::string& label, float* value, float min, float max) : UILayout(true) {
+UILabelFloatSlider::UILabelFloatSlider(const std::string& label, float* value, float min, float max, UIAction* action) : UILayout(true) {
- slider = new UIFloatSlider(value, min, max);
+ slider = new UIFloatSlider(value, min, max, action);
- flabel = new UIFloatLabel(value, true);
+ flabel = new UIFloatLabel(value, true, action);
flabel->slider = slider;
addElement(new UILabel(label, false, 120.0f));
@@ -218,11 +225,11 @@ void UILabelFloatSlider::scale(bool up) {
// UILabelIntSlider
-UILabelIntSlider::UILabelIntSlider(const std::string& label, int* value, int min, int max) : UILayout(true) {
+UILabelIntSlider::UILabelIntSlider(const std::string& label, int* value, int min, int max, UIAction* action) : UILayout(true) {
- slider = new UIIntSlider(value, min, max);
+ slider = new UIIntSlider(value, min, max, action);
- UIIntLabel* ilabel = new UIIntLabel(value, true);
+ UIIntLabel* ilabel = new UIIntLabel(value, true, action);
ilabel->slider = slider;
View
13 ui/slider.h
@@ -10,16 +10,19 @@ class UISlider : public UIElement {
TextureResource* slidertex;
float slider_width;
bool background;
+ UIAction* action;
void drawSlider(float position);
public:
- UISlider(const std::string& slider_texure, float width);
+ UISlider(const std::string& slider_texure, float width, UIAction* action = 0);
bool keyPress(SDL_KeyboardEvent *e, char c);
virtual void scroll(bool up) {};
virtual void scale(bool up) {};
+ void idle();
+
int getType() { return UI_SLIDER; };
};
@@ -29,7 +32,7 @@ class UIFloatSlider : public UISlider {
float min;
float max;
- UIFloatSlider(float* value, float min, float max);
+ UIFloatSlider(float* value, float min, float max, UIAction* action = 0);
void scale(bool up);
void scroll(bool up);
@@ -49,7 +52,7 @@ class UIIntSlider : public UISlider {
int min;
int max;
- UIIntSlider(int* value, int min, int max);
+ UIIntSlider(int* value, int min, int max, UIAction* action = 0);
void scroll(bool up);
void click(const vec2& pos);
@@ -64,7 +67,7 @@ class UILabelFloatSlider : public UILayout {
UIFloatSlider* slider;
UIFloatLabel* flabel;
public:
- UILabelFloatSlider(const std::string& label, float* value, float min, float max);
+ UILabelFloatSlider(const std::string& label, float* value, float min, float max, UIAction* action = 0);
void setFloat(float* f);
@@ -76,7 +79,7 @@ class UILabelIntSlider : public UILayout {
UIIntSlider* slider;
public:
- UILabelIntSlider(const std::string& label, int* value, int min, int max);
+ UILabelIntSlider(const std::string& label, int* value, int min, int max, UIAction* action = 0);
void scale(bool up);
void scroll(bool up);

No commit comments for this range

Something went wrong with that request. Please try again.