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@27
|
41 openGLContext_.setComponentPaintingEnabled (false);
|
andrewm@29
|
42 // Funny OpenGL bugs in Linux version that results in improper drawing when in background
|
andrewm@29
|
43 // For other OSes, save the cycles of continuous repainting.
|
andrewm@29
|
44 if(SystemStats::getOperatingSystemType() == SystemStats::Linux)
|
andrewm@29
|
45 openGLContext_.setContinuousRepainting (true);
|
andrewm@29
|
46 else
|
andrewm@29
|
47 openGLContext_.setContinuousRepainting (false);
|
andrewm@0
|
48 openGLContext_.attachTo (*this);
|
andrewm@27
|
49 display_.setCanvas(this);
|
andrewm@0
|
50 }
|
andrewm@0
|
51 ~OpenGLJuceCanvas() {
|
andrewm@0
|
52 openGLContext_.detach();
|
andrewm@0
|
53 }
|
andrewm@0
|
54
|
andrewm@0
|
55 // *** OpenGL Context Methods ***
|
andrewm@0
|
56 void newOpenGLContextCreated() {}
|
andrewm@0
|
57 void openGLContextClosing() {}
|
andrewm@0
|
58
|
andrewm@27
|
59 void mouseDown (const MouseEvent& e) {
|
andrewm@0
|
60 if(e.mods.isLeftButtonDown())
|
andrewm@0
|
61 display_.mouseDown(e.x, e.y);
|
andrewm@0
|
62 else if(e.mods.isRightButtonDown())
|
andrewm@0
|
63 display_.rightMouseDown(e.x, e.y);
|
andrewm@0
|
64 }
|
andrewm@0
|
65
|
andrewm@27
|
66 void mouseDrag (const MouseEvent& e) {
|
andrewm@0
|
67 if(e.mods.isLeftButtonDown())
|
andrewm@0
|
68 display_.mouseDragged(e.x, e.y);
|
andrewm@0
|
69 else if(e.mods.isRightButtonDown())
|
andrewm@0
|
70 display_.rightMouseDragged(e.x, e.y);
|
andrewm@0
|
71 }
|
andrewm@0
|
72
|
andrewm@27
|
73 void mouseUp (const MouseEvent& e) {
|
andrewm@0
|
74 if(e.mods.isLeftButtonDown())
|
andrewm@0
|
75 display_.mouseUp(e.x, e.y);
|
andrewm@0
|
76 else if(e.mods.isRightButtonDown())
|
andrewm@0
|
77 display_.rightMouseUp(e.x, e.y);
|
andrewm@0
|
78 }
|
andrewm@0
|
79
|
andrewm@0
|
80
|
andrewm@0
|
81 void resized() {
|
andrewm@0
|
82 display_.setDisplaySize(getWidth(), getHeight());
|
andrewm@0
|
83 }
|
andrewm@0
|
84
|
andrewm@0
|
85 void paint (Graphics&) {}
|
andrewm@0
|
86
|
andrewm@27
|
87 void renderOpenGL() {
|
andrewm@0
|
88 display_.render();
|
andrewm@0
|
89 }
|
andrewm@0
|
90
|
andrewm@27
|
91 // Method to tell the OpenGLContext to repaint
|
andrewm@27
|
92 void triggerRepaint() {
|
andrewm@27
|
93 openGLContext_.triggerRepaint();
|
andrewm@27
|
94 }
|
andrewm@27
|
95
|
andrewm@0
|
96 private:
|
andrewm@0
|
97 OpenGLDisplayBase& display_; // Reference to the TouchKeys-specific OpenGL Display
|
andrewm@0
|
98 OpenGLContext openGLContext_;
|
andrewm@0
|
99 };
|
andrewm@0
|
100
|
andrewm@0
|
101 #endif /* JUCE_OPENGL */
|
andrewm@0
|
102
|
andrewm@0
|
103 #endif /* defined(__TouchKeys__OpenGLJuceCanvas__) */
|