1 // Copyright (C) 2012-2019 The VPaint Developers. 2 // See the COPYRIGHT file at the top-level directory of this distribution 3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 #ifndef SCENE_OBJECT_EXAMPLE_H 18 #define SCENE_OBJECT_EXAMPLE_H 19 20 #include "OpenGL.h" 21 #include "SceneObject.h" 22 #include <QSet> 23 24 class SceneObject_Example : public SceneObject 25 { 26 public: SceneObject_Example()27 SceneObject_Example() : isHighlighted_(false) {} 28 draw(Time time,ViewSettings & viewSettings)29 void draw(Time time, ViewSettings & viewSettings) 30 { 31 if(selectedFrames_.contains(time.frame)) 32 { 33 if(isHighlighted_ && time.frame == highlightedFrame_) 34 glColor3d(1,0.5,0.5); 35 else 36 glColor3d(1,0,0); 37 } 38 else 39 { 40 if(isHighlighted_ && time.frame == highlightedFrame_) 41 glColor3d(0.5,0.5,1); 42 else 43 glColor3d(0,0,1); 44 } 45 46 rawDraw(time); 47 } drawPick(Time time,ViewSettings &)48 void drawPick(Time time, ViewSettings & /*viewSettings*/) 49 { 50 Picking::glColor(42); 51 rawDraw(time); 52 } 53 rawDraw(Time time,ViewSettings &)54 void rawDraw(Time time, ViewSettings & /*viewSettings*/) 55 { 56 double t = time.time; 57 58 glPointSize(10); 59 glLineWidth(2); 60 glBegin(GL_LINE_STRIP); 61 glVertex2d(100+100*t, 100); 62 glVertex2d(200, 250); 63 glEnd(); 64 glBegin(GL_POINTS); 65 glVertex2d(100+100*t, 100); 66 glVertex2d(200, 250); 67 glEnd(); 68 } 69 setHoveredObject(Time time,int)70 void setHoveredObject(Time time, int /*id*/) 71 { 72 if(!isHighlighted_) 73 { 74 isHighlighted_=true; 75 highlightedFrame_ = time.frame; 76 emit changed(); 77 } 78 } setNoHoveredObject()79 void setNoHoveredObject() 80 { 81 if(isHighlighted_) 82 { 83 isHighlighted_=false; 84 emit changed(); 85 } 86 } select(Time time,int id)87 void select(Time time, int id) 88 { 89 selectedFrames_.insert(time.frame); 90 emit changed(); 91 } deselect(Time time,int id)92 void deselect(Time time, int id) 93 { 94 deselectAll(time); 95 } toggle(Time time,int id)96 void toggle(Time time, int id) 97 { 98 if(selectedFrames_.contains(time.frame)) 99 deselect(time, id); 100 else 101 select(time, id); 102 } deselectAll(Time time)103 void deselectAll(Time time) 104 { 105 selectedFrames_.remove(time.frame); 106 emit changed(); 107 } deselectAll()108 void deselectAll() 109 { 110 selectedFrames_.clear(); 111 emit changed(); 112 } 113 114 private: 115 bool isHighlighted_; 116 int highlightedFrame_; 117 118 QSet<int> selectedFrames_; 119 120 }; 121 122 #endif 123