1 #include <../../nrnconf.h>
4 #include <InterViews/canvas.h>
5 #include <InterViews/transformer.h>
6 #include <InterViews/label.h>
7 #include <InterViews/hit.h>
8 #include <InterViews/cursor.h>
9 #include <IV-look/kit.h>
21 #define LineRubberMarker_event_ "Crosshair Graph"
22 #define DeleteLabelHandler_event_ "Delete Graph"
23 #define ChangeLabelHandler_event_ "ChangeText"
24 #define DeleteLineHandler_event_ "Delete Graph"
25 #define LinePicker_event_ "Pick Graph"
26 #define MoveLabelBand_press_ "MoveText Graph"
34 virtual ~LineRubberMarker();
55 virtual ~MoveLabelBand();
68 class DeleteLabelHandler:
public Handler {
70 DeleteLabelHandler(
GLabel*);
71 ~DeleteLabelHandler();
72 virtual bool event(
Event&);
78 class ChangeLabelHandler:
public Handler {
80 ChangeLabelHandler(
GLabel*);
81 ~ChangeLabelHandler();
82 virtual bool event(
Event&);
88 class DeleteLineHandler:
public Handler {
92 virtual bool event(
Event&);
118 if (h.count() && h.target(depth, 0)) {
121 if (h.event() && h.event()->type() == Event::down &&
122 h.event()->pointer_button() == Event::left) {
123 Coord x = h.left(),
y = h.bottom();
126 if (
near(
x,
y, 10,
c->transformer())) {
127 h.target(depth,
this, 0,
new LineRubberMarker(
this,
NULL,
c));
131 if (
near(
x,
y, 10,
c->transformer())) {
132 h.target(depth,
this, 0,
new DeleteLineHandler(
this));
136 if (
near(
x,
y, 10,
c->transformer())) {
141 if (
near(
x,
y, 5,
c->transformer())) {
142 h.target(depth,
this, 0,
new LinePicker(
this));
149 if (h.count() && h.target(depth, 0)) {
152 if (h.event() && h.event()->type() == Event::down &&
153 h.event()->pointer_button() == Event::left) {
154 Coord x = h.left(), y = h.bottom();
157 h.target(depth,
this, 0,
new LineRubberMarker(a.
x(), a.
y(),
NULL,
c));
168 Coord xc, yc, x1, x2, y1, y2;
171 if (index < x_->count() - 1) {
179 t.transform(xcm, ycm, xc, yc);
190 t.transform(x1, y1,
x,
y);
192 #define Norm2(lval, arg) \
193 t.transform(x_->get_val(arg), y_->get_val(arg), xt, yt); \
194 lval = MyMath::norm2(x - xt, y - yt);
197 if (index_begin < 0) {
200 for (
i = 1;
i < count; ++
i) {
208 float dxleft, dxright;
211 dxleft = dxright = dxmin;
213 Norm2(dxleft,
i - 1);
216 Norm2(dxright,
i + 1);
218 if (dxright < dxleft) {
219 while (++
i < count) {
260 LineRubberMarker::~LineRubberMarker() {
265 bool LineRubberMarker::event(
Event& e) {
267 if (e.type() == Event::down) {
274 if (e.mapkey(
buf, 1) > 0) {
284 if (e.type() == Event::down) {
286 }
else if (e.type() == Event::up) {
295 transformer().transform(
x_,
y_, x, y);
299 c->transformer(identity);
310 void LineRubberMarker::draw(
Coord x,
Coord y) {
313 transformer().inverse_transform(x, y, x1, y1);
316 index_ = gl_->nearest(x1, y1, transformer(), index_);
337 if (h.count() && h.target(depth, 0)) {
340 if (h.event() && h.event()->type() == Event::down &&
341 h.event()->pointer_button() == Event::left) {
345 h.target(depth,
this, 0,
new MoveLabelBand(
this,
NULL,
c));
348 h.target(depth,
this, 0,
new DeleteLabelHandler(
this));
354 h.target(depth,
this, 0,
new ChangeLabelHandler(
this));
359 DeleteLabelHandler::DeleteLabelHandler(
GLabel* gl) {
364 DeleteLabelHandler::~DeleteLabelHandler() {
367 bool DeleteLabelHandler::event(
Event& e) {
369 if (e.type() == Event::down) {
370 Oc::help(DeleteLabelHandler_event_);
378 ChangeLabelHandler::ChangeLabelHandler(
GLabel* gl) {
383 ChangeLabelHandler::~ChangeLabelHandler() {
386 bool ChangeLabelHandler::event(
Event& e) {
388 if (e.type() == Event::down) {
389 Oc::help(ChangeLabelHandler_event_);
394 strcpy(
buf, gl_->text());
405 printf(
"No method for changeing label color %s\n", gl->
text());
409 printf(
"No method for changeing line color \n");
413 printf(
"No method for deleting label %s\n", gl->
text());
416 DeleteLineHandler::DeleteLineHandler(
GPolyLine* gpl) {
421 DeleteLineHandler::~DeleteLineHandler() {
424 bool DeleteLineHandler::event(
Event& e) {
426 if (e.type() == Event::down) {
435 gpl_->erase_line(
s,
i);
445 LinePicker::~LinePicker() {
448 void LinePicker::press(
Event&) {
463 void LinePicker::release(
Event&) {
468 void LinePicker::common() {
473 if (gpl_->label() && (
i =
s->glyph_index(gpl_->label())) >= 0) {
491 transformer().transform(x0_, y0_);
503 MoveLabelBand::~MoveLabelBand() {
509 void MoveLabelBand::press(
Event&) {
521 void MoveLabelBand::release(
Event&) {
526 Coord x1, y1, x2, y2;
528 transformer().inverse_transform(x(), y(), x2, y2);
529 transformer().inverse_transform(x_begin(), y_begin(), x1, y1);
545 gr->
move(index_, x1, y1);
554 a_.x_allotment().origin(x + x0_);
555 a_.y_allotment().origin(y + y0_);
557 c->rect(
a_.x_allotment().begin(),
558 a_.y_allotment().begin(),
559 a_.x_allotment().end(),
560 a_.y_allotment().end(),
void allot_y(const Allotment &)
void allot_x(const Allotment &)
const Color * color(int) const
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
virtual Glyph * clone() const
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
bool near(Coord, Coord, float, const Transformer &) const
int nearest(Coord, Coord, const Transformer &, int index=-1) const
virtual GlyphIndex glyph_index(const Glyph *)
static bool label_chooser(const char *, char *, GLabel *, Coord x=400., Coord y=400.)
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
static bool near_line(Coord x, Coord y, Coord x1, Coord y1, Coord x2, Coord y2, float epsilon)
static void help(const char *)
virtual void unref() const
const Event & event() const
virtual void undraw(Coord x, Coord y)
virtual void release(Event &)
static const Color * color()
static const Brush * brush()
virtual void press(Event &)
virtual void draw(Coord x, Coord y)
virtual void change_label_color(GLabel *)
void move(GlyphIndex, Coord x, Coord y)
virtual void delete_label(GLabel *)
void location(GlyphIndex, Coord &x, Coord &y) const
virtual void change_line_color(GPolyLine *)
virtual void allotment(GlyphIndex, DimensionName, Allotment &) const
virtual void view_ratio(float xratio, float yratio, Coord &x, Coord &y) const
virtual Scene * scene() const
virtual void ratio_view(Coord x, Coord y, float &xratio, float &yratio) const
static XYView * current_pick_view()
#define y_(arg)
Crout matrix decomposition : Forward/Backward substitution.
int Sprintf(char(&buf)[N], const char *fmt, Args &&... args)
Redirect sprintf to snprintf if the buffer size can be deduced.