123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #include "precomp.h"
- #include "textbar.h"
- #include <bfc/ifc_canvas.h>
- #include <bfc/string/string.h>
- #include <bfc/skinclr.h>
- #include <bfc/autobitmap.h>
- #include <common/checkwnd.h>
- static SkinColor bgcolor("wasabi.textBar.background", "Text backgrounds");
- static SkinColor fgcolor("wasabi.textBar.text");
- TextBar::TextBar() {
- size = 16;
- usebt = 0;
- alignment = TEXTALIGN_LEFT;
- checkwndtarget = NULL;
- textshadowed = 1;
- textoutlined = 0;
- drawbox = 0;
- }
- int TextBar::onLeftButtonDown(int x, int y) {
- TEXTBAR_PARENT::onLeftButtonDown(x, y);
- if (checkwndtarget) checkwndtarget->toggle();
- return 1;
- }
- void TextBar::setUseBaseTexture(int u) {
- usebt = u;
- invalidate();
- }
- int TextBar::onPaint(Canvas *canvas) {
- RECT r;
- PaintCanvas paintcanvas;
- if (canvas == NULL) {
- if (!paintcanvas.beginPaint(this)) return 0;
- canvas = &paintcanvas;
- }
- TEXTBAR_PARENT::onPaint(canvas);
- getClientRect(&r);
- if (!usebt) {
- if (drawbox) {
- canvas->fillRect(&r, bgcolor);
- }
- } else
- renderBaseTexture(canvas, r);
- const char *name = getName();
- if (name != NULL) {
- canvas->setTextOpaque(FALSE);
- canvas->pushTextSize(size);
- int w, h;
- canvas->getTextExtent(name, &w, &h);
- int y = (r.bottom-r.top - h) / 2;
- int x = 0;
- switch (alignment) {
- default:
- case TEXTALIGN_LEFT: x = TEXTBAR_LEFTMARGIN; break;
- case TEXTALIGN_CENTER: x = (r.right-r.left - w) / 2; break;
- case TEXTALIGN_RIGHT: x = (r.right-r.left - w); break;
- }
- if (!drawbox && textoutlined) {
- canvas->setTextColor(bgcolor);
- canvas->textOut(r.left+x+1, r.top+y+1, getName());
- canvas->setTextColor(bgcolor);
- canvas->textOut(r.left+x+1, r.top+y-1, getName());
- canvas->setTextColor(bgcolor);
- canvas->textOut(r.left+x-1, r.top+y+1, getName());
- canvas->setTextColor(bgcolor);
- canvas->textOut(r.left+x-1, r.top+y-1, getName());
- } else if (!drawbox && textshadowed) {
- canvas->setTextColor(bgcolor);
- canvas->textOut(r.left+x+1, r.top+y+1, getName());
- }
- canvas->setTextColor(fgcolor);
- canvas->textOut(r.left+x, r.top+y, getName());
- canvas->popTextSize();
- }
- return 1;
- }
- int TextBar::setTextSize(int newsize) {
- if (newsize < 1 || newsize > 72) return 0;
- size = newsize;
- invalidate();
- return 1;
- }
- int TextBar::setInt(int i) {
- setName(StringPrintf(i));
- invalidate();
- return 1;
- }
- void TextBar::onSetName() {
- TEXTBAR_PARENT::onSetName();
- invalidate();
- }
- int TextBar::getTextWidth() {
- if (!getName()) return 0;
- BltCanvas *c = new BltCanvas(10, 10);
- c->pushTextSize(size);
- int r = c->getTextWidth(getName());
- c->popTextSize();
- delete c;
- return r+4;
- }
- int TextBar::getTextHeight() {
- return size;
- }
- void TextBar::setAlign(TextAlign align) {
- if (alignment != align) {
- alignment = align;
- invalidate();
- }
- }
- TextAlign TextBar::getAlign() {
- return alignment;
- }
|