├── .gitignore ├── COPYRIGHT ├── GLV ├── glv.h ├── glv_behavior.h ├── glv_binding.h ├── glv_buttons.h ├── glv_color.h ├── glv_color_controls.h ├── glv_conf.h ├── glv_core.h ├── glv_draw.h ├── glv_font.h ├── glv_grid.h ├── glv_icon.h ├── glv_layout.h ├── glv_model.h ├── glv_notification.h ├── glv_plots.h ├── glv_preset_controls.h ├── glv_rect.h ├── glv_sliders.h ├── glv_sono.h ├── glv_texture.h ├── glv_textview.h ├── glv_util.h ├── glv_view3D.h └── glv_widget.h ├── Makefile ├── Makefile.common ├── Makefile.config ├── Makefile.rules ├── README.md ├── doc ├── Doxyfile ├── GLV_Diagrams.graffle ├── VectorFont.graffle └── lyx │ ├── fig │ ├── ButtonActive.png │ ├── ButtonInactive.png │ ├── ButtonOff.png │ ├── ButtonOn.png │ ├── Buttons1x4.png │ ├── Buttons4x1.png │ ├── Buttons4x4.png │ ├── DensityPlot.png │ ├── Direction.pdf │ ├── FunctionPlotX.png │ ├── FunctionPlotXY.png │ ├── FunctionPlotY.png │ ├── IconCheck.png │ ├── IconFrame.png │ ├── IconMinus.png │ ├── IconPlus.png │ ├── IconRect.png │ ├── IconTriangleD.png │ ├── IconTriangleL.png │ ├── IconTriangleR.png │ ├── IconTriangleU.png │ ├── IconX.png │ ├── Label.png │ ├── NumberBox.png │ ├── NumberDialer1.png │ ├── NumberDialer2.png │ ├── Place.pdf │ ├── Rect.pdf │ ├── Screenshot1.png │ ├── Screenshot2.png │ ├── Slider1H.png │ ├── Slider1HS.png │ ├── Slider1V.png │ ├── Slider1VS.png │ ├── Slider2D.png │ ├── SliderGrid3.png │ ├── SliderGrid4.png │ ├── SliderRangeH.png │ ├── SlidersH.png │ ├── SlidersV.png │ ├── SpacerAbs.png │ ├── SpacerBL.png │ ├── SpacerCL.png │ ├── SpacerFlow.png │ ├── TableComplex.png │ ├── TableRepeat.png │ ├── View.pdf │ ├── View3D.png │ ├── ViewAnchor.pdf │ ├── ViewStretch.pdf │ ├── drawASCII.png │ ├── fontMetrics.pdf │ └── showcase.png │ └── glvTutorial.0.96.lyx ├── examples ├── attachVariable.cpp ├── chladni.cpp ├── dataPlot.cpp ├── densityPlot.cpp ├── drawText.cpp ├── example.h ├── graphicsData.cpp ├── grid.cpp ├── icons.cpp ├── mandelbrot.cpp ├── notification.cpp ├── paintDiffusion.cpp ├── paintSimple.cpp ├── paintWave.cpp ├── presets.cpp ├── scope.cpp ├── showcase.cpp ├── slidersWithValues.cpp ├── soaring.cpp ├── spaceCurve.cpp ├── spinSynth.cpp ├── stretchAnchor.cpp ├── tableLayout.cpp ├── textureView.cpp ├── views.cpp └── widgets.cpp ├── osx ├── GLV.xcodeproj │ └── project.pbxproj ├── GLV_APPL-Info.plist ├── GLV_FMWK-Info.plist ├── main.nib │ ├── classes.nib │ ├── info.nib │ └── objects.xib └── main~.nib │ ├── classes.nib │ ├── info.nib │ └── objects.xib ├── src ├── glv_binding.cpp ├── glv_binding_glut.cpp ├── glv_buttons.cpp ├── glv_color.cpp ├── glv_color_controls.cpp ├── glv_core.cpp ├── glv_draw.cpp ├── glv_font.cpp ├── glv_glv.cpp ├── glv_grid.cpp ├── glv_inputdevice.cpp ├── glv_layout.cpp ├── glv_model.cpp ├── glv_notification.cpp ├── glv_plots.cpp ├── glv_preset_controls.cpp ├── glv_sliders.cpp ├── glv_sono.cpp ├── glv_texture.cpp ├── glv_textview.cpp ├── glv_view.cpp ├── glv_view3D.cpp └── glv_widget.cpp └── test ├── test_events.cpp ├── test_glv.cpp ├── test_glv.h ├── test_icon.cpp ├── test_multi_window.cpp ├── test_notifications.cpp ├── test_text.cpp ├── test_traversal.cpp ├── test_units.cpp ├── test_widgets.cpp └── test_window.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | xcuserdata 3 | doxygen_objdb_* 4 | .DS_Store 5 | 6 | *~ 7 | *.link 8 | *.a 9 | *.o 10 | *.so 11 | *.slo 12 | *.lo 13 | *.lai 14 | *.la 15 | *.lib 16 | *.spec 17 | *.d 18 | *.framework 19 | *.perspectivev3 20 | *.pbxuser 21 | *.mode1v3 22 | *.xcworkspace 23 | *.tm_build_errors 24 | *.ncb 25 | *.suo 26 | *.vcproj.* 27 | *.wwdb 28 | 29 | #ignore thumbnails created by windows 30 | Thumbs.db 31 | #Ignore files build by Visual Studio 32 | *.obj 33 | *.exe 34 | *.pdb 35 | *.user 36 | *.aps 37 | *.pch 38 | *.vspscc 39 | *_i.c 40 | *_p.c 41 | *.ncb 42 | *.suo 43 | *.tlb 44 | *.tlh 45 | *.bak 46 | *.cache 47 | *.ilk 48 | *.log 49 | [Bb]in 50 | [Dd]ebug*/ 51 | *.lib 52 | *.sbr 53 | obj/ 54 | [Rr]elease*/ 55 | _ReSharper*/ 56 | [Tt]est[Rr]esult* 57 | *.opensdf 58 | *.sdf 59 | *.ipch 60 | [Ii]pch/ 61 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | GLV AUTHORSHIP AND COPYRIGHT NOTICE 2 | 3 | Authors 4 | --------------------------------------------------------------------------- 5 | 6 | Main design and development by Lance Putnam, Wesley Smith, and Graham Wakefield with contributions from: 7 | Eric Newman, 8 | Alex Norman, 9 | Stephen Pope, 10 | Stjepan Rajko, 11 | and others, 12 | all at the Graduate Program in Media Arts and Technology (MAT) at the University of California, Santa Barbara (UCSB). 13 | 14 | Contact: Lance Putnam (ljputnam@umail.ucsb.edu) 15 | 16 | 17 | 18 | License 19 | --------------------------------------------------------------------------- 20 | 21 | Copyright (C) 2006-2008. The Regents of the University of California (REGENTS). 22 | All Rights Reserved. 23 | 24 | Permission to use, copy, modify, distribute, and distribute modified versions 25 | of this software and its documentation without fee and without a signed 26 | licensing agreement, is hereby granted, provided that the above copyright 27 | notice, the list of contributors, this paragraph and the following two paragraphs 28 | appear in all copies, modifications, and distributions. 29 | 30 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, 31 | SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING 32 | OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS 33 | BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 36 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 37 | PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED 38 | HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE 39 | MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 40 | -------------------------------------------------------------------------------- /GLV/glv.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_H 2 | #define INC_GLV_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | /*! \mainpage GLV - OpenGL GUI library 8 | 9 | \section intro_sec Introduction 10 | 11 | GLV (short for Graphics Library of Views) is an OpenGL based GUI library, currently for OSX, 12 | Win32, and Linux. The ideal is to create a reasonably efficient, 13 | multi-platform API that makes it simple for the end-user developer to 14 | create an application's graphical user interface entirely using GPU-based 15 | OpenGL instructions, thus freeing CPU resources for other work 16 | (e.g. audio DSP). 17 | 18 | */ 19 | 20 | /* 21 | helpful include file to include all of GLV at once 22 | */ 23 | 24 | // GLV core: 25 | #include "glv_core.h" 26 | #include "glv_behavior.h" 27 | #include "glv_font.h" 28 | #include "glv_layout.h" 29 | 30 | // widgets: 31 | #include "glv_buttons.h" 32 | #include "glv_color_controls.h" 33 | #include "glv_grid.h" 34 | #include "glv_plots.h" 35 | #include "glv_preset_controls.h" 36 | #include "glv_sliders.h" 37 | #include "glv_sono.h" 38 | #include "glv_textview.h" 39 | #include "glv_view3D.h" 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /GLV/glv_behavior.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_BEHAVIOR_H 2 | #define INC_GLV_BEHAVIOR_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | #include "glv_core.h" 8 | 9 | namespace glv{ 10 | 11 | namespace Behavior{ 12 | 13 | struct MouseMove : public EventHandler { 14 | bool onEvent(View& v, GLV& g) override { 15 | if(g.mouse().left()){ 16 | v.move(g.mouse().dx(), g.mouse().dy()); 17 | return false; 18 | } 19 | return true; 20 | } 21 | }; 22 | 23 | struct MouseResizeCorner : public EventHandler { 24 | bool onEvent(View& v, GLV& g) override { 25 | if(g.mouse().left()){ 26 | 27 | float dx = g.mouse().dx(); 28 | float dy = g.mouse().dy(); 29 | float mx = g.mouse().xRel() - dx; // subtract diff because position already updated 30 | float my = g.mouse().yRel() - dy; 31 | 32 | if(mx < v.w && mx > (v.w-16) && my < v.h && my > (v.h-16)){ 33 | v.resizeRightTo(v.right() + dx); 34 | v.resizeBottomTo(v.bottom() + dy); 35 | v.rectifyGeometry(); 36 | return false; 37 | } 38 | } 39 | return true; 40 | } 41 | }; 42 | 43 | struct MouseResize : public EventHandler { 44 | bool onEvent(View& v, GLV& g) override { 45 | if(g.mouse().middle()){ 46 | 47 | float dx = g.mouse().dx(); 48 | float dy = g.mouse().dy(); 49 | float mx = g.mouse().xRel() / v.w; 50 | float my = g.mouse().yRel() / v.h; 51 | 52 | if(mx < 0.5){ 53 | v.resizeLeftTo(v.l + dx); 54 | my < 0.5 ? v.resizeTopTo(v.t + dy) : v.resizeBottomTo(v.bottom() + dy); 55 | } 56 | else{ 57 | v.resizeRightTo(v.right() + dx); 58 | my < 0.5 ? v.resizeTopTo(v.t + dy) : v.resizeBottomTo(v.bottom() + dy); 59 | } 60 | v.rectifyGeometry(); 61 | return false; 62 | } 63 | return true; 64 | } 65 | }; 66 | 67 | static MouseMove mouseMove; 68 | static MouseResizeCorner mouseResizeCorner; 69 | static MouseResize mouseResize; 70 | 71 | } // Behavior:: 72 | } // glv:: 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /GLV/glv_binding.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_BINDING_H 2 | #define INC_GLV_BINDING_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | #include 8 | #include 9 | #include "glv_core.h" 10 | 11 | namespace glv{ 12 | 13 | class GLV; 14 | 15 | /// Display mode bit masks 16 | enum{ 17 | SingleBuf = 1<<0, /**< Single-buffered */ 18 | DoubleBuf = 1<<1, /**< Double-buffered */ 19 | AccumBuf = 1<<2, /**< Use accumulation buffer */ 20 | AlphaBuf = 1<<3, /**< Use alpha buffer */ 21 | DepthBuf = 1<<4, /**< Use depth buffer */ 22 | StencilBuf = 1<<5, /**< Use stencil buffer */ 23 | Stereo = 1<<6, /**< Do left-right stereo buffering */ 24 | Multisample = 1<<7, /**< Multisampling support */ 25 | DefaultBuf = DoubleBuf|AlphaBuf|DepthBuf /**< Default display mode */ 26 | }; 27 | 28 | 29 | 30 | /// A window with an assignable GLV context 31 | class Window{ 32 | public: 33 | 34 | class Impl; // binding specific implementation 35 | 36 | /// Rectangle geometry 37 | struct Dimensions{ 38 | unsigned l; ///< left position, in pixels 39 | unsigned t; ///< top position, in pixels 40 | unsigned w; ///< width, in pixels 41 | unsigned h; ///< height, in pixels 42 | }; 43 | 44 | /// Constructor 45 | Window( 46 | unsigned width=800, unsigned height=600, 47 | const std::string& title="GLV Window", GLV * glv=0, 48 | double framerate=40.0, int mode=DefaultBuf 49 | ); 50 | 51 | ~Window(); 52 | 53 | bool active() const { return mIsActive; } ///< Returns window active 54 | unsigned bottom() const { Dimensions d=dimensions(); return d.t+d.h; } ///< Returns bottom edge position 55 | Dimensions dimensions() const; ///< Returns dimensions of window 56 | int enabled(int dispMode) const { return mDispMode & dispMode; } ///< Get a display mode status 57 | double fps() const { return mFPS; } ///< Returns requested frames/sec 58 | double fpsActual() const { return mFPSActual; } ///< Returns actual frames/sec 59 | bool fullScreen() const { return mFullScreen; } ///< Returns full screen enabled 60 | bool gameMode() const { return mGameMode; } ///< Returns game mode enabled 61 | const GLV * glv() const { return mGLV; } ///< Returns pointer to top-level GLV view 62 | unsigned height() const { return dimensions().h; } ///< Returns window height 63 | bool hideCursor() const { return mHideCursor; } ///< Returns hide cursor enabled 64 | unsigned left() const { return dimensions().l; } ///< Returns left position 65 | unsigned right() const { Dimensions d=dimensions(); return d.l+d.w; } ///< Returns right edge position 66 | bool showing() const { return implShowing(); } ///< Returns whether window is showing 67 | std::string title()const { return mTitle; } ///< Returns window title 68 | unsigned top() const { return dimensions().t; } ///< Returns top position 69 | unsigned width() const { return dimensions().w; } ///< Returns window width 70 | 71 | void dimensions(const Dimensions& d); ///< Sets dimensions of window 72 | void fit(); ///< Fit dimensions to GLV dimensions 73 | void fps(double v); ///< Sets frames/second 74 | void fullScreen(bool on); ///< Sets fullscreen mode 75 | void fullScreenToggle(); ///< Toggles fullscreen 76 | void gameMode(bool on); ///< Sets game mode 77 | void gameModeToggle(); ///< Toggles game mode 78 | void hide(); ///< Hides window 79 | void hideCursor(bool hide); ///< Shows/hides cursor 80 | void iconify(); ///< Iconifies window 81 | void maximize(bool on); ///< Maximizes window on screen 82 | void position(unsigned left, unsigned top); ///< Sets position from left-top corner of screen 83 | void resize(unsigned w, unsigned h); ///< Resize swindow 84 | void setGLV(GLV& g); ///< Sets top GLV View 85 | void setGLVDims(unsigned w, unsigned h); 86 | void show(); ///< Shows window 87 | void title(const std::string& v); ///< Sets title 88 | 89 | protected: 90 | friend class Application; 91 | 92 | GLV * mGLV; 93 | Dimensions mWinDims; // backup for when going fullscreen 94 | double mFPS, mFPSActual; 95 | std::string mTitle; 96 | int mDispMode; // display mode bit field 97 | bool mFullScreen; 98 | bool mGameMode; 99 | bool mHideCursor; // hide cursor? 100 | bool mIsActive; // window context ready? 101 | 102 | bool shouldDraw(); // if the GLV views should be drawn 103 | 104 | void onWindowCreate(); 105 | void onWindowDestroy(); 106 | 107 | // These are to be implemented by the specific binding 108 | void implCtor(unsigned l, unsigned t, unsigned w, unsigned h); // this should manually create the mImpl object 109 | void implDtor(); // this should manually delete the mImpl object 110 | void implFinalize(); // call any cleanup/termination functions in windowing impl 111 | void implFullScreen(); // go fullscreen without changing video resolution or refresh rate 112 | void implGameMode(); // go fullscreen possibly changing video resolution or refresh rate 113 | void implHideCursor(bool hide); 114 | void implInitialize(); // initialize windowing impl 115 | void implPosition(unsigned l, unsigned t); 116 | void implResize(unsigned w, unsigned h); 117 | void implHide(); 118 | void implShow(); 119 | void implTitle(); 120 | void implIconify(); 121 | 122 | bool implShowing() const; 123 | Dimensions implWinDims() const; // get current position (left,top) and size of window from impl 124 | 125 | // pointer to the binding-specific implementation 126 | //std::auto_ptr mImpl; 127 | // with the auto_ptr for the implementation, disallow assignment and copy 128 | Impl * mImpl; 129 | 130 | private: 131 | const Window& operator=(const Window&); 132 | Window(const Window&); 133 | friend class WindowImpl; 134 | }; 135 | 136 | 137 | 138 | /// Singleton GLV application 139 | class Application{ 140 | public: 141 | 142 | /// Run main application event loop. This is a blocking call. 143 | static void run(); 144 | 145 | /// Quit main application. 146 | 147 | /// This can potentially cause the program to exit directly, so use 148 | /// Event::Quit callbacks to handle any exiting code. 149 | static void quit(); 150 | 151 | protected: 152 | friend class Window; 153 | 154 | Application(){} 155 | ~Application(){ quit(); } 156 | 157 | static Window *focusedWindow; 158 | 159 | // Returns a vector of all created windows 160 | static std::vector& windows(); 161 | 162 | // These are to be implemented by the specific binding 163 | static void implRun(); 164 | static void implQuit(); 165 | }; 166 | 167 | 168 | 169 | /// Key event handler to toggle fullscreen 170 | struct FullScreenToggler : EventHandler { 171 | 172 | FullScreenToggler(Window& w, int key_ = Key::Escape): win(w), key(key_){} 173 | 174 | bool onEvent(View& v, GLV& g) override { 175 | if(g.keyboard().key() == key){ 176 | win.fullScreenToggle(); 177 | return false; 178 | } 179 | return true; 180 | } 181 | 182 | Window& win; 183 | int key; 184 | }; 185 | 186 | } // glv:: 187 | 188 | #endif 189 | 190 | -------------------------------------------------------------------------------- /GLV/glv_buttons.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_BUTTONS_H 2 | #define INC_GLV_BUTTONS_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | #include "glv_core.h" 8 | #include "glv_icon.h" 9 | #include "glv_widget.h" 10 | 11 | namespace glv { 12 | 13 | /// One or more buttons on a grid 14 | class Buttons : public Widget { 15 | public: 16 | 17 | /// \param[in] r geometry 18 | /// \param[in] nx number along x 19 | /// \param[in] ny number along y 20 | /// \param[in] momentary whether the button state matches button press state 21 | /// \param[in] mutExc whether multiple buttons can be on 22 | /// \param[in] on the on state symbol 23 | /// \param[in] off the off state symbol 24 | Buttons( 25 | const Rect& r=Rect(), int nx=1, int ny=1, 26 | bool momentary=false, bool mutExc=false, 27 | SymbolFunc on=draw::rectangle, SymbolFunc off=0 28 | ); 29 | 30 | /// Get off state symbol 31 | const SymbolFunc& symbolOff() const { return mSymOff; } 32 | 33 | /// Get on state symbol 34 | const SymbolFunc& symbolOn () const { return mSymOn; } 35 | 36 | /// Set on/off symbols 37 | Buttons& symbol(const SymbolFunc& f){ symbolOff(f); return symbolOn(f); } 38 | 39 | /// Set off state symbol 40 | Buttons& symbolOff(const SymbolFunc& f){ mSymOff=f; return *this; } 41 | 42 | /// Set on state symbol 43 | Buttons& symbolOn (const SymbolFunc& f){ mSymOn =f; return *this; } 44 | 45 | const char * className() const override { return "Buttons"; } 46 | void onDraw(GLV& g) override; 47 | bool onEvent(Event::t e, GLV& g) override; 48 | 49 | bool getValue() const { return Widget::getValue(); } 50 | bool getValue(int i) const { return Widget::getValue(i); } 51 | bool getValue(int i1, int i2) const { return Widget::getValue(i1, i2); } 52 | 53 | protected: 54 | SymbolFunc mSymOff, mSymOn; // state symbols 55 | }; 56 | 57 | 58 | 59 | /// Single button 60 | class Button : public Buttons { 61 | public: 62 | /// \param[in] r geometry 63 | /// \param[in] momentary whether the button state matches button press state 64 | /// \param[in] on the on state symbol 65 | /// \param[in] off the off state symbol 66 | Button(const Rect& r=Rect(20), bool momentary=false, SymbolFunc on=draw::rectangle, SymbolFunc off=0) 67 | : Buttons(r, 1,1, momentary, false, on, off) 68 | {} 69 | 70 | const char * className() const override { return "Button"; } 71 | }; 72 | 73 | 74 | } // glv:: 75 | 76 | #endif 77 | 78 | -------------------------------------------------------------------------------- /GLV/glv_color.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_COLOR_H 2 | #define INC_GLV_COLOR_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | namespace glv { 8 | 9 | struct HSV; 10 | 11 | /// Color represented by red, green, blue, and alpha components 12 | struct Color{ 13 | 14 | union{ 15 | struct{ 16 | float r; ///< Red component in [0, 1] 17 | float g; ///< Green component in [0, 1] 18 | float b; ///< Blue component in [0, 1] 19 | float a; ///< Alpha component in [0, 1] 20 | }; 21 | float components[4]; ///< RGBA component vector 22 | }; 23 | 24 | 25 | /// \param[in] r red component 26 | /// \param[in] g green component 27 | /// \param[in] b blue component 28 | /// \param[in] a alpha component 29 | Color(float r, float g, float b, float a = 1.f); 30 | 31 | /// \param[in] gray red/green/blue components 32 | /// \param[in] a alpha component 33 | Color(float gray=1.f, float a=1.f); 34 | 35 | /// \param[in] hsv HSV color space 36 | /// \param[in] a alpha component 37 | Color(const HSV& hsv, float a=1.f); 38 | 39 | /// \param[in] rgba 4-vector of RGBA components 40 | template 41 | Color(T * rgba): r(rgba[0]), g(rgba[1]), b(rgba[2]), a(rgba[3]){} 42 | 43 | 44 | /// Set color component at index with no bounds checking 45 | float& operator[](int i){ return components[i]; } 46 | 47 | /// Get color component at index with no bounds checking 48 | const float& operator[](int i) const { return components[i]; } 49 | 50 | 51 | Color& operator= (const HSV& hsv); ///< Set color from HSV values 52 | Color& operator*=(float v); ///< Multiply RGBA values by argument 53 | Color operator* (float v) const; ///< Multiplies RGBA components by argument 54 | Color operator+ (const Color& c) const; ///< Adds argument RGBA components 55 | Color operator- (const Color& c) const; ///< Subtracts argument RGBA components 56 | Color blackAndWhite() const; ///< Returns nearest black or white color 57 | Color inverse() const; ///< Returns inverted color 58 | float luminance() const; ///< Get luminance value 59 | Color mix(const Color& c, float amt) const; ///< Returns linear mix with another color (0 = none) 60 | Color mixRGB(const Color& c, float amt) const; 61 | 62 | 63 | void clamp(); ///< Clamp RGB components into [0,1] 64 | void invert(); ///< Invert colors 65 | void scale(float amount); ///< Scale RGB components 66 | void set(float r, float g, float b, float a); ///< Set RGBA components 67 | void set(float r, float g, float b); ///< Set RGB components 68 | void set(const Color& other, float rgbScale=1); ///< Copy another Color's colors 69 | void set(float gray); ///< Set as gray color 70 | void set(float gray, float alpha); ///< Set as gray color with alpha 71 | 72 | 73 | /// Set color from HSV values in [0, 1] 74 | void setHSV(float h, float s, float v); 75 | 76 | /// Get HSV values in [0, 1] from color 77 | void getHSV(float &h, float &s, float &v) const; 78 | 79 | /// Set color from H value in [0, 6] and SV values in [0, 1]. 80 | void setHSV6(float h, float s, float v); 81 | 82 | /// Get H value in [0, 6] and SV values in [0, 1] from color. 83 | void getHSV6(float &h, float &s, float &v) const; 84 | 85 | void print(const char * append="\n") const; 86 | }; 87 | 88 | 89 | /// Color represented by hue, saturation, and value 90 | struct HSV{ 91 | 92 | union{ 93 | struct{ 94 | float h; ///< Hue component in [0, 1] 95 | float s; ///< Saturation component in [0, 1] 96 | float v; ///< Value component in [0, 1] 97 | }; 98 | float components[3]; ///< HSV component vector 99 | }; 100 | 101 | 102 | /// \param[in] h hue 103 | /// \param[in] s saturation 104 | /// \param[in] v value 105 | HSV(float h=0, float s=1, float v=1): h(h), s(s), v(v){} 106 | 107 | /// \param[in] c RGB color to convert from 108 | HSV(const Color& c){ *this = c; } 109 | 110 | /// \param[in] hsv 3-vector of HSV components 111 | template 112 | HSV(T * hsv): h(hsv[0]), s(hsv[1]), v(hsv[2]){} 113 | 114 | 115 | /// Set from RGB color 116 | HSV& operator=(const Color& c){ c.getHSV(h, s, v); return *this; } 117 | 118 | /// Rotate hue in interval [0, 1) 119 | HSV& rotateHue(float v){ h += v; return wrapHue(); } 120 | 121 | /// Wrap hue value into valid interval [0, 1) 122 | HSV& wrapHue(){ 123 | if(h>1){ h -= int(h); } 124 | else if(h<0){ h -= int(h)-1; } 125 | return *this; 126 | } 127 | }; 128 | 129 | 130 | 131 | // Implementation ______________________________________________________________ 132 | 133 | inline Color::Color(float r, float g, float b, float a) 134 | : r(r), g(g), b(b), a(a) 135 | {} 136 | 137 | inline Color::Color(float v, float a) 138 | : Color(v,v,v, a) 139 | {} 140 | 141 | inline Color::Color(const HSV& hsv, float a) 142 | : a(a) 143 | { 144 | setHSV(hsv.h, hsv.s, hsv.v); 145 | } 146 | 147 | 148 | inline Color& Color::operator=(const HSV& hsv){ 149 | setHSV(hsv.h, hsv.s, hsv.v); return *this; 150 | } 151 | 152 | inline Color Color::operator* (float v) const { return Color(r*v, g*v, b*v, a*v); } 153 | inline Color Color::operator+ (const Color& c) const { return Color(r+c.r, g+c.g, b+c.b, a+c.a); } 154 | inline Color Color::operator- (const Color& c) const { return Color(r-c.r, g-c.g, b-c.b, a-c.a); } 155 | inline Color& Color::operator*=(float v){ set(r*v, g*v, b*v, a*v); return *this; } 156 | 157 | //inline Color Color::blackAndWhite() const { return Color((r>0.5||g>0.5||b>0.5)?1:0); } 158 | inline Color Color::blackAndWhite() const { return Color(luminance()>0.5f?1.f:0.f); } 159 | inline Color Color::inverse() const { return Color(1.f-r, 1.f-g, 1.f-b, a); } 160 | inline float Color::luminance() const { return r*0.299f+g*0.587f+b*0.114f; } 161 | inline Color Color::mix(const Color& c, float f) const { return (c-*this)*f + *this; } 162 | 163 | inline Color Color::mixRGB(const Color& c, float f) const { 164 | return Color((c.r-r)*f+r, (c.g-g)*f+g, (c.b-b)*f+b, a); 165 | } 166 | 167 | inline void Color::clamp(){ 168 | for(auto& v : components) 169 | v<0.f ? v=0.f : (v>1.f ? v=1.f : 0); 170 | } 171 | 172 | inline void Color::invert(){ set(1.f - r, 1.f - g, 1.f - b); } 173 | inline void Color::scale(float v){ set(r*v, g*v, b*v); } 174 | 175 | inline void Color::set(float re, float gr, float bl, float al){ 176 | r = re; g = gr; b = bl; a = al; 177 | } 178 | 179 | inline void Color::set(float re, float gr, float bl){ set(re, gr, bl, a); } 180 | 181 | inline void Color::set(const Color& c, float rgbScale){ 182 | set(c.r, c.g, c.b, c.a); 183 | scale(rgbScale); 184 | } 185 | inline void Color::set(float v){ set(v,v,v); } 186 | inline void Color::set(float v, float al){ set(v,v,v,al); } 187 | 188 | inline void Color::setHSV(float h, float s, float v){ 189 | setHSV6(h * 6.f, s, v); 190 | } 191 | 192 | inline void Color::getHSV(float& h, float& s, float& v) const{ 193 | getHSV6(h,s,v); 194 | h *= 0.166666667f; // 0..1 195 | } 196 | 197 | } // glv:: 198 | 199 | #endif 200 | 201 | -------------------------------------------------------------------------------- /GLV/glv_color_controls.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_COLOR_CONTROLS_H 2 | #define INC_GLV_COLOR_CONTROLS_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | #include "glv_core.h" 8 | #include "glv_sliders.h" 9 | 10 | namespace glv { 11 | 12 | /// Color picker in HSV space 13 | class ColorPicker : public View{ 14 | public: 15 | 16 | /// \param[in] r geometry 17 | /// \param[in] hueHeight height of hue slider 18 | ColorPicker(const Rect& r=Rect(60), float hueHeight=12); 19 | 20 | /// Get value 21 | HSV getValue() const; 22 | 23 | /// Set value 24 | ColorPicker& setValue(const HSV& v); 25 | 26 | const Data& getData(Data& temp) const override; 27 | void setData(const Data& d) override; 28 | 29 | const char * className() const override { return "ColorPicker"; } 30 | void onDraw(GLV& g) override; 31 | bool onEvent(Event::t e, GLV& g) override; 32 | 33 | protected: 34 | Slider mCtrlH; 35 | Slider2D mCtrlSV; 36 | }; 37 | 38 | 39 | /// Color sliders in HSV or RGB space 40 | class ColorSliders : public Sliders{ 41 | public: 42 | 43 | using Sliders::setValue; 44 | 45 | /// \param[in] r geometry 46 | /// \param[in] isHSV whether to control HSV (versus RGB) 47 | /// \param[in] useAlpha whether to include an extra slider for alpha 48 | ColorSliders(const Rect& r=Rect(100, 10*3), bool isHSV=true, bool useAlpha=false); 49 | 50 | bool isHSV() const { return mIsHSV; } 51 | 52 | /// Get value 53 | Color getValue() const; 54 | 55 | /// Set value 56 | ColorSliders& setValue(const Color& v); 57 | 58 | /// Set value 59 | ColorSliders& setValue(const HSV& v); 60 | 61 | const char * className() const override { return "ColorSliders"; } 62 | 63 | protected: 64 | Color mColor; 65 | Style mSliderStyle; 66 | bool mIsHSV, mUseAlpha; 67 | 68 | void setStyle(){ 69 | Color col = getValue(); 70 | mSliderStyle.color.fore = col; 71 | //mSliderStyle.color.back = Color(1-col.luminance()); 72 | //mSliderStyle.color.back = Color(col.luminance() > 0.5f ? 0:1); 73 | mSliderStyle.color.back = Color(0,0,0, Style::standard().color.back.a); 74 | } 75 | 76 | static void ntUpdateStyle(const Notification& n){ 77 | ColorSliders& c = *n.receiver(); 78 | c.setStyle(); 79 | } 80 | }; 81 | 82 | 83 | /// Ultra-compact color control in HSV space 84 | class HSVBar : public Sliders{ 85 | public: 86 | 87 | /// \param[in] r geometry 88 | /// \param[in] hsv initial color 89 | HSVBar(Rect r = Rect(12*3,12), const HSV& hsv = HSV(0,1,1)); 90 | 91 | /// Get value 92 | HSV getValue() const; 93 | 94 | /// Set value 95 | HSVBar& setValue(const HSV& v); 96 | 97 | const char * className() const override { return "HSVBar"; } 98 | void onDraw(GLV& g) override; 99 | bool onEvent(Event::t e, GLV& g) override; 100 | }; 101 | 102 | 103 | } // glv:: 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /GLV/glv_conf.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_CONF_H 2 | #define INC_GLV_CONF_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | #define GLV_VERSION "0.9.7" 8 | #define GLV_MAX_MOUSE_BUTTONS 8 9 | 10 | /* Fixed pipeline (non-shader) 11 | compatible with OpenGL ES 1.1 and OpenGL 1.5 */ 12 | #define GLV_FIX_PIPE 13 | 14 | /* Programmable pipeline (shader only) 15 | compatible with OpenGL ES 2.0 and OpenGL 2.0 */ 16 | //#define GLV_PRG_PIPE 17 | 18 | /* Run-time switchable fixed or programmable pipeline 19 | compatible with anything (!!!) */ 20 | #if defined(GLV_FIX_PIPE) && defined(GLV_PRG_PIPE) && !defined(GLV_DUO_PIPE) 21 | #define GLV_DUO_PIPE 22 | #endif 23 | 24 | 25 | // OpenGL platform-dependent includes 26 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 27 | //#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) 28 | //#if defined(__IPHONE_3_0) 29 | 30 | #define GLV_PLATFORM "IPHONE" 31 | #define GLV_PLATFORM_IPHONE 32 | #define GLV_PLATFORM_INIT_CONTEXT 33 | 34 | #ifdef GLV_PRG_PIPE 35 | #define GLV_OPENGL_ES2 36 | #import 37 | #import 38 | #endif 39 | 40 | #ifdef GLV_FIX_PIPE 41 | #define GLV_OPENGL_ES1 42 | #import 43 | #import 44 | 45 | // FIXME: shouldn't this only belong in windowing impl? 46 | // #define glGenFramebuffers glGenFramebuffersOES 47 | // #define glBindFramebuffer glBindFramebufferOES 48 | // #define glGenRenderbuffers glGenRenderbuffersOES 49 | // #define glBindRenderbuffer glBindRenderbufferOES 50 | // #define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES 51 | // #define GL_RENDERBUFFER GL_RENDERBUFFER_OES 52 | // #define GL_RENDERBUFFER_WIDTH GL_RENDERBUFFER_WIDTH_OES 53 | // #define GL_RENDERBUFFER_HEIGHT GL_RENDERBUFFER_HEIGHT_OES 54 | // #define glGetRenderbufferParameteriv glGetRenderbufferParameterivOES 55 | // #define glFramebufferRenderbuffer glFramebufferRenderbufferOES 56 | // #define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES 57 | // #define glCheckFramebufferStatus glCheckFramebufferStatusOES 58 | // #define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES 59 | // #define glDeleteFramebuffers glDeleteFramebuffersOES 60 | // #define glDeleteRenderbuffers glDeleteRenderbuffersOES 61 | 62 | // FIXME: this will probably conflict with ES2 63 | #define glBlendEquation glBlendEquationOES 64 | #define GL_FUNC_ADD GL_FUNC_ADD_OES 65 | #define GL_FUNC_REVERSE_SUBTRACT GL_FUNC_REVERSE_SUBTRACT_OES 66 | #endif 67 | 68 | #elif defined (__APPLE__) || defined (OSX) 69 | 70 | #define GLV_PLATFORM "OSX" 71 | #define GLV_PLATFORM_OSX 72 | #define GLV_OPENGL 73 | 74 | #define GL_SILENCE_DEPRECATION 75 | #include 76 | #include 77 | #include 78 | 79 | #define GLV_PLATFORM_INIT_CONTEXT\ 80 | { /* prevents tearing */\ 81 | GLint vsync = 1;\ 82 | CGLContextObj ctx = CGLGetCurrentContext();\ 83 | CGLSetParameter(ctx, kCGLCPSwapInterval, &vsync); } 84 | 85 | 86 | #elif defined(__linux__) 87 | 88 | #define GLV_PLATFORM "UNIX" 89 | #define GLV_PLATFORM_UNIX 90 | #define GLV_OPENGL 91 | 92 | #include 93 | #include 94 | #include 95 | #include 96 | 97 | #define GLV_PLATFORM_INIT_CONTEXT\ 98 | { GLenum err = glewInit();\ 99 | if(GLEW_OK != err){\ 100 | fprintf(stderr, "GLEW Init Error: %s\n", glewGetErrorString(err));\ 101 | }\ 102 | } 103 | 104 | 105 | #elif defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || defined(__MSYS__) 106 | 107 | #define GLV_PLATFORM "WIN32" 108 | #define GLV_PLATFORM_WIN 109 | #define GLV_OPENGL 110 | 111 | #ifndef __MINGW32__ 112 | #define GLEW_NO_GLU // GLU not used and throws errors with Mingw-w64 113 | #endif 114 | #include 115 | #include 116 | 117 | #pragma comment( lib, "glew32.lib") 118 | #pragma comment( lib, "winmm.lib") 119 | #pragma comment( lib, "opengl32.lib" ) 120 | 121 | #define GLV_PLATFORM_INIT_CONTEXT\ 122 | { GLenum err = glewInit();\ 123 | if(GLEW_OK != err){\ 124 | fprintf(stderr, "GLEW Init Error: %s\n", glewGetErrorString(err));\ 125 | }\ 126 | } 127 | 128 | #endif 129 | 130 | #define GLV_SNPRINTF snprintf 131 | 132 | #ifdef __MINGW32__ 133 | #undef GLV_SNPRINTF 134 | #define GLV_SNPRINTF _snprintf 135 | #endif 136 | 137 | #endif /* include guard */ 138 | 139 | -------------------------------------------------------------------------------- /GLV/glv_font.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_FONT_H 2 | #define INC_GLV_FONT_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | namespace glv{ 8 | 9 | class GraphicsData; 10 | 11 | /// Font 12 | class Font{ 13 | public: 14 | Font(float size=8); 15 | 16 | virtual ~Font(); 17 | 18 | /// Get advance amount (width) of character 19 | virtual float advance(const char c) const; 20 | 21 | /// Returns total advance width of text string 22 | virtual float advance(const char *text) const; 23 | 24 | /// Get bounding box of text string 25 | virtual void getBounds(float& w, float& h, const char * text) const; 26 | 27 | /// Render text string 28 | virtual void render(const char * text, float x=0, float y=0, float z=0) const; 29 | 30 | virtual void render(GraphicsData& g, const char * text, float x=0, float y=0, float z=0) const; 31 | 32 | /// Set spacing, in ems, between the left and right edges of successive letters 33 | Font& letterSpacing(float v); 34 | 35 | /// Set spacing, in ems, between lines 36 | Font& lineSpacing(float v); 37 | 38 | /// Set the font size in pixels 39 | Font& size(float size); 40 | 41 | /// Set number of spaces per tab 42 | Font& tabSpaces(unsigned spaces); 43 | 44 | float baseline() const; ///< Get absolute position on which glyphs rest 45 | float cap() const; ///< Get distance from baseline to top of uppercase glyphs 46 | float xheight() const; ///< Get distance from baseline to top of lowercase glyphs 47 | float descent() const; ///< Get distance from baseline to lowest position of glyphs 48 | 49 | /// Get letter spacing, in ems 50 | float letterSpacing() const { return mLetterSpacing; } 51 | 52 | /// Get line spacing, in ems 53 | float lineSpacing() const { return mLineSpacing; } 54 | 55 | /// Get scaling factor in x direction 56 | float scaleX() const { return mScaleX; } 57 | 58 | /// Get font size, in pixels 59 | float size() const { return mSize; } 60 | 61 | /// Get number of spaces per tab 62 | unsigned tabSpaces() const { return mTabSpaces; } 63 | 64 | private: 65 | float mSize; 66 | float mScaleX, mScaleY; 67 | float mLetterSpacing; 68 | float mLineSpacing; 69 | unsigned mTabSpaces; 70 | }; 71 | 72 | } // glv:: 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /GLV/glv_grid.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_GRID_H 2 | #define INC_GLV_GRID_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | #include "glv_core.h" 8 | #include "glv_util.h" // Interval 9 | 10 | #ifdef minor 11 | #undef minor 12 | #endif 13 | #ifdef major 14 | #undef major 15 | #endif 16 | 17 | namespace glv{ 18 | 19 | /// Interactive grid for graphing 20 | class Grid : public View{ 21 | public: 22 | 23 | /// \param[in] r geometry 24 | /// \param[in] intervalMin minimum displayed value for all dimensions 25 | /// \param[in] intervalMax maximum displayed value for all dimensions 26 | /// \param[in] majorDist distance between major grid lines 27 | /// \param[in] minorDiv number of minor divisions between major lines 28 | Grid( 29 | const Rect& r=Rect(100,100), 30 | double intervalMin=-1, double intervalMax=1, 31 | double majorDist=1, int minorDiv=4 32 | ); 33 | 34 | /// Get interval of a dimension 35 | const Interval& interval(int dim) const { return mInterval[dim]; } 36 | 37 | /// Set interval of a dimension 38 | Interval& interval(int dim){ return mInterval[dim]; } 39 | 40 | /// Get major division diameters 41 | const double * major() const { return mMajor; } 42 | 43 | /// Get minor divisions 44 | const int * minor() const { return mMinor; } 45 | 46 | /// Get lockScroll booleans 47 | const bool * lockScroll() const { return mLockScroll; } 48 | 49 | /// Get lockZoom booleans 50 | const bool * lockZoom() const { return mLockZoom; } 51 | 52 | /// Get showAxis booleans 53 | const bool * showAxis() const { return mShowAxis; } 54 | 55 | /// Get showGrid booleans 56 | const bool * showGrid() const { return mShowGrid; } 57 | 58 | /// Get showNumbering booleans 59 | const bool * showNumbering() const { return mShowNumbering; } 60 | 61 | /// Returns whether point is contained within grid region 62 | bool contains(double x, double y) const { 63 | return interval(0).contains(x) && interval(1).contains(y); 64 | } 65 | 66 | 67 | /// Set minor division 68 | 69 | /// \param[in] v number of minor divisions per major division 70 | /// \param[in] dim dimension or -1 for all dimensions 71 | Grid& minor(int v, int dim=-1); 72 | 73 | /// Set major division width 74 | 75 | /// \param[in] v width of major division 76 | /// \param[in] dim dimension or -1 for all dimensions 77 | Grid& major(double v, int dim=-1); 78 | 79 | /// Center grid on origin 80 | Grid& origin(); 81 | 82 | /// Set whether to equalize distances along axes 83 | Grid& equalizeAxes(bool v){ mEqualize=v; return *this; } 84 | 85 | /// Set dimension interval to [min, max] 86 | 87 | /// \param[in] min minimum value 88 | /// \param[in] max maximum value 89 | /// \param[in] dim dimension or -1 for all dimensions 90 | Grid& range(double min, double max, int dim=-1); 91 | 92 | /// Set all dimension intervals to [-v, v] 93 | Grid& range(double v){ return range(-v,v); } 94 | 95 | /// Set whether to show axis 96 | 97 | /// \param[in] v whether to show axis 98 | /// \param[in] dim dimension or -1 for all dimensions 99 | Grid& showAxis(bool v, int dim=-1); 100 | 101 | /// Set whether to show grid 102 | 103 | /// \param[in] v whether to show grid 104 | /// \param[in] dim dimension or -1 for all dimensions 105 | Grid& showGrid(bool v, int dim=-1); 106 | 107 | /// Set whether to show numbering 108 | 109 | /// \param[in] v whether to show numbering 110 | /// \param[in] dim dimension or -1 for all dimensions 111 | Grid& showNumbering(bool v, int dim=-1); 112 | 113 | /// Set whether to lock interactive scrolling 114 | Grid& lockScroll(bool v, int dim=-1); 115 | 116 | /// Set whether to lock zooming 117 | Grid& lockZoom(bool v, int dim=-1); 118 | 119 | /// Zoom grid on a point 120 | Grid& zoom(double amt, double x, double y); 121 | 122 | bool onEvent(Event::t e, GLV& g) override; 123 | void onAnimate(double dt) override; 124 | void onDraw(GLV& g) override; 125 | void onResize(space_t dx, space_t dy) override; 126 | 127 | protected: 128 | typedef Interval interval_t; 129 | enum{DIM=2}; 130 | 131 | interval_t mInterval[DIM]; 132 | double mMajor[DIM]; 133 | int mMinor[DIM]; 134 | float mVel[DIM], mVelW; 135 | bool mShowAxis[DIM], mShowGrid[DIM], mShowNumbering[DIM], mEqualize; 136 | bool mLockZoom[DIM]; 137 | bool mLockScroll[DIM]; 138 | 139 | int addGridLines(int i, double dist, GraphicsData& gb); 140 | 141 | // map grid coordinate to GLV pixel coordinate 142 | double gridToPix(int i, double v){ 143 | double r = interval(i).toUnit(v); 144 | return (i ? 1-r : r) * extentVector[i]; 145 | } 146 | 147 | // map GLV pixel coordinate to grid coordinate 148 | double pixToGrid(int i, double v){ 149 | if(i) v = extentVector[i]-v; 150 | return v/extentVector[i] * interval(i).diameter() + interval(i).min(); 151 | } 152 | double pixToGridMul(int i, double v){ return (interval(i).diameter()/extentVector[i])*v; } 153 | 154 | void pushGrid(); // push into grid space for drawing 155 | void popGrid(); // pop out of grid space 156 | 157 | void zoomOnMousePos(double amt, const Mouse& m); 158 | }; 159 | 160 | } // glv:: 161 | #endif 162 | -------------------------------------------------------------------------------- /GLV/glv_icon.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_ICON_H 2 | #define INC_GLV_ICON_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | #include "glv_draw.h" 8 | 9 | namespace glv{ 10 | 11 | /* 12 | These are intended to replace the function pointer icons in draw::. 13 | They are a bit more difficult to handle than function pointers, such as when 14 | passing into a constructor. C++ polymorphism forces us to use either pointers 15 | or references. 16 | */ 17 | 18 | struct Icon{ 19 | virtual ~Icon(){} 20 | virtual void draw(float l, float t, float r, float b){} 21 | }; 22 | 23 | struct Check : public Icon { 24 | void draw(float l, float t, float r, float b){ 25 | draw::shape(draw::LineStrip, l,0.5f*(t+b), l+(r-l)*0.3f,b, r,t); 26 | } 27 | }; 28 | 29 | struct Cross : public Icon{ 30 | void draw(float l, float t, float r, float b){ 31 | draw::shape(draw::Lines, l,t, r,b, l,b, r,t); 32 | } 33 | }; 34 | 35 | struct Rectangle : public Icon { 36 | void draw(float l, float t, float r, float b){ 37 | draw::shape(draw::TriangleStrip, l,t, l,b, r,t, r,b); 38 | } 39 | }; 40 | 41 | } // glv:: 42 | #endif 43 | -------------------------------------------------------------------------------- /GLV/glv_notification.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_NOTIFICATION_H 2 | #define INC_GLV_NOTIFICATION_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | #include 8 | 9 | #if __cplusplus >= 201103L 10 | #define GLV_USE_STD_FUNCTION 11 | #endif 12 | 13 | #ifdef GLV_USE_STD_FUNCTION 14 | #include 15 | #endif 16 | 17 | namespace glv { 18 | 19 | class Notifier; 20 | 21 | 22 | /// Notification update types 23 | namespace Update{ 24 | enum t{ 25 | Focus = 0, /**< Focus update */ 26 | Value, /**< Value update */ 27 | Action, /**< Perform an action based on current value */ 28 | Selection, 29 | NumTypes, /**< Number of predefined notification types */ 30 | User = 1000 /**< Start of user-defined notification types */ 31 | }; 32 | } 33 | 34 | 35 | /// Generic index/value struct for widget notifications 36 | 37 | /// Since some widgets have multiple values, an index is used to specify which 38 | /// element corresponds to the update. If a widget only has one value, an index 39 | /// of zero is used. 40 | template 41 | class ChangedValue{ 42 | public: 43 | 44 | /// \param[in] v value 45 | /// \param[in] i index of value 46 | ChangedValue(const T& v, int i=0): mIndex(i), mValue(v){} 47 | 48 | const T& value() const { return mValue; } ///< Get value 49 | int index() const { return mIndex; } ///< Get index of value 50 | 51 | private: 52 | int mIndex; 53 | T mValue; 54 | }; 55 | 56 | 57 | /// Data passed with selection change notification 58 | struct ChangedSelection{ 59 | int oldIndex; 60 | int newIndex; 61 | }; 62 | 63 | 64 | /// Notification object 65 | 66 | /// This is passed into notification callbacks 67 | /// 68 | class Notification{ 69 | public: 70 | 71 | /// \param[in] sndr Pointer to sending object (subject) 72 | /// \param[in] rcvr Pointer to receiving object (observer) 73 | /// \param[in] data Pointer to data object 74 | Notification(void * sndr, void * rcvr=0, const void * data=0) 75 | : mSender(sndr), mReceiver(rcvr), mData(data) 76 | {} 77 | 78 | /// Get pointer to sending object 79 | template 80 | T * sender() const { return static_cast(sender()); } 81 | 82 | /// Get raw pointer to sending object 83 | void * sender() const { return mSender; } 84 | 85 | /// Get pointer to receiving object 86 | template 87 | T * receiver() const { return static_cast(receiver()); } 88 | 89 | /// Get raw pointer to receiving object 90 | void * receiver() const { return mReceiver; } 91 | 92 | /// Get raw pointer to data object 93 | const void * data() const { return mData; } 94 | 95 | /// Get pointer to data object 96 | template 97 | const T * data() const { return static_cast(data()); } 98 | 99 | protected: 100 | void * mSender; 101 | void * mReceiver; 102 | const void * mData; 103 | }; 104 | 105 | 106 | 107 | 108 | /// Notifies one or more observers of state change 109 | class Notifier{ 110 | public: 111 | 112 | /// Notification callback 113 | #ifdef GLV_USE_STD_FUNCTION 114 | typedef std::function Callback; 115 | #else 116 | typedef void (* Callback)(const Notification& n); 117 | #endif 118 | 119 | Notifier(); 120 | 121 | ~Notifier(); 122 | 123 | 124 | /// Attach a new notification callback, type, and receiver 125 | void attach(Callback cb, Update::t type, void * rcvr=0); 126 | 127 | /// Detach an existing notification callback, type, and receiver 128 | void detach(Callback cb, Update::t type, void * rcvr=0); 129 | 130 | 131 | /// Notify observers of a specific update type 132 | void notify(void * sender, Update::t type, void * data=0); 133 | 134 | /// Notify observers of a specific update type 135 | void notify(Update::t type, void * data=0){ notify(this, type, data); } 136 | // LJP: The above can lead to unexpected results when casting since the 137 | // void * points to a Notifier. 138 | 139 | 140 | /// Notify observers of a specific update type 141 | template 142 | void notify(Update::t type, const ChangedValue& v){ 143 | notify(type, (void *)&v); 144 | } 145 | 146 | /// Returns number of observers for this update type 147 | int numObservers(Update::t type) const; 148 | 149 | protected: 150 | 151 | struct Handler{ 152 | Handler(Callback c, void * r): handler(c), receiver(r){} 153 | Callback handler; 154 | void * receiver; 155 | }; 156 | 157 | // Array of vectors for each notification type 158 | std::vector * mHandlers; 159 | 160 | // Setter dynamically allocates new memory 161 | std::vector * handlers(){ 162 | if(0 == mHandlers){ 163 | mHandlers = new std::vector[Update::NumTypes]; 164 | } 165 | return mHandlers; 166 | } 167 | 168 | // Getter just returns pointer (even if 0) 169 | const std::vector * handlers() const { 170 | return mHandlers; 171 | } 172 | 173 | bool hasHandlers() const { return handlers() != 0; } 174 | }; 175 | 176 | } // glv:: 177 | #endif 178 | -------------------------------------------------------------------------------- /GLV/glv_sono.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_SONO_H 2 | #define INC_GLV_SONO_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | #include 8 | #include "glv_core.h" 9 | #include "glv_plots.h" 10 | 11 | namespace glv{ 12 | 13 | /// Plots time-domain signal 14 | class TimeScope : public Plot{ 15 | public: 16 | 17 | TimeScope(const glv::Rect& r=glv::Rect(200,100), int frames=0, int chans=1); 18 | 19 | ~TimeScope(); 20 | 21 | int frames() const { return data().size(0); } 22 | int channels() const { return data().size(1); } 23 | int samples() const { return data().size(0,1); } 24 | 25 | 26 | /// Resize plot display 27 | 28 | /// This should not be called from the audio thread. 29 | /// 30 | void resize(int plotFrames, int plotChans); 31 | 32 | /// Update scope with new audio data 33 | 34 | /// This can be safely called from the audio thread. 35 | /// 36 | void update(const float * buf, int bufFrames, int bufChans, bool interleaved); 37 | 38 | /// Set whether to synchronize waveform to first positive slope zero-crossing 39 | TimeScope& sync(bool v); 40 | 41 | bool onEvent(Event::t e, GLV& g) override; 42 | const char * className() const override { return "TimeScope"; } 43 | 44 | protected: 45 | std::vector mGraphs; 46 | float * mSamples = nullptr; 47 | int mFill = 0; 48 | int mSync; 49 | bool mLocked = false; 50 | }; 51 | 52 | 53 | 54 | /// Group of peak meters for monitoring audio 55 | class PeakMeters : public View{ 56 | public: 57 | 58 | /// \param[in] r geometry 59 | PeakMeters(const Rect& r=Rect(100), int chans=4); 60 | 61 | /// Set number of channels 62 | PeakMeters& channels(int v); 63 | 64 | /// Get number of channels 65 | int channels() const { return mMonitors.size(); } 66 | 67 | void inputSample(float v, int chan){ 68 | mMonitors[chan](v); 69 | } 70 | 71 | void onDraw(GLV& g) override; 72 | bool onEvent(Event::t e, GLV& g) override; 73 | const char * className() const override { return "PeakMeters"; } 74 | 75 | protected: 76 | struct Monitor{ 77 | float lastAbs; 78 | float runSum; 79 | float max; 80 | 81 | void operator()(float v){ 82 | float absv = v>0.f?v:-v; 83 | lastAbs = absv; 84 | runSum += v; 85 | if(absv > max) max = absv; 86 | } 87 | }; 88 | 89 | std::vector mMonitors; 90 | 91 | int getMeter(float x, float y); 92 | }; 93 | 94 | } // glv:: 95 | #endif 96 | -------------------------------------------------------------------------------- /GLV/glv_texture.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_TEXTURE_H 2 | #define INC_GLV_TEXTURE_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | #include "glv_conf.h" 8 | 9 | namespace glv{ 10 | 11 | /// 2-D texture 12 | class Texture2{ 13 | public: 14 | 15 | /// Construct a texture that allocates an internal pixel buffer 16 | 17 | /// \param[in] width width, in texels 18 | /// \param[in] height height, in texels 19 | /// \param[in] format color format 20 | /// \param[in] type color data type 21 | Texture2( 22 | GLsizei width, GLsizei height, 23 | GLenum format=GL_RGB, GLenum type=GL_UNSIGNED_BYTE); 24 | 25 | /// Construct a texture that references an external pixel buffer 26 | 27 | /// \param[in] width width, in texels, of external buffer 28 | /// \param[in] height height, in texels, of external buffer 29 | /// \param[in] pixels external texel buffer 30 | /// \param[in] format color format of external buffer 31 | /// \param[in] type color data type of external buffer 32 | /// \param[in] doesLoad whether or not to load texture onto GPU 33 | Texture2( 34 | GLsizei width, GLsizei height, GLvoid * pixels, 35 | GLenum format=GL_RGB, GLenum type=GL_UNSIGNED_BYTE, 36 | bool doesLoad=false); 37 | 38 | virtual ~Texture2(); 39 | 40 | /// Get pointer to local texture memory 41 | template 42 | T * buffer() const { return static_cast(mBuffer); } 43 | 44 | GLuint id() const { return mID; } ///< Get unique identifier 45 | GLsizei width() const { return w; } ///< Get width 46 | GLsizei height() const { return h; } ///< Get height 47 | 48 | void begin() const; ///< Bind self to current context 49 | void end() const; ///< Binds default texture 50 | 51 | /// Allocate local texture memory. 52 | 53 | /// Returns total number of bytes allocated. 54 | /// 55 | int alloc(int w, int h); 56 | 57 | /// Free local texture memory 58 | void dealloc(); 59 | 60 | Texture2& bind(); ///< Bind self to current context 61 | 62 | /// Draw texture to rectangular quad 63 | Texture2& draw( 64 | float ql, float qt, float qr, float qb, 65 | float tl=0, float tt=1, float tr=1, float tb=0 66 | ); 67 | 68 | void destroy(); 69 | 70 | Texture2& create(GLsizei w, GLsizei h, GLvoid * pixels = 0); ///< Create new texture on graphics card 71 | Texture2& create(); ///< Reload texture onto GPU 72 | 73 | Texture2& recreate(); ///< Recreates texture on GPU using current settings 74 | 75 | Texture2& send(); ///< Send internal pixels to GPU 76 | Texture2& send(const GLvoid * pix); ///< Send pointed to pixels to GPU 77 | 78 | Texture2& format(GLenum v); ///< Set the color format 79 | Texture2& type(GLenum v); ///< Set the color data type 80 | Texture2& magFilter(GLenum v); ///< Set mag filter 81 | Texture2& wrapMode(GLenum v); ///< Set wrap mode 82 | 83 | /// Set texel update region 84 | Texture2& updateRegion(int x, int y, int w, int h); 85 | 86 | private: 87 | GLuint mID; 88 | GLsizei w, h; 89 | GLvoid * mPixels; // pointer to the client-side pixel data (0 if none) 90 | GLvoid * mBuffer; // internally allocated pixel buffer 91 | GLenum mFormat; // format of the pixel data: 92 | // GL_COLOR_INDEX, GL_ALPHA, 93 | // GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_LUMINANCE, and GL_LUMINANCE_ALPHA. 94 | 95 | GLenum mType; // type of the pixel data: 96 | // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_FLOAT 97 | 98 | GLenum mMagFilter; // GL_LINEAR, GL_NEAREST 99 | GLenum mWrapMode; // GL_CLAMP_TO_EDGE, GL_REPEAT 100 | int mUpdateRegion[4]; // update region (x,y,w,h) 101 | 102 | void sendParams(); 103 | }; 104 | 105 | 106 | } //glv:: 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /GLV/glv_view3D.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_VIEW3D_H 2 | #define INC_GLV_VIEW3D_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | #include "glv_core.h" 8 | 9 | namespace glv { 10 | 11 | /// View for three-dimensional rendering 12 | class View3D : public View { 13 | public: 14 | 15 | /// \param[in] r geometry 16 | View3D(const Rect& r=Rect(0)); 17 | virtual ~View3D(){} 18 | 19 | 20 | /// 2D drawing callback called after 3D 21 | virtual void onDraw2D(GLV& g){} 22 | 23 | /// 3D drawing callback 24 | virtual void onDraw3D(GLV& g){} 25 | 26 | float far() const { return mFar; } ///< Get far clip distance 27 | float near() const { return mNear; } ///< Get near clip distance 28 | float fovy() const { return mFOVY; } ///< Get field of view angle, in degrees, in the y direction 29 | 30 | void far(float v){ mFar=v; } ///< Set far clip distance 31 | void near(float v){ mNear=v; } ///< Set near clip distance 32 | void fovy(float v){ mFOVY=v; } ///< Set field of view angle, in degrees, in the y direction 33 | 34 | void ortho(bool v){ mOrtho=v; } ///< Set orthographic projection 35 | 36 | /// Set 4x4 model transform matrix (column-major) 37 | template 38 | void modelView(T * mat4x4){ 39 | for(int i=0; i<16; ++i) mModelView[i]=mat4x4[i]; 40 | } 41 | 42 | /// Get 4x4 model transform matrix 43 | float * modelView(){ return mModelView; } 44 | 45 | void resetModelView(); 46 | 47 | const char * className() const override { return "View3D"; } 48 | 49 | protected: 50 | void onDraw(GLV& g) override; 51 | bool onEvent(Event::t e, GLV& g) override; 52 | float mNear, mFar, mFOVY; 53 | float mModelView[16]; 54 | bool mOrtho; 55 | 56 | // struct ViewModel : public Model{ 57 | // ViewModel(View3D& self): v(self){} 58 | // 59 | // virtual std::string modelToToken(){ 60 | // std::string s; 61 | // addKeyValue(s, "near", v.mNear); 62 | // addKeyValue(s, "far", v.mFar); 63 | // addKeyValue(s, "fovy", v.mFOVY); 64 | // return s; 65 | // } 66 | // 67 | // virtual int modelFromString(const std::string& s){ 68 | // getValue(s, "near", v.mNear); 69 | // getValue(s, "far", v.mFar); 70 | // getValue(s, "fovy", v.mFOVY); 71 | // } 72 | // View3D& v; 73 | // }; 74 | }; 75 | 76 | 77 | } // glv:: 78 | #endif 79 | -------------------------------------------------------------------------------- /GLV/glv_widget.h: -------------------------------------------------------------------------------- 1 | #ifndef INC_GLV_WIDGET_H 2 | #define INC_GLV_WIDGET_H 3 | 4 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 5 | See COPYRIGHT file for authors and license information */ 6 | 7 | #include "glv_core.h" 8 | #include "glv_model.h" 9 | #include "glv_util.h" // Lazy 10 | 11 | namespace glv { 12 | 13 | typedef ChangedValue ModelChange; 14 | 15 | /// Base class for views having a regular grid of elements 16 | class Widget : public View, public DataObject { 17 | public: 18 | 19 | /// \param[in] r geometry 20 | /// \param[in] pad padding from border 21 | /// \param[in] momentary whether the value elements are momentary 22 | /// \param[in] mutExc whether value elements operate mutually exclusively 23 | /// \param[in] drawGrid whether to draw grid separater for multiple elements 24 | Widget( 25 | const Rect& r, space_t pad=3, 26 | bool momentary=false, bool mutExc=false, bool drawGrid=true 27 | ); 28 | 29 | 30 | /// Get selected element value type-casted to template parameter 31 | template 32 | T getValue() const { return getValue(selectedX(), selectedY()); } 33 | 34 | /// Get element value at 1D index type-casted to template parameter 35 | template 36 | T getValue(int i) const { return data().Data::at(i); } 37 | 38 | /// Get element value at 2D index type-casted to template parameter 39 | template 40 | T getValue(int i1, int i2) const { return data().Data::at(i1, i2); } 41 | 42 | /// Check if value changed 43 | 44 | /// \returns index+1 of the changed value or 0 for no value change. 45 | /// In the simplest use case, this can be used as a boolean to check for any 46 | /// value change. 47 | int changed() const { return mChangedElem; } 48 | 49 | /// Returns whether this element coordinate is selected 50 | bool isSelected(int x, int y) const { return x == selectedX() && y == selectedY(); } 51 | 52 | const Interval& interval() const { return mInterval; } ///< Get value interval 53 | const double& max() const { return mInterval.max(); } ///< Get maximum of value interval 54 | const double& min() const { return mInterval.min(); } ///< Get minimum of value interval 55 | double mid() const { return mInterval.center(); } ///< Get middle point of value interval 56 | 57 | space_t paddingX() const { return mPadding[0]; } ///< Get element padding amount along x 58 | space_t paddingY() const { return mPadding[1]; } ///< Get element padding amount along y 59 | 60 | int selected() const { return data().indexFlat(sx, sy); } ///< Get selected element index 61 | int selectedX() const { return sx; } ///< Get selected element x coordinate 62 | int selectedY() const { return sy; } ///< Get selected element y coordinate 63 | int size () const { return data().size(); } ///< Get total number of elements 64 | int sizeX() const { return data().size(0); } ///< Get number of elements along x 65 | int sizeY() const { return data().size(1); } ///< Get number of elements along y 66 | bool useInterval() const { return mUseInterval; } 67 | 68 | 69 | float dx(int dim=0) const { return w/data().size(dim); } ///< Get width, in pixels, per element 70 | float dy(int dim=1) const { return h/data().size(dim); } ///< Get height, in pixels, per element 71 | 72 | 73 | 74 | /// Attach a single variable at a specified index 75 | template 76 | void attachVariable(V& val, int i=0){ 77 | attachVariable(&val, 1, i); 78 | } 79 | 80 | /// Attach an array of variables at a specified index 81 | template 82 | void attachVariable(T * src, int size, int i=0){ 83 | variables()[i] = Data(src, size); 84 | } 85 | 86 | void clipIndices(){ clipIndices(sx,sy); } 87 | 88 | /// Set interval for numerical values 89 | Widget& interval(const double& max, const double& min=0){ 90 | if(min < max) mInterval.endpoints(min,max); 91 | else mInterval.endpoints(max,min); 92 | return *this; 93 | } 94 | 95 | /// Set padding around elements 96 | Widget& padding(space_t v){ for(int i=0; i 116 | Widget& setValue(const T& v); 117 | 118 | /// Set value at specified 1D index 119 | template 120 | Widget& setValue(const T& v, int i){ select(i); return setValue(v); } 121 | 122 | /// Set value at specified 2D index 123 | template 124 | Widget& setValue(const T& v, int ix, int iy){ select(ix,iy); return setValue(v); } 125 | 126 | Widget& setValue(const char * v){ return setValue(std::string(v)); } 127 | 128 | /// Set all values to maximum 129 | Widget& setValueMax(); 130 | 131 | /// Set all values to middle value 132 | Widget& setValueMid(); 133 | 134 | Widget& useInterval(bool v){ mUseInterval=v; return *this; } 135 | 136 | void onDataModelSync() override; 137 | const Data& getData(Data& temp) const override { return data(); } 138 | void setData(const Data& d) override { assignData(d); } 139 | 140 | void assignData(const Data& d, const int& ind=0){ 141 | int i1=0,i2=0; data().indexDim(i1,i2, ind); 142 | assignData(d, i1,i2); 143 | } 144 | 145 | // Assigns argument to elements at specified index. 146 | 147 | // assignData() is called with the input data if the indices are valid. 148 | // assignData() can be used to constrain the input data before it is 149 | // assigned. 150 | void assignData(const Data& d, int ind1, int ind2){ 151 | if(data().inBounds(ind1, ind2)){ 152 | Data t=d; t.clone(); 153 | if(onAssignData(t, ind1, ind2)){ 154 | //model().assign(t, ind1, ind2); 155 | } 156 | } 157 | } 158 | 159 | const char * className() const override { return "Widget"; } 160 | 161 | protected: 162 | enum{ DIMS=2 }; 163 | typedef std::map IndexDataMap; 164 | 165 | Lazy mVariables; // external variables to sync to, index-Data 166 | space_t mPadding[DIMS]; // num pixels to inset icon 167 | short sx, sy; // selected element position 168 | Interval mInterval; 169 | double mPrevVal; // used for momentary value 170 | int mChangedElem = 0; // index+1 of changed element 171 | bool mUseInterval; 172 | 173 | bool hasVariables() const { return mVariables.created(); } 174 | IndexDataMap& variables(){ return mVariables(); } 175 | const IndexDataMap& variables() const { return mVariables(); } 176 | 177 | int index(int ix, int iy) const { return ix + iy*sizeX(); } 178 | bool tallElems() const { return dy() > dx(); } 179 | 180 | template 181 | static void clip(Int& i, int max){ i<0 ? i=0 : i>=max ? i=max-1 : 0; } 182 | template 183 | void clipIndices(Int& x, Int& y){ clip(x, sizeX()); clip(y, sizeY()); } 184 | bool validIndex(int i) const { return (i < size()) && (i >= 0); } 185 | 186 | double diam() const { return mInterval.diameter(); } 187 | double to01(const double& v) const { return mInterval.toUnit(v); } 188 | double toInterval(const double& v) const { return mInterval.fromUnit(v); } 189 | 190 | template 191 | Widget& setValue(const T& v, int i, double mn, double mx){ 192 | double omn=min(), omx=max(); 193 | interval(mx, mn); 194 | setValue(v,i); 195 | return interval(omx, omn); 196 | } 197 | 198 | // This is the central go to for all data assignment methods of Widget. 199 | // It is responsible for updating the widget's data and attached variables, 200 | // and for sending out Update::Value notifications. 201 | // The order of events is 1) update widget's data, 2) update attached 202 | // variables, if any, and 3) send out notifications. 203 | // \param[in] d the source data 204 | // \param[in] ind1 destination index of first dimension 205 | // \param[in] ind2 destitation index of second dimension 206 | virtual bool onAssignData(Data& d, int ind1, int ind2); 207 | 208 | void onAnimate(double dsec) override; 209 | void onDraw(GLV& g) override; 210 | bool onEvent(Event::t e, GLV& g) override; 211 | 212 | void drawGrid(GraphicsData& g); 213 | void drawSelectionBox(); 214 | void selectFromMousePos(GLV& g); 215 | 216 | static bool widgetKeyDown(View * v, GLV& g); 217 | }; 218 | 219 | 220 | template 221 | Widget& Widget::setValue(const T& v){ 222 | T t = v; 223 | Data d(t); 224 | assignData(d, selectedX(), selectedY()); 225 | return *this; 226 | } 227 | 228 | } // glv:: 229 | #endif 230 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #========================================================================= 2 | # GLV main makefile 3 | #========================================================================= 4 | 5 | include Makefile.config 6 | 7 | SRCS = glv_buttons.cpp \ 8 | glv_color.cpp \ 9 | glv_color_controls.cpp \ 10 | glv_core.cpp \ 11 | glv_draw.cpp \ 12 | glv_font.cpp \ 13 | glv_glv.cpp \ 14 | glv_grid.cpp \ 15 | glv_inputdevice.cpp \ 16 | glv_layout.cpp \ 17 | glv_model.cpp \ 18 | glv_notification.cpp \ 19 | glv_plots.cpp \ 20 | glv_preset_controls.cpp \ 21 | glv_sliders.cpp \ 22 | glv_sono.cpp \ 23 | glv_texture.cpp \ 24 | glv_textview.cpp \ 25 | glv_view.cpp \ 26 | glv_view3D.cpp \ 27 | glv_widget.cpp 28 | 29 | ifdef WINDOW_BINDING 30 | SRCS += glv_binding.cpp $(BINDING_SRC) 31 | endif 32 | 33 | OBJS = $(addsuffix .o, $(basename $(notdir $(SRCS)))) 34 | CFLAGS += $(addprefix -I, $(INC_DIR)) 35 | LDFLAGS := $(addprefix -L, $(LIB_DIRS)) $(LDFLAGS) 36 | 37 | 38 | #-------------------------------------------------------------------------- 39 | # Rules 40 | #-------------------------------------------------------------------------- 41 | include Makefile.rules 42 | 43 | .PHONY: clean test 44 | 45 | 46 | # Install library into path specified by DESTDIR 47 | # Include files are copied into DESTDIR/include/LIB_NAME and 48 | # library files are copied to DESTDIR/lib 49 | install: $(LIB_PATH) 50 | # @echo 'INSTALL $(DESTDIR)' 51 | @$(INSTALL) -d $(DESTDIR)/lib 52 | @$(INSTALL) -d $(DESTDIR)/include/$(LIB_NAME) 53 | @$(INSTALL) -m 644 $(LIB_PATH) $(DESTDIR)/lib 54 | @$(INSTALL) -m 644 $(INC_DIR)/*.h $(DESTDIR)/include/$(LIB_NAME) 55 | # @$(RANLIB) $(DESTDIR)/lib/$(LIB_FILE) 56 | 57 | 58 | test: $(LIB_PATH) FORCE 59 | # @$(MAKE) -C $(TEST_DIR) 60 | @$(MAKE) --no-print-directory test/test_units.cpp 61 | 62 | buildtest: test 63 | @$(MAKE) --no-print-directory examples/*.cpp AUTORUN=0 64 | 65 | 66 | # Compile and run source files in examples/ or test/ folder 67 | EXEC_TARGETS = examples/%.cpp test/%.cpp 68 | .PRECIOUS: $(EXEC_TARGETS) 69 | $(EXEC_TARGETS): $(LIB_PATH) FORCE 70 | $(CXX) $(CFLAGS) $(CXXFLAGS) -o $(BIN_DIR)$(*F) $@ $(LIB_PATH) $(LDFLAGS) 71 | ifneq ($(AUTORUN), 0) 72 | @cd $(BIN_DIR) && ./$(*F) & 73 | endif 74 | 75 | 76 | # Remove build files 77 | clean: 78 | # Clean only removes object files for now; avoids unintentional removal of user files 79 | $(call RemoveDir, $(OBJ_DIR)) 80 | -------------------------------------------------------------------------------- /Makefile.config: -------------------------------------------------------------------------------- 1 | #========================================================================= 2 | # GLV makefile configuration 3 | #========================================================================= 4 | 5 | LIB_NAME = GLV 6 | include Makefile.common 7 | 8 | # Window binding (comment out for none) 9 | WINDOW_BINDING = GLUT 10 | 11 | USE_OPENGL_ES = 0 12 | 13 | #========================================================================= 14 | # Customize to fit your system 15 | #========================================================================= 16 | 17 | LIB_DIRS = 18 | INC_DIRS = 19 | #CFLAGS += -Wall -I/usr/include 20 | #LDFLAGS += -lm -lstdc++ -L/usr/lib 21 | 22 | BUILD_DIR = build/ 23 | INSTALL_DIR = $(PREFIX) 24 | INC_DIR = GLV/ 25 | SRC_DIR = src/ 26 | TEST_DIR = test/ 27 | EXAMPLE_DIR = example/ 28 | 29 | #========================================================================= 30 | # DO NOT EDIT BELOW! 31 | #========================================================================= 32 | #------------------------------------------------------------------------- 33 | # Platform specific section 34 | #------------------------------------------------------------------------- 35 | ifeq ($(PLATFORM), linux) 36 | LINK_LDFLAGS += -lGLEW -lGLU -lGL 37 | 38 | else ifeq ($(PLATFORM), macosx) 39 | LINK_LDFLAGS += -framework AGL -framework OpenGL 40 | 41 | else ifeq ($(PLATFORM), windows) 42 | LINK_LDFLAGS += -lglew32 -lopengl32 43 | endif 44 | 45 | BINDING_SRC = 46 | ifeq ($(WINDOW_BINDING), GLUT) 47 | BINDING_SRC = glv_binding_glut.cpp 48 | 49 | ifeq ($(PLATFORM), linux) 50 | LINK_LDFLAGS += -lglut 51 | else ifeq ($(PLATFORM), macosx) 52 | LINK_LDFLAGS += -framework GLUT 53 | else ifeq ($(PLATFORM), windows) 54 | ifeq ($(MSYS_VERSION), 2) 55 | LINK_LDFLAGS += -lfreeglut 56 | else 57 | LINK_LDFLAGS += -lglut32 58 | endif 59 | endif 60 | endif 61 | 62 | ifneq ($(USE_OPENGL_ES), 0) 63 | LINK_CPPFLAGS += -DGLV_USE_OPENGL_ES 64 | endif 65 | 66 | #------------------------------------------------------------------------- 67 | # Final (dependent) variable definitions 68 | #------------------------------------------------------------------------- 69 | VPATH = $(SRC_DIR) $(TEST_DIR) $(EXAMPLE_DIR) 70 | -------------------------------------------------------------------------------- /Makefile.rules: -------------------------------------------------------------------------------- 1 | #========================================================================= 2 | # Common rules for all Makefiles 3 | #========================================================================= 4 | 5 | # Append linker flags set elsewhere 6 | CPPFLAGS += $(LINK_CPPFLAGS) 7 | CFLAGS += $(LINK_CFLAGS) 8 | CXXFLAGS += $(LINK_CXXFLAGS) 9 | LDFLAGS += $(LINK_LDFLAGS) 10 | 11 | ALL_CFLAGS := $(CPPFLAGS) $(CFLAGS) 12 | ALL_CXXFLAGS := $(CPPFLAGS) $(CFLAGS) $(CXXFLAGS) 13 | 14 | DEPFLAGS = 15 | ifneq ($(DEP_TRACK), 0) 16 | DEPFLAGS = -MMD -MF $(basename $@).dep 17 | endif 18 | 19 | ALL_BUILD_DIRS = $(BIN_DIR)/ $(OBJ_DIR)/ $(BUILD_DIR)include/ $(BUILD_DIR)lib/ 20 | 21 | #-------------------------------------------------------------------------- 22 | # Rules 23 | #-------------------------------------------------------------------------- 24 | 25 | all: $(LIB_PATH) 26 | 27 | 28 | # Build object file from C source 29 | $(OBJ_DIR)%.o:: %.c 30 | @echo CC $< $@ 31 | $(CC) -c $(ALL_CFLAGS) $< -o $@ $(DEPFLAGS) 32 | 33 | # Build object file from C++ source 34 | $(OBJ_DIR)%.o:: %.cpp 35 | @echo CXX $< $@ 36 | $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ $(DEPFLAGS) 37 | 38 | $(OBJ_DIR)%.o:: %.cc 39 | @echo CXX $< $@ 40 | $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ $(DEPFLAGS) 41 | 42 | # Build object file from Obj-C++ source 43 | $(OBJ_DIR)%.o:: %.mm 44 | @echo CXX $< $@ 45 | $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ $(DEPFLAGS) 46 | 47 | # Build pre-compiled headers 48 | $(OBJ_DIR)%.hpp.gch:: %.hpp 49 | @echo CXX $< $@ 50 | $(CXX) -x c++ -c $(ALL_CXXFLAGS) -Winvalid-pch $< -o $@ $(DEPFLAGS) 51 | 52 | # Include GCC generated dependency files 53 | -include $(wildcard $(OBJ_DIR)*.dep) 54 | 55 | # Prevent Make from automatically searching its predefined implicit rules 56 | %.dep: ; 57 | Makefile.%: ; 58 | %.inl: ; 59 | %.h: ; 60 | %.hpp: ; 61 | 62 | # Build static library 63 | $(SLIB_PATH): $(addprefix $(OBJ_DIR), $(OBJS) $(PCHS)) 64 | ifneq ($(OBJS),) 65 | @echo AR $@ 66 | @$(RM) $@ 67 | $(AR) $@ $(filter %.o, $^) $(SLIB_FLAGS) 68 | # @$(RANLIB) $@ 69 | # libtool --mode=link --tag=CXX $(filter %.o, $^) $(SLIB_FLAGS) -o $@ 70 | # @libtool -static $@ $(patsubst %, $(DEV_DIR)lib/lib%.a, $(STATIC_LIBS)) -o $@ 71 | endif 72 | 73 | 74 | # Build dynamic library 75 | $(DLIB_PATH): $(addprefix $(OBJ_DIR), $(OBJS)) 76 | ifneq ($(OBJS),) 77 | @echo DY $@ 78 | $(CXX) $(DLIB_FLAGS) $(ALL_CXXFLAGS) -o $@ $(filter %.o, $^) $(LDFLAGS) 79 | endif 80 | 81 | 82 | # Dummy target to force rebuilds 83 | FORCE: ; 84 | 85 | 86 | # This creates a particular build folder 87 | $(ALL_BUILD_DIRS): 88 | @mkdir -p $@ 89 | 90 | # This rule creates all the build directories ONCE when the first object is built 91 | $(addprefix $(OBJ_DIR), $(OBJS)): | $(ALL_BUILD_DIRS) 92 | 93 | 94 | # Create file with settings for linking to external libraries 95 | linkfile: 96 | $(eval $@_STR := "LDFLAGS += -l$(LIB_NAME)") 97 | ifneq ($(strip $(LINK_LDFLAGS)),) 98 | $(eval $@_STR += " $(LINK_LDFLAGS)") 99 | endif 100 | ifneq ($(strip $(LINK_CPPFLAGS)),) 101 | $(eval $@_STR += "\r\nCPPFLAGS +=$(LINK_CPPFLAGS)") 102 | endif 103 | ifneq ($(strip $(LINK_CFLAGS)),) 104 | $(eval $@_STR += "\r\nCFLAGS +=$(LINK_CFLAGS)") 105 | endif 106 | ifneq ($(strip $(LINK_CXXFLAGS)),) 107 | $(eval $@_STR += "\r\nCXXFLAGS +=$(LINK_CXXFLAGS)") 108 | endif 109 | @printf "%b" $($@_STR) > Makefile.link 110 | 111 | 112 | # Archive repository 113 | archive: 114 | @echo Creating archive $(LIB_NAME).zip... 115 | @git archive --format zip --output ./$(LIB_NAME).zip master 116 | 117 | ## svn version 118 | # $(eval $@_TMP := $(shell mktemp -d tmp.XXXXXXXXXX)) 119 | # @echo Creating archive, this may take some time... 120 | # @echo Creating temporary export... 121 | # @svn export --force . $($@_TMP) 122 | # @echo Compressing... 123 | # @cd $($@_TMP) && tar -czf ../$(LIB_NAME).tar.gz . 124 | # @echo Compression complete. 125 | # @$(RM) -R $($@_TMP) 126 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GLV (Graphics Library of Views) 2 | ### GUI Building Toolkit 3 | 4 | 5 | 1. About 6 | ======================================== 7 | GLV (Graphics Library of Views) is a GUI building toolkit written in C++ for Linux, OSX, and Win32. GLV is specially designed for creating interfaces to real-time, multimedia applications using hardware accelerated graphics. GLV has no dependencies on other libraries other than OpenGL which is provided by all modern operating systems. Although windowing is technically not a part of GLV, it does provide an abstraction layer for creating bindings to a particular windowing system for creating an OpenGL context and getting mouse and keyboard input. A binding to GLUT is currently provided. 8 | 9 | 10 | 2. Compilation Instructions 11 | ======================================== 12 | 13 | The source code can either be built into a library or directly compiled from source into an application. In the following instructions, the base directory is where this README file is located. 14 | 15 | 2.1 Building a Library 16 | ---------------------------------------- 17 | 18 | ### Make (Linux, OS X) 19 | 20 | First, ensure that the correct build options are set. These can be set directly in Makefile.config or passed in as options to Make as OPTION=value. Once Make has been configured properly, run 21 | 22 | make 23 | 24 | to build the library. 25 | 26 | There are several other targets within Makefile. These are: 27 | 28 | make all - builds library and tests 29 | make clean - removes binaries from build folder 30 | make test - builds the unit tests and other empirical testing code 31 | make test/x.cpp - builds and runs source file 'x' 32 | make example/x.cpp - builds and runs source file 'x' 33 | 34 | Binaries are located in the directory ./build. 35 | 36 | 37 | ### Xcode (OS X) 38 | 39 | 1. Open osx/GLV.xcodeproj 40 | 2. Select 'ALL' as the active target and build. 41 | 42 | A static library and framework will be in project build folder. 43 | 44 | 45 | ### MS Visual Studio (Windows) 46 | 47 | There is no Visual Studio project included, but it is simple to set one up by creating your own by selecting "Console Application" and then choosing "empty project." You'll then need to add the GLV source files and OpenGL and GLEW (and if using Window, GLUT) dependencies. 48 | 49 | Obtain GLEW from 50 | http://glew.sourceforge.net/ 51 | 52 | To use the shared library version of GLEW, you need to copy the headers and libraries into their destination directories. On Windows this typically boils down to copying: 53 | 54 | bin/glew32.dll to %SystemRoot%/system32 55 | lib/glew32.lib to {VC Root}/Lib 56 | include/GL/glew.h to {VC Root}/Include/GL 57 | include/GL/wglew.h to {VC Root}/Include/GL 58 | 59 | 60 | Obtain GLUT from 61 | http://www.xmission.com/%7Enate/glut.html 62 | 63 | 1. Put the file "glut32.dll" in "C:\WINDOWS\system32" 64 | 2. Put the file "glut.h" into 65 | 66 | C:\Program Files\Microsoft Visual Studio 10.0\VC\Include\GL 67 | 68 | 3. Put the file "glut32.lib" into 69 | C:\Program Files\Microsoft Visual Studio 10.0\VC\lib 70 | 71 | Configure the linker using this 72 | 73 | Project -> Configuration Properties -> Linker -> Input 74 | add opengl32.lib; glut32.lib; glu32.lib; in "additional dependencies" 75 | 76 | 77 | 78 | 2.2 Compiling Direct From Source 79 | ---------------------------------------- 80 | GLV can easily be compiled directly from source into an existing project. 81 | 82 | Make sure to pass in the following flags to the compiler: 83 | 84 | -finline-functions (or -O3) 85 | -fpeel-loops 86 | 87 | 88 | 2.3 Dependencies 89 | ---------------------------------------- 90 | GLV requires only OpenGL, GLU, and GLEW (Linux only). There are no other dependencies, unless a window binding is used, such as GLUT. 91 | 92 | 93 | 94 | 3. File Organization 95 | ======================================== 96 | 97 | GLV/ GLV headers 98 | src/ GLV source 99 | 100 | example/ example source demonstrating various features of GLV 101 | test/ unit and visual testing source 102 | 103 | doc/ documentation of GLV source, design, etc. 104 | 105 | 106 | -------------------------------------------------------------------------------- /doc/VectorFont.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/VectorFont.graffle -------------------------------------------------------------------------------- /doc/lyx/fig/ButtonActive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/ButtonActive.png -------------------------------------------------------------------------------- /doc/lyx/fig/ButtonInactive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/ButtonInactive.png -------------------------------------------------------------------------------- /doc/lyx/fig/ButtonOff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/ButtonOff.png -------------------------------------------------------------------------------- /doc/lyx/fig/ButtonOn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/ButtonOn.png -------------------------------------------------------------------------------- /doc/lyx/fig/Buttons1x4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/Buttons1x4.png -------------------------------------------------------------------------------- /doc/lyx/fig/Buttons4x1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/Buttons4x1.png -------------------------------------------------------------------------------- /doc/lyx/fig/Buttons4x4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/Buttons4x4.png -------------------------------------------------------------------------------- /doc/lyx/fig/DensityPlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/DensityPlot.png -------------------------------------------------------------------------------- /doc/lyx/fig/Direction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/Direction.pdf -------------------------------------------------------------------------------- /doc/lyx/fig/FunctionPlotX.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/FunctionPlotX.png -------------------------------------------------------------------------------- /doc/lyx/fig/FunctionPlotXY.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/FunctionPlotXY.png -------------------------------------------------------------------------------- /doc/lyx/fig/FunctionPlotY.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/FunctionPlotY.png -------------------------------------------------------------------------------- /doc/lyx/fig/IconCheck.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/IconCheck.png -------------------------------------------------------------------------------- /doc/lyx/fig/IconFrame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/IconFrame.png -------------------------------------------------------------------------------- /doc/lyx/fig/IconMinus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/IconMinus.png -------------------------------------------------------------------------------- /doc/lyx/fig/IconPlus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/IconPlus.png -------------------------------------------------------------------------------- /doc/lyx/fig/IconRect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/IconRect.png -------------------------------------------------------------------------------- /doc/lyx/fig/IconTriangleD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/IconTriangleD.png -------------------------------------------------------------------------------- /doc/lyx/fig/IconTriangleL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/IconTriangleL.png -------------------------------------------------------------------------------- /doc/lyx/fig/IconTriangleR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/IconTriangleR.png -------------------------------------------------------------------------------- /doc/lyx/fig/IconTriangleU.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/IconTriangleU.png -------------------------------------------------------------------------------- /doc/lyx/fig/IconX.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/IconX.png -------------------------------------------------------------------------------- /doc/lyx/fig/Label.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/Label.png -------------------------------------------------------------------------------- /doc/lyx/fig/NumberBox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/NumberBox.png -------------------------------------------------------------------------------- /doc/lyx/fig/NumberDialer1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/NumberDialer1.png -------------------------------------------------------------------------------- /doc/lyx/fig/NumberDialer2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/NumberDialer2.png -------------------------------------------------------------------------------- /doc/lyx/fig/Place.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/Place.pdf -------------------------------------------------------------------------------- /doc/lyx/fig/Rect.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/Rect.pdf -------------------------------------------------------------------------------- /doc/lyx/fig/Screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/Screenshot1.png -------------------------------------------------------------------------------- /doc/lyx/fig/Screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/Screenshot2.png -------------------------------------------------------------------------------- /doc/lyx/fig/Slider1H.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/Slider1H.png -------------------------------------------------------------------------------- /doc/lyx/fig/Slider1HS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/Slider1HS.png -------------------------------------------------------------------------------- /doc/lyx/fig/Slider1V.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/Slider1V.png -------------------------------------------------------------------------------- /doc/lyx/fig/Slider1VS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/Slider1VS.png -------------------------------------------------------------------------------- /doc/lyx/fig/Slider2D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/Slider2D.png -------------------------------------------------------------------------------- /doc/lyx/fig/SliderGrid3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/SliderGrid3.png -------------------------------------------------------------------------------- /doc/lyx/fig/SliderGrid4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/SliderGrid4.png -------------------------------------------------------------------------------- /doc/lyx/fig/SliderRangeH.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/SliderRangeH.png -------------------------------------------------------------------------------- /doc/lyx/fig/SlidersH.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/SlidersH.png -------------------------------------------------------------------------------- /doc/lyx/fig/SlidersV.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/SlidersV.png -------------------------------------------------------------------------------- /doc/lyx/fig/SpacerAbs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/SpacerAbs.png -------------------------------------------------------------------------------- /doc/lyx/fig/SpacerBL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/SpacerBL.png -------------------------------------------------------------------------------- /doc/lyx/fig/SpacerCL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/SpacerCL.png -------------------------------------------------------------------------------- /doc/lyx/fig/SpacerFlow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/SpacerFlow.png -------------------------------------------------------------------------------- /doc/lyx/fig/TableComplex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/TableComplex.png -------------------------------------------------------------------------------- /doc/lyx/fig/TableRepeat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/TableRepeat.png -------------------------------------------------------------------------------- /doc/lyx/fig/View.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/View.pdf -------------------------------------------------------------------------------- /doc/lyx/fig/View3D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/View3D.png -------------------------------------------------------------------------------- /doc/lyx/fig/ViewAnchor.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/ViewAnchor.pdf -------------------------------------------------------------------------------- /doc/lyx/fig/ViewStretch.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/ViewStretch.pdf -------------------------------------------------------------------------------- /doc/lyx/fig/drawASCII.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/drawASCII.png -------------------------------------------------------------------------------- /doc/lyx/fig/fontMetrics.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/fontMetrics.pdf -------------------------------------------------------------------------------- /doc/lyx/fig/showcase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlloSphere-Research-Group/GLV/c058cff05a5b9ceb2cd327648ec5253d25cce90c/doc/lyx/fig/showcase.png -------------------------------------------------------------------------------- /examples/attachVariable.cpp: -------------------------------------------------------------------------------- 1 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 2 | See COPYRIGHT file for authors and license information */ 3 | 4 | /* 5 | Example: Attaching variables to numerical widgets 6 | 7 | A single variable is attached to two different sliders. This demonstrates how 8 | a slider can automatically update a program variable and how a slider is 9 | automatically synchronized to changes in its attached variable. When one slider 10 | is moved it sets the value of the variable which then causes the other slider 11 | to synchronize to the changed variable. If working correctly, moving one slider 12 | will move the other slider. 13 | */ 14 | 15 | #include "example.h" 16 | 17 | int main(int argc, char ** argv){ 18 | 19 | GLV glv; 20 | Slider sl1(Rect(10,10,200,20)), sl2(Rect(10,40,200,20)); 21 | 22 | float var = 0; 23 | 24 | sl1.attachVariable(var); 25 | sl2.attachVariable(var); 26 | 27 | glv << sl1 << sl2; 28 | 29 | Window win(220, 70, "", &glv); 30 | Application::run(); 31 | } 32 | -------------------------------------------------------------------------------- /examples/chladni.cpp: -------------------------------------------------------------------------------- 1 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 2 | See COPYRIGHT file for authors and license information */ 3 | /* 4 | Example: Chladni Pattern 5 | */ 6 | 7 | #include "example.h" 8 | using namespace glv; 9 | 10 | struct Canvas : public Plot{ 11 | Canvas(const Rect& r): Plot(r), plotDensity(HSV(0.3,0.5,1), 1./16){ 12 | int N = 256; 13 | data().resize(Data::FLOAT, 1, N,N); 14 | //plotDensity.interpolate(true).drawUnderGrid(true); 15 | add(plotDensity); 16 | equalizeAxes(true); 17 | showAxis(false); 18 | showGrid(false); 19 | disable(DrawBorder); 20 | } 21 | 22 | void onAnimate(double dt){ 23 | 24 | plotDensity.plotRegion(interval(0), interval(1)); 25 | 26 | Indexer i(data().size(1), data().size(2)); 27 | 28 | while(i()){ 29 | int ix = i[0]; 30 | int iy = i[1]; 31 | 32 | double px = interval(0).fromUnit(i.fracClosed(0)) * M_PI; 33 | double py = interval(1).fromUnit(i.fracClosed(1)) * M_PI; 34 | 35 | // plate vibration frequencies 36 | double f1 = 7; 37 | double f2 = 17; 38 | 39 | double val = (cos(f1*px) * cos(f2*py) - cos(f2*px) * cos(f1*py))/2; 40 | 41 | data().elem(0, ix, iy) = val; 42 | } 43 | 44 | } 45 | 46 | PlotDensity plotDensity; 47 | }; 48 | 49 | 50 | int main(){ 51 | GLV top; 52 | Canvas v1(Rect(0)); 53 | Window win(600,600, "Chladni Pattern", &top); 54 | 55 | top.colors().set(StyleColor::WhiteOnBlack); 56 | v1.stretch(1,1); 57 | top << v1; 58 | 59 | top.addHandler(Event::KeyDown, *new FullScreenToggler(win)); 60 | 61 | Application::run(); 62 | return 0; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /examples/dataPlot.cpp: -------------------------------------------------------------------------------- 1 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 2 | See COPYRIGHT file for authors and license information */ 3 | /* 4 | Example: 5 | */ 6 | 7 | #include "example.h" 8 | 9 | namespace glv{ 10 | 11 | struct PlotVector : public Plottable{ 12 | 13 | PlotVector(): Plottable(draw::Triangles){} 14 | 15 | void onMap(GraphicsData& b, const Data& d, const Indexer& i){ 16 | double dx = 2./d.size(1); 17 | double dy = 2./d.size(2); 18 | while(i()){ 19 | double x = i.frac(0)*2 - 1 + dx/2; 20 | double y = i.frac(1)*2 - 1 + dy/2; 21 | double vx=d.at(0,i[0],i[1],i[2])*dx*2; 22 | double vy=d.at(1,i[0],i[1],i[2])*dy*2; 23 | 24 | double r = 0.2/hypot(vx, vy); 25 | double Nx = vy*r*dx; 26 | double Ny =-vx*r*dy; 27 | 28 | // b.addVertex2( 29 | // x, y, 30 | // x + d.at(0,i[0],i[1],i[2])*dx, 31 | // y + d.at(1,i[0],i[1],i[2])*dy 32 | // ); 33 | b.addVertex2( 34 | x+Nx, y+Ny, 35 | x-Nx, y-Ny, 36 | x + vx, 37 | y + vy 38 | ); 39 | b.addColor( 40 | Color(0,0), 41 | Color(0,0), 42 | Color(0) 43 | ); 44 | } 45 | } 46 | }; 47 | 48 | 49 | struct MyGLV : GLV { 50 | 51 | MyGLV(): phase(0){ 52 | data.resize(Data::DOUBLE, 2,16,16); 53 | } 54 | 55 | void onAnimate(double dt){ 56 | phase += 0.013; 57 | Data& d = data; 58 | 59 | Indexer i(d.size(1), d.size(2)); 60 | 61 | while(i()){ 62 | float x = i.frac(0); 63 | float y = i.frac(1); 64 | x = (cos(x*7 + phase) + cos(x*-2 + phase*1.01))/2; 65 | y = (sin(y*5 + phase) + sin(y*-3 + phase*1.01))/2; 66 | d.assign(x, 0,i[0],i[1]); 67 | d.assign(y, 1,i[0],i[1]); 68 | } 69 | } 70 | 71 | double phase; 72 | Data data; 73 | }; 74 | } 75 | 76 | int main(){ 77 | 78 | // Create the Views 79 | MyGLV top; 80 | Plot v1(Rect(000,0, 400,400), *new PlotDensity); 81 | Plot v2(Rect(400,0, 400,400), *new PlotVector); 82 | Plot v3(Rect(800,0, 400,400), (new PlotFunction2D)->prim(draw::Points).stroke(2)); 83 | 84 | v1.data() = top.data; 85 | v2.data() = top.data; 86 | v3.data() = top.data; 87 | 88 | top << v1 << v2 << v3; 89 | 90 | Window win(80,80, "Data Plots", &top); 91 | win.fit(); 92 | Application::run(); 93 | return 0; 94 | } 95 | 96 | -------------------------------------------------------------------------------- /examples/densityPlot.cpp: -------------------------------------------------------------------------------- 1 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 2 | See COPYRIGHT file for authors and license information */ 3 | 4 | /* 5 | Example: Density Plot 6 | 7 | This demonstrates how to use multiple density plots to visualize a 3D array 8 | of color values in various ways. 9 | */ 10 | 11 | #include "example.h" 12 | 13 | int main(){ 14 | 15 | const int N = 8; 16 | const int N3 = N*N*N; 17 | float w = 100; 18 | 19 | // Initialize raw color data 20 | Color bulk[N3]; 21 | for(int i=0; i?@\n" 43 | "ABCDEFGHIJKLMNOP\n" 44 | "QRSTUVWXYZ[\\]^_`\n" 45 | "abcdefghijklmnop\n" 46 | "qrstuvwxyz{|}~", 47 | 10, y 48 | ); 49 | 50 | // tabbing is supported 51 | text("\ 52 | zero one two three\n\ 53 | zero 0 0 0 0\n\ 54 | one 0 1 2 3\n\ 55 | two 0 2 4 6\n\ 56 | three 0 3 6 9", 57 | 200, y 58 | ); 59 | 60 | y += 110; 61 | text("20 pixels", 10, y, 20); 62 | 63 | y += 30; 64 | text("12 pixels", 10, y, 12); 65 | 66 | y += 20; 67 | lineWidth(2); 68 | text("bold face", 10, y); 69 | 70 | lineWidth(1); 71 | color(HSV(0./3)); 72 | text("red", 200, y); 73 | 74 | y += 12; 75 | color(HSV(1./3)); 76 | text("green", 200, y); 77 | 78 | y += 12; 79 | color(HSV(2./3)); 80 | text("blue", 200, y); 81 | } 82 | }; 83 | 84 | int main(){ 85 | MyGLV glv; 86 | Window win(600,300, "Example: draw::text", &glv); 87 | Application::run(); 88 | } 89 | 90 | -------------------------------------------------------------------------------- /examples/example.h: -------------------------------------------------------------------------------- 1 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 2 | See COPYRIGHT file for authors and license information */ 3 | 4 | #include 5 | #include "glv.h" 6 | #include "glv_binding.h" 7 | #include "glv_util.h" 8 | 9 | using namespace glv; 10 | -------------------------------------------------------------------------------- /examples/graphicsData.cpp: -------------------------------------------------------------------------------- 1 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 2 | See COPYRIGHT file for authors and license information */ 3 | 4 | /* 5 | Example: GraphicsData 6 | 7 | This demonstrates how to use GraphicsData to draw a heptagram shape. 8 | */ 9 | 10 | #include "example.h" 11 | 12 | struct Scene : View3D{ 13 | 14 | virtual void onDraw3D(GLV& g){ 15 | 16 | GraphicsData& gd = g.graphicsData(); 17 | 18 | draw::lineWidth(2); 19 | 20 | // generate rainbow heptagon 21 | for(int i=0; i<7; ++i){ 22 | float p = float(i)/7; 23 | gd.addColor(HSV(p)); 24 | gd.addVertex(cos(p*2*M_PI), sin(p*2*M_PI), -3); 25 | } 26 | 27 | // draw heptagon 28 | draw::paint(draw::LineLoop, gd); 29 | 30 | // generate indices 0, 3, 6, 2, 5, 1, 4 31 | for(int i=0; i<7; ++i){ 32 | gd.addIndex(i*3 % 7); 33 | } 34 | 35 | // draw star heptagon 36 | draw::paint(draw::LineLoop, gd); 37 | } 38 | }; 39 | 40 | 41 | int main (int argc, char ** argv){ 42 | 43 | GLV top; 44 | Scene scene; 45 | 46 | scene.stretch(1,1); 47 | 48 | top << scene; 49 | 50 | Window win(600, 600, "Example: GraphicsData"); 51 | win.setGLV(top); 52 | Application::run(); 53 | } 54 | 55 | -------------------------------------------------------------------------------- /examples/grid.cpp: -------------------------------------------------------------------------------- 1 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 2 | See COPYRIGHT file for authors and license information */ 3 | /* 4 | Example: 5 | */ 6 | 7 | #include "example.h" 8 | 9 | int main(){ 10 | 11 | GLV top; 12 | Window win(800,800, "Grid", &top); 13 | 14 | top.colors().set(StyleColor::WhiteOnBlack); 15 | //top.colors().set(StyleColor::SmokeyGray); 16 | 17 | Grid v1(Rect(0,0)); 18 | 19 | v1.range(1); // set plot region 20 | v1.major(1); // set major tick mark placement 21 | v1.minor(2); // number of divisions per major ticks 22 | v1.equalizeAxes(true); 23 | 24 | v1.stretch(1,1); 25 | //v1.disable(CropSelf); 26 | top << v1; 27 | 28 | top.addHandler(Event::KeyDown, *new FullScreenToggler(win)); 29 | 30 | Application::run(); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /examples/icons.cpp: -------------------------------------------------------------------------------- 1 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 2 | See COPYRIGHT file for authors and license information */ 3 | 4 | /* 5 | Example: Icons 6 | 7 | This shows some of the icons provided by GLV that can be used to decorate 8 | widgets. 9 | */ 10 | 11 | #include "example.h" 12 | 13 | struct MyGLV : public GLV{ 14 | 15 | float pad, dim; 16 | 17 | MyGLV(): pad(8), dim(24) 18 | {} 19 | 20 | void onDraw(GLV& g){ 21 | using namespace glv; 22 | 23 | float x = pad; 24 | float y = pad; 25 | 26 | draw::color(0); 27 | draw::lineWidth(2); 28 | 29 | // The function signatures for the icons take the left, top, right, and 30 | // bottom positions of the rectangular containing region of the icon. 31 | 32 | draw::triangleL(x,y, x+dim, y+dim); 33 | 34 | y += dim+pad; 35 | draw::triangleR(x,y, x+dim, y+dim); 36 | 37 | y += dim+pad; 38 | draw::triangleU(x,y, x+dim, y+dim); 39 | 40 | y += dim+pad; 41 | draw::triangleD(x,y, x+dim, y+dim); 42 | 43 | 44 | y = pad; 45 | x += dim+pad; 46 | // Rectangular outline 47 | draw::frame(x,y, x+dim, y+dim); 48 | 49 | y += dim+pad; 50 | draw::rectangle(x,y, x+dim, y+dim); 51 | 52 | y += dim+pad; 53 | // Frame with truncated corners 54 | draw::frameTrunc<4,4,4,4>(x,y, x+dim, y+dim); 55 | 56 | y += dim+pad; 57 | // Rectangle with truncated corners 58 | draw::rectTrunc<4,4,4,4>(x,y, x+dim, y+dim); 59 | 60 | 61 | y = pad; 62 | x += dim+pad; 63 | // Circle with a specified number of edges 64 | draw::circle<16>(x,y, x+dim, y+dim); 65 | 66 | y += dim+pad; 67 | // Disc with a specified number of edges 68 | draw::disc<16>(x,y, x+dim, y+dim); 69 | 70 | y += dim+pad; 71 | // Polygon with a specified number of vertices, winding, and angle 72 | draw::polygon<5,2,18>(x,y, x+dim, y+dim); 73 | 74 | y += dim+pad; 75 | // Polygon with a specified number of vertices, winding, and angle 76 | draw::polygon<4,1,0>(x,y, x+dim, y+dim); 77 | 78 | 79 | y = pad; 80 | x += dim+pad; 81 | draw::check(x,y, x+dim, y+dim); 82 | 83 | y += dim+pad; 84 | draw::x(x,y, x+dim, y+dim); 85 | 86 | y += dim+pad; 87 | draw::minus(x,y, x+dim, y+dim); 88 | 89 | y += dim+pad; 90 | draw::plus(x,y, x+dim, y+dim); 91 | 92 | 93 | // Crosshatches: horizontal and vertical lines 94 | y = pad; 95 | x += dim+pad; 96 | draw::crosshatch<2,2>(x,y, x+dim, y+dim); 97 | 98 | y += dim+pad; 99 | draw::crosshatch<3,3>(x,y, x+dim, y+dim); 100 | 101 | y += dim+pad; 102 | draw::crosshatch<1,4>(x,y, x+dim, y+dim); 103 | 104 | y += dim+pad; 105 | draw::crosshatch<4,0>(x,y, x+dim, y+dim); 106 | 107 | 108 | // Rose curves with specified number of edges, harmonic numbers, and 109 | // start angles. 110 | y = pad; 111 | x += dim+pad; 112 | draw::rose<36, -1, 2, 0>(x,y, x+dim, y+dim); 113 | 114 | y += dim+pad; 115 | draw::rose<36, 1, 2, 0>(x,y, x+dim, y+dim); 116 | 117 | // Wheel spokes 118 | y += dim+pad; 119 | draw::spokes<3, 0>(x,y, x+dim, y+dim); 120 | 121 | y += dim+pad; 122 | draw::spokes<6, 0>(x,y, x+dim, y+dim); 123 | 124 | 125 | y = pad; 126 | x += dim+pad; 127 | draw::fileLoad(x,y, x+dim, y+dim); 128 | 129 | y += dim+pad; 130 | draw::fileSave(x,y, x+dim, y+dim); 131 | 132 | y += dim+pad; 133 | draw::magnifier(x,y, x+dim, y+dim); 134 | 135 | y += dim+pad; 136 | draw::question(x,y, x+dim, y+dim); 137 | 138 | 139 | y = pad; 140 | x += dim+pad; 141 | // Symbol of parent-child relationship 142 | draw::viewChild(x,y, x+dim, y+dim); 143 | 144 | y += dim+pad; 145 | // Symbol of sibling relationship 146 | draw::viewSibling(x,y, x+dim, y+dim); 147 | 148 | y += dim+pad; 149 | 150 | 151 | y += dim+pad; 152 | 153 | } 154 | }; 155 | 156 | int main(){ 157 | MyGLV myGLV; 158 | Window win( 159 | myGLV.pad*9 + myGLV.dim*8, 160 | myGLV.pad*5 + myGLV.dim*4, 161 | "GLV Example: Icons", &myGLV 162 | ); 163 | Application::run(); 164 | } 165 | 166 | -------------------------------------------------------------------------------- /examples/mandelbrot.cpp: -------------------------------------------------------------------------------- 1 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 2 | See COPYRIGHT file for authors and license information */ 3 | /* 4 | Example: Mandelbrot set 5 | */ 6 | 7 | #include 8 | #include "example.h" 9 | using namespace glv; 10 | 11 | struct Canvas : public Plot{ 12 | Canvas(const Rect& r): Plot(r), plotDensity(HSV(0.3,0.5,1), 1./16){ 13 | int N = 384; 14 | data().resize(Data::FLOAT, 1, N,N); 15 | plotDensity.interpolate(true).drawUnderGrid(true); 16 | add(plotDensity); 17 | equalizeAxes(true); 18 | showGrid(false); 19 | showAxis(false); 20 | disable(DrawBorder); 21 | } 22 | 23 | void onAnimate(double dt){ 24 | 25 | // major(interval(1).diameter()/4); 26 | // minor(1); 27 | 28 | //printf("%g\n", interval(1).diameter()); 29 | 30 | // set plot region to current grid region 31 | plotDensity.plotRegion(interval(0), interval(1)); 32 | 33 | Indexer i(data().size(1), data().size(2)); 34 | 35 | while(i()){ 36 | int ix = i[0]; 37 | int iy = i[1]; 38 | 39 | double posx = interval(0).fromUnit(i.fracClosed(0)); 40 | double posy = interval(1).fromUnit(i.fracClosed(1)); 41 | 42 | std::complex c(posx, posy); 43 | std::complex z(c); 44 | 45 | for(int i=0; i<40; ++i){ 46 | z = z*z + c; 47 | } 48 | 49 | double val = z.real() * z.real() + z.imag() * z.imag(); 50 | 51 | //val = (val > 0) ? 1./val : 0; 52 | val = (val > 0) ? log(val)/4. : 1; 53 | //val = (val > 0) ? val/4. : 1; 54 | 55 | val = glv::clip(val, 1., -1.); 56 | data().elem(0, ix, iy) = val; 57 | } 58 | 59 | } 60 | 61 | PlotDensity plotDensity; 62 | }; 63 | 64 | 65 | int main(){ 66 | GLV top; 67 | Canvas v1(Rect(0)); 68 | Window win(800,800, "Mandelbrot Set", &top); 69 | 70 | top.colors().set(StyleColor::WhiteOnBlack); 71 | v1.stretch(1,1); 72 | top << v1; 73 | 74 | top.addHandler(Event::KeyDown, *new FullScreenToggler(win)); 75 | 76 | Application::run(); 77 | return 0; 78 | } 79 | 80 | -------------------------------------------------------------------------------- /examples/notification.cpp: -------------------------------------------------------------------------------- 1 | /* Graphics Library of Views (GLV) - GUI Building Toolkit 2 | See COPYRIGHT file for authors and license information */ 3 | 4 | /* 5 | Example: Using a Notification to set a Label 6 | 7 | A Notification is used to set a label to a slider's value. 8 | 9 | */ 10 | 11 | #include "example.h" 12 | 13 | void ntSetLabel(const Notification& n){ 14 | Label& l = *n.receiver