annotate Source/Display/OpenGLJuceCanvas.h @ 16:61e3c9df4674

Fix bug where TouchKeys standalone mode turns off when mode is changed.
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Mon, 25 Nov 2013 21:36:02 +0000
parents 3580ffe87dc8
children eef567a60146
rev   line source
andrewm@0 1 /*
andrewm@0 2 TouchKeys: multi-touch musical keyboard control software
andrewm@0 3 Copyright (c) 2013 Andrew McPherson
andrewm@0 4
andrewm@0 5 This program is free software: you can redistribute it and/or modify
andrewm@0 6 it under the terms of the GNU General Public License as published by
andrewm@0 7 the Free Software Foundation, either version 3 of the License, or
andrewm@0 8 (at your option) any later version.
andrewm@0 9
andrewm@0 10 This program is distributed in the hope that it will be useful,
andrewm@0 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
andrewm@0 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
andrewm@0 13 GNU General Public License for more details.
andrewm@0 14
andrewm@0 15 You should have received a copy of the GNU General Public License
andrewm@0 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
andrewm@0 17
andrewm@0 18 =====================================================================
andrewm@0 19
andrewm@0 20 OpenGLJuceCanvas.h: Juce Component subclass which connects to the
andrewm@0 21 OpenGLDisplayBase class. Provides a generic interface between Juce and
andrewm@0 22 the specific OpenGL renderer.
andrewm@0 23 */
andrewm@0 24
andrewm@0 25 #ifndef __TouchKeys__OpenGLJuceCanvas__
andrewm@0 26 #define __TouchKeys__OpenGLJuceCanvas__
andrewm@0 27
andrewm@0 28 #include "../JuceLibraryCode/JuceHeader.h"
andrewm@0 29 #include "OpenGLDisplayBase.h"
andrewm@0 30
andrewm@0 31 #if JUCE_OPENGL
andrewm@0 32
andrewm@0 33 //==============================================================================
andrewm@0 34 class OpenGLJuceCanvas : public Component,
andrewm@0 35 public OpenGLRenderer
andrewm@0 36 {
andrewm@0 37 public:
andrewm@0 38 // *** Constructor / Destructor ***
andrewm@0 39 OpenGLJuceCanvas(OpenGLDisplayBase& display) : display_(display) {
andrewm@0 40 openGLContext_.setRenderer (this);
andrewm@0 41 openGLContext_.setComponentPaintingEnabled (true);
andrewm@0 42 openGLContext_.setContinuousRepainting (true);
andrewm@0 43 openGLContext_.attachTo (*this);
andrewm@0 44 }
andrewm@0 45 ~OpenGLJuceCanvas() {
andrewm@0 46 openGLContext_.detach();
andrewm@0 47 }
andrewm@0 48
andrewm@0 49 // *** OpenGL Context Methods ***
andrewm@0 50 void newOpenGLContextCreated() {}
andrewm@0 51 void openGLContextClosing() {}
andrewm@0 52
andrewm@0 53 void mouseDown (const MouseEvent& e)
andrewm@0 54 {
andrewm@0 55 if(e.mods.isLeftButtonDown())
andrewm@0 56 display_.mouseDown(e.x, e.y);
andrewm@0 57 else if(e.mods.isRightButtonDown())
andrewm@0 58 display_.rightMouseDown(e.x, e.y);
andrewm@0 59 }
andrewm@0 60
andrewm@0 61 void mouseDrag (const MouseEvent& e)
andrewm@0 62 {
andrewm@0 63 if(e.mods.isLeftButtonDown())
andrewm@0 64 display_.mouseDragged(e.x, e.y);
andrewm@0 65 else if(e.mods.isRightButtonDown())
andrewm@0 66 display_.rightMouseDragged(e.x, e.y);
andrewm@0 67 }
andrewm@0 68
andrewm@0 69 void mouseUp (const MouseEvent& e)
andrewm@0 70 {
andrewm@0 71 if(e.mods.isLeftButtonDown())
andrewm@0 72 display_.mouseUp(e.x, e.y);
andrewm@0 73 else if(e.mods.isRightButtonDown())
andrewm@0 74 display_.rightMouseUp(e.x, e.y);
andrewm@0 75 }
andrewm@0 76
andrewm@0 77
andrewm@0 78 void resized() {
andrewm@0 79 display_.setDisplaySize(getWidth(), getHeight());
andrewm@0 80 }
andrewm@0 81
andrewm@0 82 void paint (Graphics&) {}
andrewm@0 83
andrewm@0 84 void renderOpenGL()
andrewm@0 85 {
andrewm@0 86 display_.render();
andrewm@0 87 }
andrewm@0 88
andrewm@0 89 private:
andrewm@0 90 OpenGLDisplayBase& display_; // Reference to the TouchKeys-specific OpenGL Display
andrewm@0 91 OpenGLContext openGLContext_;
andrewm@0 92 };
andrewm@0 93
andrewm@0 94 #endif /* JUCE_OPENGL */
andrewm@0 95
andrewm@0 96 #endif /* defined(__TouchKeys__OpenGLJuceCanvas__) */