[+] Added ImageTextField

This commit is contained in:
cybermind 2015-03-12 11:08:56 +05:00
parent 3d7052c9b3
commit ad8cf65e4b
3 changed files with 96 additions and 0 deletions

View file

@ -256,6 +256,19 @@ private:
/// @todo Method to set this variable. Maybe set the variable static.
};
class ImageTextField : public gcn::TextField
{
public:
ImageTextField() : TextField(), itemImage(NULL) {}
ImageTextField(const std::string& text) : gcn::TextField(text), itemImage(NULL) {}
virtual void draw(gcn::Graphics *graphics);
virtual void drawBorder(gcn::Graphics *graphics);
void setItemImage(CGraphic *image) { itemImage = image; }
private:
CGraphic *itemImage;
};
class LuaListModel : public gcn::ListModel
{
std::vector<std::string> list;

View file

@ -467,6 +467,14 @@ class TextField : public Widget
virtual std::string &getText();
};
class ImageTextField : public Widget
{
ImageTextField(const std::string text);
virtual void setText(const std::string text);
virtual std::string &getText();
void setItemImage(CGraphic *image);
};
class ListBox : public Widget
{
};

View file

@ -1258,6 +1258,81 @@ void Windows::setBaseColor(const gcn::Color &color)
container.setBaseColor(color);
}
/*----------------------------------------------------------------------------
-- ImageTextField
----------------------------------------------------------------------------*/
void ImageTextField::draw(gcn::Graphics *graphics)
{
gcn::Font *font;
int x, y;
CGraphic *img = this->itemImage;
if (!img) {
fprintf(stderr, "Not all graphics for ImageTextField were set\n");
ExitFatal(1);
}
img->Resize(getWidth(), img->getHeight());
graphics->drawImage(img, 0, 0, 0, 0, getWidth(), img->getHeight());
if (hasFocus())
{
drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll);
}
graphics->setColor(getForegroundColor());
font = getFont();
graphics->setFont(font);
x = 1 - mXScroll;
y = 1;
if (mSelectEndOffset != 0)
{
unsigned int first;
unsigned int len;
int selX;
int selW;
std::string tmpStr;
getTextSelectionPositions(&first, &len);
tmpStr = std::string(mText.substr(0, first));
selX = font->getWidth(tmpStr);
tmpStr = std::string(mText.substr(first, len));
selW = font->getWidth(tmpStr);
graphics->setColor(gcn::Color(127, 127, 127));
graphics->fillRectangle(gcn::Rectangle(x + selX, y, selW, font->getHeight()));
}
graphics->drawText(mText, x, y);
}
void ImageTextField::drawBorder(gcn::Graphics *graphics)
{
gcn::Color faceColor = getBaseColor();
gcn::Color highlightColor, shadowColor;
int alpha = getBaseColor().a;
int width = getWidth() + getBorderSize() * 2 - 1;
int height = getHeight() + getBorderSize() * 2 - 1;
height = itemImage ? std::max<int>(height, itemImage->getHeight()) : height;
highlightColor = faceColor + 0x303030;
highlightColor.a = alpha;
shadowColor = faceColor - 0x303030;
shadowColor.a = alpha;
unsigned int i;
for (i = 0; i < getBorderSize(); ++i)
{
graphics->setColor(shadowColor);
graphics->drawLine(i,i, width - i, i);
graphics->drawLine(i,i + 1, i, height - i - 1);
graphics->setColor(highlightColor);
graphics->drawLine(width - i,i + 1, width - i, height - i);
graphics->drawLine(i,height - i, width - i - 1, height - i);
}
}
/*----------------------------------------------------------------------------
-- LuaListModel