mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-17 21:51:20 +02:00
Replace textblock with new multiline label - with text selection!!!!111!!!one!!
This commit is contained in:
@@ -452,6 +452,7 @@ int Graphics::textnwidth(char *s, int n)
|
|||||||
}
|
}
|
||||||
return x-1;
|
return x-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::textnpos(char *s, int n, int w, int *cx, int *cy)
|
void Graphics::textnpos(char *s, int n, int w, int *cx, int *cy)
|
||||||
{
|
{
|
||||||
int x = 0;
|
int x = 0;
|
||||||
@@ -508,6 +509,70 @@ int Graphics::textwidthx(char *s, int w)
|
|||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Graphics::PositionAtCharIndex(char *s, int charIndex, int & positionX, int & positionY)
|
||||||
|
{
|
||||||
|
int x = 0, y = 0, lines = 1;
|
||||||
|
for (; *s; s++)
|
||||||
|
{
|
||||||
|
if (!charIndex)
|
||||||
|
break;
|
||||||
|
if(*s == '\n') {
|
||||||
|
lines++;
|
||||||
|
x = 0;
|
||||||
|
y += FONT_H+2;
|
||||||
|
charIndex--;
|
||||||
|
continue;
|
||||||
|
} else if(*s =='\b') {
|
||||||
|
if(!s[1]) break;
|
||||||
|
s++;
|
||||||
|
charIndex-=2;
|
||||||
|
continue;
|
||||||
|
} else if(*s == '\x0F') {
|
||||||
|
if(!s[1] || !s[2] || !s[3]) break;
|
||||||
|
s+=3;
|
||||||
|
charIndex-=4;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||||
|
charIndex--;
|
||||||
|
}
|
||||||
|
positionX = x;
|
||||||
|
positionY = y;
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Graphics::CharIndexAtPosition(char *s, int positionX, int positionY)
|
||||||
|
{
|
||||||
|
int x=0, y=0,charIndex=0,cw;
|
||||||
|
for (; *s; s++)
|
||||||
|
{
|
||||||
|
if(*s == '\n') {
|
||||||
|
x = 0;
|
||||||
|
y += FONT_H+2;
|
||||||
|
charIndex++;
|
||||||
|
continue;
|
||||||
|
} else if(*s == '\b') {
|
||||||
|
if(!s[1]) break;
|
||||||
|
s++;
|
||||||
|
charIndex+=2;
|
||||||
|
continue;
|
||||||
|
} else if (*s == '\x0F') {
|
||||||
|
if(!s[1] || !s[2] || !s[3]) break;
|
||||||
|
s+=3;
|
||||||
|
charIndex+=4;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||||
|
if ((x+(cw/2) >= positionX && y+FONT_H >= positionY) || y > positionY)
|
||||||
|
break;
|
||||||
|
x += cw;
|
||||||
|
charIndex++;
|
||||||
|
}
|
||||||
|
return charIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int Graphics::textposxy(char *s, int width, int w, int h)
|
int Graphics::textposxy(char *s, int width, int w, int h)
|
||||||
{
|
{
|
||||||
int x=0,y=0,n=0,cw, wordlen, charspace;
|
int x=0,y=0,n=0,cw, wordlen, charspace;
|
||||||
|
@@ -122,6 +122,8 @@ public:
|
|||||||
static pixel *render_packed_rgb(void *image, int width, int height, int cmp_size);
|
static pixel *render_packed_rgb(void *image, int width, int height, int cmp_size);
|
||||||
|
|
||||||
//Font/text metrics
|
//Font/text metrics
|
||||||
|
static int CharIndexAtPosition(char *s, int positionX, int positionY);
|
||||||
|
static int PositionAtCharIndex(char *s, int charIndex, int & positionX, int & positionY);
|
||||||
static int textnwidth(char *s, int n);
|
static int textnwidth(char *s, int n);
|
||||||
static void textnpos(char *s, int n, int w, int *cx, int *cy);
|
static void textnpos(char *s, int n, int w, int *cx, int *cy);
|
||||||
static int textwidthx(char *s, int w);
|
static int textwidthx(char *s, int w);
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "ConfirmPrompt.h"
|
#include "ConfirmPrompt.h"
|
||||||
#include "Style.h"
|
#include "Style.h"
|
||||||
#include "interface/Textblock.h"
|
#include "interface/Label.h"
|
||||||
#include "interface/Button.h"
|
#include "interface/Button.h"
|
||||||
|
|
||||||
ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDialogueCallback * callback_):
|
ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDialogueCallback * callback_):
|
||||||
@@ -22,13 +22,12 @@ ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDial
|
|||||||
AddComponent(titleLabel);
|
AddComponent(titleLabel);
|
||||||
|
|
||||||
|
|
||||||
ui::Textblock * messageLabel = new ui::Textblock(ui::Point(4, 25), ui::Point(Size.X-8, 60), message);
|
ui::Label * messageLabel = new ui::Label(ui::Point(4, 25), ui::Point(Size.X-8, -1), message);
|
||||||
Graphics::textsize(messageLabel->GetDisplayText().c_str(), width, height);
|
|
||||||
messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||||
AddComponent(messageLabel);
|
AddComponent(messageLabel);
|
||||||
|
|
||||||
Size.Y += height;
|
Size.Y += messageLabel->Size.Y;
|
||||||
Position.Y = (ui::Engine::Ref().GetHeight()-Size.Y)/2;
|
Position.Y = (ui::Engine::Ref().GetHeight()-Size.Y)/2;
|
||||||
|
|
||||||
class CloseAction: public ui::ButtonAction
|
class CloseAction: public ui::ButtonAction
|
||||||
|
@@ -16,6 +16,7 @@ Component::Component(Window* parent_state):
|
|||||||
Locked(false),
|
Locked(false),
|
||||||
Visible(true),
|
Visible(true),
|
||||||
textPosition(0, 0),
|
textPosition(0, 0),
|
||||||
|
textSize(0, 0),
|
||||||
iconPosition(0, 0),
|
iconPosition(0, 0),
|
||||||
drawn(false)
|
drawn(false)
|
||||||
{
|
{
|
||||||
@@ -30,6 +31,7 @@ Component::Component(Point position, Point size):
|
|||||||
Locked(false),
|
Locked(false),
|
||||||
Visible(true),
|
Visible(true),
|
||||||
textPosition(0, 0),
|
textPosition(0, 0),
|
||||||
|
textSize(0, 0),
|
||||||
iconPosition(0, 0),
|
iconPosition(0, 0),
|
||||||
drawn(false)
|
drawn(false)
|
||||||
{
|
{
|
||||||
@@ -44,6 +46,7 @@ Component::Component():
|
|||||||
Locked(false),
|
Locked(false),
|
||||||
Visible(true),
|
Visible(true),
|
||||||
textPosition(0, 0),
|
textPosition(0, 0),
|
||||||
|
textSize(0, 0),
|
||||||
iconPosition(0, 0),
|
iconPosition(0, 0),
|
||||||
drawn(false)
|
drawn(false)
|
||||||
{
|
{
|
||||||
@@ -62,6 +65,7 @@ void Component::TextPosition(std::string displayText)
|
|||||||
|
|
||||||
int textWidth, textHeight = 10;
|
int textWidth, textHeight = 10;
|
||||||
Graphics::textsize((char*)displayText.c_str(), textWidth, textHeight);
|
Graphics::textsize((char*)displayText.c_str(), textWidth, textHeight);
|
||||||
|
textSize.X = textWidth; textSize.Y = textHeight;
|
||||||
textHeight-=3;
|
textHeight-=3;
|
||||||
textWidth-=1;
|
textWidth-=1;
|
||||||
if(Appearance.icon)
|
if(Appearance.icon)
|
||||||
|
@@ -23,6 +23,7 @@ namespace ui
|
|||||||
protected:
|
protected:
|
||||||
bool drawn;
|
bool drawn;
|
||||||
ui::Point textPosition;
|
ui::Point textPosition;
|
||||||
|
ui::Point textSize;
|
||||||
ui::Point iconPosition;
|
ui::Point iconPosition;
|
||||||
public:
|
public:
|
||||||
Component(Window* parent_state);
|
Component(Window* parent_state);
|
||||||
|
@@ -5,57 +5,199 @@
|
|||||||
|
|
||||||
using namespace ui;
|
using namespace ui;
|
||||||
|
|
||||||
/*Label::Label(Window* parent_state, std::string labelText):
|
|
||||||
Component(parent_state),
|
|
||||||
text(labelText),
|
|
||||||
textPosition(ui::Point(0, 0)),
|
|
||||||
textVAlign(AlignMiddle),
|
|
||||||
textHAlign(AlignCentre)
|
|
||||||
{
|
|
||||||
TextPosition();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
Label::Label(Point position, Point size, std::string labelText):
|
Label::Label(Point position, Point size, std::string labelText):
|
||||||
Component(position, size),
|
Component(position, size),
|
||||||
text(labelText),
|
text(labelText),
|
||||||
textColour(255, 255, 255)
|
textColour(255, 255, 255),
|
||||||
|
selectionIndex0(-1),
|
||||||
|
selectionIndex1(-1),
|
||||||
|
selectionXL(-1),
|
||||||
|
selectionXH(-1),
|
||||||
|
multiline(false),
|
||||||
|
selecting(false),
|
||||||
|
autoHeight(size.Y==-1?true:false),
|
||||||
|
caret(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Label::Label(std::string labelText):
|
|
||||||
Component(),
|
|
||||||
text(labelText),
|
|
||||||
textPosition(ui::Point(0, 0)),
|
|
||||||
textVAlign(AlignMiddle),
|
|
||||||
textHAlign(AlignCentre)
|
|
||||||
{
|
|
||||||
TextPosition();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
Label::~Label()
|
Label::~Label()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Label::SetMultiline(bool status)
|
||||||
|
{
|
||||||
|
multiline = status;
|
||||||
|
if(status)
|
||||||
|
{
|
||||||
|
updateMultiline();
|
||||||
|
updateSelection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Label::SetText(std::string text)
|
void Label::SetText(std::string text)
|
||||||
{
|
{
|
||||||
this->text = text;
|
this->text = text;
|
||||||
|
if(multiline)
|
||||||
|
{
|
||||||
|
updateMultiline();
|
||||||
|
updateSelection();
|
||||||
|
}
|
||||||
TextPosition(text);
|
TextPosition(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Label::updateMultiline()
|
||||||
|
{
|
||||||
|
char * rawText = new char[text.length()+1];
|
||||||
|
std::copy(text.begin(), text.end(), rawText);
|
||||||
|
rawText[text.length()] = 0;
|
||||||
|
|
||||||
|
int lines = 1;
|
||||||
|
int currentWidth = 0;
|
||||||
|
char * lastSpace = NULL;
|
||||||
|
char * currentWord = rawText;
|
||||||
|
char * nextSpace;
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
nextSpace = strchr(currentWord+1, ' ');
|
||||||
|
if(nextSpace)
|
||||||
|
nextSpace[0] = 0;
|
||||||
|
int width = Graphics::textwidth(currentWord);
|
||||||
|
if(width+currentWidth > Size.X-6)
|
||||||
|
{
|
||||||
|
currentWidth = width;
|
||||||
|
currentWord[0] = '\n';
|
||||||
|
lines++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
currentWidth += width;
|
||||||
|
if(nextSpace)
|
||||||
|
nextSpace[0] = ' ';
|
||||||
|
if(!(currentWord = strchr(currentWord+1, ' ')))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(autoHeight)
|
||||||
|
{
|
||||||
|
Size.Y = lines*12;
|
||||||
|
}
|
||||||
|
textLines = std::string(rawText);
|
||||||
|
delete[] rawText;
|
||||||
|
}
|
||||||
|
|
||||||
std::string Label::GetText()
|
std::string Label::GetText()
|
||||||
{
|
{
|
||||||
return this->text;
|
return this->text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Label::OnMouseClick(int x, int y, unsigned button)
|
||||||
|
{
|
||||||
|
if(x > textPosition.X && x < textPosition.X + textSize.X && y > textPosition.Y && y < textPosition.Y + textSize.Y)
|
||||||
|
{
|
||||||
|
selecting = true;
|
||||||
|
if(multiline)
|
||||||
|
selectionIndex0 = Graphics::CharIndexAtPosition((char*)textLines.c_str(), x-textPosition.X, y-textPosition.Y);
|
||||||
|
else
|
||||||
|
selectionIndex0 = Graphics::CharIndexAtPosition((char*)text.c_str(), x-textPosition.X, y-textPosition.Y);
|
||||||
|
selectionIndex1 = selectionIndex0;
|
||||||
|
|
||||||
|
updateSelection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Label::OnMouseUp(int x, int y, unsigned button)
|
||||||
|
{
|
||||||
|
selecting = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Label::OnMouseMoved(int localx, int localy, int dx, int dy)
|
||||||
|
{
|
||||||
|
if(selecting)
|
||||||
|
{
|
||||||
|
if(multiline)
|
||||||
|
selectionIndex1 = Graphics::CharIndexAtPosition((char*)textLines.c_str(), localx-textPosition.X, localy-textPosition.Y);
|
||||||
|
else
|
||||||
|
selectionIndex1 = Graphics::CharIndexAtPosition((char*)text.c_str(), localx-textPosition.X, localy-textPosition.Y);
|
||||||
|
updateSelection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Label::updateSelection()
|
||||||
|
{
|
||||||
|
std::string currentText;
|
||||||
|
if(multiline)
|
||||||
|
currentText = textLines;
|
||||||
|
else
|
||||||
|
currentText = text;
|
||||||
|
if(selectionIndex1 > selectionIndex0) {
|
||||||
|
selectionLineH = Graphics::PositionAtCharIndex((char*)currentText.c_str(), selectionIndex1, selectionXH, selectionYH);
|
||||||
|
selectionLineL = Graphics::PositionAtCharIndex((char*)currentText.c_str(), selectionIndex0, selectionXL, selectionYL);
|
||||||
|
|
||||||
|
textFragments = std::string(currentText);
|
||||||
|
textFragments.insert(selectionIndex1, "\x0E");
|
||||||
|
textFragments.insert(selectionIndex0, "\x0F\x01\x01\x01");
|
||||||
|
} else if(selectionIndex0 > selectionIndex1) {
|
||||||
|
selectionLineH = Graphics::PositionAtCharIndex((char*)currentText.c_str(), selectionIndex0, selectionXH, selectionYH);
|
||||||
|
selectionLineL = Graphics::PositionAtCharIndex((char*)currentText.c_str(), selectionIndex1, selectionXL, selectionYL);
|
||||||
|
|
||||||
|
textFragments = std::string(currentText);
|
||||||
|
textFragments.insert(selectionIndex0, "\x0E");
|
||||||
|
textFragments.insert(selectionIndex1, "\x0F\x01\x01\x01");
|
||||||
|
} else {
|
||||||
|
selectionXH = -1;
|
||||||
|
selectionXL = -1;
|
||||||
|
|
||||||
|
textFragments = std::string(currentText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Label::Draw(const Point& screenPos)
|
void Label::Draw(const Point& screenPos)
|
||||||
{
|
{
|
||||||
if(!drawn)
|
if(!drawn)
|
||||||
{
|
{
|
||||||
TextPosition(text);
|
if(multiline)
|
||||||
|
{
|
||||||
|
TextPosition(textLines);
|
||||||
|
updateMultiline();
|
||||||
|
updateSelection();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
TextPosition(text);
|
||||||
drawn = true;
|
drawn = true;
|
||||||
}
|
}
|
||||||
Graphics * g = Engine::Ref().g;
|
Graphics * g = Engine::Ref().g;
|
||||||
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, text, textColour.Red, textColour.Green, textColour.Blue, 255);
|
|
||||||
|
if(multiline)
|
||||||
|
{
|
||||||
|
if(selectionXL != -1 && selectionXH != -1)
|
||||||
|
{
|
||||||
|
if(selectionLineH - selectionLineL > 0)
|
||||||
|
{
|
||||||
|
g->fillrect(screenPos.X+textPosition.X+selectionXL, (screenPos.Y+textPosition.Y-1)+selectionYL, textSize.X-(selectionXL), 10, 255, 255, 255, 255);
|
||||||
|
for(int i = 1; i < selectionLineH-selectionLineL; i++)
|
||||||
|
{
|
||||||
|
g->fillrect(screenPos.X+textPosition.X, (screenPos.Y+textPosition.Y-1)+selectionYL+(i*12), textSize.X, 10, 255, 255, 255, 255);
|
||||||
|
}
|
||||||
|
g->fillrect(screenPos.X+textPosition.X, (screenPos.Y+textPosition.Y-1)+selectionYH, selectionXH, 10, 255, 255, 255, 255);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
g->fillrect(screenPos.X+textPosition.X+selectionXL, screenPos.Y+selectionYL+textPosition.Y-1, selectionXH-(selectionXL), 10, 255, 255, 255, 255);
|
||||||
|
}
|
||||||
|
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, textFragments, textColour.Red, textColour.Green, textColour.Blue, 255);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, textLines, textColour.Red, textColour.Green, textColour.Blue, 255);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(selectionXL != -1 && selectionXH != -1)
|
||||||
|
{
|
||||||
|
g->fillrect(screenPos.X+textPosition.X+selectionXL, screenPos.Y+textPosition.Y-1, selectionXH-(selectionXL), 10, 255, 255, 255, 255);
|
||||||
|
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, textFragments, textColour.Red, textColour.Green, textColour.Blue, 255);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, text, textColour.Red, textColour.Green, textColour.Blue, 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,20 +12,44 @@ namespace ui
|
|||||||
class Label : public Component
|
class Label : public Component
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
std::string textFragments;
|
||||||
|
std::string textLines;
|
||||||
|
|
||||||
std::string text;
|
std::string text;
|
||||||
Colour textColour;
|
Colour textColour;
|
||||||
|
int caret;
|
||||||
|
int selectionIndex0;
|
||||||
|
int selectionIndex1;
|
||||||
|
|
||||||
|
int selectionXL;
|
||||||
|
int selectionXH;
|
||||||
|
int selectionYL;
|
||||||
|
int selectionYH;
|
||||||
|
int selectionLineL;
|
||||||
|
int selectionLineH;
|
||||||
|
|
||||||
|
bool multiline;
|
||||||
|
bool selecting;
|
||||||
|
bool autoHeight;
|
||||||
|
|
||||||
|
void updateMultiline();
|
||||||
|
void updateSelection();
|
||||||
public:
|
public:
|
||||||
//Label(Window* parent_state, std::string labelText);
|
//Label(Window* parent_state, std::string labelText);
|
||||||
Label(Point position, Point size, std::string labelText);
|
Label(Point position, Point size, std::string labelText);
|
||||||
//Label(std::string labelText);
|
//Label(std::string labelText);
|
||||||
virtual ~Label();
|
virtual ~Label();
|
||||||
|
|
||||||
|
virtual void SetMultiline(bool status);
|
||||||
virtual void SetText(std::string text);
|
virtual void SetText(std::string text);
|
||||||
virtual std::string GetText();
|
virtual std::string GetText();
|
||||||
|
|
||||||
void SetTextColour(Colour textColour) { this->textColour = textColour; }
|
void SetTextColour(Colour textColour) { this->textColour = textColour; }
|
||||||
|
|
||||||
|
|
||||||
|
virtual void OnMouseClick(int x, int y, unsigned button);
|
||||||
|
virtual void OnMouseUp(int x, int y, unsigned button);
|
||||||
|
virtual void OnMouseMoved(int localx, int localy, int dx, int dy);
|
||||||
virtual void Draw(const Point& screenPos);
|
virtual void Draw(const Point& screenPos);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* Textblock.cpp
|
|
||||||
*
|
|
||||||
* Created on: Jan 29, 2012
|
|
||||||
* Author: Simon
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include "Textblock.h"
|
|
||||||
|
|
||||||
using namespace ui;
|
|
||||||
|
|
||||||
Textblock::Textblock(Point position, Point size, std::string textboxText):
|
|
||||||
Label(position, size, textboxText)
|
|
||||||
{
|
|
||||||
if(size.Y==-1)
|
|
||||||
autoHeight = true;
|
|
||||||
else
|
|
||||||
autoHeight = false;
|
|
||||||
updateMultiline();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Textblock::SetText(std::string text)
|
|
||||||
{
|
|
||||||
this->text = text;
|
|
||||||
updateMultiline();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Textblock::updateMultiline()
|
|
||||||
{
|
|
||||||
char * rawText = new char[text.length()+1];
|
|
||||||
std::copy(text.begin(), text.end(), rawText);
|
|
||||||
rawText[text.length()] = 0;
|
|
||||||
|
|
||||||
int lines = 1;
|
|
||||||
int currentWidth = 0;
|
|
||||||
char * lastSpace = NULL;
|
|
||||||
char * currentWord = rawText;
|
|
||||||
char * nextSpace;
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
nextSpace = strchr(currentWord+1, ' ');
|
|
||||||
if(nextSpace)
|
|
||||||
nextSpace[0] = 0;
|
|
||||||
int width = Graphics::textwidth(currentWord);
|
|
||||||
if(width+currentWidth > Size.X-6)
|
|
||||||
{
|
|
||||||
currentWidth = width;
|
|
||||||
currentWord[0] = '\n';
|
|
||||||
lines++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
currentWidth += width;
|
|
||||||
if(nextSpace)
|
|
||||||
nextSpace[0] = ' ';
|
|
||||||
if(!(currentWord = strchr(currentWord+1, ' ')))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(autoHeight)
|
|
||||||
{
|
|
||||||
Size.Y = lines*12;
|
|
||||||
}
|
|
||||||
textLines = std::string(rawText);
|
|
||||||
delete[] rawText;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Textblock::Draw(const Point &screenPos)
|
|
||||||
{
|
|
||||||
Graphics * g = ui::Engine::Ref().g;
|
|
||||||
//g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, textColour.Red, textColour.Green, textColour.Blue, 255);
|
|
||||||
g->drawtext(screenPos.X+3, screenPos.Y+3, textLines, textColour.Red, textColour.Green, textColour.Blue, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
Textblock::~Textblock() {
|
|
||||||
// TODO Auto-generated destructor stub
|
|
||||||
}
|
|
||||||
|
|
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Textblock.h
|
|
||||||
*
|
|
||||||
* Created on: Jan 29, 2012
|
|
||||||
* Author: Simon
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TEXTBLOCK_H_
|
|
||||||
#define TEXTBLOCK_H_
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <sstream>
|
|
||||||
#include "Label.h"
|
|
||||||
|
|
||||||
namespace ui
|
|
||||||
{
|
|
||||||
|
|
||||||
class Textblock: public ui::Label
|
|
||||||
{
|
|
||||||
bool autoHeight;
|
|
||||||
void updateMultiline();
|
|
||||||
std::string textLines;
|
|
||||||
public:
|
|
||||||
Textblock(Point position, Point size, std::string textboxText);
|
|
||||||
virtual void TextPosition() {}
|
|
||||||
virtual void SetText(std::string text);
|
|
||||||
virtual std::string GetDisplayText() { return textLines; }
|
|
||||||
virtual void Draw(const Point& screenPos);
|
|
||||||
virtual ~Textblock();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* TEXTBLOCK_H_ */
|
|
@@ -5,6 +5,7 @@
|
|||||||
* Author: Simon
|
* Author: Simon
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "PreviewView.h"
|
#include "PreviewView.h"
|
||||||
@@ -106,10 +107,12 @@ PreviewView::PreviewView():
|
|||||||
saveNameLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; saveNameLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
saveNameLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; saveNameLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||||
AddComponent(saveNameLabel);
|
AddComponent(saveNameLabel);
|
||||||
|
|
||||||
saveDescriptionTextblock = new ui::Textblock(ui::Point(5, (YRES/2)+15+14+17), ui::Point((XRES/2)-10, Size.Y-((YRES/2)+15+14+17)-21), "");
|
saveDescriptionLabel = new ui::Label(ui::Point(5, (YRES/2)+15+14+17), ui::Point((XRES/2)-10, Size.Y-((YRES/2)+15+14+17)-21), "");
|
||||||
saveDescriptionTextblock->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; saveDescriptionTextblock->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
saveDescriptionLabel->SetMultiline(true);
|
||||||
saveDescriptionTextblock->SetTextColour(ui::Colour(180, 180, 180));
|
saveDescriptionLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
AddComponent(saveDescriptionTextblock);
|
saveDescriptionLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||||
|
saveDescriptionLabel->SetTextColour(ui::Colour(180, 180, 180));
|
||||||
|
AddComponent(saveDescriptionLabel);
|
||||||
|
|
||||||
authorDateLabel = new ui::Label(ui::Point(5, (YRES/2)+15+14), ui::Point(100, 16), "");
|
authorDateLabel = new ui::Label(ui::Point(5, (YRES/2)+15+14), ui::Point(100, 16), "");
|
||||||
authorDateLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; authorDateLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
authorDateLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; authorDateLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||||
@@ -231,7 +234,7 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
|||||||
votesDown = save->votesDown;
|
votesDown = save->votesDown;
|
||||||
saveNameLabel->SetText(save->name);
|
saveNameLabel->SetText(save->name);
|
||||||
authorDateLabel->SetText("\bgAuthor:\bw " + save->userName + " \bgDate:\bw ");
|
authorDateLabel->SetText("\bgAuthor:\bw " + save->userName + " \bgDate:\bw ");
|
||||||
saveDescriptionTextblock->SetText(save->Description);
|
saveDescriptionLabel->SetText(save->Description);
|
||||||
if(save->Favourite)
|
if(save->Favourite)
|
||||||
favButton->Enabled = false;
|
favButton->Enabled = false;
|
||||||
else
|
else
|
||||||
@@ -261,7 +264,7 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
|||||||
votesDown = 0;
|
votesDown = 0;
|
||||||
saveNameLabel->SetText("");
|
saveNameLabel->SetText("");
|
||||||
authorDateLabel->SetText("");
|
authorDateLabel->SetText("");
|
||||||
saveDescriptionTextblock->SetText("");
|
saveDescriptionLabel->SetText("");
|
||||||
favButton->Enabled = false;
|
favButton->Enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,7 +281,7 @@ void PreviewView::displayComments(int yOffset)
|
|||||||
|
|
||||||
int currentY = -yOffset;
|
int currentY = -yOffset;
|
||||||
ui::Label * tempUsername;
|
ui::Label * tempUsername;
|
||||||
ui::Textblock * tempComment;
|
ui::Label * tempComment;
|
||||||
for(int i = 0; i < comments.size(); i++)
|
for(int i = 0; i < comments.size(); i++)
|
||||||
{
|
{
|
||||||
int usernameY = currentY+5, commentY;
|
int usernameY = currentY+5, commentY;
|
||||||
@@ -299,7 +302,8 @@ void PreviewView::displayComments(int yOffset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
commentY = currentY+5;
|
commentY = currentY+5;
|
||||||
tempComment = new ui::Textblock(ui::Point((XRES/2) + 5, currentY+5), ui::Point(Size.X-((XRES/2) + 10), -1), comments[i].comment);
|
tempComment = new ui::Label(ui::Point((XRES/2) + 5, currentY+5), ui::Point(Size.X-((XRES/2) + 10), -1), comments[i].comment);
|
||||||
|
tempComment->SetMultiline(true);
|
||||||
tempComment->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempComment->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
tempComment->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempComment->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||||
tempComment->SetTextColour(ui::Colour(180, 180, 180));
|
tempComment->SetTextColour(ui::Colour(180, 180, 180));
|
||||||
currentY += tempComment->Size.Y+4;
|
currentY += tempComment->Size.Y+4;
|
||||||
@@ -338,7 +342,7 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ui::Label * tempUsername;
|
ui::Label * tempUsername;
|
||||||
ui::Textblock * tempComment;
|
ui::Label * tempComment;
|
||||||
int maxY = 0;
|
int maxY = 0;
|
||||||
for(int i = 0; i < comments.size(); i++)
|
for(int i = 0; i < comments.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -346,7 +350,7 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
|
|||||||
tempUsername->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
tempUsername->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||||
maxY += 16;
|
maxY += 16;
|
||||||
tempComment = new ui::Textblock(ui::Point(0, 0), ui::Point(Size.X-((XRES/2) + 10), -1), comments[i].comment);
|
tempComment = new ui::Label(ui::Point(0, 0), ui::Point(Size.X-((XRES/2) + 10), -1), comments[i].comment);
|
||||||
tempComment->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
tempComment->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
tempComment->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
tempComment->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||||
tempComment->SetTextColour(ui::Colour(180, 180, 180));
|
tempComment->SetTextColour(ui::Colour(180, 180, 180));
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
#include "interface/Button.h"
|
#include "interface/Button.h"
|
||||||
#include "search/Thumbnail.h"
|
#include "search/Thumbnail.h"
|
||||||
#include "interface/Label.h"
|
#include "interface/Label.h"
|
||||||
#include "interface/Textblock.h"
|
|
||||||
|
|
||||||
class PreviewModel;
|
class PreviewModel;
|
||||||
class PreviewController;
|
class PreviewController;
|
||||||
@@ -30,7 +29,7 @@ class PreviewView: public ui::Window {
|
|||||||
ui::Label * saveNameLabel;
|
ui::Label * saveNameLabel;
|
||||||
ui::Label * authorDateLabel;
|
ui::Label * authorDateLabel;
|
||||||
ui::Label * pageInfo;
|
ui::Label * pageInfo;
|
||||||
ui::Textblock * saveDescriptionTextblock;
|
ui::Label * saveDescriptionLabel;
|
||||||
std::vector<SaveComment> comments;
|
std::vector<SaveComment> comments;
|
||||||
std::vector<ui::Component*> commentComponents;
|
std::vector<ui::Component*> commentComponents;
|
||||||
std::vector<ui::Component*> commentTextComponents;
|
std::vector<ui::Component*> commentTextComponents;
|
||||||
|
Reference in New Issue
Block a user