~ubuntu-branches/ubuntu/trusty/3depict/trusty-proposed

« back to all changes in this revision

Viewing changes to src/gui/dialogs/animateSubDialogs/colourKeyFrameDialog.cpp

  • Committer: Package Import Robot
  • Author(s): D Haley
  • Date: 2013-05-17 00:52:39 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130517005239-7bl4mnhkvrhc2ba6
Tags: 0.0.13-1
Upload to unstable 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      colourKeyFrameDialog.cpp - Colour property keyframe selection dialog
 
3
 *      Copyright (C) 2013, D Haley 
 
4
 
 
5
 *      This program is free software: you can redistribute it and/or modify
 
6
 *      it under the terms of the GNU General Public License as published by
 
7
 *      the Free Software Foundation, either version 3 of the License, or
 
8
 *      (at your option) any later version.
 
9
 
 
10
 *      This program is distributed in the hope that it will be useful,
 
11
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *      GNU General Public License for more details.
 
14
 
 
15
 *      You should have received a copy of the GNU General Public License
 
16
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
*/
 
18
// -*- C++ -*- generated by wxGlade 0.6.5 on Fri Sep 14 09:37:57 2012
 
19
 
 
20
#include "colourKeyFrameDialog.h"
 
21
#include "common/stringFuncs.h"
 
22
#include "wxcommon.h"
 
23
#include "common/translation.h"
 
24
 
 
25
#include <wx/colordlg.h>
 
26
 
 
27
 
 
28
using std::string;
 
29
 
 
30
// begin wxGlade: ::extracode
 
31
enum{
 
32
        ID_COMBO_TRANSITION,
 
33
        ID_BTN_START_VALUE,
 
34
        ID_BTN_FINAL_VALUE,
 
35
        ID_TEXT_INITIAL_VALUE,
 
36
        ID_TEXT_FRAME_START,
 
37
        ID_TEXT_FRAME_END
 
38
};
 
39
 
 
40
// end wxGlade
 
41
 
 
42
//FIXME: Is currently duplicated from realKeyframeDialog. Needs to be
 
43
// unified
 
44
enum
 
45
{
 
46
        TRANSITION_STEP,
 
47
        TRANSITION_INTERP,
 
48
        TRANSITION_END
 
49
};
 
