comparison gtk/canvas.d @ 26:06c30d250c0a

Cleanup
author "David Bryant <bagnose@gmail.com>"
date Thu, 16 Jul 2009 00:12:02 +0930
parents a24c13bb9c98
children f3d91579bb28
comparison
equal deleted inserted replaced
25:8f58a8f88735 26:06c30d250c0a
120 AttachOptions.SHRINK, 120 AttachOptions.SHRINK,
121 AttachOptions.FILL | AttachOptions.EXPAND, 121 AttachOptions.FILL | AttachOptions.EXPAND,
122 0, 0); 122 0, 0);
123 } 123 }
124 124
125 override void zoom_relative(Point pixel_datum, double factor) { 125 override void zoom_relative(in Point pixel_datum, in double factor) {
126 // Work out pixel distance from current centre to datum, 126 // Work out pixel distance from current centre to datum,
127 // Do the zoom, then work out the new centre that keeps the 127 // Do the zoom, then work out the new centre that keeps the
128 // pixel distance the same 128 // pixel distance the same
129 129
130 Point old_model_datum = pixel_to_model(pixel_datum); 130 Point old_model_datum = pixel_to_model(pixel_datum);
135 update_adjustments; 135 update_adjustments;
136 update_rulers; 136 update_rulers;
137 queueDraw; 137 queueDraw;
138 } 138 }
139 139
140 override void pan_relative(Vector pixel_displacement) { 140 override void pan_relative(in Vector pixel_displacement) {
141 mViewCentre = mViewCentre + pixel_to_model(pixel_displacement); 141 mViewCentre = mViewCentre + pixel_to_model(pixel_displacement);
142 142
143 update_adjustments; 143 update_adjustments;
144 update_rulers; 144 update_rulers;
145 queueDraw; 145 queueDraw;
146 } 146 }
147 147
148 override void damage_model(Rectangle area) { 148 override void damage_model(in Rectangle area) {
149 mDamage = mDamage | model_to_pixel(area); 149 mDamage = mDamage | model_to_pixel(area);
150 } 150 }
151 151
152 override void damage_pixel(Rectangle area) { 152 override void damage_pixel(in Rectangle area) {
153 mDamage = mDamage | area; 153 mDamage = mDamage | area;
154 } 154 }
155 155
156 override double zoom() const { 156 override double zoom() const {
157 return mZoom; 157 return mZoom;
158 } 158 }
159 159
160 override Point model_to_pixel(Point model) const { 160 override Point model_to_pixel(in Point model) const {
161 return Point.DEFAULT + mViewSize / 2.0 + mZoom * (model - mViewCentre); 161 return Point.DEFAULT + mViewSize / 2.0 + mZoom * (model - mViewCentre);
162 } 162 }
163 163
164 override Point pixel_to_model(Point pixel) const { 164 override Point pixel_to_model(in Point pixel) const {
165 return mViewCentre + (pixel - mViewSize / 2.0 - Point.DEFAULT) / mZoom; 165 return mViewCentre + (pixel - mViewSize / 2.0 - Point.DEFAULT) / mZoom;
166 } 166 }
167 167
168 override Vector model_to_pixel(Vector model) const { 168 override Vector model_to_pixel(in Vector model) const {
169 return mZoom * model; 169 return mZoom * model;
170 } 170 }
171 171
172 override Vector pixel_to_model(Vector pixel) const { 172 override Vector pixel_to_model(in Vector pixel) const {
173 return pixel / mZoom; 173 return pixel / mZoom;
174 } 174 }
175 175
176 override double model_to_pixel(double model) const { 176 override double model_to_pixel(in double model) const {
177 return mZoom * model; 177 return mZoom * model;
178 } 178 }
179 179
180 override double pixel_to_model(double pixel) const { 180 override double pixel_to_model(in double pixel) const {
181 return pixel / mZoom; 181 return pixel / mZoom;
182 } 182 }
183 183
184 override Rectangle model_to_pixel(Rectangle model) const { 184 override Rectangle model_to_pixel(in Rectangle model) const {
185 return Rectangle(model_to_pixel(model.position), model_to_pixel(model.size)); 185 return Rectangle(model_to_pixel(model.position), model_to_pixel(model.size));
186 } 186 }
187 187
188 override Rectangle pixel_to_model(Rectangle model) const { 188 override Rectangle pixel_to_model(in Rectangle model) const {
189 return Rectangle(pixel_to_model(model.position), pixel_to_model(model.size)); 189 return Rectangle(pixel_to_model(model.position), pixel_to_model(model.size));
190 } 190 }
191 191
192 private { 192 private {
193 193
441 441
442 queueDraw; 442 queueDraw;
443 } 443 }
444 444
445 void update_rulers() { 445 void update_rulers() {
446 Vector model_size = pixel_to_model(mViewSize); 446 invariant Vector model_size = pixel_to_model(mViewSize);
447 447
448 Point view_left_bottom = mViewCentre - model_size / 2.0; 448 invariant Point view_left_bottom = mViewCentre - model_size / 2.0;
449 Point view_right_top = mViewCentre + model_size / 2.0; 449 invariant Point view_right_top = mViewCentre + model_size / 2.0;
450 450
451 // Define these just to obtain the position 451 // Define these just to obtain the position
452 // below and we can preserve it 452 // below and we can preserve it
453 double lower, upper, position, max_size; 453 double lower, upper, position, max_size;
454
455 454
456 mHRuler.getRange(lower, upper, position, max_size); 455 mHRuler.getRange(lower, upper, position, max_size);
457 mHRuler.setRange(view_left_bottom.x, 456 mHRuler.setRange(view_left_bottom.x,
458 view_right_top.x, 457 view_right_top.x,
459 position, 458 position,
465 position, 464 position,
466 mZoom * 50.0); 465 mZoom * 50.0);
467 } 466 }
468 467
469 void update_adjustments() { 468 void update_adjustments() {
470 Vector model_size = pixel_to_model(mViewSize); 469 invariant Vector model_size = pixel_to_model(mViewSize);
471 470
472 Point view_left_bottom = mViewCentre - model_size / 2.0; 471 invariant Point view_left_bottom = mViewCentre - model_size / 2.0;
473 Point view_right_top = mViewCentre + model_size / 2.0; 472 invariant Point view_right_top = mViewCentre + model_size / 2.0;
474 473
475 // Adjust the canvas size if necessary 474 // Adjust the canvas size if necessary
476 mCanvasBounds = Rectangle(min_extents(mCanvasBounds.min_corner, view_left_bottom), 475 mCanvasBounds = Rectangle(min_extents(mCanvasBounds.min_corner, view_left_bottom),
477 max_extents(mCanvasBounds.max_corner, view_right_top)); 476 max_extents(mCanvasBounds.max_corner, view_right_top));
478 477
505 if (mDamage.valid) { 504 if (mDamage.valid) {
506 //writefln("Damage: %s", mDamage); 505 //writefln("Damage: %s", mDamage);
507 int x, y, w, h; 506 int x, y, w, h;
508 mDamage.get_quantised(x, y, w, h); 507 mDamage.get_quantised(x, y, w, h);
509 //writefln("Quantised damage: %d %d %d %d", x, y, w, h); 508 //writefln("Quantised damage: %d %d %d %d", x, y, w, h);
510 y = cast(int)mViewSize.y - (y + h); 509 y = cast(int)mViewSize.y - (y + h); // Flip vertical axis
511 //writefln("Flipped Quantised damage: %d %d %d %d", x, y, w, h); 510 //writefln("Flipped Quantised damage: %d %d %d %d", x, y, w, h);
512 mDrawingArea.queueDrawArea(x, y, w, h); 511 mDrawingArea.queueDrawArea(x, y, w, h);
513 //mDrawingArea.queueDraw(); 512 //mDrawingArea.queueDraw();
514 mDamage = Rectangle.DEFAULT; 513 mDamage = Rectangle.DEFAULT;
515 } 514 }
516 else { 515 else {
517 //writefln("No damage"); 516 //writefln("No damage");
518 } 517 }
519 } 518 }
520 519
521 double clamp_zoom(double zoom) { return clamp(zoom, 0.2, 10.0); } 520 double clamp_zoom(in double zoom) { return clamp(zoom, 0.2, 10.0); }
522 521
523 bool mHadConfigure; 522 bool mHadConfigure;
524 Rectangle mDamage; // pixels 523 Rectangle mDamage; // pixels
525 524
526 // Model units are in millimetres 525 // Model units are in millimetres