/[svn]/gigedit/trunk/src/dimregionchooser.cpp
ViewVC logotype

Annotation of /gigedit/trunk/src/dimregionchooser.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1197 - (hide annotations) (download)
Fri May 18 16:07:18 2007 UTC (15 years, 6 months ago) by persson
File size: 26299 byte(s)
* fixed last commit, which was bad - wrong file was committed

1 persson 1052 /*
2     * Copyright (C) 2006, 2007 Andreas Persson
3     *
4     * This program is free software; you can redistribute it and/or
5     * modify it under the terms of the GNU General Public License as
6     * published by the Free Software Foundation; either version 2, or (at
7     * your option) any later version.
8     *
9     * This program is distributed in the hope that it will be useful, but
10     * WITHOUT ANY WARRANTY; without even the implied warranty of
11     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12     * General Public License for more details.
13     *
14     * You should have received a copy of the GNU General Public License
15     * along with program; see the file COPYING. If not, write to the Free
16     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17     * 02110-1301 USA.
18     */
19    
20     #include "dimregionchooser.h"
21 persson 1092 #include <gdkmm/cursor.h>
22 persson 1052
23     DimRegionChooser::DimRegionChooser()
24     {
25     // get_window() would return 0 because the Gdk::Window has not yet been realized
26     // So we can only allocate the colors here - the rest will happen in on_realize().
27     Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
28    
29     black = Gdk::Color("black");
30     white = Gdk::Color("white");
31     red = Gdk::Color("#8070ff");
32     blue = Gdk::Color("blue");
33     green = Gdk::Color("green");
34    
35     colormap->alloc_color(black);
36     colormap->alloc_color(white);
37     colormap->alloc_color(red);
38     colormap->alloc_color(blue);
39     colormap->alloc_color(green);
40     instrument = 0;
41     region = 0;
42     dimregno = -1;
43     focus_line = 0;
44 persson 1092 resize.active = false;
45     cursor_is_resize = false;
46     h = 20;
47     w = 800;
48 persson 1052 set_flags(Gtk::CAN_FOCUS);
49 persson 1092 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::POINTER_MOTION_MASK |
50     Gdk::POINTER_MOTION_HINT_MASK);
51 persson 1052
52     for (int i = 0 ; i < 256 ; i++) {
53     dimvalue_from[i] = 0;
54     dimvalue_to[i] = 1;
55     }
56     }
57    
58     DimRegionChooser::~DimRegionChooser()
59     {
60     }
61    
62     void DimRegionChooser::on_realize()
63     {
64     // We need to call the base on_realize()
65     Gtk::DrawingArea::on_realize();
66    
67     // Now we can allocate any additional resources we need
68     Glib::RefPtr<Gdk::Window> window = get_window();
69     gc = Gdk::GC::create(window);
70     }
71    
72     bool DimRegionChooser::on_expose_event(GdkEventExpose* event)
73     {
74     if (!region) return true;
75    
76     // This is where we draw on the window
77     Glib::RefPtr<Gdk::Window> window = get_window();
78     Glib::RefPtr<Pango::Context> context = get_pango_context();
79    
80     Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);
81    
82     window->clear();
83     int y = 0;
84 persson 1078 double maxwidth = 0;
85 persson 1052 for (int i = 0 ; i < region->Dimensions ; i++) {
86 persson 1071
87     int nbZones = region->pDimensionDefinitions[i].zones;
88     if (nbZones) {
89 persson 1052 char* dstr;
90 persson 1071 char dstrbuf[10];
91 persson 1052 switch (region->pDimensionDefinitions[i].dimension) {
92     case gig::dimension_none: dstr="none"; break;
93     case gig::dimension_samplechannel: dstr="samplechannel"; break;
94     case gig::dimension_layer: dstr="layer"; break;
95     case gig::dimension_velocity: dstr="velocity"; break;
96     case gig::dimension_channelaftertouch: dstr="channelaftertouch"; break;
97     case gig::dimension_releasetrigger: dstr="releasetrigger"; break;
98     case gig::dimension_keyboard: dstr="keyboard"; break;
99     case gig::dimension_roundrobin: dstr="roundrobin"; break;
100     case gig::dimension_random: dstr="random"; break;
101 persson 1077 case gig::dimension_smartmidi: dstr="smartmidi"; break;
102     case gig::dimension_roundrobinkeyboard: dstr="roundrobinkeyboard"; break;
103 persson 1052 case gig::dimension_modwheel: dstr="modwheel"; break;
104     case gig::dimension_breath: dstr="breath"; break;
105     case gig::dimension_foot: dstr="foot"; break;
106     case gig::dimension_portamentotime: dstr="portamentotime"; break;
107     case gig::dimension_effect1: dstr="effect1"; break;
108     case gig::dimension_effect2: dstr="effect2"; break;
109     case gig::dimension_genpurpose1: dstr="genpurpose1"; break;
110     case gig::dimension_genpurpose2: dstr="genpurpose2"; break;
111     case gig::dimension_genpurpose3: dstr="genpurpose3"; break;
112     case gig::dimension_genpurpose4: dstr="genpurpose4"; break;
113     case gig::dimension_sustainpedal: dstr="sustainpedal"; break;
114     case gig::dimension_portamento: dstr="portamento"; break;
115     case gig::dimension_sostenutopedal: dstr="sostenutopedal"; break;
116     case gig::dimension_softpedal: dstr="softpedal"; break;
117     case gig::dimension_genpurpose5: dstr="genpurpose5"; break;
118     case gig::dimension_genpurpose6: dstr="genpurpose6"; break;
119     case gig::dimension_genpurpose7: dstr="genpurpose7"; break;
120     case gig::dimension_genpurpose8: dstr="genpurpose8"; break;
121     case gig::dimension_effect1depth: dstr="effect1depth"; break;
122     case gig::dimension_effect2depth: dstr="effect2depth"; break;
123     case gig::dimension_effect3depth: dstr="effect3depth"; break;
124     case gig::dimension_effect4depth: dstr="effect4depth"; break;
125     case gig::dimension_effect5depth: dstr="effect5depth"; break;
126 persson 1071 default:
127     sprintf(dstrbuf, "%d",
128     region->pDimensionDefinitions[i].dimension);
129     dstr = dstrbuf;
130     break;
131 persson 1052 }
132     layout->set_text(dstr);
133    
134 persson 1104 Pango::Rectangle rectangle = layout->get_logical_extents();
135 persson 1078 double text_w = double(rectangle.get_width()) / Pango::SCALE;
136     if (text_w > maxwidth) maxwidth = text_w;
137 persson 1104 double text_h = double(rectangle.get_height()) / Pango::SCALE;
138 persson 1052 Glib::RefPtr<const Gdk::GC> fg = get_style()->get_fg_gc(get_state());
139     window->draw_layout(fg, 4, int(y + (h - text_h) / 2 + 0.5), layout);
140    
141 persson 1078 }
142     y += h;
143     }
144     y = 0;
145     int bitpos = 0;
146     label_width = int(maxwidth + 10);
147     for (int i = 0 ; i < region->Dimensions ; i++) {
148     int nbZones = region->pDimensionDefinitions[i].zones;
149     if (nbZones) {
150    
151 persson 1052 if (has_focus() && focus_line == i) {
152 persson 1078 Gdk::Rectangle farea(0, y, 150, 20);
153 persson 1092 get_style()->paint_focus(window, get_state(), farea, *this, "",
154     0, y, label_width, 20);
155 persson 1052 }
156    
157     Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc();
158 persson 1078 window->draw_line(black, label_width, y, w - 1, y);
159     window->draw_line(black, w - 1, y + h - 1, label_width, y + h - 1);
160 persson 1092 window->draw_rectangle(get_style()->get_white_gc(), true,
161     label_width + 1, y + 1, (w - label_width - 2), h - 2);
162 persson 1052
163 persson 1071 int c = 0;
164     if (dimregno >= 0) {
165     int mask = ~(((1 << region->pDimensionDefinitions[i].bits) - 1) << bitpos);
166     c = dimregno & mask; // mask away this dimension
167     }
168     bool customsplits =
169     ((region->pDimensionDefinitions[i].split_type == gig::split_type_normal &&
170     region->pDimensionRegions[c]->DimensionUpperLimits[i]) ||
171     (region->pDimensionDefinitions[i].dimension == gig::dimension_velocity &&
172     region->pDimensionRegions[c]->VelocityUpperLimit));
173    
174     if (customsplits) {
175 persson 1078 window->draw_line(black, label_width, y + 1, label_width, y + h - 2);
176 persson 1071 for (int j = 0 ; j < nbZones ; j++) {
177     gig::DimensionRegion *d = region->pDimensionRegions[c + (j << bitpos)];
178     int upperLimit = d->DimensionUpperLimits[i];
179     if (!upperLimit) upperLimit = d->VelocityUpperLimit;
180     int v = upperLimit + 1;
181 persson 1078 int x = int((w - label_width - 1) * v / 128.0 + 0.5);
182     window->draw_line(black, label_width + x, y + 1, label_width + x, y + h - 2);
183 persson 1052 }
184     } else {
185 persson 1071 for (int j = 0 ; j <= nbZones ; j++) {
186 persson 1078 int x = int((w - label_width - 1) * j / double(nbZones) + 0.5);
187     window->draw_line(black, label_width + x, y + 1, label_width + x, y + h - 2);
188 persson 1052 }
189     }
190    
191     if (dimregno >= 0) {
192     gc->set_foreground(red);
193 persson 1071 int dr = (dimregno >> bitpos) & ((1 << region->pDimensionDefinitions[i].bits) - 1);
194     if (customsplits) {
195     int x1 = 0;
196     for (int j = 0 ; j < nbZones ; j++) {
197     gig::DimensionRegion *d = region->pDimensionRegions[c + (j << bitpos)];
198     int upperLimit = d->DimensionUpperLimits[i];
199     if (!upperLimit) upperLimit = d->VelocityUpperLimit;
200     int v = upperLimit + 1;
201 persson 1078 int x2 = int((w - label_width - 1) * v / 128.0 + 0.5);
202 persson 1071 if (j == dr && x1 < x2) {
203 persson 1092 window->draw_rectangle(gc, true, label_width + x1 + 1, y + 1,
204     (x2 - x1) - 1, h - 2);
205 persson 1052 break;
206     }
207     x1 = x2;
208     }
209     } else {
210 persson 1071 if (dr < nbZones) {
211 persson 1078 int x1 = int((w - label_width - 1) * dr / double(nbZones) + 0.5);
212     int x2 = int((w - label_width - 1) * (dr + 1) / double(nbZones) + 0.5);
213 persson 1092 window->draw_rectangle(gc, true, label_width + x1 + 1, y + 1,
214     (x2 - x1) - 1, h - 2);
215 persson 1052 }
216     }
217     }
218    
219     y += h;
220     }
221 persson 1071 bitpos += region->pDimensionDefinitions[i].bits;
222 persson 1052 }
223    
224     return true;
225     }
226    
227     void DimRegionChooser::on_size_request(GtkRequisition* requisition)
228     {
229     printf("DimRegionChooser::on_size_request\n");
230     *requisition = GtkRequisition();
231 persson 1089 requisition->height = region ? nbDimensions * 20 : 0;
232 persson 1052 requisition->width = 800;
233     }
234    
235     void DimRegionChooser::set_region(gig::Region* region)
236     {
237     this->region = region;
238     dimregno = 0;
239 persson 1089 nbDimensions = 0;
240 persson 1103 if (region) {
241 persson 1104 int bitcount = 0;
242 persson 1103 for (int dim = 0 ; dim < region->Dimensions ; dim++) {
243     if (region->pDimensionDefinitions[dim].bits == 0) continue;
244     nbDimensions++;
245 persson 1089
246 persson 1103 int from = dimvalue_from[region->pDimensionDefinitions[dim].dimension];
247     int to = dimvalue_to[region->pDimensionDefinitions[dim].dimension];
248     int z;
249     switch (region->pDimensionDefinitions[dim].split_type) {
250     case gig::split_type_normal:
251     z = int((to + from) / 2.0 / region->pDimensionDefinitions[dim].zone_size);
252     break;
253     case gig::split_type_bit:
254     z = std::min(from, region->pDimensionDefinitions[dim].zones - 1);
255     break;
256     }
257     int mask =
258     ~(((1 << region->pDimensionDefinitions[dim].bits) - 1) <<
259     bitcount);
260     dimregno &= mask;
261     dimregno |= (z << bitcount);
262     bitcount += region->pDimensionDefinitions[dim].bits;
263 persson 1052 }
264 persson 1103 dimreg = region->pDimensionRegions[dimregno];
265 persson 1104 } else {
266     dimreg = 0;
267 persson 1052 }
268     sel_changed_signal.emit();
269     queue_resize();
270     }
271    
272 persson 1092 bool DimRegionChooser::on_button_release_event(GdkEventButton* event)
273     {
274     if (resize.active) {
275     get_window()->pointer_ungrab(event->time);
276     resize.active = false;
277    
278     if (region->pDimensionDefinitions[resize.dimension].dimension == gig::dimension_velocity) {
279    
280     int bitpos = 0;
281     for (int j = 0 ; j < resize.dimension ; j++) {
282     bitpos += region->pDimensionDefinitions[j].bits;
283     }
284     int mask =
285 persson 1197 ~(((1 << region->pDimensionDefinitions[resize.dimension].bits) - 1) << bitpos);
286 persson 1092 int c = dimregno & mask; // mask away this dimension
287    
288 persson 1197 if (region->pDimensionRegions[c]->DimensionUpperLimits[resize.dimension] == 0) {
289     // the velocity dimension didn't previously have
290     // custom v3 splits, so we initialize all splits with
291     // default values
292     int nbZones = region->pDimensionDefinitions[resize.dimension].zones;
293     for (int j = 0 ; j < nbZones ; j++) {
294     gig::DimensionRegion *d = region->pDimensionRegions[c + (j << bitpos)];
295     d->DimensionUpperLimits[resize.dimension] = int(128.0 * (j + 1) / nbZones - 1);
296     }
297 persson 1092 }
298 persson 1197 if (region->pDimensionRegions[c]->VelocityUpperLimit == 0) {
299     // the velocity dimension didn't previously have
300     // custom v2 splits, so we initialize all splits with
301     // default values
302     int nbZones = region->pDimensionDefinitions[resize.dimension].zones;
303     for (int j = 0 ; j < nbZones ; j++) {
304     gig::DimensionRegion *d = region->pDimensionRegions[c + (j << bitpos)];
305     d->VelocityUpperLimit = int(128.0 * (j + 1) / nbZones - 1);
306     }
307     }
308 persson 1092
309 persson 1197 gig::DimensionRegion *d = region->pDimensionRegions[c + resize.offset];
310     // update both v2 and v3 values
311     d->DimensionUpperLimits[resize.dimension] = resize.pos - 1;
312     d->VelocityUpperLimit = resize.pos - 1;
313    
314 persson 1092 } else {
315     for (int i = 0 ; i < region->DimensionRegions ; ) {
316    
317 persson 1197 if (region->pDimensionRegions[i]->DimensionUpperLimits[resize.dimension] == 0) {
318     // the dimension didn't previously have custom
319     // limits, so we have to set default limits for
320     // all the dimension regions
321     int bitpos = 0;
322     for (int j = 0 ; j < resize.dimension ; j++) {
323     bitpos += region->pDimensionDefinitions[j].bits;
324     }
325     int nbZones = region->pDimensionDefinitions[resize.dimension].zones;
326    
327     for (int j = 0 ; j < nbZones ; j++) {
328     gig::DimensionRegion *d = region->pDimensionRegions[i + (j << bitpos)];
329     d->DimensionUpperLimits[resize.dimension] = int(128.0 * (j + 1) / nbZones - 1);
330     }
331     }
332 persson 1092 gig::DimensionRegion *d = region->pDimensionRegions[i + resize.offset];
333     d->DimensionUpperLimits[resize.dimension] = resize.pos - 1;
334    
335     int bitpos = 0;
336     int j;
337     for (j = 0 ; j < region->Dimensions ; j++) {
338     if (j != resize.dimension) {
339     int maxzones = 1 << region->pDimensionDefinitions[j].bits;
340     int dimj = (i >> bitpos) & (maxzones - 1);
341     if (dimj + 1 < region->pDimensionDefinitions[j].zones) break;
342     }
343     bitpos += region->pDimensionDefinitions[j].bits;
344     }
345     if (j == region->Dimensions) break;
346     i = (i & ~((1 << bitpos) - 1)) + (1 << bitpos);
347     }
348     }
349    
350     if (!is_in_resize_zone(event->x, event->y) && cursor_is_resize) {
351     get_window()->set_cursor();
352     cursor_is_resize = false;
353     }
354     }
355     return true;
356     }
357    
358 persson 1052 bool DimRegionChooser::on_button_press_event(GdkEventButton* event)
359     {
360 persson 1092 if (region && event->y < nbDimensions * h &&
361     event->x >= label_width && event->x < w) {
362 persson 1052
363 persson 1092 if (is_in_resize_zone(event->x, event->y)) {
364     Gdk::Cursor double_arrow(Gdk::SB_H_DOUBLE_ARROW);
365     get_window()->pointer_grab(false,
366     Gdk::BUTTON_RELEASE_MASK |
367     Gdk::POINTER_MOTION_MASK |
368     Gdk::POINTER_MOTION_HINT_MASK,
369     double_arrow, event->time);
370     resize.active = true;
371     } else {
372 persson 1089 int ydim = int(event->y / h);
373     int dim;
374     for (dim = 0 ; dim < region->Dimensions ; dim++) {
375     if (region->pDimensionDefinitions[dim].bits == 0) continue;
376     if (ydim == 0) break;
377     ydim--;
378     }
379 persson 1071 int nbZones = region->pDimensionDefinitions[dim].zones;
380 persson 1052
381     int z = -1;
382 persson 1071 int bitpos = 0;
383     for (int i = 0 ; i < dim ; i++) {
384     bitpos += region->pDimensionDefinitions[i].bits;
385     }
386 persson 1052
387 persson 1071 int i = dim;
388     if (dimregno < 0) dimregno = 0;
389     int mask = ~(((1 << region->pDimensionDefinitions[i].bits) - 1) << bitpos);
390     int c = dimregno & mask; // mask away this dimension
391 persson 1052
392 persson 1071 bool customsplits =
393     ((region->pDimensionDefinitions[i].split_type == gig::split_type_normal &&
394     region->pDimensionRegions[c]->DimensionUpperLimits[i]) ||
395     (region->pDimensionDefinitions[i].dimension == gig::dimension_velocity &&
396     region->pDimensionRegions[c]->VelocityUpperLimit));
397     if (customsplits) {
398 persson 1078 int val = int((event->x - label_width) * 128 / (w - label_width - 1));
399 persson 1071
400     if (region->pDimensionRegions[c]->DimensionUpperLimits[i]) {
401     for (z = 0 ; z < nbZones ; z++) {
402     gig::DimensionRegion *d = region->pDimensionRegions[c + (z << bitpos)];
403     if (val <= d->DimensionUpperLimits[i]) break;
404 persson 1052 }
405 persson 1071 } else {
406     for (z = 0 ; z < nbZones ; z++) {
407     gig::DimensionRegion *d = region->pDimensionRegions[c + (z << bitpos)];
408     if (val <= d->VelocityUpperLimit) break;
409     }
410 persson 1052 }
411 persson 1071 } else {
412 persson 1078 z = int((event->x - label_width) * nbZones / (w - label_width - 1));
413 persson 1052 }
414    
415     printf("dim=%d z=%d dimensionsource=%d split_type=%d zones=%d zone_size=%f\n", dim, z,
416     region->pDimensionDefinitions[dim].dimension,
417     region->pDimensionDefinitions[dim].split_type,
418     region->pDimensionDefinitions[dim].zones,
419     region->pDimensionDefinitions[dim].zone_size);
420 persson 1071 #if 0
421 persson 1052 switch (region->pDimensionDefinitions[dim].split_type) {
422     case gig::split_type_normal:
423     dimvalue_from[region->pDimensionDefinitions[dim].dimension] =
424     int(z * region->pDimensionDefinitions[dim].zone_size);
425     dimvalue_to[region->pDimensionDefinitions[dim].dimension] =
426     int((z + 1) * region->pDimensionDefinitions[dim].zone_size) - 1;
427     break;
428     case gig::split_type_bit:
429     dimvalue_from[region->pDimensionDefinitions[dim].dimension] = z;
430     dimvalue_to[region->pDimensionDefinitions[dim].dimension] = z + 1;
431     break;
432     }
433 persson 1071 #endif
434 persson 1052
435 persson 1071 dimregno = c | (z << bitpos);
436 persson 1052
437     focus_line = dim;
438     if (has_focus()) queue_draw();
439     else grab_focus();
440     dimreg = region->pDimensionRegions[dimregno];
441     sel_changed_signal.emit();
442     }
443     }
444     return true;
445     }
446    
447 persson 1092 bool DimRegionChooser::on_motion_notify_event(GdkEventMotion* event)
448     {
449     Glib::RefPtr<Gdk::Window> window = get_window();
450     int x, y;
451     Gdk::ModifierType state = Gdk::ModifierType(0);
452     window->get_pointer(x, y, state);
453    
454     if (resize.active) {
455     int k = int((x - label_width) * 128.0 / (w - label_width - 1) + 0.5);
456    
457     if (k < resize.min) k = resize.min;
458     else if (k > resize.max) k = resize.max;
459    
460     if (k < 2) k = 2; // k is upper limit + 1, upper limit 0 is forbidden
461    
462     if (k != resize.pos) {
463     Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc();
464     Glib::RefPtr<const Gdk::GC> white = get_style()->get_white_gc();
465    
466     int prevx = int((w - label_width - 1) * resize.pos / 128.0 + 0.5) + label_width;
467     int x = int((w - label_width - 1) * k / 128.0 + 0.5) + label_width;
468     int y = resize.dimension * h;
469    
470     if (resize.selected == resize.none) {
471     if (resize.pos != resize.min && resize.pos != resize.max) {
472     window->draw_line(white, prevx, y + 1, prevx, y + h - 2);
473     }
474     } else {
475     gc->set_foreground(red);
476    
477     Glib::RefPtr<const Gdk::GC> left;
478     Glib::RefPtr<const Gdk::GC> right;
479     if (resize.selected == resize.left) {
480     left = gc;
481     right = white;
482     } else {
483     left = white;
484     right = gc;
485     }
486    
487     if (k > resize.pos) {
488     int xx = resize.pos == resize.min ? 1 : 0;
489     window->draw_rectangle(left, true,
490     prevx + xx, y + 1, x - prevx - xx, h - 2);
491     } else {
492     int xx = resize.pos == resize.max ? 0 : 1;
493     window->draw_rectangle(right, true,
494     x, y + 1, prevx - x + xx, h - 2);
495     }
496     }
497     window->draw_line(black, x, y + 1, x, y + h - 2);
498     resize.pos = k;
499     }
500     } else {
501     if (is_in_resize_zone(x, y)) {
502     if (!cursor_is_resize) {
503     Gdk::Cursor double_arrow(Gdk::SB_H_DOUBLE_ARROW);
504     window->set_cursor(double_arrow);
505     cursor_is_resize = true;
506     }
507     } else if (cursor_is_resize) {
508     window->set_cursor();
509     cursor_is_resize = false;
510     }
511     }
512     return true;
513     }
514    
515     bool DimRegionChooser::is_in_resize_zone(double x, double y)
516     {
517     if (region && y < nbDimensions * h && x >= label_width && x < w) {
518     int ydim = int(y / h);
519     int dim;
520     int bitpos = 0;
521     for (dim = 0 ; dim < region->Dimensions ; dim++) {
522     if (region->pDimensionDefinitions[dim].bits == 0) continue;
523     if (ydim == 0) break;
524     ydim--;
525     bitpos += region->pDimensionDefinitions[dim].bits;
526     }
527     int nbZones = region->pDimensionDefinitions[dim].zones;
528    
529     int c = 0;
530     if (dimregno >= 0) {
531     int mask = ~(((1 << region->pDimensionDefinitions[dim].bits) - 1) << bitpos);
532     c = dimregno & mask; // mask away this dimension
533     }
534 schoenebeck 1185 const bool customsplits =
535 persson 1092 ((region->pDimensionDefinitions[dim].split_type == gig::split_type_normal &&
536     region->pDimensionRegions[c]->DimensionUpperLimits[dim]) ||
537     (region->pDimensionDefinitions[dim].dimension == gig::dimension_velocity &&
538     region->pDimensionRegions[c]->VelocityUpperLimit));
539    
540 schoenebeck 1185 // dimensions of split_type_bit cannot be resized
541     if (region->pDimensionDefinitions[dim].split_type != gig::split_type_bit) {
542 persson 1092 int prev_limit = 0;
543 schoenebeck 1185 for (int iZone = 0 ; iZone < nbZones - 1 ; iZone++) {
544     gig::DimensionRegion *d = region->pDimensionRegions[c + (iZone << bitpos)];
545     const int upperLimit =
546     (customsplits) ?
547     (d->DimensionUpperLimits[dim]) ?
548     d->DimensionUpperLimits[dim] : d->VelocityUpperLimit
549 persson 1197 : (iZone+1) * (int)region->pDimensionDefinitions[dim].zone_size - 1;
550 persson 1092 int limit = upperLimit + 1;
551     int limitx = int((w - label_width - 1) * limit / 128.0 + 0.5) + label_width;
552     if (x <= limitx - 2) break;
553     if (x <= limitx + 2) {
554     resize.dimension = dim;
555 schoenebeck 1185 resize.offset = iZone << bitpos;
556 persson 1092 resize.pos = limit;
557     resize.min = prev_limit;
558    
559     int dr = (dimregno >> bitpos) &
560     ((1 << region->pDimensionDefinitions[dim].bits) - 1);
561 schoenebeck 1185 resize.selected = dr == iZone ? resize.left :
562     dr == iZone + 1 ? resize.right : resize.none;
563 persson 1092
564 schoenebeck 1185 iZone++;
565     gig::DimensionRegion *d = region->pDimensionRegions[c + (iZone << bitpos)];
566    
567     const int upperLimit =
568     (customsplits) ?
569     (d->DimensionUpperLimits[dim]) ?
570     d->DimensionUpperLimits[dim] : d->VelocityUpperLimit
571 persson 1197 : (iZone+1) * (int)region->pDimensionDefinitions[dim].zone_size - 1;
572 schoenebeck 1185
573 persson 1092 int limit = upperLimit + 1;
574     resize.max = limit;
575     return true;
576     }
577     prev_limit = limit;
578     }
579     }
580     }
581     return false;
582     }
583    
584 persson 1052 sigc::signal<void> DimRegionChooser::signal_sel_changed()
585     {
586     return sel_changed_signal;
587     }
588    
589     bool DimRegionChooser::on_focus(Gtk::DirectionType direction)
590     {
591     // TODO: kolla att region finns osv, dvs att det g�r att s�tta
592     // fokus.
593     if (direction == Gtk::DIR_TAB_FORWARD ||
594     direction == Gtk::DIR_DOWN) {
595     if (!has_focus()) {
596     focus_line = 0;
597     grab_focus();
598     return true;
599     } else {
600     if (focus_line + 1 < region->Dimensions) {
601     focus_line++;
602     queue_draw();
603     return true;
604     } else {
605     return false;
606     }
607     }
608     } else if (direction == Gtk::DIR_TAB_BACKWARD ||
609     direction == Gtk::DIR_UP) {
610     if (!has_focus()) {
611     focus_line = region->Dimensions - 1;
612     grab_focus();
613     return true;
614     } else {
615     if (focus_line > 0) {
616     focus_line--;
617     queue_draw();
618     return true;
619     } else {
620     return false;
621     }
622     }
623     } else if (!has_focus()) {
624     // TODO: kolla att focus_line finns!
625     grab_focus();
626     return true;
627     } else {
628     // TODO: �ka eller minska v�rde!
629     }
630     }

  ViewVC Help
Powered by ViewVC