use of automenta.vivisect.gui.StyledString.TextLayoutInfo in project opennars by opennars.
the class GButton method updateBuffer.
protected void updateBuffer() {
if (bufferInvalid) {
Graphics2D g2d = buffer.g2;
// Get the latest lines of text
LinkedList<TextLayoutInfo> lines = stext.getLines(g2d);
bufferInvalid = false;
buffer.beginDraw();
// Back ground colour
switch(status) {
case OVER_CONTROL:
buffer.background(palette[6]);
break;
case PRESS_CONTROL:
buffer.background(palette[14]);
break;
default:
buffer.background(palette[4]);
}
g2d.setColor(jpalette[3]);
g2d.setStroke(pen_1_0);
g2d.drawRect(0, 0, (int) width - 1, (int) height - 1);
// Calculate text and icon placement
calcAlignment();
// If there is an icon draw it
if (iconW != 0) {
buffer.image(bicon[status], siX, siY);
}
float wrapWidth = stext.getWrapWidth();
float sx = 0, tw = 0;
buffer.translate(stX, stY);
for (TextLayoutInfo lineInfo : lines) {
TextLayout layout = lineInfo.layout;
buffer.translate(0, layout.getAscent());
switch(textAlignH) {
case CENTER:
tw = layout.getVisibleAdvance();
tw = (tw > wrapWidth) ? tw - wrapWidth : tw;
sx = (wrapWidth - tw) / 2;
break;
case RIGHT:
tw = layout.getVisibleAdvance();
tw = (tw > wrapWidth) ? tw - wrapWidth : tw;
sx = wrapWidth - tw;
break;
case LEFT:
case JUSTIFY:
default:
sx = 0;
}
// display text
g2d.setColor(jpalette[2]);
lineInfo.layout.draw(g2d, sx, 0);
buffer.translate(0, layout.getDescent() + layout.getLeading());
}
buffer.endDraw();
}
}
use of automenta.vivisect.gui.StyledString.TextLayoutInfo in project opennars by opennars.
the class GToggleControl method updateBuffer.
protected void updateBuffer() {
if (bufferInvalid) {
Graphics2D g2d = buffer.g2;
// Get the latest lines of text
LinkedList<TextLayoutInfo> lines = stext.getLines(g2d);
bufferInvalid = false;
buffer.beginDraw();
// Back ground colour
buffer.background(opaque ? palette[6] : palette[2] & 0xFFFFFF);
// Calculate text and icon placement
calcAlignment();
// If there is an icon draw it
if (iconW != 0)
if (selected)
buffer.image(bicon[1], siX, siY);
else
buffer.image(bicon[0], siX, siY);
float wrapWidth = stext.getWrapWidth();
float sx = 0, tw = 0;
buffer.translate(stX, stY);
for (TextLayoutInfo lineInfo : lines) {
TextLayout layout = lineInfo.layout;
buffer.translate(0, layout.getAscent());
switch(textAlignH) {
case CENTER:
tw = layout.getAdvance();
tw = (tw > wrapWidth) ? tw - wrapWidth : tw;
sx = (wrapWidth - tw) / 2;
break;
case RIGHT:
tw = layout.getAdvance();
tw = (tw > wrapWidth) ? tw - wrapWidth : tw;
sx = wrapWidth - tw;
break;
case LEFT:
case JUSTIFY:
default:
sx = 0;
}
// display text
g2d.setColor(jpalette[2]);
lineInfo.layout.draw(g2d, sx, 0);
buffer.translate(0, layout.getDescent() + layout.getLeading());
}
buffer.endDraw();
}
}
Aggregations