50
 
 
51
 
 
52
ColourKeyFrameDialog::ColourKeyFrameDialog(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
 
53
        wxDialog(parent, id, title, pos, size, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxMAXIMIZE_BOX|wxMINIMIZE_BOX)
 
54
{
 
55
        // begin wxGlade: ColourKeyFrameDialog::ColourKeyFrameDialog
 
56
        sizerMainArea_staticbox = new wxStaticBox(this, -1, wxTRANS("Keyframe Data"));
 
57
        labelTransition = new wxStaticText(this, wxID_ANY, wxTRANS("Transition"));
 
58
        //FIXME: THis is declared in animator.h - use that def.
 
59
        const wxString comboTransition_choices[] = {
 
60
        wxTRANS("Step"),
 
61
        wxTRANS("Ramp")
 
62
    };
 
63
        comboTransition = new wxComboBox(this, ID_COMBO_TRANSITION, _(""), wxDefaultPosition, wxDefaultSize, 2, comboTransition_choices, wxCB_DROPDOWN|wxCB_READONLY);
 
64
        labelFrameStart = new wxStaticText(this, wxID_ANY, wxTRANS("Start Frame"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
 
65
        textFrameStart = new wxTextCtrl(this, ID_TEXT_FRAME_START, wxEmptyString);
 
66
        labelFrameEnd = new wxStaticText(this, wxID_ANY, wxTRANS("End Frame"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
 
67
        textFrameEnd = new wxTextCtrl(this, ID_TEXT_FRAME_END, wxEmptyString);
 
68
        verticalLine = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL);
 
69
        labelStartVal = new wxStaticText(this, wxID_ANY, wxTRANS("Initial Value"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
 
70
        btnStartColour = new wxButton(this, ID_BTN_START_VALUE, wxTRANS("startColour"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
 
71
        labelFinalVal = new wxStaticText(this, wxID_ANY, wxTRANS("Final Value"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
 
72
        btnEndColour = new wxButton(this, ID_BTN_FINAL_VALUE, wxTRANS("endColour"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
 
73
        buttonCancel = new wxButton(this, wxID_CANCEL, wxEmptyString);
 
74
        buttonOK = new wxButton(this, wxID_OK, wxEmptyString);
 
75
 
 
76
        comboTransition->SetSelection(1);
 
77
        transitionMode=TRANSITION_INTERP;
 
78
        endFrameOK=startFrameOK=false;
 
79
        startRed=startGreen=startBlue=0;                
 
80
        endRed=endGreen=endBlue=0;              
 
81
 
 
82
 
 
83
        updateOKButton();
 
84
        updateButtonColours();
 
85
 
 
86
        set_properties();
 
87
        do_layout();
 
88
        // end wxGlade
 
89
}
 
90
 
 
91
 
 
92
BEGIN_EVENT_TABLE(ColourKeyFrameDialog, wxDialog)
 
93
        // begin wxGlade: ColourKeyFrameDialog::event_table
 
94
        EVT_COMBOBOX(ID_COMBO_TRANSITION, ColourKeyFrameDialog::OnComboTransition)
 
95
        EVT_TEXT(ID_TEXT_FRAME_START, ColourKeyFrameDialog::OnTextStartFrame)
 
96
        EVT_TEXT(ID_TEXT_FRAME_END, ColourKeyFrameDialog::OnTextEndFrame)
 
97
        EVT_BUTTON(ID_BTN_START_VALUE, ColourKeyFrameDialog::OnBtnStartColour)
 
98
        EVT_BUTTON(ID_BTN_FINAL_VALUE, ColourKeyFrameDialog::OnBtnEndColour)
 
99
        // end wxGlade
 
100
END_EVENT_TABLE();
 
101
 
 
102
size_t ColourKeyFrameDialog::getStartFrame() const
 
103
{
 
104
        ASSERT(startFrameOK);
 
105
        return startFrame;
 
106
}
 
107
 
 
108
size_t ColourKeyFrameDialog::getEndFrame() const
 
109
{
 
110
        ASSERT(endFrameOK);
 
111
        return endFrame;
 
112
}
 
113
 
 
114
std::string ColourKeyFrameDialog::getEndValue() const 
 
115
{
 
116
        ASSERT(transitionMode!=TRANSITION_STEP);
 
117
        std::string s;
 
118
        genColString(endRed,endGreen,endBlue,s);
 
119
        return s;
 
120
}
 
121
 
 
122
std::string ColourKeyFrameDialog::getStartValue() const
 
123
{
 
124
        std::string s;
 
125
        genColString(startRed,startGreen,startBlue,s);
 
126
        return s;
 
127
}
 
128
 
 
129
void ColourKeyFrameDialog::OnComboTransition(wxCommandEvent &event)
 
130
{
 
131
        ASSERT(event.GetInt() < TRANSITION_END);
 
132
 
 
133
        transitionMode=event.GetInt();
 
134
 
 
135
        btnEndColour->Enable(transitionMode != TRANSITION_STEP);
 
136
        textFrameEnd->Enable(transitionMode!=TRANSITION_STEP);
 
137
}
 
138
 
 
139
void ColourKeyFrameDialog::OnTextStartFrame(wxCommandEvent &event)
 
140
{
 
141
        startFrameOK=validateTextAsStream(textFrameStart,startFrame);
 
142
        updateOKButton();
 
143
}
 
144
 
 
145
 
 
146
void ColourKeyFrameDialog::OnTextEndFrame(wxCommandEvent &event)
 
147
{
 
148
        endFrameOK=validateTextAsStream(textFrameEnd,endFrame);
 
149
        updateOKButton();
 
150
}
 
151
 
 
152
 
 
153
void ColourKeyFrameDialog::OnBtnStartColour(wxCommandEvent &event)
 
154
{
 
155
        wxColourData d;
 
156
        wxColourDialog *colDg=new wxColourDialog(this->GetParent(),&d);
 
157
 
 
158
        if( colDg->ShowModal() == wxID_OK)
 
159
        {
 
160
                wxColour c;
 
161
                //Change the colour
 
162
                c=colDg->GetColourData().GetColour();
 
163
 
 
164
                startRed=c.Red();
 
165
                startGreen=c.Green();
 
166
                startBlue=c.Blue();
 
167
                
 
168
                updateButtonColours();
 
169
        }
 
170
}
 
171
 
 
172
 
 
173
void ColourKeyFrameDialog::OnBtnEndColour(wxCommandEvent &event)
 
174
{
 
175
        wxColourData d;
 
176
        wxColourDialog *colDg=new wxColourDialog(this->GetParent(),&d);
 
177
 
 
178
        if( colDg->ShowModal() == wxID_OK)
 
179
        {
 
180
                wxColour c;
 
181
                //Change the colour
 
182
                c=colDg->GetColourData().GetColour();
 
183
 
 
184
                endRed=c.Red();
 
185
                endGreen=c.Green();
 
186
                endBlue=c.Blue();
 
187
 
 
188
                updateButtonColours();
 
189
        }
 
190
 
 
191
        colDg->Destroy();
 
192
}
 
193
 
 
194
void ColourKeyFrameDialog::updateOKButton()
 
195
{
 
196
        bool isOK=true;
 
197
        isOK&=startFrameOK;
 
198
        isOK&=endFrameOK;
 
199
 
 
200
        //Ensure start frame is > end frame
 
201
        if(isOK)
 
202
        {
 
203
                isOK&=(startFrame<endFrame);
 
204
                if(!isOK)
 
205
                {
 
206
                        textFrameStart->SetBackgroundColour(*wxCYAN);
 
207
                        textFrameEnd->SetBackgroundColour(*wxCYAN);
 
208
                }
 
209
                else
 
210
                {
 
211
                        textFrameStart->SetBackgroundColour(wxNullColour);
 
212
                        textFrameEnd->SetBackgroundColour(wxNullColour);
 
213
                }
 
214
        }
 
215
        
 
216
        buttonOK->Enable(isOK);
 
217
}
 
218
 
 
219
void ColourKeyFrameDialog::updateButtonColours()
 
220
{
 
221
        wxColour colD;
 
222
        colD.Set(startRed,startGreen,startBlue);
 
223
        btnStartColour->SetForegroundColour(colD);
 
224
        
 
225
        colD.Set(endRed,endGreen,endBlue);
 
226
        btnEndColour->SetForegroundColour(colD);
 
227
 
 
228
}
 
229
// wxGlade: add ColourKeyFrameDialog event handlers
 
230
 
 
231
 
 
232
void ColourKeyFrameDialog::set_properties()
 
233
{
 
234
        // begin wxGlade: ColourKeyFrameDialog::set_properties
 
235
        SetTitle(wxTRANS("Key Frame : Colour"));
 
236
        comboTransition->SetSelection(-1);
 
237
        btnStartColour->SetToolTip(wxTRANS("Colour at the start of the transtition"));
 
238
        btnEndColour->SetToolTip(wxTRANS("Colour at end of transition"));
 
239
        // end wxGlade
 
240
}
 
241
 
 
242
 
 
243
void ColourKeyFrameDialog::do_layout()
 
244
{
 
245
        // begin wxGlade: ColourKeyFrameDialog::do_layout
 
246
        wxBoxSizer* sizerTop = new wxBoxSizer(wxVERTICAL);
 
247
        wxBoxSizer* sizerBUttons = new wxBoxSizer(wxHORIZONTAL);
 
248
        wxStaticBoxSizer* sizerMainArea = new wxStaticBoxSizer(sizerMainArea_staticbox, wxHORIZONTAL);
 
249
        wxBoxSizer* sizerRight = new wxBoxSizer(wxVERTICAL);
 
250
        wxBoxSizer* sizerRightFinal = new wxBoxSizer(wxHORIZONTAL);
 
251
        wxBoxSizer* sizerRightInitial = new wxBoxSizer(wxHORIZONTAL);
 
252
        wxBoxSizer* sizerLeft = new wxBoxSizer(wxVERTICAL);
 
253
        wxBoxSizer* sizerEndFrame = new wxBoxSizer(wxHORIZONTAL);
 
254
        wxBoxSizer* sizerStartFrame = new wxBoxSizer(wxHORIZONTAL);
 
255
        wxBoxSizer* sizerTransition = new wxBoxSizer(wxHORIZONTAL);
 
256
        sizerTop->Add(20, 5, 0, 0, 0);
 
257
        sizerMainArea->Add(10, 20, 0, 0, 0);
 
258
        sizerLeft->Add(20, 10, 0, 0, 0);
 
259
        sizerTransition->Add(labelTransition, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 14);
 
260
        sizerTransition->Add(comboTransition, 1, wxLEFT|wxALIGN_CENTER_VERTICAL, 5);
 
261
        sizerLeft->Add(sizerTransition, 1, wxEXPAND, 0);
 
262
        sizerStartFrame->Add(labelFrameStart, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
 
263
        sizerStartFrame->Add(textFrameStart, 1, wxLEFT|wxALIGN_CENTER_VERTICAL, 4);
 
264
        sizerLeft->Add(sizerStartFrame, 1, wxEXPAND|wxALIGN_CENTER_VERTICAL, 0);
 
265
        sizerEndFrame->Add(labelFrameEnd, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 12);
 
266
        sizerEndFrame->Add(textFrameEnd, 1, wxLEFT|wxALIGN_CENTER_VERTICAL, 4);
 
267
        sizerLeft->Add(sizerEndFrame, 1, wxEXPAND|wxALIGN_CENTER_VERTICAL, 0);
 
268
        sizerLeft->Add(20, 10, 0, 0, 0);
 
269
        sizerMainArea->Add(sizerLeft, 2, wxEXPAND, 0);
 
270
        sizerMainArea->Add(verticalLine, 0, wxLEFT|wxRIGHT|wxEXPAND, 5);
 
271
        sizerRight->Add(20, 20, 1, 0, 0);
 
272
        sizerRightInitial->Add(20, 20, 1, 0, 0);
 
273
        sizerRightInitial->Add(labelStartVal, 2, wxRIGHT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
 
274
        sizerRightInitial->Add(btnStartColour, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 3);
 
275
        sizerRightInitial->Add(20, 20, 1, 0, 0);
 
276
        sizerRight->Add(sizerRightInitial, 1, wxEXPAND|wxALIGN_CENTER_VERTICAL, 0);
 
277
        sizerRightFinal->Add(20, 20, 1, 0, 0);
 
278
        sizerRightFinal->Add(labelFinalVal, 2, wxRIGHT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 9);
 
279
        sizerRightFinal->Add(btnEndColour, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 3);
 
280
        sizerRightFinal->Add(20, 20, 1, 0, 0);
 
281
        sizerRight->Add(sizerRightFinal, 1, wxEXPAND|wxALIGN_CENTER_VERTICAL, 0);
 
282
        sizerRight->Add(20, 20, 1, 0, 0);
 
283
        sizerMainArea->Add(sizerRight, 2, wxEXPAND, 0);
 
284
        sizerMainArea->Add(10, 20, 0, 0, 0);
 
285
        sizerTop->Add(sizerMainArea, 1, wxEXPAND, 0);
 
286
        sizerBUttons->Add(20, 20, 1, 0, 0);
 
287
        sizerBUttons->Add(buttonCancel, 0, wxALL, 4);
 
288
        sizerBUttons->Add(buttonOK, 0, wxALL, 4);
 
289
        sizerTop->Add(sizerBUttons, 0, wxEXPAND, 0);
 
290
        SetSizer(sizerTop);
 
291
        sizerTop->Fit(this);
 
292
        Layout();
 
293
        // end wxGlade
 
294
}
 
295