33 |
+ (unsigned) _textSize; |
+ (unsigned) _textSize; |
34 |
@end |
@end |
35 |
|
|
36 |
|
/** |
37 |
|
* UiLabel stores and display a text. |
38 |
|
*/ |
39 |
@implementation UiLabel |
@implementation UiLabel |
40 |
|
|
41 |
+ (unsigned) _textSize |
/** |
42 |
{ |
* Initializes the label with the given text and position. |
43 |
return 18; |
* The position is relative to its container. |
44 |
} |
* The widget must be completly contained in the screen space. |
45 |
|
*/ |
|
/* Must crash if text is nil Must crash if width or height < 0 */ |
|
46 |
- (id) initWithText: (NSString *)text |
- (id) initWithText: (NSString *)text |
47 |
position: (NSPoint)position |
position: (NSPoint)position |
48 |
{ |
{ |
53 |
size: NSZeroSize]; |
size: NSZeroSize]; |
54 |
if (self != nil) |
if (self != nil) |
55 |
{ |
{ |
56 |
_text = RETAIN (text); |
[self setTextSize: 18]; |
57 |
_uiText = [[UiText alloc] initWithText: text |
[self setColor: blueColor]; |
58 |
height: [UiLabel _textSize]]; |
[self setText: text]; |
59 |
|
|
60 |
[self sizeToFit]; |
[self sizeToFit]; |
61 |
} |
} |
71 |
[super dealloc]; |
[super dealloc]; |
72 |
} |
} |
73 |
|
|
74 |
/* Must must return a no-nil value */ |
/** |
75 |
- (NSString *) text |
* Sets the label text size. |
76 |
{ |
* The default text size is 18. |
77 |
return _text; |
*/ |
78 |
|
- (void) setTextSize: (int)textSize |
79 |
|
{ |
80 |
|
NSParameterAssert (textSize > 0); |
81 |
|
|
82 |
|
_textSize = textSize; |
83 |
|
} |
84 |
|
|
85 |
|
/** |
86 |
|
* Returns the label text size. |
87 |
|
*/ |
88 |
|
- (unsigned) textSize |
89 |
|
{ |
90 |
|
return _textSize; |
91 |
|
} |
92 |
|
|
93 |
|
/** |
94 |
|
* Sets the label color. |
95 |
|
* The default color is blue. |
96 |
|
*/ |
97 |
|
- (void) setColor: (color_t)color |
98 |
|
{ |
99 |
|
_color = color; |
100 |
|
} |
101 |
|
|
102 |
|
/** |
103 |
|
* Returns the label color. |
104 |
|
*/ |
105 |
|
- (color_t) color |
106 |
|
{ |
107 |
|
return _color; |
108 |
} |
} |
109 |
|
|
110 |
/* Must crash if aText is nil */ |
/** |
111 |
|
* Sets the text contained in the label. |
112 |
|
*/ |
113 |
- (void) setText: (NSString *)text |
- (void) setText: (NSString *)text |
114 |
{ |
{ |
115 |
NSParameterAssert (text); |
NSParameterAssert (text); |
117 |
|
|
118 |
ASSIGN(_text, text); |
ASSIGN(_text, text); |
119 |
ASSIGN(_uiText, [[UiText alloc] initWithText: text |
ASSIGN(_uiText, [[UiText alloc] initWithText: text |
120 |
height: [UiLabel _textSize]]); |
height: _textSize]); |
121 |
|
|
122 |
[self sizeToFit]; |
[self sizeToFit]; |
123 |
} |
} |
124 |
|
|
125 |
/** |
/** |
126 |
* method who calculate the width and the height of the widget. |
* Returns the text contained in the label. |
127 |
|
*/ |
128 |
|
- (NSString *) text |
129 |
|
{ |
130 |
|
return _text; |
131 |
|
} |
132 |
|
|
133 |
|
/** |
134 |
|
* Makes the size of the label fit the contained text. |
135 |
*/ |
*/ |
136 |
- (void) sizeToFit |
- (void) sizeToFit |
137 |
{ |
{ |
138 |
[self setSize: [_uiText size]]; |
[self setSize: [_uiText size]]; |
139 |
} |
} |
140 |
|
|
141 |
|
/** |
142 |
|
* Displays the the label. |
143 |
|
*/ |
144 |
- (void) _display |
- (void) _display |
145 |
{ |
{ |
146 |
glColor3f (0.0f, 0.0f, 1.0f); |
glColor4f (_color.red, _color.green, _color.blue, [self alpha]); |
147 |
[_uiText display]; |
[_uiText display]; |
148 |
} |
} |
149 |
|
|