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();
47 #if defined(WIN32) || MAC
55 virtual ~MoveLabelBand();
69 class DeleteLabelHandler:
public Handler {
71 DeleteLabelHandler(
GLabel*);
72 ~DeleteLabelHandler();
73 virtual bool event(
Event&);
79 class ChangeLabelHandler:
public Handler {
81 ChangeLabelHandler(
GLabel*);
82 ~ChangeLabelHandler();
83 virtual bool event(
Event&);
89 class DeleteLineHandler:
public Handler {
93 virtual bool event(
Event&);
119 if (h.count() && h.target(depth, 0)) {
122 if (h.event() && h.event()->type() == Event::down &&
124 Coord x = h.left(),
y = h.bottom();
127 if (
near(
x,
y, 10,
c->transformer())) {
128 h.target(depth,
this, 0,
new LineRubberMarker(
this,
NULL,
c));
132 if (
near(
x,
y, 10,
c->transformer())) {
133 h.target(depth,
this, 0,
new DeleteLineHandler(
this));
137 if (
near(
x,
y, 10,
c->transformer())) {
142 if (
near(
x,
y, 5,
c->transformer())) {
143 h.target(depth,
this, 0,
new LinePicker(
this));
150 if (h.count() && h.target(depth, 0)) {
153 if (h.event() && h.event()->type() == Event::down &&
155 Coord x = h.left(), y = h.bottom();
158 h.target(depth,
this, 0,
new LineRubberMarker(a.
x(), a.
y(),
NULL,
c));
172 if (index < x_->count() - 1) {
180 t.transform(xcm, ycm,
xc, yc);
191 t.transform(x1, y1,
x,
y);
193 #define Norm2(lval, arg) \
194 t.transform(x_->get_val(arg), y_->get_val(arg), xt, yt); \
195 lval = MyMath::norm2(x - xt, y - yt);
198 if (index_begin < 0) {
201 for (
i = 1;
i < count; ++
i) {
209 float dxleft, dxright;
212 dxleft = dxright = dxmin;
214 Norm2(dxleft,
i - 1);
217 Norm2(dxright,
i + 1);
219 if (dxright < dxleft) {
220 while (++
i < count) {
261 LineRubberMarker::~LineRubberMarker() {
266 bool LineRubberMarker::event(
Event&
e) {
268 if (
e.type() == Event::down) {
275 if (
e.mapkey(
buf, 1) > 0) {
284 #if defined(WIN32) || MAC
285 if (
e.type() == Event::down) {
287 }
else if (
e.type() == Event::up) {
296 transformer().transform(
x_,
y_, x, y);
300 c->transformer(identity);
301 #if !defined(WIN32) && !MAC
311 void LineRubberMarker::draw(
Coord x,
Coord y) {
314 transformer().inverse_transform(x, y, x1, y1);
317 index_ = gl_->nearest(x1, y1, transformer(), index_);
324 #if defined(WIN32) || MAC
338 if (h.count() && h.target(depth, 0)) {
341 if (h.event() && h.event()->type() == Event::down &&
346 h.target(depth,
this, 0,
new MoveLabelBand(
this,
NULL,
c));
349 h.target(depth,
this, 0,
new DeleteLabelHandler(
this));
355 h.target(depth,
this, 0,
new ChangeLabelHandler(
this));
360 DeleteLabelHandler::DeleteLabelHandler(
GLabel* gl) {
365 DeleteLabelHandler::~DeleteLabelHandler() {
368 bool DeleteLabelHandler::event(
Event&
e) {
370 if (
e.type() == Event::down) {
371 Oc::help(DeleteLabelHandler_event_);
379 ChangeLabelHandler::ChangeLabelHandler(
GLabel* gl) {
384 ChangeLabelHandler::~ChangeLabelHandler() {
387 bool ChangeLabelHandler::event(
Event&
e) {
389 if (
e.type() == Event::down) {
390 Oc::help(ChangeLabelHandler_event_);
395 strcpy(
buf, gl_->text());
406 printf(
"No method for changeing label color %s\n", gl->
text());
410 printf(
"No method for changeing line color \n");
414 printf(
"No method for deleting label %s\n", gl->
text());
417 DeleteLineHandler::DeleteLineHandler(
GPolyLine* gpl) {
422 DeleteLineHandler::~DeleteLineHandler() {
425 bool DeleteLineHandler::event(
Event&
e) {
427 if (
e.type() == Event::down) {
436 gpl_->erase_line(s,
i);
446 LinePicker::~LinePicker() {
469 void LinePicker::common() {
474 if (gpl_->label() && (
i = s->
glyph_index(gpl_->label())) >= 0) {
492 transformer().transform(x0_, y0_);
504 MoveLabelBand::~MoveLabelBand() {
517 #if 0 && !defined(WIN32)
518 cursor_ = canvas()->window()->cursor();
519 canvas()->window()->cursor(noCursor);
521 #if !defined(WIN32) && !MAC
531 Coord x1, y1, x2, y2;
533 transformer().inverse_transform(x(), y(), x2, y2);
534 transformer().inverse_transform(x_begin(), y_begin(), x1, y1);
550 gr->
move(index_, x1, y1);
551 #if 0 && !defined(WIN32)
552 canvas()->window()->cursor(cursor_);
562 a_.x_allotment().origin(x + x0_);
563 a_.y_allotment().origin(y + y0_);
564 #if defined(WIN32) || MAC
565 c->rect(
a_.x_allotment().begin(),
566 a_.y_allotment().begin(),
567 a_.x_allotment().end(),
568 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 GlyphIndex glyph_index(const Glyph *)
virtual void change_label_color(GLabel *)
void move(GlyphIndex, Coord x, Coord y)
virtual void damage(GlyphIndex)
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 modified(GlyphIndex)
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()
sprintf(buf, " if (secondorder) {\n" " int _i;\n" " for (_i = 0; _i < %d; ++_i) {\n" " _p[_slist%d[_i]] += dt*_p[_dlist%d[_i]];\n" " }}\n", numeqn, listnum, listnum)