94 |
94 |
95 |
95 |
96 /* -------------------- text layout functions -------------------- */ |
96 /* -------------------- text layout functions -------------------- */ |
97 UiTextLayout* ui_text(UiGraphics *g) { |
97 UiTextLayout* ui_text(UiGraphics *g) { |
98 UiTextLayout *text = malloc(sizeof(UiTextLayout)); |
98 UiTextLayout *text = malloc(sizeof(UiTextLayout)); |
|
99 memset(text, 0, sizeof(UiTextLayout)); |
99 text->text = NULL; |
100 text->text = NULL; |
100 text->length = 0; |
101 text->length = 0; |
101 text->widget = ((UiXlibGraphics*)g)->widget; |
102 text->widget = ((UiXlibGraphics*)g)->widget; |
102 text->fontset = NULL; |
103 text->fontset = NULL; |
103 return text; |
104 return text; |
132 void ui_text_free(UiTextLayout *text) { |
133 void ui_text_free(UiTextLayout *text) { |
133 // TODO |
134 // TODO |
134 } |
135 } |
135 |
136 |
136 void ui_text_setstring(UiTextLayout *layout, char *str) { |
137 void ui_text_setstring(UiTextLayout *layout, char *str) { |
137 layout->text = str; |
138 ui_text_setstringl(layout, str, strlen(str)); |
138 layout->length = strlen(str); |
|
139 } |
139 } |
140 |
140 |
141 void ui_text_setstringl(UiTextLayout *layout, char *str, int len) { |
141 void ui_text_setstringl(UiTextLayout *layout, char *str, int len) { |
142 layout->text = str; |
142 layout->text = str; |
143 layout->length = len; |
143 layout->length = len; |
|
144 layout->changed = 1; |
144 } |
145 } |
145 |
146 |
146 void ui_text_setfont(UiTextLayout *layout, char *font, int size) { |
147 void ui_text_setfont(UiTextLayout *layout, char *font, int size) { |
147 create_default_fontset(layout);//TODO |
148 create_default_fontset(layout);//TODO |
|
149 layout->changed = 1; |
148 } |
150 } |
149 |
151 |
150 void ui_text_getsize(UiTextLayout *layout, int *width, int *height) { |
152 void ui_text_getsize(UiTextLayout *layout, int *width, int *height) { |
151 // TODO |
153 if(layout->changed) { |
|
154 XRectangle ext, lext; |
|
155 XmbTextExtents(layout->fontset, layout->text, layout->length, &ext, &lext); |
|
156 layout->width = ext.width; |
|
157 layout->height = ext.height; |
|
158 layout->changed = 0; |
|
159 } |
|
160 *width = layout->width; |
|
161 *height = layout->height; |
152 } |
162 } |
153 |
163 |
154 void ui_text_setwidth(UiTextLayout *layout, int width) { |
164 void ui_text_setwidth(UiTextLayout *layout, int width) { |
155 // TODO |
165 layout->maxwidth = width; |
156 } |
166 } |
157 |
167 |
158 |
168 |
159 /* -------------------- drawing functions -------------------- */ |
169 /* -------------------- drawing functions -------------------- */ |
160 |
170 |
178 } |
188 } |
179 } |
189 } |
180 |
190 |
181 void ui_draw_text(UiGraphics *g, int x, int y, UiTextLayout *text) { |
191 void ui_draw_text(UiGraphics *g, int x, int y, UiTextLayout *text) { |
182 UiXlibGraphics *gr = (UiXlibGraphics*)g; |
192 UiXlibGraphics *gr = (UiXlibGraphics*)g; |
|
193 int width, height; |
|
194 ui_text_getsize(text, &width, &height); |
|
195 if(text->maxwidth > 0) { |
|
196 XRectangle clip; |
|
197 clip.x = x; |
|
198 clip.y = y; |
|
199 clip.width = text->maxwidth; |
|
200 clip.height = height; |
|
201 XSetClipRectangles(gr->display, gr->gc, 0, 0, &clip, 1, Unsorted); |
|
202 } |
|
203 |
183 XmbDrawString( |
204 XmbDrawString( |
184 gr->display, |
205 gr->display, |
185 XtWindow(gr->widget), |
206 XtWindow(gr->widget), |
186 text->fontset, |
207 text->fontset, |
187 gr->gc, |
208 gr->gc, |
188 x, |
209 x, |
189 y, |
210 y + height, |
190 text->text, |
211 text->text, |
191 text->length); |
212 text->length); |
192 } |
213 |
|
214 XSetClipMask(gr->display, gr->gc, None); |
|
215 } |