Commit eabb3dc14c90e4100dc6ebe2def42cacb12cb1a1

Authored by Calvin Bulla
1 parent 393269eb
Exists in master and in 1 other branch dev

Added ofxUI

Showing 190 changed files with 17894 additions and 17894 deletions   Show diff stats

Too many changes.

To preserve performance only 100 of 190 files displayed.

app/ofxGUI/README.md
... ... @@ -1,169 +0,0 @@
1   -ofxUI
2   -=====
3   -
4   -A User Interface Library/Addon for openFrameworks
5   -
6   -ofxUI is an addon for openFrameworks (version 0.8.0+) that easily allows for the creation of user interfaces aka GUIs. ofxUI also takes care of widget layout, spacing, font loading, saving and loading settings, and widget callbacks. ofxUI can be easily customized (colors, font & widget sizes, padding, layout, etc).
7   -
8   -Featured Projects: http://www.syedrezaali.com/blog/?p=3102
9   -
10   -ofxUI contains a collection of minimally designed graphical user interface (GUI) widgets including:
11   -
12   -- Buttons (push, state, toggle, image, label)
13   -- Button Matrices
14   -- Dropdown Menus
15   -- Labels
16   -- Sliders (rotary, range, vertical, horizontal)
17   -- Number Dials
18   -- 2D Pads
19   -- Text Input Areas
20   -- Base Draws (ofImages, ofTexture, ofFbo, etc)
21   -- Image Sliders
22   -- Image Buttons
23   -- Image Color Sampler
24   -- Value Plotters
25   -- Moving Graphs
26   -- Waveform & Spectrum Graphs
27   -- Radio Toggles
28   -- Text Areas
29   -- Sortable List
30   -
31   -This library allows for rapid UI design and development. It uses ofTrueTypeFonts for nice font rendering. Widget layout is semi-automatic, and can be easily customized. ofxUI is a GL based GUI and uses openFramework's drawings calls to render its widgets. It integrates into openFrameworks projects very easily since it was designed specifically for OF. There are many examples included in the download that show how to add widgets, customize their placement, get values from different types of widgets, set widget values, add callback functions for gui events, saving and loading settings, and more.
32   -
33   -This UI library was inspired & influenced by:
34   -
35   -- controlP5 (http://www.sojamo.de/libraries/controlP5/)
36   -- GLV (http://mat.ucsb.edu/glv/)
37   -- SimpleGUI (http://marcinignac.com/blog/simplegui/)
38   -- Apple's User Interface
39   -
40   -It has been tested on OSX and iOS (OF 073+). It should work on linux and windows, since its only dependency is openFrameworks & ofxXmlSettings. ofxUI is open source under an MIT License, therefore you can use it in commercial and non-commercial projects. If you do end up using it, please let me know. I would love to see more examples of it out there in the wild. If you plan to use it in a commercial project please consider donating to help support this addon and future releases/fixes/features (http://www.syedrezaali.com/blog/?p=2172).
41   -
42   -In terms of performance, I haven't compared it to other GUIs out there, but since its written using OF drawing calls and uses Listeners built in to OF, it run very fast and doesn't take a lot of CPU cycles...atleast when I tested it when my sketches. On my laptop (Apple Macbook Pro 2009) without vertical sync the all widgets example runs upwards of ~350 fps.
43   -
44   -On a personal note: I designed ofxUI so that if I present my work to a client or put out an App on the App store, it would have a decent aesthetic and be presentable to non-hackers/programmers. I really like the widgets in MaxMsp, so I wanted to have something similar so when I prototype in C++ I could easily go about creating a UI that is pleasing to use and works robustly.
45   -
46   -Additionally, I was motived to write my own since I wanted something like ControlP5 (which is easy to get up and running) for Processing for OF. I use ControlP5 a lot and love its minimal aesthetic. I also love simpleGUI for Cinder, but since I primarily code using OF, I developed ofxUI with the intentions that it needs to be minimally designed, intuitive to use, easily integrated, flexible and customizable.
47   -
48   -When I first started programming with C++ it was difficult for me to use the other GUIs...their either depended on other libraries, which weren't included in the download, and it wouldn't work out of the box, or they were complicated to integrate into my projects. Additionally, I was motived to write my own since I wanted something like ControlP5 (which is easy to get up and running) for Processing for OF. I use ControlP5 a lot and love its minimal aesthetic. I also love simpleGUI for Cinder, but since I primarily code using OF, I developed ofxUI with the intentions that it needs to be minimally designed, intuitive to use, easily integrated, flexible and customizable.
49   -
50   -## Requirements
51   -- openFrameworks 0.8.0+
52   -
53   -## Getting Started
54   -
55   -This tutorial will provide step by step instructions on how to get started with ofxUI. For this we are going to be assuming you are using openFrameworks 0.8.0+ for OSX, however these instructions should be easily adaptable for iOS.
56   -
57   -- After downloading or cloning ofxUI, place it in your openframeworks addons folder.
58   -
59   -- Create a new openframeworks project using the project generator, make sure ofxUI and ofxXmlSettings are enabled from the list of addons shown.
60   -
61   -- Open the project in xCode.
62   -
63   -- Now select your ofApp.h file and add ```#include "ofxUI.h"``` under ```#include "ofMain.h"```
64   -
65   -- Then in your ofApp.h file, create a new ```ofxUICanvas``` object within the ofApp class like so:
66   -
67   -```cpp
68   -ofxUICanvas *gui;
69   -```
70   -
71   -In addition create two functions:
72   -
73   -```cpp
74   -void exit();
75   -void guiEvent(ofxUIEventArgs &e);
76   -```
77   -
78   -- Switch over to your ofApp.cpp file and define the exit and `guiEvent` functions:
79   -
80   -```cpp
81   -void ofApp::exit()
82   -{
83   -
84   -}
85   -
86   -void ofApp::guiEvent(ofxUIEventArgs &e)
87   -{
88   -
89   -}
90   -```
91   -
92   -- Within the setup function we are going to initialize the gui object and add widgets to it. So one way to do that is:
93   -
94   -```cpp
95   -gui = new ofxUICanvas(); //Creates a canvas at (0,0) using the default width
96   -```
97   -
98   -- In the exit function we have to delete the gui after we are done using the application. But before this we want to tell the GUI to save the current values in the widgets to an XML file. Thus your exit function should look like:
99   -
100   -```cpp
101   -void ofApp::exit()
102   -{
103   - gui->saveSettings("settings.xml");
104   - delete gui;
105   -}
106   -```
107   -
108   -- We are now going to:
109   -
110   - - add a slider widget to the GUI
111   - - automatically size the gui to fit all the widgets
112   - - add an event listener to the ofApp
113   - - load settings from an xml file called settings.xml
114   -
115   -```cpp
116   -gui->addSlider("BACKGROUND",0.0,255.0,100.0);
117   -gui->autoSizeToFitWidgets();
118   -ofAddListener(gui->newGUIEvent, this, &ofApp::guiEvent);
119   -gui->loadSettings("settings.xml");
120   -```
121   -
122   -Note: The second to last line adds a listener/callback, so the gui knows what function to call once a widget is triggered or interacted with by the user, don't worry if its doesn't make too much sense right now, you'll get the hang of it. The last line tells the gui to load settings (widget values from a saved xml file, if the file isn't present it uses the default value of the widgets).
123   -
124   -- Now to the `guiEvent` function, we need to react to the user input. The argument of the `guiEvent` function, ```ofxUIEventArgs &e```, contains the widget which was modified. To access the widget we do the following:
125   -
126   -```cpp
127   -void testApp::guiEvent(ofxUIEventArgs &e)
128   -{
129   - if(e.getName() == "BACKGROUND")
130   - {
131   - ofxUISlider *slider = e.getSlider();
132   - ofBackground(slider->getScaledValue());
133   - }
134   -}
135   -```
136   -
137   -Note: The if statement compares the widget's name with "BACKGROUND". It does that via a string comparison. If the widget's name is "BACKGROUND", then its the slider widget we created earlier. The slider's value is retrieved by the ``` getScaledValue()``` function.
138   -
139   -- Lets add a toggle to toggle the window between fullscreen and window mode. In the setup function add another widget after the slider widget:
140   -
141   -```cpp
142   -gui->addToggle("FULLSCREEN", false);
143   -```
144   -
145   -- We have to now respond to the "FULLSCREEN" toggle widget so we add more functionality to our `guiEvent` function. In the end it should look like:
146   -
147   -```cpp
148   -void testApp::guiEvent(ofxUIEventArgs &e)
149   -{
150   - if(e.getName() == "BACKGROUND")
151   - {
152   - ofxUISlider *slider = e.getSlider();
153   - ofBackground(slider->getScaledValue());
154   - }
155   - else if(e.getName() == "FULLSCREEN")
156   - {
157   - ofxUIToggle *toggle = e.getToggle();
158   - ofSetFullscreen(toggle->getValue());
159   - }
160   -}
161   -```
162   -
163   -Note: So you can see adding other kinds of widgets and reacting to them are done in a very similar manner. Explore the examples to check out how to access some of the more complex widgets and variable binding so callbacks are needed as often. I hope you'll see thats its pretty intuitive. I tried my best to limit the amount of code that needs to be written, however I kept it open enough so people can be expressive with it.
164   -
165   -If you lost your way somewhere in the tutorial, don't worry the whole project is included in the examples in the ofxUI addon folder!
166   -
167   -Note: If you don't need to save/load the gui settings and don't want to include ofxXmlSettings in your project, you can set the following define in your project build settings: OFX_UI_NO_XML
168   -
169   -ofxUI was / is developed by Reza Ali (www.syedrezaali.com || syed.reza.ali@gmail.com || @rezaali). Since its release in early 2012, its had more than 250 commits and now has 18 contributors: Camilo, obviousjim, prisonerjohn, syedhali, falcon4ever, SoylentGraham, NickHardeman, bilderbuchi, danomatika, rc1, emmanuelgeoffray, samdraz, danoli3, JohnSebastianHussey, markpitchless, kikko, and Garoe.
170 0 \ No newline at end of file
app/ofxGUI/src/ofxUI.h
... ... @@ -1,35 +0,0 @@
1   -/**********************************************************************************
2   -
3   - Copyright (C) 2012 Syed Reza Ali (www.syedrezaali.com)
4   -
5   - Permission is hereby granted, free of charge, to any person obtaining a copy of
6   - this software and associated documentation files (the "Software"), to deal in
7   - the Software without restriction, including without limitation the rights to
8   - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9   - of the Software, and to permit persons to whom the Software is furnished to do
10   - so, subject to the following conditions:
11   -
12   - The above copyright notice and this permission notice shall be included in all
13   - copies or substantial portions of the Software.
14   -
15   - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16   - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17   - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18   - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19   - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20   - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21   - SOFTWARE.
22   -
23   - **********************************************************************************/
24   -
25   -#pragma once
26   -
27   -#include "ofxUIDefines.h"
28   -#include "ofxUIWidget.h"
29   -#include "ofxUIWidgetWithLabel.h"
30   -#include "ofxUIEventArgs.h"
31   -#include "ofxUIWidgets.h"
32   -#include "ofxUICanvas.h"
33   -#include "ofxUIScrollableCanvas.h"
34   -#include "ofxUISuperCanvas.h"
35   -#include "ofxUITabBar.h"
36 0 \ No newline at end of file
app/ofxGUI/src/ofxUI2DGraph.cpp
... ... @@ -1,112 +0,0 @@
1   -/**********************************************************************************
2   -
3   - Copyright (C) 2012 Syed Reza Ali (www.syedrezaali.com)
4   -
5   - Permission is hereby granted, free of charge, to any person obtaining a copy of
6   - this software and associated documentation files (the "Software"), to deal in
7   - the Software without restriction, including without limitation the rights to
8   - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9   - of the Software, and to permit persons to whom the Software is furnished to do
10   - so, subject to the following conditions:
11   -
12   - The above copyright notice and this permission notice shall be included in all
13   - copies or substantial portions of the Software.
14   -
15   - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16   - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17   - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18   - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19   - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20   - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21   - SOFTWARE.
22   -
23   - **********************************************************************************/
24   -
25   -#include "ofxUI2DGraph.h"
26   -#include "ofxUI.h"
27   -
28   -ofxUI2DGraph::ofxUI2DGraph(string _name, ofPoint _rangeX, ofPoint _rangeY, int _bufferSize, float * _xValues, float * _yValues, float w, float h, float x, float y) : ofxUIWidget()
29   -{
30   - init(_name, _rangeX, _rangeY, _bufferSize, _xValues, _yValues, w, h, x, y);
31   -}
32   -
33   -void ofxUI2DGraph::init(string _name, ofPoint _rangeX, ofPoint _rangeY, float _bufferSize, float * _xValues, float * _yValues, float w, float h, float x, float y)
34   -{
35   - initRect(x, y, w, h);
36   - name = string(_name);
37   - kind = OFX_UI_WIDGET_2DGRAPH;
38   - draw_fill = true;
39   -
40   - bufferSize = _bufferSize;
41   - rangeX = _rangeX;
42   - rangeY = _rangeY;
43   -
44   - xValues = _xValues;
45   - yValues = _yValues;
46   -
47   - inc = MAX(rect->getHalfHeight(), rect->getHalfWidth())/6.0;
48   -}
49   -
50   -void ofxUI2DGraph::drawBack()
51   -{
52   - if(draw_back)
53   - {
54   - ofFill();
55   - ofSetColor(color_back);
56   - rect->draw();
57   -
58   - ofPushMatrix();
59   - ofTranslate(rect->getX(), rect->getY(), 0);
60   -
61   - for(int x = 0; x <= rect->getWidth(); x+=inc)
62   - {
63   - ofDrawLine(x, 0, x, rect->getHeight()); //y
64   - }
65   -
66   - for(int y = 0; y <= rect->getHeight(); y+=inc)
67   - {
68   - ofDrawLine(0, y, rect->getWidth(), y); //x
69   - }
70   -
71   - ofSetLineWidth(2);
72   - ofDrawLine(rect->getHalfWidth(), 0, rect->getHalfWidth(), rect->getHeight());
73   - ofDrawLine(0, rect->getHalfHeight(), rect->getWidth(), rect->getHalfHeight());
74   - ofPopMatrix();
75   - ofNoFill();
76   - rect->draw();
77   -
78   - ofSetLineWidth(1);
79   - ofFill();
80   - }
81   -}
82   -
83   -
84   -void ofxUI2DGraph::drawFill()
85   -{
86   - if(draw_fill)
87   - {
88   - ofNoFill();
89   - if(draw_fill_highlight)
90   - {
91   - ofSetColor(color_fill_highlight);
92   - }
93   - else
94   - {
95   - ofSetColor(color_fill);
96   - }
97   - if(xValues != NULL && yValues != NULL)
98   - {
99   - ofPushMatrix();
100   - ofTranslate(rect->getX(), rect->getY(), 0);
101   - ofSetLineWidth(1.5);
102   - ofPolyline line;
103   - for(int i =0; i < bufferSize; i++)
104   - {
105   - line.addVertex(ofMap(xValues[i], rangeX.x, rangeX.y, 0.0, rect->getWidth(), true), ofMap(yValues[i], rangeY.x, rangeY.y, 0.0, rect->getHeight(), true));
106   - }
107   - line.draw();
108   - ofSetLineWidth(1);
109   - ofPopMatrix();
110   - }
111   - }
112   -}
app/ofxGUI/src/ofxUI2DGraph.h
... ... @@ -1,44 +0,0 @@
1   -/**********************************************************************************
2   -
3   - Copyright (C) 2012 Syed Reza Ali (www.syedrezaali.com)
4   -
5   - Permission is hereby granted, free of charge, to any person obtaining a copy of
6   - this software and associated documentation files (the "Software"), to deal in
7   - the Software without restriction, including without limitation the rights to
8   - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9   - of the Software, and to permit persons to whom the Software is furnished to do
10   - so, subject to the following conditions:
11   -
12   - The above copyright notice and this permission notice shall be included in all
13   - copies or substantial portions of the Software.
14   -
15   - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16   - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17   - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18   - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19   - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20   - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21   - SOFTWARE.
22   -
23   - **********************************************************************************/
24   -
25   -#pragma once
26   -
27   -#include "ofxUIWidget.h"
28   -
29   -class ofxUI2DGraph : public ofxUIWidget
30   -{
31   -public:
32   - ofxUI2DGraph(string _name, ofPoint _rangeX, ofPoint _rangeY, int _bufferSize, float * _xValues, float * _yValues, float w, float h, float x = 0, float y = 0);
33   -
34   -protected:
35   - void init(string _name, ofPoint _rangeX, ofPoint _rangeY, float _bufferSize, float * _xValues, float * _yValues, float w, float h, float x = 0, float y = 0);
36   - void drawBack();
37   - void drawFill();
38   -
39   - float *xValues;
40   - float *yValues;
41   - ofPoint rangeX, rangeY;
42   - float inc;
43   - int bufferSize;
44   -};
45 0 \ No newline at end of file
app/ofxGUI/src/ofxUI2DPad.cpp
... ... @@ -1,416 +0,0 @@
1   -/**********************************************************************************
2   -
3   - Copyright (C) 2012 Syed Reza Ali (www.syedrezaali.com)
4   -
5   - Permission is hereby granted, free of charge, to any person obtaining a copy of
6   - this software and associated documentation files (the "Software"), to deal in
7   - the Software without restriction, including without limitation the rights to
8   - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9   - of the Software, and to permit persons to whom the Software is furnished to do
10   - so, subject to the following conditions:
11   -
12   - The above copyright notice and this permission notice shall be included in all
13   - copies or substantial portions of the Software.
14   -
15   - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16   - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17   - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18   - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19   - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20   - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21   - SOFTWARE.
22   -
23   - **********************************************************************************/
24   -
25   -#include "ofxUI2DPad.h"
26   -#include "ofxUI.h"
27   -
28   -ofxUI2DPad::ofxUI2DPad(string _name, ofxUIVec3f _rangeX, ofxUIVec3f _rangeY, ofxUIVec3f _value, float w, float h, float x, float y) : ofxUIWidgetWithLabel()
29   -{
30   - useReference = false;
31   - init(_name, _rangeX, _rangeY, &_value, w, h, x, y);
32   -}
33   -
34   -ofxUI2DPad::ofxUI2DPad(string _name, ofxUIVec3f _rangeX, ofxUIVec3f _rangeY, ofxUIVec3f *_value, float w, float h, float x, float y) : ofxUIWidgetWithLabel()
35   -{
36   - useReference = true;
37   - init(_name, _rangeX, _rangeY, _value, w, h, x, y);
38   -}
39   -
40   -ofxUI2DPad::~ofxUI2DPad()
41   -{
42   - if(!useReference)
43   - {
44   - delete valueRef;
45   - }
46   -}
47   -
48   -void ofxUI2DPad::init(string _name, ofxUIVec3f _rangeX, ofxUIVec3f _rangeY, ofxUIVec3f *_value, float w, float h, float x, float y)
49   -{
50   - initRect(x, y, w, h);
51   - name = string(_name);
52   - kind = OFX_UI_WIDGET_2DPAD;
53   - draw_fill = true;
54   - draw_outline = true;
55   - value = *_value; //the widget's value
56   - if(useReference)
57   - {
58   - valueRef = _value;
59   - }
60   - else
61   - {
62   - valueRef = new ofxUIVec3f();
63   - *valueRef = value;
64   - }
65   -
66   - rangeX = _rangeX;
67   - rangeY = _rangeY;
68   - labelPrecision = 2;
69   -
70   - value.x = ofxUIMap(value.x, rangeX.x, rangeX.y, 0.0, 1.0, true);
71   - value.y = ofxUIMap(value.y, rangeY.x, rangeY.y, 0.0, 1.0, true);
72   -
73   - if(value.x > 1)
74   - {
75   - value.x = 1;
76   - }
77   - else if(value.x < 0)
78   - {
79   - value.x = 0;
80   - }
81   -
82   - if(value.y > 1)
83   - {
84   - value.y = 1;
85   - }
86   - else if(value.y < 0)
87   - {
88   - value.y = 0;
89   - }
90   -
91   - label = new ofxUILabel(0,h+padding*2.0,(name+" LABEL"), (name + ": " + ofxUIToString(getScaledValue().x,labelPrecision) + ", " + ofxUIToString(getScaledValue().y,labelPrecision)), OFX_UI_FONT_SMALL);
92   - addEmbeddedWidget(label);
93   -
94   - float horizontalRange = abs(rangeX.x - rangeX.y);
95   - float verticalRange = abs(rangeY.x - rangeY.y);
96   - increment = MIN(horizontalRange, verticalRange) / 10.0;
97   -}
98   -
99   -void ofxUI2DPad::update()
100   -{
101   - if(useReference)
102   - {
103   - value.x = ofxUIMap(valueRef->x, rangeX.x, rangeX.y, 0.0, 1.0, true);
104   - value.y = ofxUIMap(valueRef->y, rangeY.x, rangeY.y, 0.0, 1.0, true);
105   - }
106   -}
107   -
108   -void ofxUI2DPad::setDrawPadding(bool _draw_padded_rect)
109   -{
110   - draw_padded_rect = _draw_padded_rect;
111   - label->setDrawPadding(false);
112   -}
113   -
114   -void ofxUI2DPad::setDrawPaddingOutline(bool _draw_padded_rect_outline)
115   -{
116   - draw_padded_rect_outline = _draw_padded_rect_outline;
117   - label->setDrawPaddingOutline(false);
118   -}
119   -
120   -void ofxUI2DPad::drawFill()
121   -{
122   - if(draw_fill)
123   - {
124   - ofxUIFill();
125   - ofxUISetColor(color_fill);
126   - ofxUISetRectMode(OFX_UI_RECTMODE_CENTER);
127   - ofxUIDrawRect(rect->getX()+value.x*rect->getWidth(), rect->getY()+value.y*rect->getHeight(), OFX_UI_GLOBAL_WIDGET_SPACING, OFX_UI_GLOBAL_WIDGET_SPACING);
128   - ofxUISetRectMode(OFX_UI_RECTMODE_CORNER);
129   -
130   - ofxUIDrawLine(rect->getX()+value.x*rect->getWidth(), rect->getY(), rect->getX()+value.x*rect->getWidth(), rect->getY()+rect->getHeight());
131   - ofxUIDrawLine(rect->getX(), rect->getY()+value.y*rect->getHeight(), rect->getX()+rect->getWidth(), rect->getY()+value.y*rect->getHeight());
132   - }
133   -}
134   -
135   -void ofxUI2DPad::drawFillHighlight()
136   -{
137   - if(draw_fill_highlight)
138   - {
139   - ofxUIFill();
140   - ofxUISetColor(color_fill_highlight);
141   - ofxUISetRectMode(OFX_UI_RECTMODE_CENTER);
142   - ofxUIDrawRect(rect->getX()+value.x*rect->getWidth(), rect->getY()+value.y*rect->getHeight(), OFX_UI_GLOBAL_WIDGET_SPACING, OFX_UI_GLOBAL_WIDGET_SPACING);
143   - ofxUISetRectMode(OFX_UI_RECTMODE_CORNER);
144   -
145   - ofxUIDrawLine(rect->getX()+value.x*rect->getWidth(), rect->getY(), rect->getX()+value.x*rect->getWidth(), rect->getY()+rect->getHeight());
146   - ofxUIDrawLine(rect->getX(), rect->getY()+value.y*rect->getHeight(), rect->getX()+rect->getWidth(), rect->getY()+value.y*rect->getHeight());
147   -
148   - label->drawString(rect->getX()+value.x*rect->getWidth()+OFX_UI_GLOBAL_WIDGET_SPACING, rect->getY()+value.y*rect->getHeight(), "(" +ofxUIToString(getScaledValue().x,labelPrecision) + ", " + ofxUIToString(getScaledValue().y,labelPrecision)+")");
149   - }
150   -}
151   -
152   -float ofxUI2DPad::getIncrement()
153   -{
154   - return increment;
155   -}
156   -
157   -void ofxUI2DPad::setIncrement(float _increment)
158   -{
159   - increment = _increment;
160   -}
161   -
162   -void ofxUI2DPad::mouseMoved(int x, int y )
163   -{
164   - if(rect->inside(x, y))
165   - {
166   - state = OFX_UI_STATE_OVER;
167   - }
168   - else
169   - {
170   - state = OFX_UI_STATE_NORMAL;
171   - }
172   - stateChange();
173   -}
174   -
175   -void ofxUI2DPad::mouseDragged(int x, int y, int button)
176   -{
177   - if(hit)
178   - {
179   - state = OFX_UI_STATE_DOWN;
180   - if(triggerType & OFX_UI_TRIGGER_CHANGE)
181   - {
182   - input(x, y);
183   - triggerEvent(this);
184   - }
185   - }
186   - else
187   - {
188   - state = OFX_UI_STATE_NORMAL;
189   - }
190   - stateChange();
191   -}
192   -
193   -void ofxUI2DPad::mousePressed(int x, int y, int button)
194   -{
195   - if(rect->inside(x, y))
196   - {
197   - hit = true;
198   - state = OFX_UI_STATE_DOWN;
199   - if(triggerType & OFX_UI_TRIGGER_BEGIN)
200   - {
201   - input(x, y);
202   - triggerEvent(this);
203   - }
204   - }
205   - else
206   - {
207   - state = OFX_UI_STATE_NORMAL;
208   - }
209   - stateChange();
210   -}
211   -
212   -void ofxUI2DPad::mouseReleased(int x, int y, int button)
213   -{
214   - if(hit)
215   - {
216   -#ifdef OFX_UI_TARGET_TOUCH
217   - state = OFX_UI_STATE_NORMAL;
218   -#else
219   - state = OFX_UI_STATE_OVER;
220   -#endif
221   - if(triggerType & OFX_UI_TRIGGER_END)
222   - {
223   - input(x, y);
224   - triggerEvent(this);
225   - }
226   - }
227   - else
228   - {
229   - state = OFX_UI_STATE_NORMAL;
230   - }
231   - stateChange();
232   - hit = false;
233   -}
234   -
235   -void ofxUI2DPad::keyPressed(int key)
236   -{
237   - if(state == OFX_UI_STATE_OVER)
238   - {
239   - switch (key)
240   - {
241   - case OF_KEY_RIGHT:
242   - {
243   - ofxUIVec3f p = getScaledValue();
244   - p.x+=increment;
245   - value.x = ofxUIMap(p.x, rangeX.x, rangeX.y, 0.0, 1.0, true);
246   - updateValueRef();
247   - updateLabel();
248   - triggerEvent(this);
249   - }
250   - break;
251   -
252   - case OF_KEY_UP:
253   - {
254   - ofxUIVec3f p = getScaledValue();
255   - p.y +=increment;
256   - value.y = ofxUIMap(p.y, rangeY.x, rangeY.y, 0.0, 1.0, true);
257   - updateValueRef();
258   - updateLabel();
259   - triggerEvent(this);
260   - }
261   - break;
262   -
263   - case OF_KEY_LEFT:
264   - {
265   - ofxUIVec3f p = getScaledValue();
266   - p.x-=increment;
267   - value.x = ofxUIMap(p.x, rangeX.x, rangeX.y, 0.0, 1.0, true);
268   - updateValueRef();
269   - updateLabel();
270   - triggerEvent(this);
271   - }
272   - break;
273   -
274   - case OF_KEY_DOWN:
275   - {
276   - ofxUIVec3f p = getScaledValue();
277   - p.y -=increment;
278   - value.y = ofxUIMap(p.y, rangeY.x, rangeY.y, 0.0, 1.0, true);
279   - updateValueRef();
280   - updateLabel();
281   - triggerEvent(this);
282   - }
283   - break;
284   -
285   - default:
286   - break;
287   - }
288   - }
289   -}
290   -
291   -void ofxUI2DPad::input(float x, float y)
292   -{
293   - value.x = MIN(1.0, MAX(0.0, rect->percentInside(x, y).x));
294   - value.y = MIN(1.0, MAX(0.0, rect->percentInside(x, y).y));
295   -
296   - updateValueRef();
297   - updateLabel();
298   -}
299   -
300   -void ofxUI2DPad::updateValueRef()
301   -{
302   - (*valueRef) = getScaledValue();
303   -}
304   -
305   -void ofxUI2DPad::updateLabel()
306   -{
307   - label->setLabel(name + ": " + ofxUIToString(getScaledValue().x,labelPrecision) + ", " + ofxUIToString(getScaledValue().y,labelPrecision));
308   -}
309   -
310   -void ofxUI2DPad::stateChange()
311   -{
312   - switch (state) {
313   - case OFX_UI_STATE_NORMAL:
314   - {
315   - draw_fill_highlight = false;
316   - draw_outline_highlight = false;
317   - label->unfocus();
318   - }
319   - break;
320   - case OFX_UI_STATE_OVER:
321   - {
322   - draw_fill_highlight = false;
323   - draw_outline_highlight = true;
324   - label->unfocus();
325   - }
326   - break;
327   - case OFX_UI_STATE_DOWN:
328   - {
329   - draw_fill_highlight = true;
330   - draw_outline_highlight = true;
331   - label->focus();
332   - }
333   - break;
334   - case OFX_UI_STATE_SUSTAINED:
335   - {
336   - draw_fill_highlight = false;
337   - draw_outline_highlight = false;
338   - label->unfocus();
339   - }
340   - break;
341   -
342   - default:
343   - break;
344   - }
345   -}
346   -
347   -void ofxUI2DPad::setValue(ofxUIVec3f _value)
348   -{
349   - if(_value.x > rangeX.y)
350   - {
351   - _value.x = rangeX.y;
352   - }
353   - else if(_value.x < rangeX.x)
354   - {
355   - _value.x = rangeX.x;
356   - }
357   -
358   - if(_value.y > rangeY.y)
359   - {
360   - _value.y = rangeY.y;
361   - }
362   - else if(_value.y < rangeY.x)
363   - {
364   - _value.y = rangeY.x;
365   - }
366   -
367   - value.x = ofxUIMap(_value.x, rangeX.x, rangeX.y, 0.0, 1.0, true);
368   - value.y = ofxUIMap(_value.y, rangeY.x, rangeY.y, 0.0, 1.0, true);
369   - updateValueRef();
370   - updateLabel();
371   -}
372   -
373   -ofxUIVec3f ofxUI2DPad::getValue()
374   -{
375   - return value;
376   -}
377   -
378   -ofxUIVec3f ofxUI2DPad::getPercentValue()
379   -{
380   - return value;
381   -}
382   -
383   -ofxUIVec3f ofxUI2DPad::getScaledValue()
384   -{
385   - ofxUIVec3f p = value;
386   - p.x = ofxUIMap(p.x, 0, 1, rangeX.x, rangeX.y, true);
387   - p.y = ofxUIMap(p.y, 0, 1, rangeY.x, rangeY.y, true);
388   - return p;
389   -}
390   -
391   -bool ofxUI2DPad::isDraggable()
392   -{
393   - return true;
394   -}
395   -
396   -void ofxUI2DPad::setLabelPrecision(int _precision)
397   -{
398   - labelPrecision = _precision;
399   - updateValueRef();
400   - updateLabel();
401   -}
402   -
403   -#ifndef OFX_UI_NO_XML
404   -
405   -void ofxUI2DPad::saveState(ofxXmlSettings *XML)
406   -{
407   - XML->setValue("XValue", getScaledValue().x, 0);
408   - XML->setValue("YValue", getScaledValue().y, 0);
409   -}
410   -
411   -void ofxUI2DPad::loadState(ofxXmlSettings *XML)
412   -{
413   - setValue(ofxUIVec3f(XML->getValue("XValue", getScaledValue().x, 0), XML->getValue("YValue", getScaledValue().y, 0)));
414   -}
415   -
416   -#endif
417 0 \ No newline at end of file
app/ofxGUI/src/ofxUI2DPad.h
... ... @@ -1,71 +0,0 @@
1   -/**********************************************************************************
2   -
3   - Copyright (C) 2012 Syed Reza Ali (www.syedrezaali.com)
4   -
5   - Permission is hereby granted, free of charge, to any person obtaining a copy of
6   - this software and associated documentation files (the "Software"), to deal in
7   - the Software without restriction, including without limitation the rights to
8   - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9   - of the Software, and to permit persons to whom the Software is furnished to do
10   - so, subject to the following conditions:
11   -
12   - The above copyright notice and this permission notice shall be included in all
13   - copies or substantial portions of the Software.
14   -
15   - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16   - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17   - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18   - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19   - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20   - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21   - SOFTWARE.
22   -
23   - **********************************************************************************/
24   -
25   -#pragma once
26   -
27   -#include "ofxUIWidgetWithLabel.h"
28   -
29   -class ofxUI2DPad : public ofxUIWidgetWithLabel
30   -{
31   -public:
32   - ofxUI2DPad(string _name, ofxUIVec3f _rangeX, ofxUIVec3f _rangeY, ofxUIVec3f _value, float w, float h, float x = 0, float y = 0);
33   - ofxUI2DPad(string _name, ofxUIVec3f _rangeX, ofxUIVec3f _rangeY, ofxUIVec3f *_value, float w, float h, float x = 0, float y = 0);
34   - ~ofxUI2DPad();
35   - void init(string _name, ofxUIVec3f _rangeX, ofxUIVec3f _rangeY, ofxUIVec3f *_value, float w, float h, float x = 0, float y = 0);
36   - virtual void update();
37   - virtual void setDrawPadding(bool _draw_padded_rect);
38   - virtual void setDrawPaddingOutline(bool _draw_padded_rect_outline);
39   - virtual void drawFill();
40   - virtual void drawFillHighlight();
41   - float getIncrement();
42   - void setIncrement(float _increment);
43   - void mouseMoved(int x, int y);
44   - void mouseDragged(int x, int y, int button);
45   - void mousePressed(int x, int y, int button);
46   - void mouseReleased(int x, int y, int button);
47   - void keyPressed(int key);
48   - void input(float x, float y);
49   - void updateValueRef();
50   - void updateLabel();
51   - void stateChange();
52   - void setValue(ofxUIVec3f _value);
53   - ofxUIVec3f getValue();
54   - ofxUIVec3f getPercentValue();
55   - ofxUIVec3f getScaledValue();
56   - bool isDraggable();
57   - void setLabelPrecision(int _precision);
58   - bool hasState(){ return true; };
59   -#ifndef OFX_UI_NO_XML
60   - virtual void saveState(ofxXmlSettings *XML);
61   - virtual void loadState(ofxXmlSettings *XML);
62   -#endif
63   -
64   -protected:
65   - ofxUIVec3f value;
66   - ofxUIVec3f *valueRef;
67   - float increment;
68   - int labelPrecision;
69   - bool useReference;
70   - ofxUIVec3f rangeX, rangeY;
71   -};
72 0 \ No newline at end of file
app/ofxGUI/src/ofxUIBaseDraws.cpp
... ... @@ -1,99 +0,0 @@
1   -/**********************************************************************************
2   -
3   - Copyright (C) 2012 Syed Reza Ali (www.syedrezaali.com)
4   -
5   - Permission is hereby granted, free of charge, to any person obtaining a copy of
6   - this software and associated documentation files (the "Software"), to deal in
7   - the Software without restriction, including without limitation the rights to
8   - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9   - of the Software, and to permit persons to whom the Software is furnished to do
10   - so, subject to the following conditions:
11   -
12   - The above copyright notice and this permission notice shall be included in all
13   - copies or substantial portions of the Software.
14   -
15   - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16   - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17   - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18   - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19   - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20   - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21   - SOFTWARE.
22   -
23   - **********************************************************************************/
24   -
25   -#include "ofxUIBaseDraws.h"
26   -#include "ofxUI.h"
27   -
28   -ofxUIBaseDraws::ofxUIBaseDraws(float x, float y, float w, float h, ofBaseDraws* _image, string _name) : ofxUIWidgetWithLabel()
29   -{
30   - init(x, y, w, h, _image, _name);
31   -}
32   -
33   -ofxUIBaseDraws::ofxUIBaseDraws(float x, float y, float w, float h, ofBaseDraws* _image, string _name, bool _showLabel) : ofxUIWidgetWithLabel()
34   -{
35   - init(x, y, w, h, _image, _name);
36   - setLabelVisible(_showLabel);
37   -}
38   -
39   -ofxUIBaseDraws::ofxUIBaseDraws(float w, float h, ofBaseDraws* _image, string _name) : ofxUIWidgetWithLabel()
40   -{
41   - init(0, 0, w, h, _image, _name);
42   -}
43   -
44   -ofxUIBaseDraws::ofxUIBaseDraws(float w, float h, ofBaseDraws* _image, string _name, bool _showLabel) : ofxUIWidgetWithLabel()
45   -{
46   - init(0, 0, w, h, _image, _name);
47   - setLabelVisible(_showLabel);
48   -}
49   -
50   -void ofxUIBaseDraws::init(float x, float y, float w, float h, ofBaseDraws* _image, string _name)
51   -{
52   - initRect(x, y, w, h);
53   - name = _name;
54   - kind = OFX_UI_WIDGET_BASE_DRAWS;
55   -
56   - draw_back = false;
57   - draw_fill = true;
58   -
59   - image = _image;
60   -
61   - label = new ofxUILabel(0,h+padding*2.0,(name+" LABEL"),name, OFX_UI_FONT_SMALL);
62   - addEmbeddedWidget(label);
63   -}
64   -
65   -void ofxUIBaseDraws::setDrawPadding(bool _draw_padded_rect)
66   -{
67   - draw_padded_rect = _draw_padded_rect;
68   - label->setDrawPadding(false);
69   -}
70   -
71   -void ofxUIBaseDraws::setDrawPaddingOutline(bool _draw_padded_rect_outline)
72   -{
73   - draw_padded_rect_outline = _draw_padded_rect_outline;
74   - label->setDrawPaddingOutline(false);
75   -}
76   -
77   -void ofxUIBaseDraws::drawFill()
78   -{
79   - ofSetDepthTest(false);
80   - if(draw_fill)
81   - {
82   - if(image != NULL)
83   - {
84   - ofFill();
85   - ofSetColor(255);
86   - image->draw(rect->getX(), rect->getY(), rect->width, rect->height);
87   - }
88   - }
89   -}
90   -
91   -void ofxUIBaseDraws::set(ofBaseDraws *_image)
92   -{
93   - image = _image;
94   -}
95   -
96   -bool ofxUIBaseDraws::isDraggable()
97   -{
98   - return false;
99   -}
100 0 \ No newline at end of file
app/ofxGUI/src/ofxUIBaseDraws.h
... ... @@ -1,45 +0,0 @@
1   -/**********************************************************************************
2   -
3   - Copyright (C) 2012 Syed Reza Ali (www.syedrezaali.com)
4   -
5   - Permission is hereby granted, free of charge, to any person obtaining a copy of
6   - this software and associated documentation files (the "Software"), to deal in
7   - the Software without restriction, including without limitation the rights to
8   - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9   - of the Software, and to permit persons to whom the Software is furnished to do
10   - so, subject to the following conditions:
11   -
12   - The above copyright notice and this permission notice shall be included in all
13   - copies or substantial portions of the Software.
14   -
15   - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16   - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17   - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18   - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19   - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20   - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21   - SOFTWARE.
22   -
23   - **********************************************************************************/
24   -
25   -#pragma once
26   -
27   -#include "ofxUIWidgetWithLabel.h"
28   -
29   -class ofxUIBaseDraws : public ofxUIWidgetWithLabel
30   -{
31   -public:
32   - ofxUIBaseDraws(float x, float y, float w, float h, ofBaseDraws* _image, string _name);
33   - ofxUIBaseDraws(float x, float y, float w, float h, ofBaseDraws* _image, string _name, bool _showLabel);
34   - ofxUIBaseDraws(float w, float h, ofBaseDraws* _image, string _name);
35   - ofxUIBaseDraws(float w, float h, ofBaseDraws* _image, string _name, bool _showLabel);
36   - void init(float x, float y, float w, float h, ofBaseDraws* _image, string _name);
37   - virtual void setDrawPadding(bool _draw_padded_rect);
38   - virtual void setDrawPaddingOutline(bool _draw_padded_rect_outline);
39