1 |
/* |
/* |
2 |
* Copyright (C) 2006-2014 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 |
17 |
* 02110-1301 USA. |
* 02110-1301 USA. |
18 |
*/ |
*/ |
19 |
|
|
20 |
|
#include <gtkmm/box.h> |
21 |
#include "dimregionchooser.h" |
#include "dimregionchooser.h" |
22 |
#include <cairomm/context.h> |
#include <cairomm/context.h> |
23 |
#include <gdkmm/cursor.h> |
#include <gdkmm/cursor.h> |
87 |
focus_line = 0; |
focus_line = 0; |
88 |
resize.active = false; |
resize.active = false; |
89 |
cursor_is_resize = false; |
cursor_is_resize = false; |
90 |
h = 20; |
h = 24; |
91 |
multiSelectKeyDown = false; |
multiSelectKeyDown = false; |
92 |
set_can_focus(); |
set_can_focus(); |
93 |
|
|
274 |
// draw focus rectangle around dimension's label and zones |
// draw focus rectangle around dimension's label and zones |
275 |
if (has_focus() && focus_line == i) { |
if (has_focus() && focus_line == i) { |
276 |
#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 |
277 |
Gdk::Rectangle farea(0, y, 150, 20); |
Gdk::Rectangle farea(0, y, 150, h); |
278 |
get_style()->paint_focus(get_window(), get_state(), farea, |
get_style()->paint_focus(get_window(), get_state(), farea, |
279 |
*this, "", |
*this, "", |
280 |
0, y, label_width, 20); |
0, y, label_width, h); |
281 |
#else |
#else |
282 |
get_style_context()->render_focus(cr, |
get_style_context()->render_focus(cr, |
283 |
0, y, label_width, 20); |
0, y, label_width, h); |
284 |
#endif |
#endif |
285 |
} |
} |
286 |
|
|
319 |
cr->move_to(label_width + 0.5, y + 1); |
cr->move_to(label_width + 0.5, y + 1); |
320 |
cr->line_to(label_width + 0.5, y + h - 1); |
cr->line_to(label_width + 0.5, y + h - 1); |
321 |
int prevX = label_width; |
int prevX = label_width; |
322 |
int prevUpperLimit = 0; |
int prevUpperLimit = -1; |
323 |
|
|
324 |
for (int j = 0 ; j < nbZones ; j++) { |
for (int j = 0 ; j < nbZones ; j++) { |
325 |
// draw dimension zone's borders for custom splits |
// draw dimension zone's borders for custom splits |
347 |
// as numeric value to the user |
// as numeric value to the user |
348 |
{ |
{ |
349 |
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context); |
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context); |
350 |
layout->set_text(Glib::Ascii::dtostr(prevUpperLimit)); |
layout->set_text(Glib::Ascii::dtostr(prevUpperLimit+1)); |
351 |
Gdk::Cairo::set_source_rgba(cr, black); |
Gdk::Cairo::set_source_rgba(cr, black); |
|
Pango::Rectangle rect = layout->get_logical_extents(); |
|
352 |
// get the text dimensions |
// get the text dimensions |
353 |
int text_width, text_height; |
int text_width, text_height; |
354 |
layout->get_pixel_size(text_width, text_height); |
layout->get_pixel_size(text_width, text_height); |
355 |
// move text to the left end of the dimension zone |
// move text to the left end of the dimension zone |
356 |
cr->move_to(prevX + 3, y + 1); |
cr->move_to(prevX + 3, y + (h - text_height) / 2); |
357 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2 |
358 |
pango_cairo_show_layout(cr->cobj(), layout->gobj()); |
pango_cairo_show_layout(cr->cobj(), layout->gobj()); |
359 |
#else |
#else |
366 |
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context); |
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context); |
367 |
layout->set_text(Glib::Ascii::dtostr(upperLimit)); |
layout->set_text(Glib::Ascii::dtostr(upperLimit)); |
368 |
Gdk::Cairo::set_source_rgba(cr, black); |
Gdk::Cairo::set_source_rgba(cr, black); |
|
Pango::Rectangle rect = layout->get_logical_extents(); |
|
369 |
// get the text dimensions |
// get the text dimensions |
370 |
int text_width, text_height; |
int text_width, text_height; |
371 |
layout->get_pixel_size(text_width, text_height); |
layout->get_pixel_size(text_width, text_height); |
372 |
// move text to the left end of the dimension zone |
// move text to the left end of the dimension zone |
373 |
cr->move_to(x - 3 - text_width, y + 1); |
cr->move_to(x - 3 - text_width, y + (h - text_height) / 2); |
374 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2 |
375 |
pango_cairo_show_layout(cr->cobj(), layout->gobj()); |
pango_cairo_show_layout(cr->cobj(), layout->gobj()); |
376 |
#else |
#else |
407 |
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context); |
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context); |
408 |
layout->set_text(Glib::Ascii::dtostr((j-1) * 128/nbZones)); |
layout->set_text(Glib::Ascii::dtostr((j-1) * 128/nbZones)); |
409 |
Gdk::Cairo::set_source_rgba(cr, black); |
Gdk::Cairo::set_source_rgba(cr, black); |
|
Pango::Rectangle rect = layout->get_logical_extents(); |
|
410 |
// get the text dimensions |
// get the text dimensions |
411 |
int text_width, text_height; |
int text_width, text_height; |
412 |
layout->get_pixel_size(text_width, text_height); |
layout->get_pixel_size(text_width, text_height); |
413 |
// move text to the left end of the dimension zone |
// move text to the left end of the dimension zone |
414 |
cr->move_to(prevX + 3, y + 1); |
cr->move_to(prevX + 3, y + (h - text_height) / 2); |
415 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2 |
416 |
pango_cairo_show_layout(cr->cobj(), layout->gobj()); |
pango_cairo_show_layout(cr->cobj(), layout->gobj()); |
417 |
#else |
#else |
424 |
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context); |
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context); |
425 |
layout->set_text(Glib::Ascii::dtostr(j * 128/nbZones - 1)); |
layout->set_text(Glib::Ascii::dtostr(j * 128/nbZones - 1)); |
426 |
Gdk::Cairo::set_source_rgba(cr, black); |
Gdk::Cairo::set_source_rgba(cr, black); |
|
Pango::Rectangle rect = layout->get_logical_extents(); |
|
427 |
// get the text dimensions |
// get the text dimensions |
428 |
int text_width, text_height; |
int text_width, text_height; |
429 |
layout->get_pixel_size(text_width, text_height); |
layout->get_pixel_size(text_width, text_height); |
430 |
// move text to the left end of the dimension zone |
// move text to the left end of the dimension zone |
431 |
cr->move_to(x - 3 - text_width, y + 1); |
cr->move_to(x - 3 - text_width, y + (h - text_height) / 2); |
432 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2 |
433 |
pango_cairo_show_layout(cr->cobj(), layout->gobj()); |
pango_cairo_show_layout(cr->cobj(), layout->gobj()); |
434 |
#else |
#else |
466 |
} |
} |
467 |
} |
} |
468 |
dimregion_selected(); |
dimregion_selected(); |
469 |
set_size_request(800, region ? nbDimensions * 20 : 0); |
set_size_request(800, region ? nbDimensions * h : 0); |
470 |
|
|
471 |
labels_changed = true; |
labels_changed = true; |
472 |
queue_resize(); |
queue_resize(); |
847 |
|
|
848 |
bool DimRegionChooser::on_focus(Gtk::DirectionType direction) |
bool DimRegionChooser::on_focus(Gtk::DirectionType direction) |
849 |
{ |
{ |
850 |
// 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 |
851 |
// fokus. |
// to set focus |
852 |
if (direction == Gtk::DIR_TAB_FORWARD || |
if (direction == Gtk::DIR_TAB_FORWARD || |
853 |
direction == Gtk::DIR_DOWN) { |
direction == Gtk::DIR_DOWN) { |
854 |
if (!has_focus()) { |
if (!has_focus()) { |
880 |
} |
} |
881 |
} |
} |
882 |
} else if (!has_focus()) { |
} else if (!has_focus()) { |
883 |
// TODO: kolla att focus_line finns! |
// TODO: check that focus_line exists |
884 |
grab_focus(); |
grab_focus(); |
885 |
return true; |
return true; |
886 |
} else { |
} else { |
887 |
// TODO: öka eller minska värde! |
// TODO: increase or decrease value |
888 |
} |
} |
889 |
|
return false; |
890 |
} |
} |
891 |
|
|
892 |
void DimRegionChooser::split_dimension_zone() { |
void DimRegionChooser::split_dimension_zone() { |
923 |
//printf("key down\n"); |
//printf("key down\n"); |
924 |
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) |
925 |
multiSelectKeyDown = true; |
multiSelectKeyDown = true; |
926 |
|
return false; |
927 |
} |
} |
928 |
|
|
929 |
bool DimRegionChooser::onKeyReleased(GdkEventKey* key) { |
bool DimRegionChooser::onKeyReleased(GdkEventKey* key) { |
930 |
//printf("key up\n"); |
//printf("key up\n"); |
931 |
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) |
932 |
multiSelectKeyDown = false; |
multiSelectKeyDown = false; |
933 |
|
return false; |
934 |
|
} |
935 |
|
|
936 |
|
void DimRegionChooser::resetSelectedZones() { |
937 |
|
this->dimzones.clear(); |
938 |
|
if (!region) { |
939 |
|
queue_draw(); // redraw required parts |
940 |
|
return; |
941 |
|
} |
942 |
|
if (maindimregno < 0 || maindimregno >= region->DimensionRegions) { |
943 |
|
queue_draw(); // redraw required parts |
944 |
|
return; |
945 |
|
} |
946 |
|
if (!region->pDimensionRegions[maindimregno]) { |
947 |
|
queue_draw(); // redraw required parts |
948 |
|
return; |
949 |
|
} |
950 |
|
gig::DimensionRegion* dimrgn = region->pDimensionRegions[maindimregno]; |
951 |
|
|
952 |
|
bool isValidZone; |
953 |
|
this->maindimcase = caseOfDimRegion(dimrgn, &isValidZone); |
954 |
|
if (!isValidZone) { |
955 |
|
queue_draw(); // redraw required parts |
956 |
|
return; |
957 |
|
} |
958 |
|
|
959 |
|
for (std::map<gig::dimension_t,int>::const_iterator it = this->maindimcase.begin(); |
960 |
|
it != this->maindimcase.end(); ++it) |
961 |
|
{ |
962 |
|
this->dimzones[it->first].insert(it->second); |
963 |
|
} |
964 |
|
|
965 |
|
// redraw required parts |
966 |
|
queue_draw(); |
967 |
|
} |
968 |
|
|
969 |
|
bool DimRegionChooser::select_dimregion(gig::DimensionRegion* dimrgn) { |
970 |
|
if (!region) return false; //.selection failed |
971 |
|
|
972 |
|
for (int dr = 0; dr < region->DimensionRegions && region->pDimensionRegions[dr]; ++dr) { |
973 |
|
if (region->pDimensionRegions[dr] == dimrgn) { |
974 |
|
// reset dim region zone selection to the requested specific dim region case |
975 |
|
maindimregno = dr; |
976 |
|
resetSelectedZones(); |
977 |
|
|
978 |
|
// emit signal that dimregion selection has changed, for external entities |
979 |
|
dimregion_selected(); |
980 |
|
|
981 |
|
return true; // selection success |
982 |
|
} |
983 |
|
} |
984 |
|
|
985 |
|
return false; //.selection failed |
986 |
} |
} |
987 |
|
|
988 |
gig::DimensionRegion* DimRegionChooser::get_main_dimregion() const { |
gig::DimensionRegion* DimRegionChooser::get_main_dimregion() const { |