/** Checks if the Box's size has changed, dirties it if necessary, and makes sure childrens' sizes are up to date */
void repack() {
if (!needs_reflow) return;
- if (numChildren() == 0) { contentwidth = minwidth; contentheight = minheight; return; }
+ if (numChildren() == 0) {
+ contentwidth = max(textwidth, minwidth);
+ contentheight = max(textheight, minheight);
+ return;
+ }
// --- Phase 0 ----------------------------------------------------------------------
// recurse
if (tile) renderTiledImage(globalx, globaly, clipx, clipy, clipw, cliph, buf);
else renderStretchedImage(globalx, globaly, clipx, clipy, clipw, cliph, buf);
- //if (text != null && !text.equals("")) renderText(x, y, w, h, buf);
+ if (text != null && !text.equals("")) renderText(x, y, clipx, clipy, clipw, cliph, buf);
// now subtract the pad region from the clip region before proceeding
clipw = min(max(clipx, globalx + hpad) + clipw, globalx + width - hpad) - clipx;
}
}
- void renderText(int x, int y, int w, int h, DoubleBuffer buf) {
- /*
- if ((textcolor & 0xFF000000) == 0x00000000) return;
- buf.setClip(x, y, w + x, h + y);
+ void renderText(int x, int y, int clipx, int clipy, int clipw, int cliph, DoubleBuffer buf) {
+
+ Log.log(this, "rendering text: " + text);
+ //buf.setClip(clipx, clipy, clipw, cliph);
+ try {
+ ImageDecoder id = org.xwt.imp.Font.render(new FileInputStream("COMIC.TTF"), 24, text);
+ Picture p = Platform.createPicture(id);
+ buf.drawPicture(p, x, y);
+ buf.setClip(0, 0, buf.getWidth(), buf.getHeight());
+ } catch (Exception e) {
+ Log.log(this, e);
+ }
+
+ /*
buf.drawString(font(), text, x + hpad, y + vpad + Platform.getMaxAscent(font()) - 1, textcolor);
buf.setClip(0, 0, buf.getWidth(), buf.getHeight());
int i=0; while(i<font().length() && !Character.isDigit(font().charAt(i))) i++;
y + vpad + (xwf == null ? Platform.getMaxAscent(font()) : xwf.getMaxAscent()) + 2 + 1,
textcolor);
}
- */
+ */
}
public void put(Box b, Object value) {
String t = value == null ? "null" : value.toString();
if (t.equals(b.text)) return;
- // FIXME text is broken
+ b.text = t;
+ if (t == null) {
+ b.textwidth = b.textheight = 0;
+ } else {
+ try {
+ ImageDecoder id = org.xwt.imp.Font.render(new FileInputStream("COMIC.TTF"), 24, b.text);
+ b.textwidth = id.getWidth();
+ b.textheight = id.getHeight();
+ } catch (Exception e) {
+ Log.log(this, e);
+ }
+ }
+ b.dirty();
+ MARK_FOR_REFLOW_b;
} });
specialBoxProperties.put("font", new SpecialBoxProperty() {
public Object get(Box b) { return b.font; }