comparison canvas.d @ 20:d6e7a5a6f008

Checkpoint
author "David Bryant <bagnose@gmail.com>"
date Wed, 15 Jul 2009 23:23:02 +0930
parents 22abbf4cde96
children
comparison
equal deleted inserted replaced
19:22abbf4cde96 20:d6e7a5a6f008
56 attach(mHRuler, 56 attach(mHRuler,
57 1, 2, 57 1, 2,
58 0, 1, 58 0, 1,
59 AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.SHRINK, 59 AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.SHRINK,
60 0, 0); 60 0, 0);
61 mHRuler.setMetric(GtkMetricType.PIXELS); 61 mHRuler.setMetric(MetricType.PIXELS);
62 62
63 mVRuler = new VRuler; 63 mVRuler = new VRuler;
64 attach(mVRuler, 64 attach(mVRuler,
65 0, 1, 65 0, 1,
66 1, 2, 66 1, 2,
67 AttachOptions.SHRINK, AttachOptions.FILL | AttachOptions.EXPAND, 67 AttachOptions.SHRINK, AttachOptions.FILL | AttachOptions.EXPAND,
68 0, 0); 68 0, 0);
69 mVRuler.setMetric(GtkMetricType.PIXELS); 69 mVRuler.setMetric(MetricType.PIXELS);
70 70
71 mDrawingArea = new DrawingArea; 71 mDrawingArea = new DrawingArea;
72 mDrawingArea.addOnRealize(&onRealize); 72 mDrawingArea.addOnRealize(&onRealize);
73 mDrawingArea.addOnConfigure(&onConfigure); 73 mDrawingArea.addOnConfigure(&onConfigure);
74 mDrawingArea.addOnExpose(&onExpose); 74 mDrawingArea.addOnExpose(&onExpose);
76 mDrawingArea.addOnButtonRelease(&onButtonRelease); 76 mDrawingArea.addOnButtonRelease(&onButtonRelease);
77 mDrawingArea.addOnKeyPress(&onKeyEvent); 77 mDrawingArea.addOnKeyPress(&onKeyEvent);
78 mDrawingArea.addOnKeyRelease(&onKeyEvent); 78 mDrawingArea.addOnKeyRelease(&onKeyEvent);
79 mDrawingArea.addOnMotionNotify(&onMotionNotify); 79 mDrawingArea.addOnMotionNotify(&onMotionNotify);
80 mDrawingArea.addOnScroll(&onScroll); 80 mDrawingArea.addOnScroll(&onScroll);
81 mDrawingArea.addOnEnterNotify(&onEnterNotify);
82 mDrawingArea.addOnLeaveNotify(&onLeaveNotify);
83 mDrawingArea.setEvents(EventMask.EXPOSURE_MASK |
84 EventMask.POINTER_MOTION_MASK |
85 EventMask.POINTER_MOTION_HINT_MASK |
86 EventMask.BUTTON_MOTION_MASK |
87 EventMask.BUTTON_PRESS_MASK |
88 EventMask.BUTTON_RELEASE_MASK |
89 EventMask.KEY_PRESS_MASK |
90 EventMask.KEY_RELEASE_MASK |
91 EventMask.ENTER_NOTIFY_MASK |
92 EventMask.LEAVE_NOTIFY_MASK |
93 EventMask.FOCUS_CHANGE_MASK |
94 EventMask.SCROLL_MASK);
95
81 attach(mDrawingArea, 96 attach(mDrawingArea,
82 1, 2, 97 1, 2,
83 1, 2, 98 1, 2,
84 AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL | AttachOptions.EXPAND, 99 AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL | AttachOptions.EXPAND,
85 0, 0); 100 0, 0);
106 AttachOptions.SHRINK, 121 AttachOptions.SHRINK,
107 AttachOptions.FILL | AttachOptions.EXPAND, 122 AttachOptions.FILL | AttachOptions.EXPAND,
108 0, 0); 123 0, 0);
109 } 124 }
110 125
111 override void rel_zoom(Point pixel_datum, double factor) { 126 override void zoom_relative(Point pixel_datum, double factor) {
112 // Work out pixel distance from current centre to datum, 127 // Work out pixel distance from current centre to datum,
113 // Do the zoom, then work out the new centre that keeps the 128 // Do the zoom, then work out the new centre that keeps the
114 // pixel distance the same 129 // pixel distance the same
115 130
116 Point old_model_datum = pixel_to_model(pixel_datum); 131 Point old_model_datum = pixel_to_model(pixel_datum);
121 update_adjustments; 136 update_adjustments;
122 update_rulers; 137 update_rulers;
123 queueDraw; 138 queueDraw;
124 } 139 }
125 140
126 override void rel_pan(Vector pixel_displacement) { 141 override void pan_relative(Vector pixel_displacement) {
127 mViewCentre = mViewCentre + pixel_to_model(pixel_displacement); 142 mViewCentre = mViewCentre + pixel_to_model(pixel_displacement);
128 143
129 update_adjustments; 144 update_adjustments;
130 update_rulers; 145 update_rulers;
131 queueDraw; 146 queueDraw;
366 381
367 mEventHandler.handle_scroll(this, scroll_event); 382 mEventHandler.handle_scroll(this, scroll_event);
368 383
369 process_damage; 384 process_damage;
370 385
386 return true;
387 }
388
389 /*
390 public enum GdkCrossingMode {
391 NORMAL,
392 GRAB,
393 UNGRAB,
394 GTK_GRAB,
395 GTK_UNGRAB,
396 STATE_CHANGED
397 }
398
399 public struct GdkEventCrossing {
400 GdkEventType type;
401 GdkWindow *window;
402 byte sendEvent;
403 GdkWindow *subwindow;
404 uint time;
405 double x;
406 double y;
407 double xRoot;
408 double yRoot;
409 GdkCrossingMode mode;
410 GdkNotifyType detail;
411 int focus;
412 uint state;
413 }
414 */
415
416 bool onEnterNotify(GdkEventCrossing * event, Widget widget) {
417 assert(widget is mDrawingArea);
418 writefln("Enter %d %d %d", cast(int)event.mode, event.focus, event.state);
419 return true;
420 }
421
422 bool onLeaveNotify(GdkEventCrossing * event, Widget widget) {
423 assert(widget is mDrawingArea);
424 writefln("Leave %d %d %d", cast(int)event.mode, event.focus, event.state);
371 return true; 425 return true;
372 } 426 }
373 427
374 void onValueChanged(Adjustment adjustment) { 428 void onValueChanged(Adjustment adjustment) {
375 GtkAdjustment * h_gtkAdjustment = mHAdjustment.getAdjustmentStruct; 429 GtkAdjustment * h_gtkAdjustment = mHAdjustment.getAdjustmentStruct;