1 |
/* |
/* |
2 |
* Copyright (C) 2006-2011 Andreas Persson |
* Copyright (C) 2006-2015 Andreas Persson |
3 |
* |
* |
4 |
* This program is free software; you can redistribute it and/or |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
* modify it under the terms of the GNU General Public License as |
21 |
#include <cairomm/context.h> |
#include <cairomm/context.h> |
22 |
#include <gdkmm/cursor.h> |
#include <gdkmm/cursor.h> |
23 |
#include <gdkmm/general.h> |
#include <gdkmm/general.h> |
24 |
|
#include <glibmm/stringutils.h> |
25 |
|
#include <gtkmm/stock.h> |
26 |
|
#include <glibmm/ustring.h> |
27 |
|
#include <gtkmm/messagedialog.h> |
28 |
|
|
29 |
#include "global.h" |
#include "global.h" |
30 |
|
|
31 |
DimRegionChooser::DimRegionChooser() : |
// taken from gdk/gdkkeysyms.h |
32 |
|
// (define on demand, to avoid unnecessary dev lib package build dependency) |
33 |
|
#ifndef GDK_KEY_Control_L |
34 |
|
# define GDK_KEY_Control_L 0xffe3 |
35 |
|
#endif |
36 |
|
#ifndef GDK_KEY_Control_R |
37 |
|
# define GDK_KEY_Control_R 0xffe4 |
38 |
|
#endif |
39 |
|
|
40 |
|
static std::map<gig::dimension_t,int> caseOfDimRegion(gig::DimensionRegion* dr, bool* isValidZone) { |
41 |
|
std::map<gig::dimension_t,int> dimCase; |
42 |
|
if (!dr) { |
43 |
|
*isValidZone = false; |
44 |
|
return dimCase; |
45 |
|
} |
46 |
|
|
47 |
|
gig::Region* rgn = (gig::Region*) dr->GetParent(); |
48 |
|
|
49 |
|
// find the dimension region index of the passed dimension region |
50 |
|
int drIndex; |
51 |
|
for (drIndex = 0; drIndex < 256; ++drIndex) |
52 |
|
if (rgn->pDimensionRegions[drIndex] == dr) |
53 |
|
break; |
54 |
|
|
55 |
|
// not found in region, something's horribly wrong |
56 |
|
if (drIndex == 256) { |
57 |
|
fprintf(stderr, "DimRegionChooser: ERROR: index of dim region not found!\n"); |
58 |
|
*isValidZone = false; |
59 |
|
return std::map<gig::dimension_t,int>(); |
60 |
|
} |
61 |
|
|
62 |
|
for (int d = 0, baseBits = 0; d < rgn->Dimensions; ++d) { |
63 |
|
const int bits = rgn->pDimensionDefinitions[d].bits; |
64 |
|
dimCase[rgn->pDimensionDefinitions[d].dimension] = |
65 |
|
(drIndex >> baseBits) & ((1 << bits) - 1); |
66 |
|
baseBits += bits; |
67 |
|
// there are also DimensionRegion objects of unused zones, skip them |
68 |
|
if (dimCase[rgn->pDimensionDefinitions[d].dimension] >= rgn->pDimensionDefinitions[d].zones) { |
69 |
|
*isValidZone = false; |
70 |
|
return std::map<gig::dimension_t,int>(); |
71 |
|
} |
72 |
|
} |
73 |
|
|
74 |
|
*isValidZone = true; |
75 |
|
return dimCase; |
76 |
|
} |
77 |
|
|
78 |
|
DimRegionChooser::DimRegionChooser(Gtk::Window& window) : |
79 |
red("#8070ff"), |
red("#8070ff"), |
80 |
black("black"), |
black("black"), |
81 |
white("white") |
white("white") |
82 |
{ |
{ |
83 |
instrument = 0; |
instrument = 0; |
84 |
region = 0; |
region = 0; |
85 |
dimregno = -1; |
maindimregno = -1; |
86 |
focus_line = 0; |
focus_line = 0; |
87 |
resize.active = false; |
resize.active = false; |
88 |
cursor_is_resize = false; |
cursor_is_resize = false; |
89 |
h = 20; |
h = 24; |
90 |
|
multiSelectKeyDown = false; |
91 |
set_can_focus(); |
set_can_focus(); |
92 |
|
|
93 |
|
actionGroup = Gtk::ActionGroup::create(); |
94 |
|
actionGroup->add( |
95 |
|
Gtk::Action::create("SplitDimZone", _("Split Dimensions Zone")), |
96 |
|
sigc::mem_fun(*this, &DimRegionChooser::split_dimension_zone) |
97 |
|
); |
98 |
|
actionGroup->add( |
99 |
|
Gtk::Action::create("DeleteDimZone", _("Delete Dimension Zone")), |
100 |
|
sigc::mem_fun(*this, &DimRegionChooser::delete_dimension_zone) |
101 |
|
); |
102 |
|
|
103 |
|
uiManager = Gtk::UIManager::create(); |
104 |
|
uiManager->insert_action_group(actionGroup); |
105 |
|
Glib::ustring ui_info = |
106 |
|
"<ui>" |
107 |
|
" <popup name='PopupMenuInsideDimRegion'>" |
108 |
|
" <menuitem action='SplitDimZone'/>" |
109 |
|
" <menuitem action='DeleteDimZone'/>" |
110 |
|
" </popup>" |
111 |
|
// " <popup name='PopupMenuOutsideDimRegion'>" |
112 |
|
// " <menuitem action='Add'/>" |
113 |
|
// " </popup>" |
114 |
|
"</ui>"; |
115 |
|
uiManager->add_ui_from_string(ui_info); |
116 |
|
|
117 |
|
popup_menu_inside_dimregion = dynamic_cast<Gtk::Menu*>( |
118 |
|
uiManager->get_widget("/PopupMenuInsideDimRegion")); |
119 |
|
// popup_menu_outside_dimregion = dynamic_cast<Gtk::Menu*>( |
120 |
|
// uiManager->get_widget("/PopupMenuOutsideDimRegion")); |
121 |
|
|
122 |
add_events(Gdk::BUTTON_PRESS_MASK | Gdk::POINTER_MOTION_MASK | |
add_events(Gdk::BUTTON_PRESS_MASK | Gdk::POINTER_MOTION_MASK | |
123 |
Gdk::POINTER_MOTION_HINT_MASK); |
Gdk::POINTER_MOTION_HINT_MASK); |
124 |
|
|
|
for (int i = 0 ; i < 256 ; i++) dimvalue[i] = 0; |
|
125 |
labels_changed = true; |
labels_changed = true; |
126 |
|
|
127 |
|
set_tooltip_text(_( |
128 |
|
"Right click here for options on altering dimension zones. Press and " |
129 |
|
"hold CTRL key for selecting multiple dimension zones simultaniously." |
130 |
|
)); |
131 |
|
|
132 |
|
window.signal_key_press_event().connect( |
133 |
|
sigc::mem_fun(*this, &DimRegionChooser::onKeyPressed) |
134 |
|
); |
135 |
|
window.signal_key_release_event().connect( |
136 |
|
sigc::mem_fun(*this, &DimRegionChooser::onKeyReleased) |
137 |
|
); |
138 |
} |
} |
139 |
|
|
140 |
DimRegionChooser::~DimRegionChooser() |
DimRegionChooser::~DimRegionChooser() |
151 |
|
|
152 |
const Cairo::RefPtr<Cairo::Context>& cr = |
const Cairo::RefPtr<Cairo::Context>& cr = |
153 |
get_window()->create_cairo_context(); |
get_window()->create_cairo_context(); |
|
#if 0 |
|
|
} |
|
|
#endif |
|
154 |
#else |
#else |
155 |
bool DimRegionChooser::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) |
bool DimRegionChooser::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) |
156 |
{ |
{ |
266 |
for (int i = 0 ; i < region->Dimensions ; i++) { |
for (int i = 0 ; i < region->Dimensions ; i++) { |
267 |
int nbZones = region->pDimensionDefinitions[i].zones; |
int nbZones = region->pDimensionDefinitions[i].zones; |
268 |
if (nbZones) { |
if (nbZones) { |
269 |
|
const gig::dimension_t dimension = region->pDimensionDefinitions[i].dimension; |
270 |
|
|
271 |
if (y >= clipy2) break; |
if (y >= clipy2) break; |
272 |
if (y + h > clipy1) { |
if (y + h > clipy1) { |
273 |
// draw focus rectangle around dimension's label and zones |
// draw focus rectangle around dimension's label and zones |
274 |
if (has_focus() && focus_line == i) { |
if (has_focus() && focus_line == i) { |
275 |
#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 |
276 |
Gdk::Rectangle farea(0, y, 150, 20); |
Gdk::Rectangle farea(0, y, 150, h); |
277 |
get_style()->paint_focus(get_window(), get_state(), farea, |
get_style()->paint_focus(get_window(), get_state(), farea, |
278 |
*this, "", |
*this, "", |
279 |
0, y, label_width, 20); |
0, y, label_width, h); |
280 |
#else |
#else |
281 |
get_style_context()->render_focus(cr, |
get_style_context()->render_focus(cr, |
282 |
0, y, label_width, 20); |
0, y, label_width, h); |
283 |
#endif |
#endif |
284 |
} |
} |
285 |
|
|
298 |
cr->fill(); |
cr->fill(); |
299 |
|
|
300 |
int c = 0; |
int c = 0; |
301 |
if (dimregno >= 0) { |
if (maindimregno >= 0) { |
302 |
int mask = |
int mask = |
303 |
~(((1 << region->pDimensionDefinitions[i].bits) - 1) << |
~(((1 << region->pDimensionDefinitions[i].bits) - 1) << |
304 |
bitpos); |
bitpos); |
305 |
c = dimregno & mask; // mask away this dimension |
c = maindimregno & mask; // mask away this dimension |
306 |
} |
} |
307 |
bool customsplits = |
bool customsplits = |
308 |
((region->pDimensionDefinitions[i].split_type == |
((region->pDimensionDefinitions[i].split_type == |
312 |
gig::dimension_velocity && |
gig::dimension_velocity && |
313 |
region->pDimensionRegions[c]->VelocityUpperLimit)); |
region->pDimensionRegions[c]->VelocityUpperLimit)); |
314 |
|
|
315 |
// draw dimension's zone borders |
// draw dimension zones |
316 |
Gdk::Cairo::set_source_rgba(cr, black); |
Gdk::Cairo::set_source_rgba(cr, black); |
317 |
if (customsplits) { |
if (customsplits) { |
318 |
cr->move_to(label_width + 0.5, y + 1); |
cr->move_to(label_width + 0.5, y + 1); |
319 |
cr->line_to(label_width + 0.5, y + h - 1); |
cr->line_to(label_width + 0.5, y + h - 1); |
320 |
|
int prevX = label_width; |
321 |
|
int prevUpperLimit = -1; |
322 |
|
|
323 |
for (int j = 0 ; j < nbZones ; j++) { |
for (int j = 0 ; j < nbZones ; j++) { |
324 |
|
// draw dimension zone's borders for custom splits |
325 |
gig::DimensionRegion* d = |
gig::DimensionRegion* d = |
326 |
region->pDimensionRegions[c + (j << bitpos)]; |
region->pDimensionRegions[c + (j << bitpos)]; |
327 |
int upperLimit = d->DimensionUpperLimits[i]; |
int upperLimit = d->DimensionUpperLimits[i]; |
331 |
label_width; |
label_width; |
332 |
if (x >= clipx2) break; |
if (x >= clipx2) break; |
333 |
if (x < clipx1) continue; |
if (x < clipx1) continue; |
334 |
|
Gdk::Cairo::set_source_rgba(cr, black); |
335 |
cr->move_to(x + 0.5, y + 1); |
cr->move_to(x + 0.5, y + 1); |
336 |
cr->line_to(x + 0.5, y + h - 1); |
cr->line_to(x + 0.5, y + h - 1); |
337 |
|
cr->stroke(); |
338 |
|
|
339 |
|
// draw fill for zone |
340 |
|
bool isSelectedZone = this->dimzones[dimension].count(j); |
341 |
|
Gdk::Cairo::set_source_rgba(cr, isSelectedZone ? red : white); |
342 |
|
cr->rectangle(prevX + 1, y + 1, x - prevX - 1, h - 1); |
343 |
|
cr->fill(); |
344 |
|
|
345 |
|
// draw text showing the beginning of the dimension zone |
346 |
|
// as numeric value to the user |
347 |
|
{ |
348 |
|
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context); |
349 |
|
layout->set_text(Glib::Ascii::dtostr(prevUpperLimit+1)); |
350 |
|
Gdk::Cairo::set_source_rgba(cr, black); |
351 |
|
// get the text dimensions |
352 |
|
int text_width, text_height; |
353 |
|
layout->get_pixel_size(text_width, text_height); |
354 |
|
// move text to the left end of the dimension zone |
355 |
|
cr->move_to(prevX + 3, y + (h - text_height) / 2); |
356 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2 |
357 |
|
pango_cairo_show_layout(cr->cobj(), layout->gobj()); |
358 |
|
#else |
359 |
|
layout->show_in_cairo_context(cr); |
360 |
|
#endif |
361 |
|
} |
362 |
|
// draw text showing the end of the dimension zone |
363 |
|
// as numeric value to the user |
364 |
|
{ |
365 |
|
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context); |
366 |
|
layout->set_text(Glib::Ascii::dtostr(upperLimit)); |
367 |
|
Gdk::Cairo::set_source_rgba(cr, black); |
368 |
|
// get the text dimensions |
369 |
|
int text_width, text_height; |
370 |
|
layout->get_pixel_size(text_width, text_height); |
371 |
|
// move text to the left end of the dimension zone |
372 |
|
cr->move_to(x - 3 - text_width, y + (h - text_height) / 2); |
373 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2 |
374 |
|
pango_cairo_show_layout(cr->cobj(), layout->gobj()); |
375 |
|
#else |
376 |
|
layout->show_in_cairo_context(cr); |
377 |
|
#endif |
378 |
|
} |
379 |
|
|
380 |
|
prevX = x; |
381 |
|
prevUpperLimit = upperLimit; |
382 |
} |
} |
383 |
} else { |
} else { |
384 |
|
int prevX = 0; |
385 |
for (int j = 0 ; j <= nbZones ; j++) { |
for (int j = 0 ; j <= nbZones ; j++) { |
386 |
|
// draw dimension zone's borders for normal splits |
387 |
int x = int((w - label_width - 1) * j / |
int x = int((w - label_width - 1) * j / |
388 |
double(nbZones) + 0.5) + label_width; |
double(nbZones) + 0.5) + label_width; |
389 |
if (x >= clipx2) break; |
if (x >= clipx2) break; |
390 |
if (x < clipx1) continue; |
if (x < clipx1) continue; |
391 |
|
Gdk::Cairo::set_source_rgba(cr, black); |
392 |
cr->move_to(x + 0.5, y + 1); |
cr->move_to(x + 0.5, y + 1); |
393 |
cr->line_to(x + 0.5, y + h - 1); |
cr->line_to(x + 0.5, y + h - 1); |
394 |
} |
cr->stroke(); |
395 |
} |
|
396 |
cr->stroke(); |
if (j != 0) { |
397 |
|
// draw fill for zone |
398 |
|
bool isSelectedZone = this->dimzones[dimension].count(j-1); |
399 |
|
Gdk::Cairo::set_source_rgba(cr, isSelectedZone ? red : white); |
400 |
|
cr->rectangle(prevX + 1, y + 1, x - prevX - 1, h - 1); |
401 |
|
cr->fill(); |
402 |
|
|
403 |
// draw fill for currently selected zone |
// draw text showing the beginning of the dimension zone |
404 |
if (dimregno >= 0) { |
// as numeric value to the user |
405 |
Gdk::Cairo::set_source_rgba(cr, red); |
{ |
406 |
int dr = (dimregno >> bitpos) & |
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context); |
407 |
((1 << region->pDimensionDefinitions[i].bits) - 1); |
layout->set_text(Glib::Ascii::dtostr((j-1) * 128/nbZones)); |
408 |
if (customsplits) { |
Gdk::Cairo::set_source_rgba(cr, black); |
409 |
int x1 = label_width; |
// get the text dimensions |
410 |
for (int j = 0 ; j < nbZones && x1 + 1 < clipx2 ; j++) { |
int text_width, text_height; |
411 |
gig::DimensionRegion* d = |
layout->get_pixel_size(text_width, text_height); |
412 |
region->pDimensionRegions[c + (j << bitpos)]; |
// move text to the left end of the dimension zone |
413 |
int upperLimit = d->DimensionUpperLimits[i]; |
cr->move_to(prevX + 3, y + (h - text_height) / 2); |
414 |
if (!upperLimit) { |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2 |
415 |
upperLimit = d->VelocityUpperLimit; |
pango_cairo_show_layout(cr->cobj(), layout->gobj()); |
416 |
|
#else |
417 |
|
layout->show_in_cairo_context(cr); |
418 |
|
#endif |
419 |
} |
} |
420 |
int v = upperLimit + 1; |
// draw text showing the end of the dimension zone |
421 |
int x2 = int((w - label_width - 1) * v / 128.0 + |
// as numeric value to the user |
422 |
0.5) + label_width; |
{ |
423 |
if (j == dr && x1 < x2) { |
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context); |
424 |
cr->rectangle(x1 + 1, y + 1, |
layout->set_text(Glib::Ascii::dtostr(j * 128/nbZones - 1)); |
425 |
(x2 - x1) - 1, h - 2); |
Gdk::Cairo::set_source_rgba(cr, black); |
426 |
cr->fill(); |
// get the text dimensions |
427 |
break; |
int text_width, text_height; |
428 |
|
layout->get_pixel_size(text_width, text_height); |
429 |
|
// move text to the left end of the dimension zone |
430 |
|
cr->move_to(x - 3 - text_width, y + (h - text_height) / 2); |
431 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2 |
432 |
|
pango_cairo_show_layout(cr->cobj(), layout->gobj()); |
433 |
|
#else |
434 |
|
layout->show_in_cairo_context(cr); |
435 |
|
#endif |
436 |
} |
} |
|
x1 = x2; |
|
|
} |
|
|
} else { |
|
|
if (dr < nbZones) { |
|
|
int x1 = int((w - label_width - 1) * dr / |
|
|
double(nbZones) + 0.5); |
|
|
int x2 = int((w - label_width - 1) * (dr + 1) / |
|
|
double(nbZones) + 0.5); |
|
|
cr->rectangle(label_width + x1 + 1, y + 1, |
|
|
(x2 - x1) - 1, h - 2); |
|
|
cr->fill(); |
|
437 |
} |
} |
438 |
} |
prevX = x; |
439 |
|
} |
440 |
} |
} |
441 |
} |
} |
|
|
|
442 |
y += h; |
y += h; |
443 |
} |
} |
444 |
bitpos += region->pDimensionDefinitions[i].bits; |
bitpos += region->pDimensionDefinitions[i].bits; |
450 |
void DimRegionChooser::set_region(gig::Region* region) |
void DimRegionChooser::set_region(gig::Region* region) |
451 |
{ |
{ |
452 |
this->region = region; |
this->region = region; |
453 |
dimregno = 0; |
maindimregno = 0; |
454 |
nbDimensions = 0; |
nbDimensions = 0; |
455 |
if (region) { |
if (region) { |
456 |
int bitcount = 0; |
int bitcount = 0; |
458 |
if (region->pDimensionDefinitions[dim].bits == 0) continue; |
if (region->pDimensionDefinitions[dim].bits == 0) continue; |
459 |
nbDimensions++; |
nbDimensions++; |
460 |
|
|
461 |
int z = std::min(dimvalue[region->pDimensionDefinitions[dim].dimension], |
int z = std::min(maindimcase[region->pDimensionDefinitions[dim].dimension], |
462 |
region->pDimensionDefinitions[dim].zones - 1); |
region->pDimensionDefinitions[dim].zones - 1); |
463 |
dimregno |= (z << bitcount); |
maindimregno |= (z << bitcount); |
464 |
bitcount += region->pDimensionDefinitions[dim].bits; |
bitcount += region->pDimensionDefinitions[dim].bits; |
465 |
} |
} |
|
dimreg = region->pDimensionRegions[dimregno]; |
|
|
} else { |
|
|
dimreg = 0; |
|
466 |
} |
} |
467 |
dimregion_selected(); |
dimregion_selected(); |
468 |
set_size_request(800, region ? nbDimensions * 20 : 0); |
set_size_request(800, region ? nbDimensions * h : 0); |
469 |
|
|
470 |
labels_changed = true; |
labels_changed = true; |
471 |
queue_resize(); |
queue_resize(); |
472 |
|
queue_draw(); |
473 |
} |
} |
474 |
|
|
475 |
|
void DimRegionChooser::refresh_all() { |
476 |
|
set_region(region); |
477 |
|
} |
478 |
|
|
479 |
void DimRegionChooser::get_dimregions(const gig::Region* region, bool stereo, |
void DimRegionChooser::get_dimregions(const gig::Region* region, bool stereo, |
480 |
std::set<gig::DimensionRegion*>& dimregs) const |
std::set<gig::DimensionRegion*>& dimregs) const |
481 |
{ |
{ |
482 |
int dimregno = 0; |
for (int iDimRgn = 0; iDimRgn < 256; ++iDimRgn) { |
483 |
int bitcount = 0; |
gig::DimensionRegion* dimRgn = region->pDimensionRegions[iDimRgn]; |
484 |
int stereo_bit = 0; |
if (!dimRgn) continue; |
485 |
for (int dim = 0 ; dim < region->Dimensions ; dim++) { |
bool isValidZone; |
486 |
if (region->pDimensionDefinitions[dim].bits == 0) continue; |
std::map<gig::dimension_t,int> dimCase = caseOfDimRegion(dimRgn, &isValidZone); |
487 |
if (stereo && |
if (!isValidZone) continue; |
488 |
region->pDimensionDefinitions[dim].dimension == gig::dimension_samplechannel) { |
for (std::map<gig::dimension_t,int>::const_iterator it = dimCase.begin(); |
489 |
stereo_bit = (1 << bitcount); |
it != dimCase.end(); ++it) |
490 |
} else { |
{ |
491 |
int z = std::min(dimvalue[region->pDimensionDefinitions[dim].dimension], |
if (stereo && it->first == gig::dimension_samplechannel) continue; // is selected |
492 |
region->pDimensionDefinitions[dim].zones - 1); |
|
493 |
dimregno |= (z << bitcount); |
std::map<gig::dimension_t, std::set<int> >::const_iterator itSelectedDimension = |
494 |
|
this->dimzones.find(it->first); |
495 |
|
if (itSelectedDimension != this->dimzones.end() && |
496 |
|
itSelectedDimension->second.count(it->second)) continue; // is selected |
497 |
|
|
498 |
|
goto notSelected; |
499 |
} |
} |
500 |
bitcount += region->pDimensionDefinitions[dim].bits; |
|
501 |
|
dimregs.insert(dimRgn); |
502 |
|
|
503 |
|
notSelected: |
504 |
|
; |
505 |
} |
} |
|
dimregs.insert(region->pDimensionRegions[dimregno]); |
|
|
if (stereo_bit) dimregs.insert(region->pDimensionRegions[dimregno | stereo_bit]); |
|
506 |
} |
} |
507 |
|
|
508 |
void DimRegionChooser::update_after_resize() |
void DimRegionChooser::update_after_resize() |
515 |
} |
} |
516 |
int mask = |
int mask = |
517 |
~(((1 << region->pDimensionDefinitions[resize.dimension].bits) - 1) << bitpos); |
~(((1 << region->pDimensionDefinitions[resize.dimension].bits) - 1) << bitpos); |
518 |
int c = dimregno & mask; // mask away this dimension |
int c = maindimregno & mask; // mask away this dimension |
519 |
|
|
520 |
if (region->pDimensionRegions[c]->DimensionUpperLimits[resize.dimension] == 0) { |
if (region->pDimensionRegions[c]->DimensionUpperLimits[resize.dimension] == 0) { |
521 |
// the velocity dimension didn't previously have |
// the velocity dimension didn't previously have |
642 |
} |
} |
643 |
|
|
644 |
int i = dim; |
int i = dim; |
645 |
if (dimregno < 0) dimregno = 0; |
if (maindimregno < 0) maindimregno = 0; |
646 |
int mask = ~(((1 << region->pDimensionDefinitions[i].bits) - 1) << bitpos); |
int mask = ~(((1 << region->pDimensionDefinitions[i].bits) - 1) << bitpos); |
647 |
int c = dimregno & mask; // mask away this dimension |
int c = this->maindimregno & mask; // mask away this dimension |
648 |
|
|
649 |
bool customsplits = |
bool customsplits = |
650 |
((region->pDimensionDefinitions[i].split_type == gig::split_type_normal && |
((region->pDimensionDefinitions[i].split_type == gig::split_type_normal && |
674 |
region->pDimensionDefinitions[dim].split_type, |
region->pDimensionDefinitions[dim].split_type, |
675 |
region->pDimensionDefinitions[dim].zones, |
region->pDimensionDefinitions[dim].zones, |
676 |
region->pDimensionDefinitions[dim].zone_size); |
region->pDimensionDefinitions[dim].zone_size); |
677 |
dimvalue[region->pDimensionDefinitions[dim].dimension] = z; |
this->maindimcase[region->pDimensionDefinitions[dim].dimension] = z; |
678 |
|
this->maindimregno = c | (z << bitpos); |
679 |
dimregno = c | (z << bitpos); |
this->maindimtype = region->pDimensionDefinitions[dim].dimension; |
680 |
|
|
681 |
|
if (multiSelectKeyDown) { |
682 |
|
if (dimzones[this->maindimtype].count(z)) { |
683 |
|
if (dimzones[this->maindimtype].size() > 1) { |
684 |
|
dimzones[this->maindimtype].erase(z); |
685 |
|
} |
686 |
|
} else { |
687 |
|
dimzones[this->maindimtype].insert(z); |
688 |
|
} |
689 |
|
} else { |
690 |
|
this->dimzones.clear(); |
691 |
|
for (std::map<gig::dimension_t,int>::const_iterator it = this->maindimcase.begin(); |
692 |
|
it != this->maindimcase.end(); ++it) |
693 |
|
{ |
694 |
|
this->dimzones[it->first].insert(it->second); |
695 |
|
} |
696 |
|
} |
697 |
|
|
698 |
focus_line = dim; |
focus_line = dim; |
699 |
if (has_focus()) queue_draw(); |
if (has_focus()) queue_draw(); |
700 |
else grab_focus(); |
else grab_focus(); |
|
dimreg = region->pDimensionRegions[dimregno]; |
|
701 |
dimregion_selected(); |
dimregion_selected(); |
702 |
|
|
703 |
|
if (event->button == 3) { |
704 |
|
printf("dimregion right click\n"); |
705 |
|
popup_menu_inside_dimregion->popup(event->button, event->time); |
706 |
|
} |
707 |
|
|
708 |
|
queue_draw(); |
709 |
} |
} |
710 |
} |
} |
711 |
return true; |
return true; |
743 |
|
|
744 |
resize.pos = k; |
resize.pos = k; |
745 |
update_after_resize(); |
update_after_resize(); |
746 |
get_window()->invalidate_rect(rect, false); |
get_window()->invalidate_rect(rect, false); // not sufficient ... |
747 |
|
queue_draw(); // ... so do a complete redraw instead. |
748 |
} |
} |
749 |
} else { |
} else { |
750 |
if (is_in_resize_zone(x, y)) { |
if (is_in_resize_zone(x, y)) { |
780 |
int nbZones = region->pDimensionDefinitions[dim].zones; |
int nbZones = region->pDimensionDefinitions[dim].zones; |
781 |
|
|
782 |
int c = 0; |
int c = 0; |
783 |
if (dimregno >= 0) { |
if (maindimregno >= 0) { |
784 |
int mask = ~(((1 << region->pDimensionDefinitions[dim].bits) - 1) << bitpos); |
int mask = ~(((1 << region->pDimensionDefinitions[dim].bits) - 1) << bitpos); |
785 |
c = dimregno & mask; // mask away this dimension |
c = maindimregno & mask; // mask away this dimension |
786 |
} |
} |
787 |
const bool customsplits = |
const bool customsplits = |
788 |
((region->pDimensionDefinitions[dim].split_type == gig::split_type_normal && |
((region->pDimensionDefinitions[dim].split_type == gig::split_type_normal && |
809 |
resize.pos = limit; |
resize.pos = limit; |
810 |
resize.min = prev_limit; |
resize.min = prev_limit; |
811 |
|
|
812 |
int dr = (dimregno >> bitpos) & |
int dr = (maindimregno >> bitpos) & |
813 |
((1 << region->pDimensionDefinitions[dim].bits) - 1); |
((1 << region->pDimensionDefinitions[dim].bits) - 1); |
814 |
resize.selected = dr == iZone ? resize.left : |
resize.selected = dr == iZone ? resize.left : |
815 |
dr == iZone + 1 ? resize.right : resize.none; |
dr == iZone + 1 ? resize.right : resize.none; |
846 |
|
|
847 |
bool DimRegionChooser::on_focus(Gtk::DirectionType direction) |
bool DimRegionChooser::on_focus(Gtk::DirectionType direction) |
848 |
{ |
{ |
849 |
// TODO: kolla att region finns osv, dvs att det går att sätta |
// TODO: check that region exists etc, that is, that it's possible |
850 |
// fokus. |
// to set focus |
851 |
if (direction == Gtk::DIR_TAB_FORWARD || |
if (direction == Gtk::DIR_TAB_FORWARD || |
852 |
direction == Gtk::DIR_DOWN) { |
direction == Gtk::DIR_DOWN) { |
853 |
if (!has_focus()) { |
if (!has_focus()) { |
879 |
} |
} |
880 |
} |
} |
881 |
} else if (!has_focus()) { |
} else if (!has_focus()) { |
882 |
// TODO: kolla att focus_line finns! |
// TODO: check that focus_line exists |
883 |
grab_focus(); |
grab_focus(); |
884 |
return true; |
return true; |
885 |
} else { |
} else { |
886 |
// TODO: öka eller minska värde! |
// TODO: increase or decrease value |
887 |
|
} |
888 |
|
return false; |
889 |
|
} |
890 |
|
|
891 |
|
void DimRegionChooser::split_dimension_zone() { |
892 |
|
printf("split_dimension_zone() type=%d, zone=%d\n", maindimtype, maindimcase[maindimtype]); |
893 |
|
try { |
894 |
|
region->SplitDimensionZone(maindimtype, maindimcase[maindimtype]); |
895 |
|
} catch (RIFF::Exception e) { |
896 |
|
Gtk::MessageDialog msg(e.Message, false, Gtk::MESSAGE_ERROR); |
897 |
|
msg.run(); |
898 |
|
} catch (...) { |
899 |
|
Glib::ustring txt = _("An unknown exception occurred!"); |
900 |
|
Gtk::MessageDialog msg(txt, false, Gtk::MESSAGE_ERROR); |
901 |
|
msg.run(); |
902 |
|
} |
903 |
|
refresh_all(); |
904 |
|
} |
905 |
|
|
906 |
|
void DimRegionChooser::delete_dimension_zone() { |
907 |
|
printf("delete_dimension_zone() type=%d, zone=%d\n", maindimtype, maindimcase[maindimtype]); |
908 |
|
try { |
909 |
|
region->DeleteDimensionZone(maindimtype, maindimcase[maindimtype]); |
910 |
|
} catch (RIFF::Exception e) { |
911 |
|
Gtk::MessageDialog msg(e.Message, false, Gtk::MESSAGE_ERROR); |
912 |
|
msg.run(); |
913 |
|
} catch (...) { |
914 |
|
Glib::ustring txt = _("An unknown exception occurred!"); |
915 |
|
Gtk::MessageDialog msg(txt, false, Gtk::MESSAGE_ERROR); |
916 |
|
msg.run(); |
917 |
} |
} |
918 |
|
refresh_all(); |
919 |
|
} |
920 |
|
|
921 |
|
bool DimRegionChooser::onKeyPressed(GdkEventKey* key) { |
922 |
|
//printf("key down\n"); |
923 |
|
if (key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R) |
924 |
|
multiSelectKeyDown = true; |
925 |
|
return false; |
926 |
|
} |
927 |
|
|
928 |
|
bool DimRegionChooser::onKeyReleased(GdkEventKey* key) { |
929 |
|
//printf("key up\n"); |
930 |
|
if (key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R) |
931 |
|
multiSelectKeyDown = false; |
932 |
|
return false; |
933 |
|
} |
934 |
|
|
935 |
|
void DimRegionChooser::resetSelectedZones() { |
936 |
|
this->dimzones.clear(); |
937 |
|
if (!region) { |
938 |
|
queue_draw(); // redraw required parts |
939 |
|
return; |
940 |
|
} |
941 |
|
if (maindimregno < 0 || maindimregno >= region->DimensionRegions) { |
942 |
|
queue_draw(); // redraw required parts |
943 |
|
return; |
944 |
|
} |
945 |
|
if (!region->pDimensionRegions[maindimregno]) { |
946 |
|
queue_draw(); // redraw required parts |
947 |
|
return; |
948 |
|
} |
949 |
|
gig::DimensionRegion* dimrgn = region->pDimensionRegions[maindimregno]; |
950 |
|
|
951 |
|
bool isValidZone; |
952 |
|
this->maindimcase = caseOfDimRegion(dimrgn, &isValidZone); |
953 |
|
if (!isValidZone) { |
954 |
|
queue_draw(); // redraw required parts |
955 |
|
return; |
956 |
|
} |
957 |
|
|
958 |
|
for (std::map<gig::dimension_t,int>::const_iterator it = this->maindimcase.begin(); |
959 |
|
it != this->maindimcase.end(); ++it) |
960 |
|
{ |
961 |
|
this->dimzones[it->first].insert(it->second); |
962 |
|
} |
963 |
|
|
964 |
|
// redraw required parts |
965 |
|
queue_draw(); |
966 |
|
} |
967 |
|
|
968 |
|
bool DimRegionChooser::select_dimregion(gig::DimensionRegion* dimrgn) { |
969 |
|
if (!region) return false; //.selection failed |
970 |
|
|
971 |
|
for (int dr = 0; dr < region->DimensionRegions && region->pDimensionRegions[dr]; ++dr) { |
972 |
|
if (region->pDimensionRegions[dr] == dimrgn) { |
973 |
|
// reset dim region zone selection to the requested specific dim region case |
974 |
|
maindimregno = dr; |
975 |
|
resetSelectedZones(); |
976 |
|
|
977 |
|
// emit signal that dimregion selection has changed, for external entities |
978 |
|
dimregion_selected(); |
979 |
|
|
980 |
|
return true; // selection success |
981 |
|
} |
982 |
|
} |
983 |
|
|
984 |
|
return false; //.selection failed |
985 |
|
} |
986 |
|
|
987 |
|
gig::DimensionRegion* DimRegionChooser::get_main_dimregion() const { |
988 |
|
if (!region) return NULL; |
989 |
|
return region->pDimensionRegions[maindimregno]; |
990 |
} |
} |