20 |
#include <gtkmm/box.h> |
#include <gtkmm/box.h> |
21 |
#include "dimregionchooser.h" |
#include "dimregionchooser.h" |
22 |
#include <cairomm/context.h> |
#include <cairomm/context.h> |
23 |
|
#include <cairomm/surface.h> |
24 |
#include <gdkmm/cursor.h> |
#include <gdkmm/cursor.h> |
25 |
#include <gdkmm/general.h> |
#include <gdkmm/general.h> |
26 |
#include <glibmm/stringutils.h> |
#include <glibmm/stringutils.h> |
29 |
#include <assert.h> |
#include <assert.h> |
30 |
|
|
31 |
#include "global.h" |
#include "global.h" |
32 |
|
#include "builtinpix.h" |
33 |
|
|
34 |
//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! |
35 |
static DimensionCase caseOfDimRegion(gig::DimensionRegion* dr, bool* isValidZone) { |
static DimensionCase caseOfDimRegion(gig::DimensionRegion* dr, bool* isValidZone) { |
71 |
} |
} |
72 |
|
|
73 |
DimRegionChooser::DimRegionChooser(Gtk::Window& window) : |
DimRegionChooser::DimRegionChooser(Gtk::Window& window) : |
74 |
red("#8070ff"), |
red("#ff476e"), |
75 |
|
blue("#4796ff"), |
76 |
black("black"), |
black("black"), |
77 |
white("white") |
white("white") |
78 |
{ |
{ |
79 |
|
// make sure blue hatched pattern pixmap is loaded |
80 |
|
loadBuiltInPix(); |
81 |
|
|
82 |
|
// create blue hatched pattern |
83 |
|
{ |
84 |
|
const int width = blueHatchedPattern->get_width(); |
85 |
|
const int height = blueHatchedPattern->get_height(); |
86 |
|
const int stride = blueHatchedPattern->get_rowstride(); |
87 |
|
|
88 |
|
// manually convert from RGBA to ARGB |
89 |
|
this->blueHatchedPatternARGB = blueHatchedPattern->copy(); |
90 |
|
const int pixelSize = stride / width; |
91 |
|
const int totalPixels = width * height; |
92 |
|
assert(pixelSize == 4); |
93 |
|
unsigned char* ptr = this->blueHatchedPatternARGB->get_pixels(); |
94 |
|
for (int iPixel = 0; iPixel < totalPixels; ++iPixel, ptr += pixelSize) { |
95 |
|
const unsigned char r = ptr[0]; |
96 |
|
const unsigned char g = ptr[1]; |
97 |
|
const unsigned char b = ptr[2]; |
98 |
|
const unsigned char a = ptr[3]; |
99 |
|
ptr[0] = b; |
100 |
|
ptr[1] = g; |
101 |
|
ptr[2] = r; |
102 |
|
ptr[3] = a; |
103 |
|
} |
104 |
|
|
105 |
|
Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create( |
106 |
|
this->blueHatchedPatternARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride |
107 |
|
); |
108 |
|
this->blueHatchedSurfacePattern = Cairo::SurfacePattern::create(imageSurface); |
109 |
|
this->blueHatchedSurfacePattern->set_extend(Cairo::EXTEND_REPEAT); |
110 |
|
} |
111 |
|
|
112 |
instrument = 0; |
instrument = 0; |
113 |
region = 0; |
region = 0; |
114 |
maindimregno = -1; |
maindimregno = -1; |
118 |
cursor_is_resize = false; |
cursor_is_resize = false; |
119 |
h = 24; |
h = 24; |
120 |
multiSelectKeyDown = false; |
multiSelectKeyDown = false; |
121 |
|
primaryKeyDown = false; |
122 |
|
shiftKeyDown = false; |
123 |
modifybothchannels = modifyalldimregs = modifybothchannels = false; |
modifybothchannels = modifyalldimregs = modifybothchannels = false; |
124 |
set_can_focus(); |
set_can_focus(); |
125 |
|
|
284 |
dstr = dstrbuf; |
dstr = dstrbuf; |
285 |
break; |
break; |
286 |
} |
} |
|
layout->set_text(dstr); |
|
287 |
|
|
288 |
|
// Since bold font yields in larger label width, we first always |
289 |
|
// set the bold text variant, retrieve its dimensions (as worst |
290 |
|
// case dimensions of the label) ... |
291 |
|
layout->set_markup("<b>" + Glib::ustring(dstr) + "</b>"); |
292 |
Pango::Rectangle rectangle = layout->get_logical_extents(); |
Pango::Rectangle rectangle = layout->get_logical_extents(); |
293 |
|
// ... and then reset the label to regular font style in case |
294 |
|
// the line is not selected. Otherwise the right hand side |
295 |
|
// actual dimension zones would jump around on selection change. |
296 |
|
bool isSelectedLine = (focus_line == i); |
297 |
|
if (!isSelectedLine) |
298 |
|
layout->set_markup(dstr); |
299 |
|
|
300 |
double text_w = double(rectangle.get_width()) / Pango::SCALE; |
double text_w = double(rectangle.get_width()) / Pango::SCALE; |
301 |
if (text_w > maxwidth) maxwidth = text_w; |
if (text_w > maxwidth) maxwidth = text_w; |
302 |
|
|
403 |
|
|
404 |
// draw fill for zone |
// draw fill for zone |
405 |
bool isSelectedZone = this->dimzones[dimension].count(j); |
bool isSelectedZone = this->dimzones[dimension].count(j); |
406 |
Gdk::Cairo::set_source_rgba(cr, isSelectedZone ? red : white); |
bool isMainSelection = |
407 |
|
this->maindimcase.find(dimension) != this->maindimcase.end() && |
408 |
|
this->maindimcase[dimension] == j; |
409 |
|
if (isMainSelection) |
410 |
|
Gdk::Cairo::set_source_rgba(cr, blue); |
411 |
|
else if (isSelectedZone) |
412 |
|
cr->set_source(blueHatchedSurfacePattern); |
413 |
|
else |
414 |
|
Gdk::Cairo::set_source_rgba(cr, white); |
415 |
|
|
416 |
cr->rectangle(prevX + 1, y + 1, x - prevX - 1, h - 1); |
cr->rectangle(prevX + 1, y + 1, x - prevX - 1, h - 1); |
417 |
cr->fill(); |
cr->fill(); |
418 |
|
|
470 |
if (j != 0) { |
if (j != 0) { |
471 |
// draw fill for zone |
// draw fill for zone |
472 |
bool isSelectedZone = this->dimzones[dimension].count(j-1); |
bool isSelectedZone = this->dimzones[dimension].count(j-1); |
473 |
Gdk::Cairo::set_source_rgba(cr, isSelectedZone ? red : white); |
bool isMainSelection = |
474 |
|
this->maindimcase.find(dimension) != this->maindimcase.end() && |
475 |
|
this->maindimcase[dimension] == (j-1); |
476 |
|
if (isMainSelection) |
477 |
|
Gdk::Cairo::set_source_rgba(cr, blue); |
478 |
|
else if (isSelectedZone) |
479 |
|
cr->set_source(blueHatchedSurfacePattern); |
480 |
|
else |
481 |
|
Gdk::Cairo::set_source_rgba(cr, white); |
482 |
cr->rectangle(prevX + 1, y + 1, x - prevX - 1, h - 1); |
cr->rectangle(prevX + 1, y + 1, x - prevX - 1, h - 1); |
483 |
cr->fill(); |
cr->fill(); |
484 |
|
|
1195 |
refresh_all(); |
refresh_all(); |
1196 |
} |
} |
1197 |
|
|
1198 |
|
// Cmd key on Mac, Ctrl key on all other OSs |
1199 |
|
static const guint primaryKeyL = |
1200 |
|
#if defined(__APPLE__) |
1201 |
|
GDK_KEY_Meta_L; |
1202 |
|
#else |
1203 |
|
GDK_KEY_Control_L; |
1204 |
|
#endif |
1205 |
|
|
1206 |
|
static const guint primaryKeyR = |
1207 |
|
#if defined(__APPLE__) |
1208 |
|
GDK_KEY_Meta_R; |
1209 |
|
#else |
1210 |
|
GDK_KEY_Control_R; |
1211 |
|
#endif |
1212 |
|
|
1213 |
bool DimRegionChooser::onKeyPressed(GdkEventKey* key) { |
bool DimRegionChooser::onKeyPressed(GdkEventKey* key) { |
1214 |
//printf("key down 0x%x\n", key->keyval); |
//printf("key down 0x%x\n", key->keyval); |
1215 |
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) |
1216 |
multiSelectKeyDown = true; |
multiSelectKeyDown = true; |
1217 |
|
if (key->keyval == primaryKeyL || key->keyval == primaryKeyR) |
1218 |
|
primaryKeyDown = true; |
1219 |
|
if (key->keyval == GDK_KEY_Shift_L || key->keyval == GDK_KEY_Shift_R) |
1220 |
|
shiftKeyDown = true; |
1221 |
|
|
1222 |
//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 |
1223 |
/*if (key->keyval == GDK_KEY_Left) |
/*if (key->keyval == GDK_KEY_Left) |
1224 |
select_prev_dimzone(); |
select_prev_dimzone(); |
1235 |
//printf("key up 0x%x\n", key->keyval); |
//printf("key up 0x%x\n", key->keyval); |
1236 |
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) |
1237 |
multiSelectKeyDown = false; |
multiSelectKeyDown = false; |
1238 |
|
if (key->keyval == primaryKeyL || key->keyval == primaryKeyR) |
1239 |
|
primaryKeyDown = false; |
1240 |
|
if (key->keyval == GDK_KEY_Shift_L || key->keyval == GDK_KEY_Shift_R) |
1241 |
|
shiftKeyDown = false; |
1242 |
|
|
1243 |
if (!has_focus()) return false; |
if (!has_focus()) return false; |
1244 |
|
|
1245 |
|
// avoid conflict with Ctrl+Left and Ctrl+Right accelerators on mainwindow |
1246 |
|
// (which is supposed to switch between regions) |
1247 |
|
if (primaryKeyDown) return false; |
1248 |
|
|
1249 |
if (key->keyval == GDK_KEY_Left) |
if (key->keyval == GDK_KEY_Left) |
1250 |
select_prev_dimzone(); |
select_prev_dimzone(); |
1251 |
if (key->keyval == GDK_KEY_Right) |
if (key->keyval == GDK_KEY_Right) |