andrewm@0: /* andrewm@0: TouchKeys: multi-touch musical keyboard control software andrewm@0: Copyright (c) 2013 Andrew McPherson andrewm@0: andrewm@0: This program is free software: you can redistribute it and/or modify andrewm@0: it under the terms of the GNU General Public License as published by andrewm@0: the Free Software Foundation, either version 3 of the License, or andrewm@0: (at your option) any later version. andrewm@0: andrewm@0: This program is distributed in the hope that it will be useful, andrewm@0: but WITHOUT ANY WARRANTY; without even the implied warranty of andrewm@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrewm@0: GNU General Public License for more details. andrewm@0: andrewm@0: You should have received a copy of the GNU General Public License andrewm@0: along with this program. If not, see . andrewm@0: andrewm@0: ===================================================================== andrewm@0: andrewm@0: OpenGLJuceCanvas.h: Juce Component subclass which connects to the andrewm@0: OpenGLDisplayBase class. Provides a generic interface between Juce and andrewm@0: the specific OpenGL renderer. andrewm@0: */ andrewm@0: andrewm@0: #ifndef __TouchKeys__OpenGLJuceCanvas__ andrewm@0: #define __TouchKeys__OpenGLJuceCanvas__ andrewm@0: andrewm@0: #include "../JuceLibraryCode/JuceHeader.h" andrewm@0: #include "OpenGLDisplayBase.h" andrewm@0: andrewm@0: #if JUCE_OPENGL andrewm@0: andrewm@0: //============================================================================== andrewm@0: class OpenGLJuceCanvas : public Component, andrewm@0: public OpenGLRenderer andrewm@0: { andrewm@0: public: andrewm@0: // *** Constructor / Destructor *** andrewm@0: OpenGLJuceCanvas(OpenGLDisplayBase& display) : display_(display) { andrewm@0: openGLContext_.setRenderer (this); andrewm@27: openGLContext_.setComponentPaintingEnabled (false); andrewm@29: // Funny OpenGL bugs in Linux version that results in improper drawing when in background andrewm@29: // For other OSes, save the cycles of continuous repainting. andrewm@29: if(SystemStats::getOperatingSystemType() == SystemStats::Linux) andrewm@29: openGLContext_.setContinuousRepainting (true); andrewm@29: else andrewm@29: openGLContext_.setContinuousRepainting (false); andrewm@0: openGLContext_.attachTo (*this); andrewm@27: display_.setCanvas(this); andrewm@0: } andrewm@0: ~OpenGLJuceCanvas() { andrewm@0: openGLContext_.detach(); andrewm@0: } andrewm@0: andrewm@0: // *** OpenGL Context Methods *** andrewm@0: void newOpenGLContextCreated() {} andrewm@0: void openGLContextClosing() {} andrewm@0: andrewm@27: void mouseDown (const MouseEvent& e) { andrewm@0: if(e.mods.isLeftButtonDown()) andrewm@0: display_.mouseDown(e.x, e.y); andrewm@0: else if(e.mods.isRightButtonDown()) andrewm@0: display_.rightMouseDown(e.x, e.y); andrewm@0: } andrewm@0: andrewm@27: void mouseDrag (const MouseEvent& e) { andrewm@0: if(e.mods.isLeftButtonDown()) andrewm@0: display_.mouseDragged(e.x, e.y); andrewm@0: else if(e.mods.isRightButtonDown()) andrewm@0: display_.rightMouseDragged(e.x, e.y); andrewm@0: } andrewm@0: andrewm@27: void mouseUp (const MouseEvent& e) { andrewm@0: if(e.mods.isLeftButtonDown()) andrewm@0: display_.mouseUp(e.x, e.y); andrewm@0: else if(e.mods.isRightButtonDown()) andrewm@0: display_.rightMouseUp(e.x, e.y); andrewm@0: } andrewm@0: andrewm@0: andrewm@0: void resized() { andrewm@0: display_.setDisplaySize(getWidth(), getHeight()); andrewm@0: } andrewm@0: andrewm@0: void paint (Graphics&) {} andrewm@0: andrewm@27: void renderOpenGL() { andrewm@0: display_.render(); andrewm@0: } andrewm@0: andrewm@27: // Method to tell the OpenGLContext to repaint andrewm@27: void triggerRepaint() { andrewm@27: openGLContext_.triggerRepaint(); andrewm@27: } andrewm@27: andrewm@0: private: andrewm@0: OpenGLDisplayBase& display_; // Reference to the TouchKeys-specific OpenGL Display andrewm@0: OpenGLContext openGLContext_; andrewm@0: }; andrewm@0: andrewm@0: #endif /* JUCE_OPENGL */ andrewm@0: andrewm@0: #endif /* defined(__TouchKeys__OpenGLJuceCanvas__) */