forked from solvespace/solvespace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.cpp
More file actions
136 lines (110 loc) · 4.29 KB
/
gui.cpp
File metadata and controls
136 lines (110 loc) · 4.29 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
//-----------------------------------------------------------------------------
// Platform-dependent GUI functionality that has only minor differences.
//
// Copyright 2018 whitequark
//-----------------------------------------------------------------------------
#include "solvespace.h"
namespace SolveSpace {
namespace Platform {
//-----------------------------------------------------------------------------
// Keyboard events
//-----------------------------------------------------------------------------
std::string AcceleratorDescription(const KeyboardEvent &accel) {
std::string label;
if(accel.controlDown) {
#ifdef __APPLE__
label += "⌘+";
#else
label += "Ctrl+";
#endif
}
if(accel.shiftDown) {
label += "Shift+";
}
switch(accel.key) {
case KeyboardEvent::Key::FUNCTION:
label += ssprintf("F%d", accel.num);
break;
case KeyboardEvent::Key::CHARACTER:
if(accel.chr == '\t') {
label += "Tab";
} else if(accel.chr == ' ') {
label += "Space";
} else if(accel.chr == '\x1b') {
label += "Esc";
} else if(accel.chr == '\x7f') {
label += "Del";
} else if(accel.chr != 0) {
label += toupper((char)(accel.chr & 0xff));
}
break;
}
return label;
}
//-----------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------
void Settings::FreezeBool(const std::string &key, bool value) {
FreezeInt(key, (int)value);
}
bool Settings::ThawBool(const std::string &key, bool defaultValue) {
return ThawInt(key, (int)defaultValue) != 0;
}
void Settings::FreezeColor(const std::string &key, RgbaColor value) {
FreezeInt(key, value.ToPackedInt());
}
RgbaColor Settings::ThawColor(const std::string &key, RgbaColor defaultValue) {
return RgbaColor::FromPackedInt(ThawInt(key, defaultValue.ToPackedInt()));
}
//-----------------------------------------------------------------------------
// File dialogs
//-----------------------------------------------------------------------------
void FileDialog::AddFilter(const FileFilter &filter) {
AddFilter(Translate("file-type", filter.name.c_str()), filter.extensions);
}
void FileDialog::AddFilters(const std::vector<FileFilter> &filters) {
for(auto filter : filters) AddFilter(filter);
}
std::vector<FileFilter> SolveSpaceModelFileFilters = {
{ CN_("file-type", "SolveSpace models"), { "slvs" } },
};
std::vector<FileFilter> SolveSpaceLinkFileFilters = {
{ CN_("file-type", "ALL"), { "slvs", "emn", "stl" } },
{ CN_("file-type", "SolveSpace models"), { "slvs" } },
{ CN_("file-type", "IDF circuit board"), { "emn" } },
{ CN_("file-type", "STL triangle mesh"), { "stl" } },
};
std::vector<FileFilter> RasterFileFilters = {
{ CN_("file-type", "PNG image"), { "png" } },
};
std::vector<FileFilter> MeshFileFilters = {
{ CN_("file-type", "STL mesh"), { "stl" } },
{ CN_("file-type", "Wavefront OBJ mesh"), { "obj" } },
{ CN_("file-type", "Three.js-compatible mesh, with viewer"), { "html" } },
{ CN_("file-type", "Three.js-compatible mesh, mesh only"), { "js" } },
{ CN_("file-type", "VRML text file"), { "wrl" } },
};
std::vector<FileFilter> SurfaceFileFilters = {
{ CN_("file-type", "STEP file"), { "step", "stp" } },
};
std::vector<FileFilter> VectorFileFilters = {
{ CN_("file-type", "PDF file"), { "pdf" } },
{ CN_("file-type", "Encapsulated PostScript"), { "eps", "ps" } },
{ CN_("file-type", "Scalable Vector Graphics"), { "svg" } },
{ CN_("file-type", "STEP file"), { "step", "stp" } },
{ CN_("file-type", "DXF file (AutoCAD 2007)"), { "dxf" } },
{ CN_("file-type", "HPGL file"), { "plt", "hpgl" } },
{ CN_("file-type", "G Code"), { "ngc", "txt" } },
};
std::vector<FileFilter> Vector3dFileFilters = {
{ CN_("file-type", "STEP file"), { "step", "stp" } },
{ CN_("file-type", "DXF file (AutoCAD 2007)"), { "dxf" } },
};
std::vector<FileFilter> ImportFileFilters = {
{ CN_("file-type", "AutoCAD DXF and DWG files"), { "dxf", "dwg" } },
};
std::vector<FileFilter> CsvFileFilters = {
{ CN_("file-type", "Comma-separated values"), { "csv" } },
};
}
}