Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/vaclgui/digset.hpp @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 1997-2002 Parsifal Software. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * digset.hpp | |
7 */ | |
8 | |
9 #ifndef DIGSET_HPP | |
10 #define DIGSET_HPP | |
11 | |
12 #include <icolor.hpp> | |
13 #include <ifont.hpp> | |
14 #include <ipainevt.hpp> | |
15 //#include <ipoint.hpp> | |
16 #include <irect.hpp> | |
17 | |
18 #include "cint.h" | |
19 #include "dspar.hpp" | |
20 | |
21 | |
22 class DigSetter | |
23 { | |
24 public: | |
25 struct Style { | |
26 FontSpec &font; | |
27 ColorSpec &color; | |
28 Style() | |
29 : color(ColorSpec::defaultSetting) | |
30 , font(FontSpec::defaultSetting) | |
31 {} | |
32 Style(FontSpec &f, ColorSpec &color_) | |
33 : font(f) | |
34 , color(color_) | |
35 {} | |
36 int enWidth() { | |
37 IFont &f = font; | |
38 return f.avgCharWidth(); | |
39 } | |
40 int height() { | |
41 IFont &f = font; | |
42 return f.maxSize().height(); | |
43 } | |
44 int topToBaseline() { | |
45 IFont &f = font; | |
46 return f.maxAscender(); | |
47 } | |
48 int descender() { | |
49 IFont &f = font; | |
50 return f.maxDescender(); | |
51 } | |
52 }; | |
53 | |
54 struct Dig { | |
55 char *text; | |
56 int textLength; | |
57 cint where; | |
58 int width; | |
59 int styleIndex; | |
60 Dig() {} | |
61 Dig(char *text_, const int length, const cint where_, const int index) | |
62 : text(text_) | |
63 , textLength(length) | |
64 , where(where_) | |
65 , styleIndex(index) | |
66 , width(0) | |
67 {} | |
68 Dig(const Dig &dig) | |
69 : text(dig.text) | |
70 , textLength(dig.textLength) | |
71 , where(dig.where) | |
72 , styleIndex(dig.styleIndex) | |
73 , width(dig.width) | |
74 {} | |
75 int operator < (const Dig &d) const { return where < d.where; } | |
76 }; | |
77 | |
78 struct Hole { | |
79 cint where; | |
80 cint size; | |
81 int styleIndex; | |
82 Hole() {} | |
83 Hole(cint where_, cint size_, int index) | |
84 : where(where_) | |
85 , size(size_) | |
86 , styleIndex(index) | |
87 {} | |
88 Hole(IRectangle r, int index = 0) | |
89 : where(r.minX(), r.minY()) | |
90 , size(r.size().width(), r.size().height()) | |
91 , styleIndex(index) | |
92 {} | |
93 int operator < (const Hole &d) const { return where < d.where; } | |
94 }; | |
95 | |
96 protected: | |
97 IWindow *window; | |
98 IPaintEvent *event; | |
99 Style *style; | |
100 int currentStyleIndex; | |
101 int windowHeight; | |
102 IPresSpaceHandle presSpaceHandle; | |
103 | |
104 public: | |
105 DigSetter(IWindow *window_, Style *style_, int index = -1) | |
106 : event(0) | |
107 , window(window_) | |
108 , style(style_) | |
109 , currentStyleIndex(index) | |
110 , windowHeight(0) | |
111 {} | |
112 | |
113 DigSetter &setEvent(IPaintEvent &e); | |
114 DigSetter &closeEvent(); | |
115 | |
116 int top(Dig d) { | |
117 return d.where.y - style[d.styleIndex].topToBaseline(); | |
118 } | |
119 int bottom(Dig d) { | |
120 return d.where.y + style[d.styleIndex].descender(); | |
121 } | |
122 | |
123 DigSetter &measureDig(Dig &dig); | |
124 DigSetter &setDig(const Dig &dig, int reverseVideo = 0); | |
125 DigSetter &clear(const Hole &hole); | |
126 DigSetter &reverse(const Hole &hole); | |
127 DigSetter &clear(const IRectangle &r); | |
128 | |
129 DigSetter &refresh(const Hole &hole); | |
130 DigSetter &refresh(const Dig &dig); | |
131 | |
132 Hole makeHole(const Dig &dig); | |
133 }; | |
134 | |
135 | |
136 #endif /* DIGSET_HPP */ |