From 084d6e9f87fbe81d500fe2de273cefd8d78a0d77 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 26 Feb 2010 10:54:32 +0000 Subject: [PATCH] Use the Root widget for tooltips Add a status bar for non-tooltip-like status messages --- source/designer/designer.cpp | 96 +++++++++++++----------------------- source/designer/designer.h | 6 +-- 2 files changed, 37 insertions(+), 65 deletions(-) diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 9965568..a21dd09 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -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 &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(ui_res.get_default_font().get_string_width(text)*fontsize)+6; - x = max(min(static_cast(window.get_width())-w, x), 0); - y = max(min(static_cast(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(); +} diff --git a/source/designer/designer.h b/source/designer/designer.h index c4591ab..0f9b35d 100644 --- a/source/designer/designer.h +++ b/source/designer/designer.h @@ -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 -- 2.45.2