Mercurial > projects > dwt-addons
comparison dwtx/draw2d/widgets/ImageBorder.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) 2004, 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.widgets.ImageBorder; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 | |
17 | |
18 | |
19 import dwt.graphics.Image; | |
20 import dwtx.draw2d.AbstractBorder; | |
21 import dwtx.draw2d.Graphics; | |
22 import dwtx.draw2d.IFigure; | |
23 import dwtx.draw2d.geometry.Dimension; | |
24 import dwtx.draw2d.geometry.Insets; | |
25 import dwtx.draw2d.geometry.Rectangle; | |
26 | |
27 /** | |
28 * @author Pratik Shah | |
29 */ | |
30 class ImageBorder | |
31 : AbstractBorder | |
32 { | |
33 | |
34 /* | |
35 * @TODO:Pratik Need to test this class extensively | |
36 * @TODO Test inside compound borders | |
37 */ | |
38 | |
39 private Insets imgInsets; | |
40 private Image image; | |
41 private Dimension imageSize; | |
42 | |
43 public this(Image image) { | |
44 setImage(image); | |
45 } | |
46 | |
47 public Insets getInsets(IFigure figure) { | |
48 return imgInsets; | |
49 } | |
50 | |
51 public Image getImage() { | |
52 return image; | |
53 } | |
54 | |
55 /** | |
56 * @see dwtx.draw2d.AbstractBorder#getPreferredSize(dwtx.draw2d.IFigure) | |
57 */ | |
58 public Dimension getPreferredSize(IFigure f) { | |
59 return imageSize; | |
60 } | |
61 | |
62 public void paint(IFigure figure, Graphics graphics, Insets insets) { | |
63 if (image is null) | |
64 return; | |
65 Rectangle rect = getPaintRectangle(figure, insets); | |
66 int x = rect.x; | |
67 int y = rect.y + (rect.height - imageSize.height) / 2; | |
68 graphics.drawImage(getImage(), x, y); | |
69 } | |
70 | |
71 public void setImage(Image img) { | |
72 image = img; | |
73 imageSize = new Dimension(image); | |
74 imgInsets = new Insets(); | |
75 imgInsets.left = imageSize.width; | |
76 } | |
77 | |
78 } |