Fixed issue #1510 (cross hair cursor, with options to enable from menu, color and line style can be configured)

This commit is contained in:
Matthias Koefferlein
2023-10-19 02:00:31 +02:00
parent 67d934194f
commit 45f3216530
9 changed files with 171 additions and 7 deletions
@@ -741,6 +741,10 @@ LayoutViewBase::configure (const std::string &name, const std::string &value)
return true;
}
if (mp_tracker && mp_tracker->configure (name, value)) {
return true;
}
if (name == cfg_default_lyp_file) {
m_def_lyp_file = value;
@@ -72,11 +72,15 @@ public:
options.push_back (std::pair<std::string, std::string> (cfg_sel_line_width, "1"));
options.push_back (std::pair<std::string, std::string> (cfg_sel_vertex_size, "3"));
options.push_back (std::pair<std::string, std::string> (cfg_sel_dither_pattern, "1"));
options.push_back (std::pair<std::string, std::string> (cfg_sel_line_style, "0"));
options.push_back (std::pair<std::string, std::string> (cfg_sel_halo, "true"));
options.push_back (std::pair<std::string, std::string> (cfg_sel_transient_mode, "true"));
options.push_back (std::pair<std::string, std::string> (cfg_sel_inside_pcells_mode, "false"));
options.push_back (std::pair<std::string, std::string> (cfg_tracking_cursor_enabled, "true"));
options.push_back (std::pair<std::string, std::string> (cfg_tracking_cursor_color, cc.to_string (tl::Color ())));
options.push_back (std::pair<std::string, std::string> (cfg_crosshair_cursor_color, cc.to_string (tl::Color ())));
options.push_back (std::pair<std::string, std::string> (cfg_crosshair_cursor_line_style, "0"));
options.push_back (std::pair<std::string, std::string> (cfg_crosshair_cursor_enabled, "false"));
options.push_back (std::pair<std::string, std::string> (cfg_background_color, cc.to_string (tl::Color ())));
options.push_back (std::pair<std::string, std::string> (cfg_ctx_color, cc.to_string (tl::Color ())));
options.push_back (std::pair<std::string, std::string> (cfg_ctx_dimming, "50"));
+69 -2
View File
@@ -24,20 +24,69 @@
#include "layMouseTracker.h"
#include "layLayoutCanvas.h"
#include "layLayoutViewBase.h"
#include "layConverters.h"
#include "laybasicConfig.h"
namespace lay
{
MouseTracker::MouseTracker (lay::LayoutViewBase *view)
: lay::ViewService (view->canvas ()), mp_view (view)
: lay::ViewService (view->canvas ()), mp_view (view),
m_cursor_color (tl::Color ()), m_cursor_line_style (0), m_cursor_enabled (false)
{
ui ()->grab_mouse (this, false);
}
bool
MouseTracker::leave_event (bool)
{
mp_markers.clear ();
return false;
}
bool
MouseTracker::configure (const std::string &name, const std::string &value)
{
if (name == cfg_crosshair_cursor_color) {
tl::Color color;
lay::ColorConverter ().from_string (value, color);
// Change the color
if (lay::test_and_set (m_cursor_color, color)) {
mp_markers.clear ();
}
} else if (name == cfg_crosshair_cursor_line_style) {
int dp = 0;
tl::from_string (value, dp);
// Change the vertex_size
if (lay::test_and_set (m_cursor_line_style, dp)) {
mp_markers.clear ();
}
} else if (name == cfg_crosshair_cursor_enabled) {
bool f = m_cursor_enabled;
tl::from_string (value, f);
if (f != m_cursor_enabled) {
m_cursor_enabled = f;
mp_markers.clear ();
}
}
return false; // not taken
}
bool
MouseTracker::mouse_move_event (const db::DPoint &p, unsigned int /*buttons*/, bool prio)
{
if (prio) {
// NOTE: by catching events with low prio, the tracking position was already set by consumers
// with high prio
if (! prio) {
// NOTE: because the tracker grabs first and grabbers are registered first gets served last, the
// tracker will receive the event after all other mouse grabbers have been served and had their
@@ -50,6 +99,24 @@ MouseTracker::mouse_move_event (const db::DPoint &p, unsigned int /*buttons*/, b
mp_view->current_pos (tp.x (), tp.y ());
mp_markers.clear ();
if (m_cursor_enabled) {
double max_coord = 1e30; // big enough I guess
mp_markers.push_back (new lay::DMarker (mp_view));
mp_markers.back ()->set_line_style (m_cursor_line_style);
mp_markers.back ()->set_color (m_cursor_color);
mp_markers.back ()->set (db::DEdge (db::DPoint (tp.x (), -max_coord), db::DPoint (tp.x (), max_coord)));
mp_markers.push_back (new lay::DMarker (mp_view));
mp_markers.back ()->set_line_style (m_cursor_line_style);
mp_markers.back ()->set_color (m_cursor_color);
mp_markers.back ()->set (db::DEdge (db::DPoint (-max_coord, tp.y ()), db::DPoint (max_coord, tp.y ())));
}
}
return false;
+9
View File
@@ -25,6 +25,8 @@
#define HDR_layMouseTracker
#include "layViewObject.h"
#include "layMarker.h"
#include "tlObject.h"
class QMouseEvent;
@@ -38,10 +40,17 @@ class MouseTracker
{
public:
MouseTracker (lay::LayoutViewBase *view);
virtual bool mouse_move_event (const db::DPoint &p, unsigned int buttons, bool prio);
bool leave_event (bool prio);
bool configure (const std::string &name, const std::string &value);
private:
lay::LayoutViewBase *mp_view;
tl::shared_collection<lay::DMarker> mp_markers;
tl::Color m_cursor_color;
int m_cursor_line_style;
bool m_cursor_enabled;
};
}
+1 -1
View File
@@ -41,7 +41,7 @@ public:
MoveService (lay::LayoutViewBase *view);
~MoveService ();
virtual bool configure (const std::string &name, const std::string &value);
bool configure (const std::string &name, const std::string &value);
bool begin_move (db::Transaction *transaction = 0, bool transient_selection = false);
private:
+3
View File
@@ -77,6 +77,9 @@ static const std::string cfg_sel_inside_pcells_mode ("sel-inside-pcells-mode");
static const std::string cfg_tracking_cursor_color ("tracking-cursor-color");
static const std::string cfg_tracking_cursor_enabled ("tracking-cursor-enabled");
static const std::string cfg_crosshair_cursor_color ("crosshair-cursor-color");
static const std::string cfg_crosshair_cursor_line_style ("crosshair-cursor-line-style");
static const std::string cfg_crosshair_cursor_enabled ("crosshair-cursor-enabled");
static const std::string cfg_markers_visible ("markers-visible");