-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollageFrame.cpp
More file actions
148 lines (117 loc) · 4.43 KB
/
CollageFrame.cpp
File metadata and controls
148 lines (117 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
///////////////////////////////////////////////////////////////////////////////////////////////
//
// Name: CollageFrame.h
//
// Author: David Borland
//
// DeRenciiption: Frame for Collage application.
//
///////////////////////////////////////////////////////////////////////////////////////////////
#include "CollageFrame.h"
#include "CollageGraphics.h"
#include <wx/colordlg.h>
#include <string>
#include <vector>
BEGIN_EVENT_TABLE(CollageFrame, RenciFrame)
EVT_CHAR(CollageFrame::OnKey)
EVT_MOUSE_EVENTS(CollageFrame::OnMouse)
END_EVENT_TABLE()
CollageFrame::CollageFrame(const wxString& title, const wxSize& size, RenciGraphics* theGraphics,
EnvironmentMode environmentMode, bool toroidalMode)
: RenciFrame(title, size, theGraphics, environmentMode, toroidalMode) {
}
CollageFrame::~CollageFrame() {
}
void CollageFrame::OnKey(wxKeyEvent& e) {
int c = e.GetKeyCode();
if (c == 'q') {
// Quit
// XXX : Using Close(), the log window doesn't always close...
// Close(true);
exit(0);
}
else if (c == 'o') {
// Open media
ChooseMedia(e.GetX(), e.GetY());
}
else if (c == 'b') {
// Select background color
ChooseBackgroundColor(e.GetX(), e.GetY());
}
else {
graphics->OnKey(e);
}
}
void CollageFrame::OnMouse(wxMouseEvent& e) {
// Call the base class method to get mouse wraparound
RenciFrame::OnMouse(e);
// Send to the graphics
graphics->OnMouse(e);
}
void CollageFrame::ChooseMedia(wxCoord x, wxCoord y) {
// Dialogs can be created on the stack
wxFileDialog fileDialog(this, "Open files", "", "",
"All supported media files|*.avi;*.bmp;*.gif;*.jpg;*.jpeg;*.mov;*.mpg;*.mpeg;*.png;*.tga;*.tif;*.tiff;*.wmv|\
All supported image files|*.bmp;*.gif;*.jpg;*.jpeg;*.png;*.tga;*.tif;*.tiff|\
All supported video files|*.avi;*.mov;*.mpg;*.mpeg;*.wmv|\
AVI files (*.avi)|*.avi|\
BMP files (*.bmp)|*.bmp|\
GIF files (*.gif)|*.gif|\
JPG/JPEG files (*.jpg;*.jpeg)|*.jpg;*.jpeg|\
MOV files (*.mov)|*.mov|\
MPG/MPEG files (*.mpg;*.mpeg)|*.mpg;*.mpeg|\
PNG files (*.png)|*.png|\
TGA files (*.tga)|*.tga|\
TIF/TIFF files (*.tif;*.tiff)|*.tif;*.tiff|\
WMV files (*.wmv)|*.wmv",
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR | wxFD_MULTIPLE);
// Set the position
// XXX : This does not appear to work for the wxFileDialog.
// Perhaps add it to a frame that we can move?
fileDialog.SetPosition(wxPoint(x, y));
if (fileDialog.ShowModal() == wxID_OK) {
// Get the files
std::string directory = fileDialog.GetDirectory().c_str();
directory += "\\";
wxArrayString fileList;
fileDialog.GetFilenames(fileList);
// Create full file paths
std::vector<std::string> paths;
for (int i = 0; i < (int)fileList.size(); i++) {
paths.push_back(directory + fileList[i].c_str());
}
// Pass to the graphics
CollageGraphics* cg = static_cast<CollageGraphics*>(graphics);
int startImage = cg->GetImages().size();
for (int i = 0; i < (int)paths.size(); i++) {
std::string extension = paths[i].substr(paths[i].rfind('.') + 1);
if (extension.compare("avi") == 0 ||
extension.compare("mpg") == 0 ||
extension.compare("mpeg") == 0 ||
extension.compare("wmv") == 0) {
cg->LoadVideo(paths[i]);
}
else if (extension.compare("mov") == 0) {
cg->LoadVideo(paths[i], true);
}
else {
cg->LoadImage(paths[i]);
}
cg->DoLayout(startImage);
Render();
}
}
}
void CollageFrame::ChooseBackgroundColor(wxCoord x, wxCoord y) {
// Dialogs can be created on the stack
wxColourDialog colorDialog;
// Set the position
colorDialog.SetPosition(wxPoint(x, y));
if (colorDialog.ShowModal() == wxID_OK) {
// Set the color
wxColour color = colorDialog.GetColourData().GetColour();
((CollageGraphics*)graphics)->SetBackgroundColor((float)color.Red() / 255.0,
(float)color.Green() / 255.0,
(float)color.Blue() / 255.0);
}
}