17 |
* 02110-1301 USA. |
* 02110-1301 USA. |
18 |
*/ |
*/ |
19 |
|
|
20 |
|
#include "global.h" |
21 |
#include <gtkmm/box.h> |
#include <gtkmm/box.h> |
22 |
#include "dimregionchooser.h" |
#include "dimregionchooser.h" |
23 |
#include <cairomm/context.h> |
#include <cairomm/context.h> |
24 |
|
#include <cairomm/surface.h> |
25 |
#include <gdkmm/cursor.h> |
#include <gdkmm/cursor.h> |
26 |
#include <gdkmm/general.h> |
#include <gdkmm/general.h> |
27 |
#include <glibmm/stringutils.h> |
#include <glibmm/stringutils.h> |
28 |
|
#include <gtkmm/stock.h> |
29 |
#include <glibmm/ustring.h> |
#include <glibmm/ustring.h> |
30 |
#include <gtkmm/messagedialog.h> |
#include <gtkmm/messagedialog.h> |
31 |
#include <assert.h> |
#include <assert.h> |
32 |
|
|
33 |
#include "global.h" |
#include "gfx/builtinpix.h" |
34 |
|
|
35 |
//TODO: this function and dimensionCaseOf() from global.h are duplicates, eliminate either one of them! |
//TODO: this function and dimensionCaseOf() from global.h are duplicates, eliminate either one of them! |
36 |
static DimensionCase caseOfDimRegion(gig::DimensionRegion* dr, bool* isValidZone) { |
static DimensionCase caseOfDimRegion(gig::DimensionRegion* dr, bool* isValidZone) { |
72 |
} |
} |
73 |
|
|
74 |
DimRegionChooser::DimRegionChooser(Gtk::Window& window) : |
DimRegionChooser::DimRegionChooser(Gtk::Window& window) : |
75 |
red("#8070ff"), |
red("#ff476e"), |
76 |
|
blue("#4796ff"), |
77 |
black("black"), |
black("black"), |
78 |
white("white") |
white("white") |
79 |
{ |
{ |
80 |
|
// make sure blue hatched pattern pixmap is loaded |
81 |
|
loadBuiltInPix(); |
82 |
|
|
83 |
|
// create blue hatched pattern 1 |
84 |
|
{ |
85 |
|
const int width = blueHatchedPattern->get_width(); |
86 |
|
const int height = blueHatchedPattern->get_height(); |
87 |
|
const int stride = blueHatchedPattern->get_rowstride(); |
88 |
|
|
89 |
|
// manually convert from RGBA to ARGB |
90 |
|
this->blueHatchedPatternARGB = blueHatchedPattern->copy(); |
91 |
|
const int pixelSize = stride / width; |
92 |
|
const int totalPixels = width * height; |
93 |
|
assert(pixelSize == 4); |
94 |
|
unsigned char* ptr = this->blueHatchedPatternARGB->get_pixels(); |
95 |
|
for (int iPixel = 0; iPixel < totalPixels; ++iPixel, ptr += pixelSize) { |
96 |
|
const unsigned char r = ptr[0]; |
97 |
|
const unsigned char g = ptr[1]; |
98 |
|
const unsigned char b = ptr[2]; |
99 |
|
const unsigned char a = ptr[3]; |
100 |
|
ptr[0] = b; |
101 |
|
ptr[1] = g; |
102 |
|
ptr[2] = r; |
103 |
|
ptr[3] = a; |
104 |
|
} |
105 |
|
|
106 |
|
Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create( |
107 |
|
this->blueHatchedPatternARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride |
108 |
|
); |
109 |
|
this->blueHatchedSurfacePattern = Cairo::SurfacePattern::create(imageSurface); |
110 |
|
this->blueHatchedSurfacePattern->set_extend(Cairo::EXTEND_REPEAT); |
111 |
|
} |
112 |
|
|
113 |
|
// create blue hatched pattern 2 |
114 |
|
{ |
115 |
|
const int width = blueHatchedPattern2->get_width(); |
116 |
|
const int height = blueHatchedPattern2->get_height(); |
117 |
|
const int stride = blueHatchedPattern2->get_rowstride(); |
118 |
|
|
119 |
|
// manually convert from RGBA to ARGB |
120 |
|
this->blueHatchedPattern2ARGB = blueHatchedPattern2->copy(); |
121 |
|
const int pixelSize = stride / width; |
122 |
|
const int totalPixels = width * height; |
123 |
|
assert(pixelSize == 4); |
124 |
|
unsigned char* ptr = this->blueHatchedPattern2ARGB->get_pixels(); |
125 |
|
for (int iPixel = 0; iPixel < totalPixels; ++iPixel, ptr += pixelSize) { |
126 |
|
const unsigned char r = ptr[0]; |
127 |
|
const unsigned char g = ptr[1]; |
128 |
|
const unsigned char b = ptr[2]; |
129 |
|
const unsigned char a = ptr[3]; |
130 |
|
ptr[0] = b; |
131 |
|
ptr[1] = g; |
132 |
|
ptr[2] = r; |
133 |
|
ptr[3] = a; |
134 |
|
} |
135 |
|
|
136 |
|
Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create( |
137 |
|
this->blueHatchedPattern2ARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride |
138 |
|
); |
139 |
|
this->blueHatchedSurfacePattern2 = Cairo::SurfacePattern::create(imageSurface); |
140 |
|
this->blueHatchedSurfacePattern2->set_extend(Cairo::EXTEND_REPEAT); |
141 |
|
} |
142 |
|
|
143 |
|
// create gray blue hatched pattern |
144 |
|
{ |
145 |
|
const int width = grayBlueHatchedPattern->get_width(); |
146 |
|
const int height = grayBlueHatchedPattern->get_height(); |
147 |
|
const int stride = grayBlueHatchedPattern->get_rowstride(); |
148 |
|
|
149 |
|
// manually convert from RGBA to ARGB |
150 |
|
this->grayBlueHatchedPatternARGB = grayBlueHatchedPattern->copy(); |
151 |
|
const int pixelSize = stride / width; |
152 |
|
const int totalPixels = width * height; |
153 |
|
assert(pixelSize == 4); |
154 |
|
unsigned char* ptr = this->grayBlueHatchedPatternARGB->get_pixels(); |
155 |
|
for (int iPixel = 0; iPixel < totalPixels; ++iPixel, ptr += pixelSize) { |
156 |
|
const unsigned char r = ptr[0]; |
157 |
|
const unsigned char g = ptr[1]; |
158 |
|
const unsigned char b = ptr[2]; |
159 |
|
const unsigned char a = ptr[3]; |
160 |
|
ptr[0] = b; |
161 |
|
ptr[1] = g; |
162 |
|
ptr[2] = r; |
163 |
|
ptr[3] = a; |
164 |
|
} |
165 |
|
|
166 |
|
Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create( |
167 |
|
this->grayBlueHatchedPatternARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride |
168 |
|
); |
169 |
|
this->grayBlueHatchedSurfacePattern = Cairo::SurfacePattern::create(imageSurface); |
170 |
|
this->grayBlueHatchedSurfacePattern->set_extend(Cairo::EXTEND_REPEAT); |
171 |
|
} |
172 |
|
|
173 |
instrument = 0; |
instrument = 0; |
174 |
region = 0; |
region = 0; |
175 |
maindimregno = -1; |
maindimregno = -1; |
179 |
cursor_is_resize = false; |
cursor_is_resize = false; |
180 |
h = 24; |
h = 24; |
181 |
multiSelectKeyDown = false; |
multiSelectKeyDown = false; |
182 |
|
primaryKeyDown = false; |
183 |
|
shiftKeyDown = false; |
184 |
modifybothchannels = modifyalldimregs = modifybothchannels = false; |
modifybothchannels = modifyalldimregs = modifybothchannels = false; |
185 |
set_can_focus(); |
set_can_focus(); |
186 |
|
|
244 |
|
|
245 |
void DimRegionChooser::setModifyBothChannels(bool b) { |
void DimRegionChooser::setModifyBothChannels(bool b) { |
246 |
modifybothchannels = b; |
modifybothchannels = b; |
247 |
|
// redraw required parts |
248 |
|
queue_draw(); |
249 |
} |
} |
250 |
|
|
251 |
void DimRegionChooser::setModifyAllDimensionRegions(bool b) { |
void DimRegionChooser::setModifyAllDimensionRegions(bool b) { |
252 |
modifyalldimregs = b; |
modifyalldimregs = b; |
253 |
|
// redraw required parts |
254 |
|
queue_draw(); |
255 |
} |
} |
256 |
|
|
257 |
void DimRegionChooser::setModifyAllRegions(bool b) { |
void DimRegionChooser::setModifyAllRegions(bool b) { |
259 |
|
|
260 |
actionDeleteDimZone->set_label(b ? _("Delete Dimension Zone [ALL REGIONS]") : _("Delete Dimension Zone")); |
actionDeleteDimZone->set_label(b ? _("Delete Dimension Zone [ALL REGIONS]") : _("Delete Dimension Zone")); |
261 |
actionSplitDimZone->set_label(b ? _("Split Dimensions Zone [ALL REGIONS]") : _("Split Dimensions Zone")); |
actionSplitDimZone->set_label(b ? _("Split Dimensions Zone [ALL REGIONS]") : _("Split Dimensions Zone")); |
262 |
|
|
263 |
|
// redraw required parts |
264 |
|
queue_draw(); |
265 |
|
} |
266 |
|
|
267 |
|
void DimRegionChooser::drawIconsFor( |
268 |
|
gig::dimension_t dimension, uint zone, |
269 |
|
const Cairo::RefPtr<Cairo::Context>& cr, |
270 |
|
int x, int y, int w, int h) |
271 |
|
{ |
272 |
|
DimensionCase dimCase; |
273 |
|
dimCase[dimension] = zone; |
274 |
|
|
275 |
|
std::vector<gig::DimensionRegion*> dimregs = |
276 |
|
dimensionRegionsMatching(dimCase, region, true); |
277 |
|
|
278 |
|
if (dimregs.empty()) return; |
279 |
|
|
280 |
|
int iSampleRefs = 0; |
281 |
|
int iLoops = 0; |
282 |
|
|
283 |
|
for (uint i = 0; i < dimregs.size(); ++i) { |
284 |
|
if (dimregs[i]->pSample) iSampleRefs++; |
285 |
|
if (dimregs[i]->SampleLoops) iLoops++; |
286 |
|
} |
287 |
|
|
288 |
|
bool bShowLoopSymbol = (iLoops > 0); |
289 |
|
bool bShowSampleRefSymbol = (iSampleRefs < dimregs.size()); |
290 |
|
|
291 |
|
if (bShowLoopSymbol || bShowSampleRefSymbol) { |
292 |
|
const int margin = 1; |
293 |
|
|
294 |
|
cr->save(); |
295 |
|
cr->set_line_width(1); |
296 |
|
cr->rectangle(x, y + margin, w, h - 2*margin); |
297 |
|
cr->clip(); |
298 |
|
if (bShowSampleRefSymbol) { |
299 |
|
const int wPic = 8; |
300 |
|
const int hPic = 8; |
301 |
|
Gdk::Cairo::set_source_pixbuf( |
302 |
|
cr, (iSampleRefs) ? yellowDot : redDot, |
303 |
|
x + (w-wPic)/2.f, |
304 |
|
y + ( |
305 |
|
(bShowLoopSymbol) ? margin : (h-hPic)/2.f |
306 |
|
) |
307 |
|
); |
308 |
|
cr->paint(); |
309 |
|
} |
310 |
|
if (bShowLoopSymbol) { |
311 |
|
const int wPic = 12; |
312 |
|
const int hPic = 14; |
313 |
|
Gdk::Cairo::set_source_pixbuf( |
314 |
|
cr, (iLoops == dimregs.size()) ? blackLoop : grayLoop, |
315 |
|
x + (w-wPic)/2.f, |
316 |
|
y + ( |
317 |
|
(bShowSampleRefSymbol) ? h - hPic - margin : (h-hPic)/2.f |
318 |
|
) |
319 |
|
); |
320 |
|
cr->paint(); |
321 |
|
} |
322 |
|
cr->restore(); |
323 |
|
} |
324 |
} |
} |
325 |
|
|
326 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
411 |
dstr = dstrbuf; |
dstr = dstrbuf; |
412 |
break; |
break; |
413 |
} |
} |
|
layout->set_text(dstr); |
|
414 |
|
|
415 |
|
// Since bold font yields in larger label width, we first always |
416 |
|
// set the bold text variant, retrieve its dimensions (as worst |
417 |
|
// case dimensions of the label) ... |
418 |
|
layout->set_markup("<b>" + Glib::ustring(dstr) + "</b>"); |
419 |
Pango::Rectangle rectangle = layout->get_logical_extents(); |
Pango::Rectangle rectangle = layout->get_logical_extents(); |
420 |
|
// ... and then reset the label to regular font style in case |
421 |
|
// the line is not selected. Otherwise the right hand side |
422 |
|
// actual dimension zones would jump around on selection change. |
423 |
|
bool isSelectedLine = (focus_line == i); |
424 |
|
if (!isSelectedLine) |
425 |
|
layout->set_markup(dstr); |
426 |
|
|
427 |
double text_w = double(rectangle.get_width()) / Pango::SCALE; |
double text_w = double(rectangle.get_width()) / Pango::SCALE; |
428 |
if (text_w > maxwidth) maxwidth = text_w; |
if (text_w > maxwidth) maxwidth = text_w; |
429 |
|
|
530 |
|
|
531 |
// draw fill for zone |
// draw fill for zone |
532 |
bool isSelectedZone = this->dimzones[dimension].count(j); |
bool isSelectedZone = this->dimzones[dimension].count(j); |
533 |
Gdk::Cairo::set_source_rgba(cr, isSelectedZone ? red : white); |
bool isMainSelection = |
534 |
cr->rectangle(prevX + 1, y + 1, x - prevX - 1, h - 1); |
this->maindimcase.find(dimension) != this->maindimcase.end() && |
535 |
|
this->maindimcase[dimension] == j; |
536 |
|
bool isCheckBoxSelected = |
537 |
|
modifyalldimregs || |
538 |
|
(modifybothchannels && |
539 |
|
dimension == gig::dimension_samplechannel); |
540 |
|
if (isMainSelection) |
541 |
|
Gdk::Cairo::set_source_rgba(cr, blue); |
542 |
|
else if (isSelectedZone) |
543 |
|
cr->set_source(blueHatchedSurfacePattern2); |
544 |
|
else if (isCheckBoxSelected) |
545 |
|
cr->set_source(blueHatchedSurfacePattern); |
546 |
|
else |
547 |
|
Gdk::Cairo::set_source_rgba(cr, white); |
548 |
|
|
549 |
|
const int wZone = x - prevX - 1; |
550 |
|
|
551 |
|
cr->rectangle(prevX + 1, y + 1, wZone, h - 1); |
552 |
cr->fill(); |
cr->fill(); |
553 |
|
|
554 |
|
// draw icons |
555 |
|
drawIconsFor(dimension, j, cr, prevX, y, wZone, h); |
556 |
|
|
557 |
// draw text showing the beginning of the dimension zone |
// draw text showing the beginning of the dimension zone |
558 |
// as numeric value to the user |
// as numeric value to the user |
559 |
{ |
{ |
606 |
cr->stroke(); |
cr->stroke(); |
607 |
|
|
608 |
if (j != 0) { |
if (j != 0) { |
609 |
|
const int wZone = x - prevX - 1; |
610 |
|
|
611 |
// draw fill for zone |
// draw fill for zone |
612 |
bool isSelectedZone = this->dimzones[dimension].count(j-1); |
bool isSelectedZone = this->dimzones[dimension].count(j-1); |
613 |
Gdk::Cairo::set_source_rgba(cr, isSelectedZone ? red : white); |
bool isMainSelection = |
614 |
cr->rectangle(prevX + 1, y + 1, x - prevX - 1, h - 1); |
this->maindimcase.find(dimension) != this->maindimcase.end() && |
615 |
|
this->maindimcase[dimension] == (j-1); |
616 |
|
bool isCheckBoxSelected = |
617 |
|
modifyalldimregs || |
618 |
|
(modifybothchannels && |
619 |
|
dimension == gig::dimension_samplechannel); |
620 |
|
if (isMainSelection) |
621 |
|
Gdk::Cairo::set_source_rgba(cr, blue); |
622 |
|
else if (isSelectedZone) |
623 |
|
cr->set_source(blueHatchedSurfacePattern2); |
624 |
|
else if (isCheckBoxSelected) |
625 |
|
cr->set_source(blueHatchedSurfacePattern); |
626 |
|
else |
627 |
|
Gdk::Cairo::set_source_rgba(cr, white); |
628 |
|
cr->rectangle(prevX + 1, y + 1, wZone, h - 1); |
629 |
cr->fill(); |
cr->fill(); |
630 |
|
|
631 |
|
// draw icons |
632 |
|
drawIconsFor(dimension, j - 1, cr, prevX, y, wZone, h); |
633 |
|
|
634 |
// draw text showing the beginning of the dimension zone |
// draw text showing the beginning of the dimension zone |
635 |
// as numeric value to the user |
// as numeric value to the user |
636 |
{ |
{ |
1344 |
refresh_all(); |
refresh_all(); |
1345 |
} |
} |
1346 |
|
|
1347 |
|
// Cmd key on Mac, Ctrl key on all other OSs |
1348 |
|
static const guint primaryKeyL = |
1349 |
|
#if defined(__APPLE__) |
1350 |
|
GDK_KEY_Meta_L; |
1351 |
|
#else |
1352 |
|
GDK_KEY_Control_L; |
1353 |
|
#endif |
1354 |
|
|
1355 |
|
static const guint primaryKeyR = |
1356 |
|
#if defined(__APPLE__) |
1357 |
|
GDK_KEY_Meta_R; |
1358 |
|
#else |
1359 |
|
GDK_KEY_Control_R; |
1360 |
|
#endif |
1361 |
|
|
1362 |
bool DimRegionChooser::onKeyPressed(GdkEventKey* key) { |
bool DimRegionChooser::onKeyPressed(GdkEventKey* key) { |
1363 |
//printf("key down 0x%x\n", key->keyval); |
//printf("key down 0x%x\n", key->keyval); |
1364 |
if (key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R) |
if (key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R) |
1365 |
multiSelectKeyDown = true; |
multiSelectKeyDown = true; |
1366 |
|
if (key->keyval == primaryKeyL || key->keyval == primaryKeyR) |
1367 |
|
primaryKeyDown = true; |
1368 |
|
if (key->keyval == GDK_KEY_Shift_L || key->keyval == GDK_KEY_Shift_R) |
1369 |
|
shiftKeyDown = true; |
1370 |
|
|
1371 |
//FIXME: hmm, for some reason GDKMM does not fire arrow key down events, so we are doing those handlers in the key up handler instead for now |
//FIXME: hmm, for some reason GDKMM does not fire arrow key down events, so we are doing those handlers in the key up handler instead for now |
1372 |
/*if (key->keyval == GDK_KEY_Left) |
/*if (key->keyval == GDK_KEY_Left) |
1373 |
select_prev_dimzone(); |
select_prev_dimzone(); |
1384 |
//printf("key up 0x%x\n", key->keyval); |
//printf("key up 0x%x\n", key->keyval); |
1385 |
if (key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R) |
if (key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R) |
1386 |
multiSelectKeyDown = false; |
multiSelectKeyDown = false; |
1387 |
|
if (key->keyval == primaryKeyL || key->keyval == primaryKeyR) |
1388 |
|
primaryKeyDown = false; |
1389 |
|
if (key->keyval == GDK_KEY_Shift_L || key->keyval == GDK_KEY_Shift_R) |
1390 |
|
shiftKeyDown = false; |
1391 |
|
|
1392 |
if (!has_focus()) return false; |
if (!has_focus()) return false; |
1393 |
|
|
1394 |
|
// avoid conflict with Ctrl+Left and Ctrl+Right accelerators on mainwindow |
1395 |
|
// (which is supposed to switch between regions) |
1396 |
|
if (primaryKeyDown) return false; |
1397 |
|
|
1398 |
|
// avoid conflict with Alt+Shift+Left and Alt+Shift+Right accelerators on |
1399 |
|
// mainwindow |
1400 |
|
if (shiftKeyDown) return false; |
1401 |
|
|
1402 |
if (key->keyval == GDK_KEY_Left) |
if (key->keyval == GDK_KEY_Left) |
1403 |
select_prev_dimzone(); |
select_prev_dimzone(); |
1404 |
if (key->keyval == GDK_KEY_Right) |
if (key->keyval == GDK_KEY_Right) |
1459 |
return false; //.selection failed |
return false; //.selection failed |
1460 |
} |
} |
1461 |
|
|
1462 |
void DimRegionChooser::select_next_dimzone() { |
void DimRegionChooser::select_next_dimzone(bool add) { |
1463 |
select_dimzone_by_dir(+1); |
select_dimzone_by_dir(+1, add); |
1464 |
} |
} |
1465 |
|
|
1466 |
void DimRegionChooser::select_prev_dimzone() { |
void DimRegionChooser::select_prev_dimzone(bool add) { |
1467 |
select_dimzone_by_dir(-1); |
select_dimzone_by_dir(-1, add); |
1468 |
} |
} |
1469 |
|
|
1470 |
void DimRegionChooser::select_dimzone_by_dir(int dir) { |
void DimRegionChooser::select_dimzone_by_dir(int dir, bool add) { |
1471 |
if (!region) return; |
if (!region) return; |
1472 |
if (!region->Dimensions) return; |
if (!region->Dimensions) return; |
1473 |
if (focus_line < 0) focus_line = 0; |
if (focus_line < 0) focus_line = 0; |
1502 |
|
|
1503 |
maindimregno = getDimensionRegionIndex(dr); |
maindimregno = getDimensionRegionIndex(dr); |
1504 |
|
|
1505 |
// reset selected dimregion zones |
if (!add) { |
1506 |
dimzones.clear(); |
// reset selected dimregion zones |
1507 |
|
dimzones.clear(); |
1508 |
|
} |
1509 |
for (DimensionCase::const_iterator it = maindimcase.begin(); |
for (DimensionCase::const_iterator it = maindimcase.begin(); |
1510 |
it != maindimcase.end(); ++it) |
it != maindimcase.end(); ++it) |
1511 |
{ |
{ |