comparison anagram/vaclgui/digset.cpp @ 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.cpp
7 */
8
9 //#include <iwindow.hpp>
10 #include <windows.h>
11
12 #include "digset.hpp"
13
14 //#define INCLUDE_LOGGING
15 #include "log.h"
16
17
18 DigSetter &DigSetter::setEvent(IPaintEvent &e) {
19 //LOGSECTION("DigSetter::setEvent", Log::off);
20 LOGSECTION_OFF("DigSetter::setEvent");
21 event = &e;
22 presSpaceHandle = event->presSpaceHandle();
23 SetBkMode(presSpaceHandle, TRANSPARENT);
24
25 LOGV((int) event);
26 windowHeight = window->size().height();
27 LOGV(currentStyleIndex);
28 if (currentStyleIndex == -1) {
29 return *this;
30 }
31 IFont &font = style[currentStyleIndex].font;
32 font.beginUsingFont(presSpaceHandle);
33 LOGV(windowHeight);
34 return *this;
35 }
36
37
38 DigSetter &DigSetter::closeEvent() {
39 if (currentStyleIndex == -1) {
40 return *this;
41 }
42 IFont &font = style[currentStyleIndex].font;
43 font.endUsingFont(presSpaceHandle);
44 return *this;
45 }
46
47 DigSetter &DigSetter::measureDig(Dig &dig) {
48 LOGSECTION("DigSetter::measureDig");
49 char *p = dig.text;
50 int length = dig.textLength;
51 char save = p[length];
52 p[length] = 0;
53 IFont &currentFont = style[dig.styleIndex].font;
54 dig.width = currentFont.textWidth(p);
55 p[length] = save;
56 int width = 0;
57 while (length--) {
58 width += currentFont.charWidth(*p++);
59 }
60 LOGV(dig.width) LCV(width);
61 return *this;
62 }
63
64 DigSetter &DigSetter::setDig(const Dig &dig, int reverseVideo) {
65 LOGSECTION("DigSetter::setDig");
66 char *p = dig.text;
67 int length = dig.textLength;
68 char save = p[length];
69 p[length] = 0;
70 cint where = dig.where;
71 if (reverseVideo) {
72 reverse(makeHole(dig));
73 }
74 if (dig.styleIndex != currentStyleIndex) {
75 if (currentStyleIndex >= 0) {
76 IFont &oldFont = style[currentStyleIndex].font;
77 oldFont.endUsingFont(presSpaceHandle);
78 }
79 currentStyleIndex = dig.styleIndex;
80 IFont &currentFont = style[currentStyleIndex].font;
81 currentFont.beginUsingFont(presSpaceHandle);
82 }
83 IColor color = reverseVideo ? style[currentStyleIndex].color.bg()
84 : style[currentStyleIndex].color.fg();
85 where.y -= style[currentStyleIndex].topToBaseline();
86 event->drawText(p, IPoint(where.x, where.y), color);
87
88 p[length] = save;
89 return *this;
90 }
91
92 DigSetter::Hole DigSetter::makeHole(const Dig &dig) {
93 LOGSECTION("DigSetter::makeHole");
94 IFont &currentFont = style[dig.styleIndex].font;
95 ISize digSize(dig.width, currentFont.maxCharHeight());
96 cint where = dig.where;
97 where.y -= currentFont.maxAscender();
98 return Hole(where, digSize, dig.styleIndex);
99 }
100
101 DigSetter &DigSetter::clear(const Hole &hole) {
102 //LOGSECTION("DigSetter::clear", Log::off);
103 LOGSECTION_OFF("DigSetter::clear");
104 LOGV(hole.styleIndex);
105 cint where = hole.where;
106 cint size = hole.size;
107 const IRectangle rect(IPoint(where.x, where.y),
108 ISize(hole.size.x, hole.size.y));
109 event->clearBackground(rect, style[hole.styleIndex].color.bg());
110 return *this;
111 }
112
113 DigSetter &DigSetter::reverse(const Hole &hole) {
114 //LOGSECTION("DigSetter::reverse", Log::off);
115 LOGSECTION_OFF("DigSetter::reverse");
116 LOGV(hole.styleIndex);
117 cint where = hole.where;
118 cint size = hole.size;
119 LOGV(where) LCV(size);
120 const IRectangle rect(IPoint(where.x, where.y),
121 ISize(hole.size.x, hole.size.y));
122 event->clearBackground(rect, style[hole.styleIndex].color.fg());
123 return *this;
124 }
125
126 DigSetter &DigSetter::clear(const IRectangle &r) {
127 Hole hole(r);
128 clear(hole);
129 return *this;
130 }
131
132
133 DigSetter &DigSetter::refresh(const Hole &hole) {
134 //LOGSECTION("refresh hole", Log::off);
135 LOGSECTION_OFF("refresh hole");
136 cint where = hole.where;
137 cint size = hole.size;
138 LOGV(where) LCV(size);
139 const IRectangle rect(IPoint(where.x, where.y),
140 ISize(hole.size.x, hole.size.y));
141 LOGV(rect.asString());
142 LOGV((int) event) LCV(hole.styleIndex);
143 window->refresh(rect);
144 return *this;
145 }
146
147 DigSetter &DigSetter::refresh(const Dig &dig) {
148 //LOGSECTION("refresh dig", Log::off);
149 LOGSECTION_OFF("refresh dig");
150 cint where(dig.where.x, top(dig));
151 cint size(dig.width, bottom(dig) - where.y);
152 LOGV(where) LCV(size);
153 const IRectangle rect(IPoint(where.x, where.y), ISize(size.x, size.y));
154 LOGV(rect.asString());
155 LOGV((int) event) LCV(dig.styleIndex);
156 window->refresh(rect);
157 return *this;
158 }