]> git.tdb.fi Git - r2c2.git/commitdiff
Use the Root widget for tooltips
authorMikko Rasa <tdb@tdb.fi>
Fri, 26 Feb 2010 10:54:32 +0000 (10:54 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 26 Feb 2010 10:54:32 +0000 (10:54 +0000)
Add a status bar for non-tooltip-like status messages

source/designer/designer.cpp
source/designer/designer.h

index 99655683c1a3bc772d3fe6737d336d2a6d2e7802..a21dd096497dcf36a34c67edfaeb21bc4a806974 100644 (file)
@@ -106,17 +106,22 @@ Designer::Designer(int argc, char **argv):
        // Setup UI
        DataFile::load(ui_res, "marklin.res");
        root = new GLtk::Root(ui_res, window);
-
-       lbl_tooltip = new GLtk::Label(ui_res);
-       lbl_tooltip->set_style("tooltip");
-       root->add(*lbl_tooltip);
-       lbl_tooltip->set_visible(false);
+       root->signal_tooltip.connect(sigc::mem_fun(this, &Designer::tooltip));
 
        toolbar = new Toolbar(*this);
        root->add(*toolbar);
        toolbar->set_position(0, window.get_height()-toolbar->get_geometry().h);
        toolbar->set_visible(true);
 
+       GLtk::Panel *statusbar = new GLtk::Panel(ui_res);
+       root->add(*statusbar);
+       statusbar->set_size(window.get_width(), 20);
+       statusbar->set_visible(true);
+
+       lbl_status = new GLtk::Label(ui_res);
+       statusbar->add(*lbl_status);
+       lbl_status->set_geometry(GLtk::Geometry(20, 2, 300, 16));
+
        overlay = new Overlay3D(window, camera, ui_res.get_default_font());
 
        const list<Track3D *> &tracks = layout_3d->get_tracks();
@@ -196,37 +201,9 @@ void Designer::tick()
        last_tick = t;
 
        window.get_display().tick();
+       root->tick();
        camera_ctl.tick(dt);
 
-       if(tooltip_timeout && t>tooltip_timeout)
-       {
-               Track3D *t3d = 0;
-
-               if(mode==CATALOGUE)
-                       t3d = pick_track(pointer_x, pointer_y);
-               else
-                       t3d = pick_track(pointer_x, pointer_y);
-
-               if(t3d)
-               {
-                       const Track &track = t3d->get_track();
-                       const TrackType &ttype = track.get_type();
-                       string info = format("%d %s", ttype.get_article_number(), ttype.get_description());
-                       if(mode!=CATALOGUE && abs(track.get_slope())>1e-4)
-                               info += format(" (slope %.1f%%)", abs(track.get_slope()/ttype.get_total_length()*100));
-                       if(track.get_turnout_id())
-                               info += format(" (turnout %d)", track.get_turnout_id());
-                       else if(track.get_sensor_id())
-                               info += format(" (sensor %d)", track.get_sensor_id());
-
-                       set_tooltip(pointer_x, pointer_y, info);
-               }
-               else
-                       clear_tooltip();
-
-               tooltip_timeout = Msp::Time::TimeStamp();
-       }
-
        render();
 
        window.swap_buffers();
@@ -425,14 +402,6 @@ void Designer::pointer_motion(int x, int y)
 {
        y = window.get_height()-y-1;
 
-       pointer_x = x;
-       pointer_y = y;
-
-       if(mode==SELECT || mode==CATALOGUE)
-               tooltip_timeout = Msp::Time::now()+100*Msp::Time::msec;
-
-       clear_tooltip();
-
        if(mode!=INPUT)
        {
                Point ground = map_pointer_coords(x, y);
@@ -545,11 +514,12 @@ void Designer::update_track_icon(Track3D &track)
 
 void Designer::manipulation_status(const string &status)
 {
-       set_tooltip(pointer_x, pointer_y, status);
+       lbl_status->set_text(status);
 }
 
 void Designer::manipulation_done(bool)
 {
+       lbl_status->set_text(string());
        mode = SELECT;
 }
 
@@ -560,31 +530,15 @@ void Designer::measure_changed()
        float d = sqrt(pard*pard+perpd*perpd);
        float adiff = measure.get_angle_difference()*180/M_PI;
        string info = format("Par %.1fmm - Perp %.1fmm - Total %.1fmm - Angle %.1f°", pard, perpd, d, adiff);
-       set_tooltip(pointer_x, pointer_y, info);
+       lbl_status->set_text(info);
 }
 
 void Designer::measure_done()
 {
+       lbl_status->set_text(string());
        mode = SELECT;
 }
 
-void Designer::set_tooltip(int x, int y, const std::string &text)
-{
-       int fontsize = ui_res.get_default_font().get_default_size();
-       int h = fontsize+6;
-       int w = static_cast<int>(ui_res.get_default_font().get_string_width(text)*fontsize)+6;
-       x = max(min(static_cast<int>(window.get_width())-w, x), 0);
-       y = max(min(static_cast<int>(window.get_height())-h, y), 0);
-       lbl_tooltip->set_text(text);
-       lbl_tooltip->set_geometry(GLtk::Geometry(x, y, w, h));
-       lbl_tooltip->set_visible(true);
-}
-
-void Designer::clear_tooltip()
-{
-       lbl_tooltip->set_visible(false);
-}
-
 void Designer::save_accept()
 {
        layout->save(input->get_text());
@@ -648,3 +602,23 @@ void Designer::view_all()
        camera.set_position(GL::Vector3(center.x, center.y-cam_dist*0.5, cam_dist*0.866));
        camera.set_look_direction(GL::Vector3(0, 0.5, -0.866));
 }
+
+string Designer::tooltip(int x, int y)
+{
+       if(Track3D *t3d = pick_track(x, y))
+       {
+               const Track &track = t3d->get_track();
+               const TrackType &ttype = track.get_type();
+               string info = format("%d %s", ttype.get_article_number(), ttype.get_description());
+               if(mode!=CATALOGUE && abs(track.get_slope())>1e-4)
+                       info += format(" (slope %.1f%%)", abs(track.get_slope()/ttype.get_total_length()*100));
+               if(track.get_turnout_id())
+                       info += format(" (turnout %d)", track.get_turnout_id());
+               else if(track.get_sensor_id())
+                       info += format(" (sensor %d)", track.get_sensor_id());
+
+               return info;
+       }
+
+       return string();
+}
index c4591abf5f1260991044d2b1839dd11448f161dd..0f9b35d6792aad4bd601335e72624a7b782352cb 100644 (file)
@@ -51,8 +51,7 @@ private:
        Msp::GLtk::Root *root;
 
        Toolbar *toolbar;
-       Msp::GLtk::Label *lbl_tooltip;
-       Msp::Time::TimeStamp tooltip_timeout;
+       Msp::GLtk::Label *lbl_status;
 
        Marklin::Catalogue catalogue;
        Marklin::Layout3D *cat_layout_3d;
@@ -75,8 +74,6 @@ private:
        CameraController camera_ctl;
 
        bool shift;
-       int pointer_x;
-       int pointer_y;
 
        Msp::Time::TimeStamp last_tick;
 
@@ -121,6 +118,7 @@ private:
        void sensor_id_accept();
        void input_dismiss();
        void view_all();
+       std::string tooltip(int, int);
 };
 
 #endif