Fix saving Lua Callbacks when un/register succeeds
[ardour.git] / gtk2_ardour / midi_scroomer.cc
index a38911d98c7579f0a4ef440eb12f0da2586c9ae3..6fad2cc1f1ce32aef2a14e6a359267ba335c7f33 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2008 Paul Davis 
+    Copyright (C) 2008 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include "midi_scroomer.h"
-
+#include <iostream>
 #include <cairomm/context.h>
 
-#include <iostream>
+#include "midi_scroomer.h"
+#include "ui_config.h"
 
-using namespace Gtkmm2ext;
 using namespace Gtk;
 using namespace std;
 
 //std::map<int, Glib::RefPtr<Gdk::Pixmap> > MidiScroomer::piano_pixmaps;
 
 MidiScroomer::MidiScroomer(Adjustment& adj)
-       : Gtkmm2ext::Scroomer(adj) {
+       : ArdourWidgets::Scroomer(adj)
+{
 
        adj.set_lower(0);
        adj.set_upper(127);
@@ -38,11 +38,13 @@ MidiScroomer::MidiScroomer(Adjustment& adj)
        set_min_page_size(12);
 }
 
-MidiScroomer::~MidiScroomer() {
+MidiScroomer::~MidiScroomer()
+{
 }
 
 bool
-MidiScroomer::on_expose_event(GdkEventExpose* ev) {
+MidiScroomer::on_expose_event(GdkEventExpose* ev)
+{
        Cairo::RefPtr<Cairo::Context> cc = get_window()->create_cairo_context();
        GdkRectangle comp_rect, clip_rect;
        Component first_comp = point_in(ev->area.y);
@@ -54,36 +56,36 @@ MidiScroomer::on_expose_event(GdkEventExpose* ev) {
        double note_width = 0.8 * get_width();
        double note_height = 1.4 * note2y;
        double black_shift = 0.1 * note2y;
-       double colors[6];
+       double colors[6] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
 
        //cerr << ev->area.y << " " << ev->area.height << endl;
 
        comp_rect.x = 0;
        comp_rect.width = get_width();
 
-       for(int i = first_comp; i <= last_comp; ++i) {
+       for (int i = first_comp; i <= last_comp; ++i) {
                Component comp = (Component) i;
                set_comp_rect(comp_rect, comp);
 
-               if(gdk_rectangle_intersect(&comp_rect, &ev->area, &clip_rect)) {
+               if (gdk_rectangle_intersect(&comp_rect, &ev->area, &clip_rect)) {
                        get_colors(colors, comp);
 
                        cc->rectangle(clip_rect.x, clip_rect.y, clip_rect.width, clip_rect.height);
                        cc->set_source_rgb (colors[3], colors[4], colors[5]);
                        cc->fill_preserve();
-                       
                        cc->clip();
+
                        cc->set_source_rgb(colors[0], colors[1], colors[2]);
                        cc->set_line_width(note_height);
 
                        lnote = 127 - (int) floor((double) (clip_rect.y + clip_rect.height) * y2note) - 1;
                        hnote = 127 - (int) floor((double) clip_rect.y * y2note) + 1;
 
-                       for(int note = lnote; note < hnote + 1; ++note) {
+                       for (int note = lnote; note < hnote + 1; ++note) {
                                double y = height - note * note2y;
                                bool draw = false;
-                               
-                               switch(note % 12) {
+
+                               switch (note % 12) {
                                case 1:
                                case 6:
                                        y -= black_shift;
@@ -100,7 +102,7 @@ MidiScroomer::on_expose_event(GdkEventExpose* ev) {
                                default:
                                        break;
                                }
-                               
+
                                if(draw) {
                                        cc->set_line_width(1.4 * note2y);
                                        cc->move_to(0, y);
@@ -109,6 +111,13 @@ MidiScroomer::on_expose_event(GdkEventExpose* ev) {
                                }
                        }
 
+                       if (i == Handle1 || i == Handle2) {
+                               cc->rectangle(comp_rect.x + 0.5f, comp_rect.y + 0.5f, comp_rect.width - 1.0f, comp_rect.height - 1.0f);
+                               cc->set_line_width(1.0f);
+                               cc->set_source_rgb (1.0f, 1.0f, 1.0f);
+                               cc->stroke();
+                       }
+
                        cc->reset_clip();
                }
        }
@@ -117,33 +126,34 @@ MidiScroomer::on_expose_event(GdkEventExpose* ev) {
 }
 
 void
-MidiScroomer::get_colors(double color[], Component comp) {
+MidiScroomer::get_colors(double color[], Component comp)
+{
        switch (comp) {
        case TopBase:
        case BottomBase:
-               color[0] = 0.24;
-               color[1] = 0.24;
-               color[2] = 0.24;
-               color[3] = 0.33;
-               color[4] = 0.33;
-               color[5] = 0.33;
+               color[0] = 0.24f;
+               color[1] = 0.24f;
+               color[2] = 0.24f;
+               color[3] = 0.33f;
+               color[4] = 0.33f;
+               color[5] = 0.33f;
                break;
        case Handle1:
        case Handle2:
-               color[0] = 0.38;
-               color[1] = 0.38;
-               color[2] = 0.38;
-               color[3] = 0.91;
-               color[4] = 0.91;
-               color[5] = 0.91;
+               color[0] = 0.91f;
+               color[1] = 0.91f;
+               color[2] = 0.91f;
+               color[3] = 0.0f;
+               color[4] = 0.0f;
+               color[5] = 0.0f;
                break;
        case Slider:
-               color[0] = 0.38;
-               color[1] = 0.38;
-               color[2] = 0.38;
-               color[3] = 0.77;
-               color[4] = 0.77;
-               color[5] = 0.77;
+               color[0] = 0.38f;
+               color[1] = 0.38f;
+               color[2] = 0.38f;
+               color[3] = 0.77f;
+               color[4] = 0.77f;
+               color[5] = 0.77f;
                break;
        default:
                break;
@@ -151,14 +161,7 @@ MidiScroomer::get_colors(double color[], Component comp) {
 }
 
 void
-MidiScroomer::on_size_request(Gtk::Requisition* r) {
-       r->width = 16;
-       r->height = 100;
-       //r->width = 32;
-       //r->height = 512;
-}
-
-void
-MidiScroomer::on_size_allocate(Gtk::Allocation& a) {
-       Scroomer::on_size_allocate(a);
+MidiScroomer::on_size_request(Gtk::Requisition* r)
+{
+       r->width = std::max (12.f, rintf (12.f * UIConfiguration::instance().get_ui_scale()));
 }