comparison doodle/gtk/canvas.d @ 68:64bd864db30d

Bah
author daveb
date Fri, 13 Aug 2010 15:53:48 +0930
parents 31d10176415d
children d540f7e4af9e
comparison
equal deleted inserted replaced
67:31d10176415d 68:64bd864db30d
48 // User operations: 48 // User operations:
49 // pan (middle click and drag) 49 // pan (middle click and drag)
50 // zoom about a point (hold control and move scroll wheel) 50 // zoom about a point (hold control and move scroll wheel)
51 // resize the widget 51 // resize the widget
52 52
53 final class Canvas : Table, IViewport { 53 final class Canvas : Table, private IViewport {
54 this(in Layer[] layers, IEventHandler eventHandler, IGrid grid, in double ppi) { 54 this(in Layer[] layers, IEventHandler eventHandler, IGrid grid, in double ppi) {
55 super(3, 3, 0); 55 super(3, 3, 0);
56 56
57 _damage = Rectangle.DEFAULT; 57 _damage = Rectangle.DEFAULT;
58 58
151 AttachOptions.SHRINK, 151 AttachOptions.SHRINK,
152 AttachOptions.FILL | AttachOptions.EXPAND, 152 AttachOptions.FILL | AttachOptions.EXPAND,
153 0, 0); 153 0, 0);
154 } 154 }
155 155
156 // IViewport overrides: 156 protected { // XXX the compiler complains about unimplemented methods if this is private
157 157
158 void zoomRelative(in Point pixelDatum, in double factor) { 158 // IViewport overrides:
159 // Work out pixel distance from current centre to datum, 159
160 // Do the zoom, then work out the new centre that keeps the 160 void zoomRelative(in Point pixelDatum, in double factor) {
161 // pixel distance the same 161 // Work out pixel distance from current centre to datum,
162 162 // Do the zoom, then work out the new centre that keeps the
163 Point oldModelDatum = pixelToModel(pixelDatum); 163 // pixel distance the same
164 Vector pixelDistance = modelToPixel(oldModelDatum - _viewCentre); 164
165 _zoom = clampZoom(factor * _zoom); 165 Point oldModelDatum = pixelToModel(pixelDatum);
166 _viewCentre = oldModelDatum - pixelToModel(pixelDistance); 166 Vector pixelDistance = modelToPixel(oldModelDatum - _viewCentre);
167 167 _zoom = clampZoom(factor * _zoom);
168 consolidateBounds; 168 _viewCentre = oldModelDatum - pixelToModel(pixelDistance);
169 169
170 updateAdjustments; 170 consolidateBounds;
171 updateRulers; 171
172 _grid.zoomChanged(_zoom); 172 updateAdjustments;
173 queueDraw; 173 updateRulers;
174 } 174 _grid.zoomChanged(_zoom);
175 175 queueDraw;
176 void panRelative(in Vector pixelDisplacement) { 176 }
177 _viewCentre = _viewCentre + pixelToModel(pixelDisplacement); 177
178 178 void panRelative(in Vector pixelDisplacement) {
179 consolidateBounds; 179 _viewCentre = _viewCentre + pixelToModel(pixelDisplacement);
180 180
181 updateAdjustments; 181 consolidateBounds;
182 updateRulers; 182
183 queueDraw; 183 updateAdjustments;
184 } 184 updateRulers;
185 185 queueDraw;
186 void setCursor(in Cursor cursor) { 186 }
187 CursorType cursorType; 187
188 188 void setCursor(in Cursor cursor) {
189 switch (cursor) { 189 CursorType cursorType;
190 case Cursor.DEFAULT: 190
191 cursorType = CursorType.ARROW; 191 switch (cursor) {
192 break; 192 case Cursor.DEFAULT:
193 case Cursor.HAND: 193 cursorType = CursorType.ARROW;
194 cursorType = CursorType.HAND1; 194 break;
195 break; 195 case Cursor.HAND:
196 case Cursor.CROSSHAIR: 196 cursorType = CursorType.HAND1;
197 cursorType = CursorType.CROSSHAIR; 197 break;
198 break; 198 case Cursor.CROSSHAIR:
199 case Cursor.PENCIL: 199 cursorType = CursorType.CROSSHAIR;
200 cursorType = CursorType.PENCIL; 200 break;
201 break; 201 case Cursor.PENCIL:
202 default: 202 cursorType = CursorType.PENCIL;
203 assert(0); 203 break;
204 } 204 default:
205 205 assert(0);
206 _drawingArea.setCursor(new gdk.Cursor.Cursor(cursorType)); 206 }
207 } 207
208 208 _drawingArea.setCursor(new gdk.Cursor.Cursor(cursorType));
209 void damageModel(in Rectangle area) { 209 }
210 _damage = _damage | modelToPixel(area); 210
211 } 211 void damageModel(in Rectangle area) {
212 212 _damage = _damage | modelToPixel(area);
213 void damagePixel(in Rectangle area) { 213 }
214 _damage = _damage | area; 214
215 void damagePixel(in Rectangle area) {
216 _damage = _damage | area;
217 }
215 } 218 }
216 219
217 private { 220 private {
218 221
219 void initialiseBounds() { 222 void initialiseBounds() {