Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
44 KB
Referenced Files
None
Subscribers
None
diff --git a/util/gui/context-box.cpp b/util/gui/context-box.cpp
index 123fff09..ca4f791f 100644
--- a/util/gui/context-box.cpp
+++ b/util/gui/context-box.cpp
@@ -1,398 +1,428 @@
#include "util/bitmap.h"
#include "util/trans-bitmap.h"
#include "context-box.h"
#include "util/font.h"
#include <math.h>
static const double FONT_SPACER = 1.3;
static const int GradientMax = 50;
static int selectedGradientStart(){
static int color = Graphics::makeColor(19, 167, 168);
return color;
}
static int selectedGradientEnd(){
static int color = Graphics::makeColor(27, 237, 239);
return color;
}
using namespace std;
-using namespace Gui;
+
+namespace Gui{
ContextItem::ContextItem(){
}
+
ContextItem::~ContextItem(){
}
+
bool ContextItem::isAdjustable(){
return false;
}
int ContextItem::getLeftColor(){
return 0;
}
int ContextItem::getRightColor(){
return 0;
}
+void ContextItem::draw(int x, int y, const Graphics::Bitmap & where, const Font & font) const {
+ font.printf(x, y, Graphics::makeColor(255, 255, 255), where, getName(), 0);
+}
+
+int ContextItem::size() const {
+ return 0;
+}
+
ContextBox::ContextBox():
-current(0),
fadeState(NotActive),
/*
fontWidth(0),
fontHeight(0),
*/
fadeSpeed(12),
fadeAlpha(0),
cursorCenter(0),
cursorLocation(0),
scrollWait(4),
selectedGradient(GradientMax, selectedGradientStart(), selectedGradientEnd()),
useGradient(true),
renderOnlyText(false){
}
ContextBox::ContextBox( const ContextBox & copy ):
-current(0),
fadeState(NotActive),
selectedGradient(GradientMax, selectedGradientStart(), selectedGradientEnd()),
renderOnlyText(false){
- this->context = copy.context;
+ this->list = copy.list;
+ // this->context = copy.context;
/*
this->font = copy.font;
this->fontWidth = copy.fontWidth;
this->fontHeight = copy.fontHeight;
*/
this->fadeSpeed = copy.fadeSpeed;
this->fadeAlpha = copy.fadeAlpha;
this->cursorCenter = copy.cursorCenter;
this->cursorLocation = copy.cursorLocation;
this->scrollWait = copy.scrollWait;
this->useGradient = copy.useGradient;
this->renderOnlyText = copy.renderOnlyText;
}
ContextBox::~ContextBox(){
}
ContextBox & ContextBox::operator=( const ContextBox & copy){
- this->current = 0;
this->fadeState = NotActive;
- this->context = copy.context;
+ this->list = copy.list;
+ // this->context = copy.context;
/*
this->font = copy.font;
this->fontWidth = copy.fontWidth;
this->fontHeight = copy.fontHeight;
*/
this->fadeSpeed = copy.fadeSpeed;
this->fadeAlpha = copy.fadeAlpha;
this->cursorCenter = copy.cursorCenter;
this->cursorLocation = copy.cursorLocation;
this->scrollWait = copy.scrollWait;
this->useGradient = copy.useGradient;
this->renderOnlyText = copy.renderOnlyText;
return *this;
}
void ContextBox::act(const Font & font){
// update board
board.act(font);
// Calculate text info
- calculateText(font);
+ // calculateText(font);
+ list.act();
// do fade
doFade();
// Update gradient
selectedGradient.update();
}
void ContextBox::render(const Graphics::Bitmap & work){
}
void ContextBox::render(const Graphics::Bitmap & work, const Font & font){
-
if (!renderOnlyText){
board.render(work);
}
drawText(work, font);
}
bool ContextBox::next(const Font & font){
if (fadeState == FadeOut){
return false;
}
+ list.next();
+
/*
- const Font & vFont = Font::getFont(font, fontWidth, fontHeight);
- */
cursorLocation += (int)(font.getHeight()/FONT_SPACER);
if (current < context.size()-1){
current++;
} else {
current = 0;
}
+ */
return true;
}
bool ContextBox::previous(const Font & font){
if (fadeState == FadeOut){
return false;
}
+ list.previous();
+
/*
- const Font & vFont = Font::getFont(font, fontWidth, fontHeight);
- */
cursorLocation -= (int)(font.getHeight()/FONT_SPACER);
if (current > 0){
current--;
} else {
current = context.size()-1;
}
+ */
return true;
}
void ContextBox::adjustLeft(){
}
void ContextBox::adjustRight(){
}
void ContextBox::open(){
// Set the fade stuff
fadeState = FadeIn;
//board.position = position;
board.location = location;
board.colors = colors;
board.open();
fadeAlpha = 0;
cursorLocation = 0;
}
void ContextBox::close(){
fadeState = FadeOut;
board.close();
fadeAlpha = 255;
cursorLocation = 480;
}
void ContextBox::doFade(){
switch ( fadeState ){
case FadeIn: {
if (fadeAlpha < 255){
fadeAlpha += (fadeSpeed+2);
}
if (fadeAlpha >= 255){
fadeAlpha = 255;
if (board.isActive()){
fadeState = Active;
}
}
break;
}
case FadeOut: {
if (fadeAlpha > 0){
fadeAlpha -= (fadeSpeed+2);
}
if (fadeAlpha <= 0){
fadeAlpha = 0;
if (!board.isActive()){
fadeState = NotActive;
}
}
break;
}
case Active:
case NotActive:
default:
break;
}
}
void ContextBox::calculateText(const Font & vFont){
+ /*
if (context.empty()){
return;
}
// const Font & vFont = Font::getFont(font, fontWidth, fontHeight);
cursorCenter = (location.getY() + (int)location.getHeight()/2) - vFont.getHeight()/2;//(position.y + (int)position.height/2) - vFont.getHeight()/2;
if (cursorLocation == cursorCenter){
scrollWait = 4;
} else {
if (scrollWait <= 0){
cursorLocation = (cursorLocation + cursorCenter)/2;
scrollWait = 4;
} else {
scrollWait--;
}
}
+ */
}
/* draws the text, fading the items according to the distance from the
* current selection.
*/
void ContextBox::doDraw(int x, int y, int middle_x, int min_y, int max_y, const Font & font, int current, int selected, const Graphics::Bitmap & area, int direction){
+#if 0
while (y < max_y && y > min_y){
int pick = current;
while (pick < 0){
pick += context.size();
}
pick = pick % context.size();
ContextItem * option = context[pick];
const int startx = middle_x - font.textLength(option->getName().c_str())/2;
/* draw current selection, make it glow */
if (current == selected){
Graphics::Bitmap::transBlender(0, 0, 0, fadeAlpha);
Graphics::TranslucentBitmap translucent(area);
const int color = useGradient ? selectedGradient.current() : selectedGradientStart();
font.printf(x + startx, y, color, translucent, option->getName(), 0 );
if (option->isAdjustable()){
const int triangleSize = 14;
int cx = startx - 15;
int cy = (int)(y + (font.getHeight()/FONT_SPACER) / 2 + 2);
/* do the triangles need to be translucent? */
translucent.equilateralTriangle(cx, cy, 180, triangleSize, option->getLeftColor());
cx = (x + startx + font.textLength(option->getName().c_str()))+15;
translucent.equilateralTriangle(cx, cy, 0, triangleSize, option->getRightColor());
}
} else {
/* draw some other item, and fade it */
int count = (int) fabs((double) current - (double) selected);
/* TODO: maybe scale by the number of total items instead of using 35 */
int textAlpha = fadeAlpha - (count * 35);
if (textAlpha < 0){
textAlpha = 0;
}
Graphics::Bitmap::transBlender(0, 0, 0, textAlpha);
const int color = Graphics::makeColor(255,255,255);
font.printf(x + startx, y, color, area.translucent(), option->getName(), 0);
}
if (context.size() == 1){
return;
}
current += direction;
y += direction * font.getHeight() / FONT_SPACER;
}
+#endif
+}
+
+void ContextBox::setList(const std::vector<Util::ReferenceCount<ContextItem> > & list){
+ for (vector<Util::ReferenceCount<ContextItem> >::const_iterator it = list.begin(); it != list.end(); it++){
+ const Util::ReferenceCount<ContextItem> & item = *it;
+ this->list.addItem(item.convert<ScrollItem>());
+ }
}
void ContextBox::drawText(const Graphics::Bitmap & bmp, const Font & font){
+ /*
if (context.empty()){
return;
}
+ */
// const Font & vFont = Font::getFont(font, fontWidth, fontHeight);
const int x1 = board.getArea().getX()+(int)(board.getArea().getRadius()/2);
const int y1 = board.getArea().getY()+2;//(board.getArea().radius/2);
const int x2 = board.getArea().getX2()-(int)(board.getArea().getRadius()/2);
const int y2 = board.getArea().getY2()-2;//(board.getArea().radius/2);
Graphics::Bitmap area(bmp, x1, y1, x2 - x1, y2 - y1);
int min_y = location.getX() - font.getHeight() - y1;
int max_y = location.getX2() + font.getHeight() - y1;
+ list.render(area, font);
+
+#if 0
/* draw from the current selection down */
doDraw(0, cursorLocation - y1, area.getWidth() / 2, min_y, max_y, font, current, current, area, 1);
/* draw above the current selection */
doDraw(0, cursorLocation - y1 - font.getHeight() / FONT_SPACER, area.getWidth() / 2, min_y, max_y, font, current - 1, current, area, -1);
+#endif
#if 0
int currentOption = current;
int count = 0;
/* draw the current selection and everything below it */
while (locationY < location.getX2() + vFont.getHeight()){
const int startx = (location.getWidth()/2)-(vFont.textLength(context[currentOption]->getName().c_str())/2);
if (count == 0){
Graphics::Bitmap::transBlender(0, 0, 0, fadeAlpha);
Graphics::TranslucentBitmap translucent(area);
// Bitmap::drawingMode( Bitmap::MODE_TRANS );
const int color = useGradient ? selectedGradient.current() : selectedGradientStart();
vFont.printf(location.getX() + startx - x1, locationY - y1, color, translucent, context[currentOption]->getName(), 0 );
if (context[currentOption]->isAdjustable()){
const int triangleSize = 14;
int cx = (location.getX() + startx) - 15;
int cy = (int)(locationY + (vFont.getHeight()/FONT_SPACER) / 2 + 2);
/*
int cx1 = cx + triangleSize / 2;
int cy1 = cy - triangleSize / 2;
int cx2 = cx - triangleSize;
int cy2 = cy;
int cx3 = cx + triangleSize / 2;
int cy3 = cy + triangleSize / 2;
*/
/* do the triangles need to be translucent? */
// translucent.triangle(cx1, cy1, cx2, cy2, cx3, cy3, context[currentOption]->getLeftColor());
translucent.equilateralTriangle(cx, cy, 180, triangleSize, context[currentOption]->getLeftColor());
cx = (location.getX()+startx + vFont.textLength(context[currentOption]->getName().c_str()))+15;
translucent.equilateralTriangle(cx, cy, 0, triangleSize, context[currentOption]->getLeftColor());
// translucent.triangle( cx - triangleSize / 2, cy - triangleSize / 2, cx + triangleSize, cy, cx - triangleSize / 2, cy + triangleSize / 2, context[currentOption]->getRightColor() );
}
// Bitmap::drawingMode(Bitmap::MODE_SOLID);
} else {
int textAlpha = fadeAlpha - (count * 35);
if (textAlpha < 0){
textAlpha = 0;
}
Graphics::Bitmap::transBlender(0, 0, 0, textAlpha);
// Bitmap::drawingMode( Bitmap::MODE_TRANS );
const int color = Graphics::makeColor(255,255,255);
vFont.printf(location.getX() + startx - x1, locationY - y1, color, area.translucent(), context[currentOption]->getName(), 0 );
// Bitmap::drawingMode( Bitmap::MODE_SOLID );
}
if (context.size() == 1){
// area.setClipRect(0, 0, bmp.getWidth(), bmp.getHeight());
return;
}
currentOption++;
if (currentOption == (int)context.size()){
currentOption = 0;
}
locationY += (int)(vFont.getHeight()/FONT_SPACER);
count++;
/*if (context.size() < 2 && count == 2){
break;
}*/
}
locationY = cursorLocation - (int)(vFont.getHeight()/FONT_SPACER);
currentOption = current;
currentOption--;
count = 0;
/* this draws the stuff above the current selection */
while (locationY > location.getX() - vFont.getHeight()){
if (currentOption < 0){
currentOption = context.size()-1;
}
const int startx = (location.getWidth()/2)-(vFont.textLength(context[currentOption]->getName().c_str())/2);
int textAlpha = fadeAlpha - (count * 35);
if (textAlpha < 0){
textAlpha = 0;
}
Graphics::Bitmap::transBlender(0, 0, 0, textAlpha);
const int color = Graphics::makeColor(255,255,255);
vFont.printf(location.getX() + startx - x1, locationY - y1, color, area.translucent(), context[currentOption]->getName(), 0 );
currentOption--;
locationY -= (int)(vFont.getHeight()/FONT_SPACER);
count++;
/*if (context.size() < 2 && count == 1){
break;
}*/
}
// bmp.setClipRect(0, 0, bmp.getWidth(), bmp.getHeight());
#endif
}
+}
diff --git a/util/gui/context-box.h b/util/gui/context-box.h
index 987ae276..0145f77c 100644
--- a/util/gui/context-box.h
+++ b/util/gui/context-box.h
@@ -1,152 +1,153 @@
#ifndef _paintown_gui_context_box_h
#define _paintown_gui_context_box_h
#include <string>
#include <vector>
#include "widget.h"
#include "popup-box.h"
+#include "scroll-list.h"
#include "../gradient.h"
#include "../file-system.h"
namespace Gui{
-class ContextItem{
- public:
- ContextItem();
- virtual ~ContextItem();
-
- virtual const std::string getName() = 0;
- virtual bool isAdjustable();
- virtual int getLeftColor();
- virtual int getRightColor();
+class ContextItem: public ScrollItem {
+public:
+ ContextItem();
+ virtual ~ContextItem();
+
+ virtual const std::string getName() const = 0;
+ virtual bool isAdjustable();
+ virtual int getLeftColor();
+ virtual int getRightColor();
+ virtual void draw(int x, int y, const Graphics::Bitmap & where, const Font & font) const;
+ virtual int size() const;
};
class ContextBox : public Widget {
public:
ContextBox();
ContextBox(const ContextBox &);
virtual ~ContextBox();
//! copy
ContextBox &operator=(const ContextBox &);
//! Logic
virtual void act(const Font &);
//! Render
using Widget::render;
virtual void render(const Graphics::Bitmap &);
virtual void render(const Graphics::Bitmap &, const Font & font);
//! Next
virtual bool next(const Font &);
//! Previous
virtual bool previous(const Font &);
//! Adjust left
virtual void adjustLeft();
//! Adjust right
virtual void adjustRight();
//! open context box
virtual void open();
//! Close context box
virtual void close();
//! Set context list
- virtual inline void setList(const std::vector<ContextItem *> & list){
- this->context = list;
- this->current = 0;
- }
+ virtual void setList(const std::vector<Util::ReferenceCount<ContextItem> > & list);
//! Set current font
/*
virtual inline void setFont(const Filesystem::RelativePath & font, int width, int height){
this->font = font;
this->fontWidth = width;
this->fontHeight = height;
}
*/
//! Get current index
virtual inline unsigned int getCurrentIndex(){
- return this->current;
+ return this->list.getCurrentIndex();
}
//! Is active?
virtual inline bool isActive(){
return (this->fadeState != NotActive);
}
//!set fadespeed
virtual inline void setFadeSpeed(int speed){
this->fadeSpeed = speed;
this->board.setFadeSpeed(speed);
}
//!set fade alpha
virtual inline void setFadeAlpha(int alpha){
this->fadeAlpha = alpha;
}
//! use gradient?
virtual inline void setUseGradient(bool useGradient){
this->useGradient = useGradient;
}
//! Set to use only text on background
virtual inline void setRenderOnlyText(bool render){
this->renderOnlyText = render;
}
private:
void doFade();
void calculateText(const Font & font);
void doDraw(int x, int y, int middle_x, int min_y, int max_y, const Font & font, int current, int selected, const Graphics::Bitmap & area, int direction);
void drawText(const Graphics::Bitmap &, const Font & font);
enum FadeState{
NotActive,
FadeIn,
Active,
FadeOut,
};
//! Current index
- unsigned int current;
+ // unsigned int current;
//! Current fade state
FadeState fadeState;
//! Context list
- std::vector<ContextItem *> context;
+ // std::vector<ContextItem *> context;
+ ScrollList list;
//! Current font
/*
Filesystem::RelativePath font;
int fontWidth;
int fontHeight;
*/
//! Fade speed
int fadeSpeed;
//! Fade Aplha
int fadeAlpha;
//! Board
PopupBox board;
//! The centered position
int cursorCenter;
//! Current y coordinate to render text from
int cursorLocation;
//! scroll wait
int scrollWait;
//! Gradient for selected cursor
Effects::Gradient selectedGradient;
//! Use gradient
bool useGradient;
//! Render Text only
bool renderOnlyText;
};
}
#endif
diff --git a/util/gui/scroll-list.cpp b/util/gui/scroll-list.cpp
index 90791771..d0fe0a1b 100644
--- a/util/gui/scroll-list.cpp
+++ b/util/gui/scroll-list.cpp
@@ -1,99 +1,122 @@
#include "../bitmap.h"
+#include "../trans-bitmap.h"
#include "scroll-list.h"
#include "../font.h"
-using namespace Gui;
+namespace Gui{
static const int GradientMax = 50;
static int selectedGradientStart(){
static int color = Graphics::makeColor(19, 167, 168);
return color;
}
static int selectedGradientEnd(){
static int color = Graphics::makeColor(27, 237, 239);
return color;
}
+
+ScrollItem::ScrollItem(){
+}
+
+ScrollItem::~ScrollItem(){
+}
ScrollList::ScrollList():
currentIndex(0),
fontSpacingX(0),
fontSpacingY(0),
currentPosition(0),
scrollWait(0),
selectedGradient(GradientMax, selectedGradientStart(), selectedGradientEnd()),
useGradient(false),
useHighlight(false),
allowWrap(true){}
ScrollList::ScrollList(const ScrollList & copy):
currentIndex(copy.currentIndex),
fontSpacingX(copy.fontSpacingX),
fontSpacingY(copy.fontSpacingY),
currentPosition(copy.currentPosition),
scrollWait(copy.scrollWait),
selectedGradient(GradientMax, selectedGradientStart(), selectedGradientEnd()),
useGradient(copy.useGradient),
useHighlight(copy.useHighlight),
allowWrap(true){}
ScrollList::~ScrollList(){}
ScrollList & ScrollList::operator=(const ScrollList & copy){
return *this;
}
void ScrollList::act(){
}
-void ScrollList::render(const Graphics::Bitmap &, const Font & font){
+void ScrollList::render(const Graphics::Bitmap & where, const Font & font){
+ int y = 0;
+ int x = 5;
+ int current = currentIndex;
+ while (y < where.getHeight()){
+ Util::ReferenceCount<ScrollItem> & item = this->text[current];
+ if (current == currentIndex){
+ Graphics::Bitmap::transBlender(0, 0, 0, 255);
+ } else {
+ Graphics::Bitmap::transBlender(0, 0, 0, 128);
+ }
+ item->draw(x, y, where.translucent(), font);
+ y += font.getHeight();
+ current = (current + 1 + this->text.size()) % this->text.size();
+ }
}
void ScrollList::addItem(const Util::ReferenceCount<ScrollItem> & text){
this->text.push_back(text);
}
void ScrollList::addItems(const std::vector<Util::ReferenceCount<ScrollItem> > & texts){
this->text.insert(text.end(), texts.begin(), texts.end());
}
void ScrollList::setPosition(const Gui::Coordinate & location){
this->position = location;
}
bool ScrollList::next(){
currentIndex++;
if (currentIndex >= text.size()){
if (allowWrap){
currentIndex = 0;
return true;
} else {
currentIndex = text.size()-1;
return false;
}
}
return true;
}
bool ScrollList::previous(){
if (currentIndex > 0){
currentIndex--;
} else if (currentIndex == 0){
if (allowWrap){
currentIndex = text.size()-1;
return true;
} else {
return false;
}
}
return true;
}
bool ScrollList::setCurrentIndex(unsigned int index){
if (index >= text.size()){
return false;
}
currentIndex = index;
return true;
}
+
+}
diff --git a/util/gui/scroll-list.h b/util/gui/scroll-list.h
index 9a268274..eb995554 100644
--- a/util/gui/scroll-list.h
+++ b/util/gui/scroll-list.h
@@ -1,150 +1,150 @@
#ifndef _gui_scroll_list_h
#define _gui_scroll_list_h
#include <string>
#include <vector>
#include "coordinate.h"
#include "../gradient.h"
#include "../pointer.h"
class Font;
namespace Gui{
/* pure virtual class */
class ScrollItem{
public:
ScrollItem();
- void draw(int x, int y, const Graphics::Bitmap & where) const;
+ virtual void draw(int x, int y, const Graphics::Bitmap & where, const Font & font) const = 0;
/* size in pixels, used for justification */
- virtual int size() const;
+ virtual int size() const = 0;
virtual ~ScrollItem();
};
class ScrollList {
public:
ScrollList();
ScrollList(const ScrollList &);
virtual ~ScrollList();
//! copy
ScrollList & operator=(const ScrollList &);
//! Logic
virtual void act();
//! Render
virtual void render(const Graphics::Bitmap &, const Font & font);
//! Add item
virtual void addItem(const Util::ReferenceCount<ScrollItem> & item);
//! Add vector of text
virtual void addItems(const std::vector<Util::ReferenceCount<ScrollItem> > & items);
//! Set Position
virtual void setPosition(const Gui::Coordinate &);
//! Set font spacing
inline virtual void setFontSpacing(int x, int y){
this->fontSpacingX = x;
this->fontSpacingY = y;
}
//! Set font spacing X
inline virtual void setFontSpacingX(int x){
this->fontSpacingX = x;
}
//! Set font spacing X
inline virtual void setFontSpacingY(int y){
this->fontSpacingY = y;
}
//! Next
virtual bool next();
//! Previous
virtual bool previous();
//! Set current index
virtual bool setCurrentIndex(unsigned int index);
//! Get current index
- virtual inline unsigned int getCurrentIndex() const{
+ virtual inline unsigned int getCurrentIndex() const {
return this->currentIndex;
}
//! Set gradient
virtual inline void setGradient(bool use){
this->useGradient = use;
}
//! Get gradient
virtual inline bool gradientActive() const {
return this->useGradient;
}
//! Set highlight
virtual inline void setHighlight(bool use){
this->useHighlight = use;
}
//! Get highlight
virtual inline bool highlightActive() const {
return this->useHighlight;
}
//! Set wrap
virtual inline void setWrap(bool wrap){
this->allowWrap = wrap;
}
//! Get wrap
virtual inline bool getWrap() const {
return this->allowWrap;
}
private:
//! Text
std::vector<Util::ReferenceCount<ScrollItem> > text;
//! Current index
unsigned int currentIndex;
//! Coordinates (size of)
Gui::Coordinate position;
//! Font Spacing
int fontSpacingX, fontSpacingY;
//! Current position for smooth scrolling
int currentPosition;
//! Scroll wait
int scrollWait;
//! Gradient for selected cursor
Effects::Gradient selectedGradient;
//! Use gradient
bool useGradient;
//! Use highlight
bool useHighlight;
//! Is wrappable
bool allowWrap;
};
}
#endif
diff --git a/util/gui/tabbed-box.cpp b/util/gui/tabbed-box.cpp
index 540ae4ed..0f31267d 100644
--- a/util/gui/tabbed-box.cpp
+++ b/util/gui/tabbed-box.cpp
@@ -1,301 +1,301 @@
#include "../bitmap.h"
#include "../trans-bitmap.h"
#include "tabbed-box.h"
#include "menu/menu.h"
#include "util/font.h"
#include "context-box.h"
using namespace Gui;
#if 0
/* FIXME add rounded tabs */
static void roundTab( const Bitmap & work, int radius, int x1, int y1, int x2, int y2, int color, bool bottom = true ){
const int width = x2 - x1;
const int height = y2 - y1;
radius = Mid(0, radius, Min((x1+width - x1)/2, (y1+height - y1)/2));
work.circleFill(x1+radius, y1+radius, radius, color);
work.circleFill((x1+width)-radius, y1+radius, radius, color);
work.circleFill(x1+radius, (y1+height)-radius, radius, color);
work.circleFill((x1+width)-radius, (y1+height)-radius, radius, color);
work.rectangleFill( x1+radius, y1, x2-radius, y1+radius, color);
work.rectangleFill( x1, y1+radius, x2, y2-radius, color);
work.rectangleFill( x1+radius, y2-radius, x2-radius, y2, color);
work.line(x1+radius, y1, x1+width-radius, y1, color);
work.line(x1+radius, y1+height, x1+width-radius,y1+height, color);
work.line(x1, y1+radius,x1, y1+height-radius, color);
work.line(x1+width, y1+radius,x1+width, y1+height-radius, color);
arc(work, x1+radius, y1+radius, S_PI-1.115, radius, color);
arc(work, x1+radius + (width - radius *2), y1+radius, -S_PI/2 +0.116, radius, color);
arc(work, x1+width-radius, y1+height-radius, -0.110, radius ,color);
arc(work, x1+radius, y1+height-radius, S_PI/2-0.119, radius, color);
}
#endif
Tab::Tab():
context(new ContextBox()),
active(false){
// Set alpha to 0 as we are not interested in the box
context->setRenderOnlyText(true);
}
Tab::~Tab(){
delete context;
}
TabbedBox::TabbedBox():
current(0),
fontWidth(24),
fontHeight(24),
inTab(false),
tabWidthMax(0),
tabFontColor(Graphics::makeColor(255,255,255)),
currentTabFontColor(Graphics::makeColor(0,0,255)){
activeTabFontColor = new Effects::Gradient(50, tabFontColor, currentTabFontColor);
}
TabbedBox::TabbedBox(const TabbedBox & b):
activeTabFontColor(NULL){
this->location = b.location;
this->workArea = b.workArea;
}
TabbedBox::~TabbedBox(){
for (std::vector<Gui::Tab *>::iterator i = tabs.begin(); i != tabs.end(); ++i){
Gui::Tab * tab = *i;
if (tab){
delete tab;
}
}
if (activeTabFontColor){
delete activeTabFontColor;
}
}
TabbedBox &TabbedBox::operator=( const TabbedBox &copy){
location = copy.location;
workArea = copy.workArea;
return *this;
}
// Logic
void TabbedBox::act(const Font & font){
if (!tabs.empty()){
// const Font & vFont = Font::getFont(font, fontWidth, fontHeight);
//tabWidthMax = location.getWidth()/tabs.size();
const int width = font.textLength(tabs[current]->name.c_str()) + 5;
tabWidthMax = (location.getWidth() - width) / (tabs.size() - 1);
} else {
return;
}
if (!tabs[current]->active){
tabs[current]->active = true;
}
tabs[current]->context->act(font);
if (inTab){
if (activeTabFontColor){
activeTabFontColor->update();
}
}
}
void TabbedBox::render(const Graphics::Bitmap & work){
/* nothing */
}
// Render
void TabbedBox::render(const Graphics::Bitmap & work, const Font & font){
const int tabHeight = fontHeight + 5;
// checkWorkArea();
Graphics::Bitmap area(work, location.getX(), location.getY(), location.getWidth(), location.getHeight());
// Check if we are using a rounded box
if (location.getRadius() > 0){
//roundRectFill( *workArea, (int)location.getRadius(), 0, 0, location.getWidth()-1, location.getHeight()-1, colors.body );
//roundRect( *workArea, (int)location.getRadius(), 0, 0, location.getWidth()-1, location.getHeight()-1, colors.border );
} else {
area.translucent().rectangleFill(0, tabHeight+1, location.getWidth()-1, location.getHeight()-1, colors.body );
//area.translucent().rectangle(0, tabHeight, location.getWidth()-1, location.getHeight()-1, colors.border );
area.translucent().vLine(tabHeight,0,location.getHeight()-1,colors.border);
area.translucent().hLine(0,location.getHeight()-1,location.getWidth()-1,colors.border);
area.translucent().vLine(tabHeight,location.getWidth()-1,location.getHeight()-1,colors.border);
}
tabs[current]->context->render(area, font);
renderTabs(area, font);
/* FIXME: only render the background in translucent mode, the text should
* not be translucent
*/
// workArea->draw(location.getX(), location.getY(), work);
}
// Add tab
-void TabbedBox::addTab(const std::string & name, const std::vector<ContextItem *> & list){
+void TabbedBox::addTab(const std::string & name, const std::vector<Util::ReferenceCount<ContextItem> > & list){
for (std::vector<Tab *>::iterator i = tabs.begin(); i != tabs.end(); ++i){
Tab * tab = *i;
if (tab->name == name){
return;
}
}
Tab * tab = new Tab();
tab->name = name;
tab->context->setList(list);
// tab->context->setFont(font, fontWidth, fontHeight);
const int modifier = fontHeight * .35;
tab->context->location.setPosition(Gui::AbsolutePoint(0, fontHeight + modifier));
tab->context->location.setPosition2(Gui::AbsolutePoint(location.getWidth(), location.getHeight()- modifier));
tab->context->open();
tabs.push_back(tab);
}
void TabbedBox::moveTab(int direction){
tabs[current]->context->close();
tabs[current]->active = false;
current = (unsigned int) ((int)current + direction + (int) tabs.size()) % tabs.size();
/*
if (current == 0){
current = tabs.size()-1;
} else {
current--;
}
*/
tabs[current]->context->open();
tabs[current]->active = true;
}
void TabbedBox::up(const Font & font){
if (tabs.size() == 0){
return;
}
if (!inTab){
moveTab(-1);
} else {
tabs[current]->context->previous(font);
}
}
void TabbedBox::down(const Font & font){
if (tabs.size() == 0){
return;
}
if (!inTab){
moveTab(1);
} else {
tabs[current]->context->next(font);
}
}
void TabbedBox::left(const Font & font){
if (tabs.size() == 0){
return;
}
if (!inTab){
moveTab(-1);
} else {
tabs[current]->context->adjustLeft();
}
}
void TabbedBox::right(const Font & font){
if (tabs.size() == 0){
return;
}
if (!inTab){
moveTab(1);
} else {
tabs[current]->context->adjustRight();
}
}
void TabbedBox::toggleTabSelect(){
inTab = !inTab;
}
unsigned int TabbedBox::getCurrentIndex() const {
if (tabs.size() == 0){
return 0;
}
return this->tabs[current]->context->getCurrentIndex();
}
void TabbedBox::setTabFontColor(int color){
tabFontColor = color;
if (activeTabFontColor){
delete activeTabFontColor;
}
activeTabFontColor = new Effects::Gradient(50, tabFontColor, currentTabFontColor);
}
void TabbedBox::setSelectedTabFontColor(int color){
currentTabFontColor = color;
if (activeTabFontColor){
delete activeTabFontColor;
}
activeTabFontColor = new Effects::Gradient(50, tabFontColor, currentTabFontColor);
}
void TabbedBox::renderTabs(const Graphics::Bitmap & bmp, const Font & vFont){
const int tabHeight = fontHeight + 5;
// const Font & vFont = Font::getFont(font, fontWidth, fontHeight);
int x = 0;
Graphics::Bitmap::transBlender(0, 0, 0, colors.bodyAlpha);
for (std::vector<Gui::Tab *>::iterator i = tabs.begin(); i != tabs.end(); ++i){
Gui::Tab * tab = *i;
const int textWidth = vFont.textLength(tab->name.c_str()) + 5;
// for last tab
int modifier = 0;
// Check last tab so we can ensure proper sizing
if ( i == (tabs.begin() + tabs.size() -1)){
if ( ( (tabWidthMax * (tabs.size() - 1) ) + textWidth ) != (unsigned int)location.getWidth() ){
modifier = location.getWidth() - x - (tab->active ? textWidth : tabWidthMax);
}
}
if (tab->context->location.getRadius() > 0){
} else {
if (tab->active){
if (!inTab){
//bmp.translucent().rectangle(x, 0, x+textWidth + modifier - 1, tabHeight, colors.border);
bmp.translucent().vLine(0,x,tabHeight,colors.border);
bmp.translucent().hLine(x,0,x+textWidth+modifier-1,colors.border);
bmp.translucent().vLine(0,x+textWidth+modifier-1,tabHeight,colors.border);
bmp.translucent().rectangleFill( x+1, 1, x+textWidth + modifier - 2, tabHeight, colors.body);
bmp.setClipRect(x, 0, x+textWidth + modifier, tabHeight-1);
vFont.printf(x + (((textWidth + modifier)/2)-(((textWidth + modifier) - 5)/2)), 0, currentTabFontColor, bmp, tab->name, 0 );
} else {
//bmp.translucent().rectangle(x, 0, x+textWidth + modifier -1, tabHeight, colors.border);
bmp.translucent().vLine(0,x,tabHeight,colors.border);
bmp.translucent().hLine(x,0,x+textWidth+modifier-1,colors.border);
bmp.translucent().vLine(0,x+textWidth+modifier-1,tabHeight,colors.border);
bmp.translucent().rectangleFill( x+1, 1, x+textWidth-2 + modifier, tabHeight, colors.body );
bmp.setClipRect(x, 0, x+textWidth + modifier, tabHeight-1);
vFont.printf(x + (((textWidth + modifier)/2)-(((textWidth + modifier) - 5)/2)), 0, activeTabFontColor->current(), bmp, tab->name, 0 );
}
x+=textWidth + modifier;
} else {
const int heightMod = tabHeight * .15;
bmp.translucent().rectangle(x, 1 + heightMod, x+tabWidthMax + modifier -1, tabHeight, tabColors.border);
bmp.translucent().hLine(x,tabHeight,x+tabWidthMax+modifier-1,colors.border);
bmp.translucent().rectangleFill( x+1, 2 + heightMod, x+tabWidthMax + modifier -2, tabHeight-2, tabColors.body);
bmp.setClipRect(x+2, 6 + heightMod, x+tabWidthMax + modifier -3, tabHeight-1);
vFont.printf(x + (((tabWidthMax + modifier)/2)-((textWidth + modifier)/2)), 0, tabFontColor, bmp, tab->name, 0 );
x += tabWidthMax + modifier;
}
bmp.setClipRect(0, 0, bmp.getWidth(), bmp.getHeight());
}
}
}
diff --git a/util/gui/tabbed-box.h b/util/gui/tabbed-box.h
index 7e051c6d..abac69ae 100644
--- a/util/gui/tabbed-box.h
+++ b/util/gui/tabbed-box.h
@@ -1,134 +1,135 @@
#ifndef _paintown_gui_tabbed_box_h
#define _paintown_gui_tabbed_box_h
#include <string>
#include <vector>
#include "widget.h"
#include "../file-system.h"
+#include "../pointer.h"
#include "../gradient.h"
class Token;
namespace Gui{
class ContextBox;
class ContextItem;
class Tab{
public:
Tab();
~Tab();
std::string name;
Gui::ContextBox * context;
bool active;
};
class TabbedBox : public Widget{
public:
TabbedBox();
TabbedBox( const TabbedBox & );
virtual ~TabbedBox();
//! copy
TabbedBox &operator=( const TabbedBox &);
//! Logic
virtual void act(const Font &);
//! Render
using Widget::render;
virtual void render(const Graphics::Bitmap &);
virtual void render(const Graphics::Bitmap &, const Font &);
//! Add tab
- virtual void addTab(const std::string &, const std::vector<ContextItem *> & list);
+ virtual void addTab(const std::string &, const std::vector<Util::ReferenceCount<ContextItem> > & list);
//! Up
virtual void up(const Font &);
//! Down
virtual void down(const Font &);
//! Left
virtual void left(const Font &);
//! Right
virtual void right(const Font &);
//! Virtual
virtual void toggleTabSelect();
//! Set current font
virtual inline void setFont(const Filesystem::RelativePath & font, int width, int height){
this->font = font;
this->fontWidth = width;
this->fontHeight = height;
}
//! Get current tab
virtual inline unsigned int getCurrentTab() const {
return this->current;
}
//! Get current index on selected tab
virtual unsigned int getCurrentIndex() const;
//! Set tab font colors
virtual void setTabFontColor(int color);
//! Set selected tab font color
virtual void setSelectedTabFontColor(int color);
//! Empty
virtual inline bool empty() const {
return this->tabs.empty();
}
virtual inline bool isInTab() const {
return this->inTab;
}
/*! Tab Colors */
ColorInfo tabColors;
/*! Selected Tab Colors */
ColorInfo selectedTabColors;
/*! Selected Tab Colors */
ColorInfo runningTabColors;
protected:
void moveTab(int direction);
std::vector<Gui::Tab *> tabs;
unsigned int current;
Filesystem::RelativePath font;
int fontWidth;
int fontHeight;
/*! Is in tab */
bool inTab;
/*! Max Width of tabs */
int tabWidthMax;
/*! Render tab */
void renderTabs(const Graphics::Bitmap &, const Font &);
/*! Font Color */
int tabFontColor;
/*! Current Tab Font Color */
int currentTabFontColor;
/*! Gradient for selected Font */
Effects::Gradient * activeTabFontColor;
};
}
#endif
diff --git a/util/language-string.cpp b/util/language-string.cpp
index cf007977..588404a2 100644
--- a/util/language-string.cpp
+++ b/util/language-string.cpp
@@ -1,48 +1,60 @@
#include <string>
#include "language-string.h"
#include "configuration.h"
using namespace std;
LanguageString::LanguageString(){
}
LanguageString::LanguageString(const std::string & stuff){
add(stuff);
}
LanguageString::LanguageString(const char * stuff){
add(stuff);
}
LanguageString::LanguageString(const std::string & stuff, const std::string & language){
add(stuff, language);
}
LanguageString::LanguageString(const LanguageString & language){
languages = language.languages;
}
LanguageString & LanguageString::operator=(const LanguageString & obj){
this->languages = obj.languages;
return *this;
}
void LanguageString::add(const std::string & stuff, const std::string & language){
languages[language] = stuff;
}
void LanguageString::add(const std::string & stuff){
add(stuff, defaultLanguage());
}
const string LanguageString::currentLanguage() const {
return Configuration::getLanguage();
}
-const std::string & LanguageString::get(){
+const std::string & LanguageString::get() const {
+ map<std::string, std::string>::const_iterator find = languages.find(currentLanguage());
+ if (find != languages.end()){
+ return find->second;
+ }
+ find = languages.find(defaultLanguage());
+ if (find != languages.end()){
+ return find->second;
+ }
+ return "";
+
+ /*
if (languages[currentLanguage()] != ""){
return languages[currentLanguage()];
}
return languages[defaultLanguage()];
+ */
}
diff --git a/util/language-string.h b/util/language-string.h
index b996e6a6..db9861b4 100644
--- a/util/language-string.h
+++ b/util/language-string.h
@@ -1,38 +1,38 @@
#ifndef _paintown_language_string_h
#define _paintown_language_string_h
#include <string>
#include <map>
class LanguageString: public std::string {
public:
LanguageString();
LanguageString(const char * stuff);
LanguageString(const std::string & stuff);
LanguageString(const std::string & stuff, const std::string & language);
LanguageString(const LanguageString & language);
LanguageString & operator=(const LanguageString & obj);
static const std::string defaultLanguage(){
return "English";
}
const std::string currentLanguage() const;
/* add a new language translation */
void add(const std::string & stuff, const std::string & language);
/* adds with the default language */
void add(const std::string & stuff);
- const std::string & get();
+ const std::string & get() const;
inline const std::map<std::string, std::string> & getLanguages() const {
return languages;
}
protected:
std::map<std::string, std::string> languages;
};
#endif
diff --git a/util/pointer.h b/util/pointer.h
index 4f3883d5..735e0a94 100644
--- a/util/pointer.h
+++ b/util/pointer.h
@@ -1,149 +1,170 @@
#ifndef _paintown_util_pointer_h
#define _paintown_util_pointer_h
#include <stdlib.h>
namespace Util{
/* Some helpful pointer classes, probably equivalent to stuff in boost
*/
template <class Data>
class ReferenceCount{
public:
ReferenceCount(Data * what = NULL):
count(NULL),
data(what){
count = new int;
*count = 1;
}
ReferenceCount(const ReferenceCount<Data> & him){
data = him.data;
count = him.count;
*count += 1;
}
ReferenceCount & operator=(const ReferenceCount<Data> & him){
/* this object might have a link to `him' so if we release first
* then `him' will get deleted before we can capture his data.
* we need to increase his count first and then release our data
* to insure that `him' will still be alive.
*/
int * temp_count = him.count;
*temp_count += 1;
Data * temp_data = him.data;
release();
data = temp_data;
count = temp_count;
return *this;
}
ReferenceCount & operator=(Data * what){
release();
count = new int;
*count = 1;
data = what;
return *this;
}
+ /* use this if you need to convert between classes in a heirarchy.
+ * Base
+ * Child: public Base
+ * ReferenceCount<Base> base;
+ * ReferenceCount<Child> child;
+ * base = child; is illegal but
+ * base = child.convert<Base>(); is ok
+ */
+ template <class Convert>
+ ReferenceCount<Convert> convert() const {
+ ReferenceCount<Convert> what;
+ what.count = count;
+ *what.count += 1;
+ what.data = (Convert*) data;
+ return what;
+ }
+
bool operator!() const {
return !this->data;
}
Data * operator->() const {
return data;
}
Data & operator*() const {
return *data;
}
bool operator==(const ReferenceCount<Data> & him) const {
return data == him.data;
}
bool operator!=(const ReferenceCount<Data> & him) const {
return !(*this == him);
}
bool operator==(const void * what) const {
return data == what;
}
bool operator!=(const void * what) const {
return !(*this == what);
}
virtual ~ReferenceCount(){
release();
}
protected:
void release(){
*count -= 1;
if (*count == 0){
delete data;
delete count;
data = NULL;
count = NULL;
}
}
+ /* this has to be public to make the convert() function work but pretend
+ * its private!
+ */
+public:
int * count;
Data * data;
};
/* Initializes its pointer to NULL and deletes the data in the destructor.
* how is this different from the ReferenceCount class above? its basically
* the same thing but only allows one owner at a time.
*/
template <class Data>
class ClassPointer{
public:
ClassPointer():
data(NULL){
}
ClassPointer(Data * him):
data(him){
}
ClassPointer & operator=(Data * him){
if (data != NULL){
delete data;
}
data = him;
return *this;
}
Data & operator*() const {
return *data;
}
bool operator==(const void * what) const {
return data == what;
}
bool operator!=(const void * what) const {
return !(*this == what);
}
Data* operator->() const {
return data;
}
virtual ~ClassPointer(){
delete data;
}
private:
Data* data;
};
}
#endif

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 11:08 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68646
Default Alt Text
(44 KB)

Event Timeline