root / argos / src / UI Panels / EditorActions.cpp @ 63

View | Annotate | Download (3.4 KB)

1
/***********************************************************************
2
 
3
 Copyright (c) 2009, 2010 Dimitri Diakopoulos, http://argos.dimitridiakopoulos.com/
4
5
        Redistribution and use in source and binary forms, with or without modification, 
6
        are permitted provided that the following conditions are met:
7
8
        1. Redistributions of source code must retain the above copyright notice, 
9
        this list of conditions and the following disclaimer.
10
11
        2. Redistributions in binary form must reproduce the above copyright notice, 
12
        this list of conditions and the following disclaimer in the documentation and/or 
13
        other materials provided with the distribution.
14
15
        3. The name of the author may not be used to endorse or promote products derived 
16
        from this software without specific prior written permission.
17
18
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
19
        ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
20
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
21
        ARE DISCLAIMED. IN NOEVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 
22
        INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
23
        (INCLUDING, BUT NOT LIMITED TO,PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
24
        LOSS OF USE, DATA, ORPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
25
        AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
27
        OF THE USE OF THIS SOFTWARE,EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
28
29
*************************************************************************/ 
30
31
#include "EditorActions.h"
32
#include "EditorCore.h"
33
34
resizeControl::resizeControl(EditorPanel *ed) : ofxArgosUI_Control("resizeControl") {
35
        controlType = "resizeControl";
36
        editor = ed;
37
        dragging = false; 
38
}
39
40
void resizeControl::setControl() {
41
        if (focus.focused != NULL){
42
                setPos(focus.focused->x + focus.focused->width + 5, focus.focused->y + focus.focused->height + 5); 
43
                setSize(10,10);
44
        }
45
}
46
47
void resizeControl::onRollOver(int x, int y) {
48
        glutSetCursor(GLUT_CURSOR_BOTTOM_RIGHT_CORNER);         
49
}
50
51
void resizeControl::onRollOut() {
52
        glutSetCursor(GLUT_CURSOR_LEFT_ARROW);
53
}
54
55
void resizeControl::onDragOutside(int x, int y, int button) {
56
        
57
        glutSetCursor(GLUT_CURSOR_BOTTOM_RIGHT_CORNER); 
58
        dragging = true; 
59
60
        dragX = (floor(((float) x / 20)) * 20);
61
        dragY = (floor(((float) y / 20)) * 20);
62
63
}
64
65
void resizeControl::onRelease(int x, int y, int button) {
66
        glutSetCursor(GLUT_CURSOR_LEFT_ARROW);
67
68
        dragging = false; 
69
70
}
71
72
void resizeControl::onReleaseOutside(int x, int y, int button) {
73
        glutSetCursor(GLUT_CURSOR_LEFT_ARROW);
74
75
        dragging = false; 
76
77
        if (focus.focused != NULL){
78
                editor->updateSize((newWidth - focus.focused->width), (newHeight - focus.focused->height));
79
        }
80
81
}
82
83
void resizeControl::update() {}
84
85
void resizeControl::draw() {
86
87
        setControl(); 
88
89
        if (dragging) {
90
91
                if (focus.focused != NULL){
92
                        ofNoFill(); 
93
                        ofSetColor(255, 255, 255); ;
94
95
                        newWidth = focus.focused->width + (dragX - (focus.focused->x + focus.focused->width));
96
                        newHeight = focus.focused->height + (dragY - (focus.focused->y + focus.focused->height));
97
98
                        ofRect(focus.focused->x, focus.focused->y, newWidth, newHeight); 
99
100
                }
101
        }
102
103
        ofEnableAlphaBlending();
104
105
                glPushMatrix();
106
107
                        ofFill(); 
108
                                ofSetColor(0xe3e3e3); 
109
                                ofRect(x, y, 5, 5); 
110
                        ofNoFill(); 
111
112
                glPopMatrix();
113
114
        ofDisableAlphaBlending();
115
116
}