comparison dwtx/draw2d/ScalableFreeformLayeredPane.d @ 98:95307ad235d9

Added Draw2d code, still work in progress
author Frank Benoit <benoit@tionex.de>
date Sun, 03 Aug 2008 00:52:14 +0200
parents
children
comparison
equal deleted inserted replaced
96:b492ba44e44d 98:95307ad235d9
1 /*******************************************************************************
2 * Copyright (c) 2000, 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module dwtx.draw2d.ScalableFreeformLayeredPane;
14
15 import dwt.dwthelper.utils;
16
17 import dwtx.draw2d.geometry.Rectangle;
18 import dwtx.draw2d.geometry.Translatable;
19 import dwtx.draw2d.FreeformLayeredPane;
20 import dwtx.draw2d.ScalableFigure;
21 import dwtx.draw2d.Graphics;
22 import dwtx.draw2d.ScaledGraphics;
23
24 /**
25 * @author hudsonr
26 * @since 2.1
27 */
28 public class ScalableFreeformLayeredPane
29 : FreeformLayeredPane
30 , ScalableFigure
31 {
32
33 private double scale = 1.0;
34
35 /**
36 * @see dwtx.draw2d.Figure#getClientArea()
37 */
38 public Rectangle getClientArea(Rectangle rect) {
39 super.getClientArea(rect);
40 rect.width /= scale;
41 rect.height /= scale;
42 rect.x /= scale;
43 rect.y /= scale;
44 return rect;
45 }
46
47 /**
48 * Returns the current zoom scale level.
49 * @return the scale
50 */
51 public double getScale() {
52 return scale;
53 }
54
55 /**
56 * @see dwtx.draw2d.IFigure#isCoordinateSystem()
57 */
58 public bool isCoordinateSystem() {
59 return true;
60 }
61
62 /**
63 * @see dwtx.draw2d.Figure#paintClientArea(Graphics)
64 */
65 protected void paintClientArea(Graphics graphics) {
66 if (getChildren().isEmpty())
67 return;
68 if (scale is 1.0) {
69 super.paintClientArea(graphics);
70 } else {
71 ScaledGraphics g = new ScaledGraphics(graphics);
72 bool optimizeClip = getBorder() is null || getBorder().isOpaque();
73 if (!optimizeClip)
74 g.clipRect(getBounds().getCropped(getInsets()));
75 g.scale(scale);
76 g.pushState();
77 paintChildren(g);
78 g.dispose();
79 graphics.restoreState();
80 }
81 }
82
83 /**
84 * Sets the zoom level
85 * @param newZoom The new zoom level
86 */
87 public void setScale(double newZoom) {
88 if (scale is newZoom)
89 return;
90 scale = newZoom;
91 superFireMoved(); //For AncestorListener compatibility
92 getFreeformHelper().invalidate();
93 repaint();
94 }
95
96 /**
97 * @see dwtx.draw2d.Figure#translateToParent(Translatable)
98 */
99 public void translateToParent(Translatable t) {
100 t.performScale(scale);
101 }
102
103 /**
104 * @see dwtx.draw2d.Figure#translateFromParent(Translatable)
105 */
106 public void translateFromParent(Translatable t) {
107 t.performScale(1 / scale);
108 }
109
110 /**
111 * @see dwtx.draw2d.Figure#useLocalCoordinates()
112 */
113 protected final bool useLocalCoordinates() {
114 return false;
115 }
116
117 }