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 HocMark::HocMark(char style, float size, const Color* c, const Brush* b)
20  : PolyGlyph(2) {
21  style_ = style;
22  size_ = size;
23  c_ = c;
25  b_ = b;
26  Resource::ref(b);
27 }
28 
32 }
33 
34 void HocMark::request(Requisition& req) const {
35  float size = 1;
36  if (b_) {
37  size = b_->width();
38  }
39  Requirement rx(size_ + size, 0, 0, .5);
40  Requirement ry(size_ + size, 0, 0, .5);
41  req.require_x(rx);
42  req.require_y(ry);
43 }
44 void HocMark::allocate(Canvas* c, const Allocation& a, Extension& e) {
45  e.set(c, a);
46 }
47 void HocMark::draw(Canvas* c, const Allocation& a) const {
48  IfIdraw(pict());
49  for (long i = count() - 1; i >= 0; --i) {
50  component(i)->draw(c, a);
51  }
52  IfIdraw(end());
53 }
54 
55 HocMark* HocMark::instance(char style, float size, const Color* c, const Brush* b) {
56  // printf("HocMark::instance\n");
57  HocMark* m = search(style, size, c, b);
58  if (!m) {
59  switch (style) {
60  case 0:
61  case '+':
62  m = new HocMarkP(style, size, c, b);
63  break;
64  case 1:
65  case 'o':
66  m = new HocMark(style, size, c, b);
67  m->append(new Circle(size / 2, false, c, b));
68  break;
69  case 2:
70  case 's':
71  m = new HocMark(style, size, c, b);
72  m->append(new Rectangle(size, size, false, c, b));
73  break;
74  case 3:
75  case 't':
76  m = new HocMark(style, size, c, b);
77  m->append(new Triangle(size, false, c, b));
78  break;
79  case 4:
80  case 'O':
81  m = new HocMark(style, size, c, b);
82  m->append(new Circle(size / 2, true, c, b));
83  break;
84  case 5:
85  case 'S':
86  m = new HocMark(style, size, c, b);
87  m->append(new Rectangle(size, size, true, c, b));
88  break;
89  case 6:
90  case 'T':
91  m = new HocMark(style, size, c, b);
92  m->append(new Triangle(size, true, c, b));
93  break;
94  case 7:
95  case '|':
96  m = new HocMark(style, size, c, b);
97  m->append(new Line(0, size, .5, .5, c, b));
98  break;
99  case 8:
100  case '-':
101  m = new HocMark(style, size, c, b);
102  m->append(new Line(size, 0, .5, .5, c, b));
103  break;
104  default:
105  hoc_execerror("implemented styles are + o t s O T S | -; waiting on x *", 0);
106  }
107  add(m);
108  }
109  return m;
110 }
111 
112 void HocMark::add(HocMark* m) {
113  if (!mark_list_) {
114  mark_list_ = new PolyGlyph();
115  }
116  mark_list_->append(m);
117  most_recent_ = m;
118 }
119 
120 HocMark* HocMark::search(char style, float size, const Color* c, const Brush* b) {
121  HocMark* m;
122  if (!most_recent_) {
123  return NULL;
124  }
125  m = check(style, size, c, b);
126  if (m) {
127  return m;
128  }
129  for (long i = mark_list_->count() - 1; i >= 0; --i) {
130  most_recent_ = (HocMark*) mark_list_->component(i);
131  m = check(style, size, c, b);
132  if (m) {
133  return m;
134  }
135  }
136  return NULL;
137 }
138 
139 HocMark* HocMark::check(char style, float size, const Color* c, const Brush* b) {
140  if (most_recent_->style_ == style && most_recent_->size_ == size && most_recent_->c_ == c &&
141  most_recent_->b_ == b) {
142  return most_recent_;
143  }
144  return NULL;
145 }
146 
149 
150 
151 HocMarkP::HocMarkP(char style, float size, const Color* c, const Brush* b)
152  : HocMark(style, size, c, b) {
153  // printf("new mark +\n");
154  append(new Line(size, 0, .5, .5, c, b));
155  append(new Line(0, size, .5, .5, c, b));
156 }
157 HocMarkP::~HocMarkP(){};
158 #endif
#define Color
Definition: _defines.h:72
#define Canvas
Definition: _defines.h:63
#define Brush
Definition: _defines.h:57
#define Line
Definition: _defines.h:9
#define PolyGlyph
Definition: _defines.h:205
Definition: rect.h:81
void set(Canvas *, const Allocation &)
const Brush * b_
Definition: hocmark.h:27
static HocMark * search(char style, float size, const Color *, const Brush *)
static HocMark * check(char style, float size, const Color *, const Brush *)
static HocMark * most_recent_
Definition: hocmark.h:37
HocMark(char style, float size, const Color *, const Brush *)
virtual void draw(Canvas *, const Allocation &) const
virtual ~HocMark()
float size_
Definition: hocmark.h:25
char style_
Definition: hocmark.h:28
virtual void request(Requisition &) const
static HocMark * instance(char style, float size, const Color *, const Brush *)
const Color * c_
Definition: hocmark.h:26
static void add(HocMark *)
static PolyGlyph * mark_list_
Definition: hocmark.h:36
virtual void allocate(Canvas *, const Allocation &, Extension &)
void require_x(const Requirement &)
Definition: geometry.h:243
void require_y(const Requirement &)
Definition: geometry.h:244
virtual void ref() const
Definition: resource.cpp:42
virtual void unref() const
Definition: resource.cpp:47
Definition: rect.h:95
#define i
Definition: md1redef.h:19
#define b_(arg)
Definition: crout.hpp:137
static int c
Definition: hoc.cpp:169
#define IfIdraw(arg)
Definition: idraw.h:102
void append(Item *ql, Item *q)
Definition: list.cpp:289
void hoc_execerror(const char *s1, const char *s2)
Definition: nrnoc_aux.cpp:39
static HocReturnType component(PyHocObject *po)
Definition: nrnpy_hoc.cpp:510
static realtype c_
#define NULL
Definition: spdefs.h:105