NEURON
hocmark.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #if HAVE_IV // to end of file
3 
4 #include <stdio.h>
5 #include <InterViews/color.h>
6 #include <InterViews/brush.h>
7 #include "hocmark.h"
8 #include "oc2iv.h"
9 #include "rect.h"
10 #include "idraw.h"
11 
12 /*static*/ class HocMarkP : public HocMark {
13 public:
14  HocMarkP(char, float, const Color*, const Brush*);
15  virtual ~HocMarkP();
16 };
17 
18 
19 
20 HocMark::HocMark(char style, float size, const Color* c, const Brush* b)
21  : PolyGlyph(2)
22 {
23  style_ = style;
24  size_ = size;
25  c_ = c;
26  Resource::ref(c);
27  b_ = b;
28  Resource::ref(b);
29 }
30 
34 }
35 
36 void HocMark::request(Requisition& req) const {
37  float size = 1;
38  if (b_) {
39  size = b_->width();
40  }
41  Requirement rx(size_ + size, 0, 0, .5);
42  Requirement ry(size_ + size, 0, 0, .5);
43  req.require_x(rx);
44  req.require_y(ry);
45 }
46 void HocMark::allocate(Canvas* c, const Allocation& a, Extension& e) {
47  e.set(c, a);
48 }
49 void HocMark::draw(Canvas* c, const Allocation& a) const {
50  IfIdraw(pict());
51  for (long i = count() - 1; i >= 0; --i) {
52  component(i)->draw(c, a);
53  }
54  IfIdraw(end());
55 }
56 
57 HocMark* HocMark::instance(char style, float size,
58  const Color* c, const Brush* b)
59 {
60 //printf("HocMark::instance\n");
61  HocMark* m = search(style, size, c, b);
62  if (!m) {
63  switch (style) {
64  case 0:
65  case '+':
66  m = new HocMarkP(style, size, c, b);
67  break;
68  case 1:
69  case 'o':
70  m = new HocMark(style, size, c, b);
71  m->append(new Circle(size/2, false, c, b));
72  break;
73  case 2:
74  case 's':
75  m = new HocMark(style, size, c, b);
76  m->append(new Rectangle(size, size, false, c, b));
77  break;
78  case 3:
79  case 't':
80  m = new HocMark(style, size, c, b);
81  m->append(new Triangle(size, false, c, b));
82  break;
83  case 4:
84  case 'O':
85  m = new HocMark(style, size, c, b);
86  m->append(new Circle(size/2, true, c, b));
87  break;
88  case 5:
89  case 'S':
90  m = new HocMark(style, size, c, b);
91  m->append(new Rectangle(size, size, true, c, b));
92  break;
93  case 6:
94  case 'T':
95  m = new HocMark(style, size, c, b);
96  m->append(new Triangle(size, true, c, b));
97  break;
98  case 7:
99  case '|':
100  m = new HocMark(style, size, c, b);
101  m->append(new Line(0, size, .5, .5, c, b));
102  break;
103  case 8:
104  case '-':
105  m = new HocMark(style, size, c, b);
106  m->append(new Line(size, 0, .5, .5, c, b));
107  break;
108  default :
109  hoc_execerror("implemented styles are + o t s O T S | -; waiting on x *", 0);
110  }
111  add(m);
112  }
113  return m;
114 }
115 
116 void HocMark::add(HocMark* m) {
117  if (!mark_list_) {
118  mark_list_ = new PolyGlyph();
119  }
120  mark_list_->append(m);
121  most_recent_ = m;
122 }
123 
124 HocMark* HocMark::search(char style, float size,
125  const Color* c, const Brush* b)
126 {
127  HocMark* m;
128  if (!most_recent_) {
129  return NULL;
130  }
131  m = check(style, size, c, b);
132  if (m) {
133  return m;
134  }
135  for (long i = mark_list_->count() - 1; i >= 0; --i) {
136  most_recent_ = (HocMark*)mark_list_->component(i);
137  m = check(style, size, c, b);
138  if (m) {
139  return m;
140  }
141  }
142  return NULL;
143 }
144 
145 HocMark* HocMark::check(char style, float size,
146  const Color* c, const Brush* b)
147 {
148  if (
149  most_recent_->style_ == style
150  && most_recent_->size_ == size
151  && most_recent_->c_ == c
152  && most_recent_->b_ == b
153  ) {
154  return most_recent_;
155  }
156  return NULL;
157 }
158 
161 
162 
163 HocMarkP::HocMarkP(char style, float size, const Color* c, const Brush* b)
164  : HocMark(style, size, c, b)
165 {
166 //printf("new mark +\n");
167  append(new Line(size, 0, .5, .5, c, b));
168  append(new Line(0, size, .5, .5, c, b));
169 }
170 HocMarkP::~HocMarkP(){};
171 #endif
Definition: rect.h:76
static HocMark * instance(char style, float size, const Color *, const Brush *)
virtual ~HocMark()
void set(Canvas *, const Allocation &)
static HocMark * search(char style, float size, const Color *, const Brush *)
Definition: rect.h:89
#define Brush
Definition: _defines.h:59
#define Color
Definition: _defines.h:74
#define IfIdraw(arg)
Definition: idraw.h:61
static HocMark * check(char style, float size, const Color *, const Brush *)
virtual void ref() const
Definition: resource.cpp:47
#define PolyGlyph
Definition: _defines.h:207
#define e
Definition: passive0.cpp:24
virtual void request(Requisition &) const
virtual void draw(Canvas *, const Allocation &) const
void append(Item *ql, Item *q)
Definition: list.cpp:348
static double check(double t, Daspk *ida)
Definition: nrndaspk.cpp:214
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:741
static PolyGlyph * mark_list_
Definition: hocmark.h:35
#define Canvas
Definition: _defines.h:65
void require_y(const Requirement &)
Definition: geometry.h:248
virtual void unref() const
Definition: resource.cpp:52
inode< _nt-> end
Definition: multicore.cpp:985
static HocMark * most_recent_
Definition: hocmark.h:36
#define Line
Definition: _defines.h:11
void require_x(const Requirement &)
Definition: geometry.h:247
static int component(PyHocObject *po)
Definition: nrnpy_hoc.cpp:448
HocMark(char style, float size, const Color *, const Brush *)
static void add(HocMark *)
#define i
Definition: md1redef.h:12
#define c
#define add
Definition: redef.h:24
return NULL
Definition: cabcode.cpp:461
static realtype c_
static realtype b_
virtual void allocate(Canvas *, const Allocation &, Extension &)