NS/main/source/cl_dll/CLabelHeader.h
Karl 8552ac617c Import from old repository
git-svn-id: https://unknownworlds.svn.cloudforge.com/ns1@1 67975925-1194-0748-b3d5-c16f83f1a3a1
2005-03-09 01:31:56 +00:00

193 lines
No EOL
3.4 KiB
C++

#ifndef CLABELHEADER_H
#define CLABELHEADER_H
#include<VGUI_TextImage.h>
#include "cl_dll/vgui_TeamFortressViewport.h"
class CTextImage2 : public Image
{
public:
CTextImage2()
{
_image[0] = new TextImage("");
_image[1] = new TextImage("");
}
~CTextImage2()
{
delete _image[0];
delete _image[1];
}
TextImage *GetImage(int image)
{
return _image[image];
}
void getSize(int &wide, int &tall)
{
int w1, w2, t1, t2;
_image[0]->getTextSize(w1, t1);
_image[1]->getTextSize(w2, t2);
wide = w1 + w2;
tall = max(t1, t2);
setSize(wide, tall);
}
void doPaint(Panel *panel)
{
_image[0]->doPaint(panel);
_image[1]->doPaint(panel);
}
void setPos(int x, int y)
{
_image[0]->setPos(x, y);
int swide, stall;
_image[0]->getSize(swide, stall);
int wide, tall;
_image[1]->getSize(wide, tall);
_image[1]->setPos(x + wide, y + (stall * 0.9) - tall);
}
void setColor(Color color)
{
_image[0]->setColor(color);
}
void setColor2(Color color)
{
_image[1]->setColor(color);
}
private:
TextImage *_image[2];
};
class CLabelHeader : public Label
{
public:
CLabelHeader() : Label("")
{
_dualImage = new CTextImage2();
_dualImage->setColor2(Color(255, 170, 0, 0));
_row = -2;
_useFgColorAsImageColor = true;
_offset[0] = 0;
_offset[1] = 0;
}
~CLabelHeader()
{
delete _dualImage;
}
void setRow(int row)
{
_row = row;
}
void setFgColorAsImageColor(bool state)
{
_useFgColorAsImageColor = state;
}
virtual void setText(int textBufferLen, const char* text)
{
_dualImage->GetImage(0)->setText(text);
// calculate the text size
Font *font = _dualImage->GetImage(0)->getFont();
_gap = 0;
for (const char *ch = text; *ch != 0; ch++)
{
int a, b, c;
font->getCharABCwide(*ch, a, b, c);
_gap += (a + b + c);
}
_gap += XRES(5);
}
virtual void setText(const char* text)
{
// strip any non-alnum characters from the end
char buf[512];
strcpy(buf, text);
int len = strlen(buf);
while (len && isspace(buf[--len]))
{
buf[len] = 0;
}
CLabelHeader::setText(0, buf);
}
void setText2(const char *text)
{
_dualImage->GetImage(1)->setText(text);
}
void getTextSize(int &wide, int &tall)
{
_dualImage->getSize(wide, tall);
}
void setFgColor(int r,int g,int b,int a)
{
Label::setFgColor(r,g,b,a);
Color color(r,g,b,a);
_dualImage->setColor(color);
_dualImage->setColor2(color);
if (_image && _useFgColorAsImageColor)
{
_image->setColor(color);
}
repaint();
}
void setFgColor(Scheme::SchemeColor sc)
{
int r, g, b, a;
Label::setFgColor(sc);
Label::getFgColor( r, g, b, a );
// Call the r,g,b,a version so it sets the color in the dualImage..
setFgColor( r, g, b, a );
}
void setFont(Font *font)
{
_dualImage->GetImage(0)->setFont(font);
}
void setFont2(Font *font)
{
_dualImage->GetImage(1)->setFont(font);
}
// this adjust the absolute position of the text after alignment is calculated
void setTextOffset(int x, int y)
{
_offset[0] = x;
_offset[1] = y;
}
void paint();
void paintBackground();
void calcAlignment(int iwide, int itall, int &x, int &y);
private:
CTextImage2 *_dualImage;
int _row;
int _gap;
int _offset[2];
bool _useFgColorAsImageColor;
};
#endif