diff options
author | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
---|---|---|
committer | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
commit | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Wasabi/api/wnd/wndclass/textbar.cpp | |
parent | 537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff) | |
download | winamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz |
Initial community commit
Diffstat (limited to 'Src/Wasabi/api/wnd/wndclass/textbar.cpp')
-rw-r--r-- | Src/Wasabi/api/wnd/wndclass/textbar.cpp | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/Src/Wasabi/api/wnd/wndclass/textbar.cpp b/Src/Wasabi/api/wnd/wndclass/textbar.cpp new file mode 100644 index 00000000..ae695419 --- /dev/null +++ b/Src/Wasabi/api/wnd/wndclass/textbar.cpp @@ -0,0 +1,148 @@ +#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; //set default alignment + checkwndtarget = NULL; + + textshadowed = 1; // display a shadow of the text in bgcolor. default: on + textoutlined = 0; // draw an outline of the text in bgcolor. default: off + drawbox = 0; // draw a box of bgcolor the size of the boundsrect. default: off + +// bgbitmap = "studio.textBar.background"; +} + +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); + } +/* + if (bgbitmap.getBitmap()->isInvalid()) + canvas->fillRect(&r, bgcolor); + else { + RECT br; + br.left = 0; + br.top = 0; + br.right = bgbitmap.getWidth(); + br.bottom = bgbitmap.getHeight(); + bgbitmap.getBitmap()->blitToRect(canvas, &br, &r, 255); + } +*/ + } 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 = centered ? (r.right-r.left - w) / 2 : TEXTBAR_LEFTMARGIN; //teh old code + + 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; +} |