Mercurial > projects > dwt-addons
comparison dwtx/draw2d/text/CaretInfo.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 | |
14 module dwtx.draw2d.text.CaretInfo; | |
15 | |
16 import dwt.dwthelper.utils; | |
17 | |
18 import dwtx.draw2d.geometry.Translatable; | |
19 | |
20 /** | |
21 * Stores positional information about where a caret should be placed. This structure | |
22 * currently only offers integer precision. Scaling operations will result in rounding. | |
23 * @since 3.1 | |
24 */ | |
25 public class CaretInfo | |
26 : Translatable | |
27 { | |
28 | |
29 private int ascent, lineAscent, descent, lineDescent, baseline, x; | |
30 | |
31 /** | |
32 * Constructor for use by TextFlow. Constructs a new CaretInfo with the figure's ascent | |
33 * and descent and line information. | |
34 * <P> | |
35 * <EM>WARNING:</EM> This constructor should not be called by clients. It is for use by | |
36 * {@link TextFlow}, and may change in future releases. | |
37 * @param x the x location | |
38 * @param y the y location of the top of the caret | |
39 * @param ascent the ascent | |
40 * @param descent the descent | |
41 * @param lineAscent the ascent of the line on which the caret is placed | |
42 * @param lineDescent the descent of the line on which the caret is placed | |
43 */ | |
44 /+protected+/ this(int x, int y, int ascent, int descent, int lineAscent, int lineDescent) { | |
45 this.x = x; | |
46 this.baseline = y + ascent; | |
47 this.ascent = ascent; | |
48 this.descent = descent; | |
49 this.lineAscent = lineAscent; | |
50 this.lineDescent = lineDescent; | |
51 } | |
52 | |
53 /** | |
54 * Constructs a CaretInfo object by copying the values from another instance. | |
55 * @param info the reference | |
56 * @since 3.2 | |
57 */ | |
58 /+protected+/ this(CaretInfo info) { | |
59 this.ascent = info.ascent; | |
60 this.baseline = info.baseline; | |
61 this.descent = info.descent; | |
62 this.lineAscent = info.lineAscent; | |
63 this.lineDescent = info.lineDescent; | |
64 this.x = info.x; | |
65 } | |
66 | |
67 /** | |
68 * Returns the y location of the baseline. | |
69 * @return the y coordinate of the baseline | |
70 */ | |
71 public int getBaseline() { | |
72 return baseline; | |
73 } | |
74 | |
75 /** | |
76 * Returns the total height of the caret. The height is the sum of the ascent and descent. | |
77 * @return the height | |
78 */ | |
79 public int getHeight() { | |
80 return ascent + descent; | |
81 } | |
82 | |
83 /** | |
84 * @return the total height of the line on which the caret is placed | |
85 */ | |
86 public int getLineHeight() { | |
87 return lineAscent + lineDescent; | |
88 } | |
89 | |
90 /** | |
91 * @return the y location of the line on which the caret is placed | |
92 */ | |
93 public int getLineY() { | |
94 return baseline - lineAscent; | |
95 } | |
96 | |
97 /** | |
98 * Returns the x location of the caret. | |
99 * @return the x coordinate | |
100 */ | |
101 public int getX() { | |
102 return x; | |
103 } | |
104 | |
105 /** | |
106 * Returns the y location of the caret. | |
107 * @return the y coordinate | |
108 */ | |
109 public int getY() { | |
110 return baseline - ascent; | |
111 } | |
112 | |
113 /** | |
114 * @see Translatable#performScale(double) | |
115 */ | |
116 public void performScale(double factor) { | |
117 x *= factor; | |
118 baseline *= factor; | |
119 descent *= factor; | |
120 ascent *= factor; | |
121 lineAscent *= factor; | |
122 lineDescent *= factor; | |
123 } | |
124 | |
125 /** | |
126 * @see Translatable#performTranslate(int, int) | |
127 */ | |
128 public void performTranslate(int dx, int dy) { | |
129 x += dx; | |
130 baseline += dy; | |
131 } | |
132 | |
133 } |