Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
70 KB
Referenced Files
None
Subscribers
None
diff --git a/util/gui/box.cpp b/util/gui/box.cpp
index 5b841da4..9b0cd19b 100644
--- a/util/gui/box.cpp
+++ b/util/gui/box.cpp
@@ -1,73 +1,73 @@
#include "util/bitmap.h"
#include "util/trans-bitmap.h"
#include "box.h"
#include "menu/menu.h"
#include "util/font.h"
using namespace Gui;
Box::Box(){
// Nothing yet
}
Box::Box( const Box & b ){
this->location = b.location;
this->workArea = b.workArea;
}
Box::~Box(){
// Nothing yet
}
Box &Box::operator=( const Box &copy){
location = copy.location;
workArea = copy.workArea;
return *this;
}
// Logic
void Box::act(const Font & font){
// Nothing yet
}
// Render
void Box::render(const Graphics::Bitmap & work){
checkWorkArea();
// 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);
+ if (transforms.getRadius() > 0){
+ roundRectFill(*workArea, (int)transforms.getRadius(), 0, 0, location.getWidth()-1, location.getHeight()-1, colors.body);
+ roundRect(*workArea, (int)transforms.getRadius(), 0, 0, location.getWidth()-1, location.getHeight()-1, colors.border);
} else {
workArea->rectangleFill(0, 0, location.getWidth()-1, location.getHeight()-1, colors.body );
workArea->rectangle(0, 0, location.getWidth()-1, location.getHeight()-1, colors.border );
}
Graphics::Bitmap::transBlender( 0, 0, 0, colors.bodyAlpha );
// workArea->drawingMode( Bitmap::MODE_TRANS );
workArea->translucent().draw(location.getX(), location.getY(), work);
// work.drawingMode( Bitmap::MODE_SOLID );
}
void Box::messageDialog(int centerWidth, int centerHeight, const std::string & message, int radius){
/* FIXME Get rid of this */
#if 0
const Font &vFont = Font::getFont(OldMenu::Menu::getFont(),OldMenu::Menu::getFontWidth(),OldMenu::Menu::getFontHeight());
const int width = vFont.textLength(message.c_str()) + 10;
const int height = vFont.getHeight() + 10;
const int x = (centerWidth/2) - (width/2);
const int y = (centerHeight/2) - (height/2);
Box dialog;
dialog.location.setDimensions(width, height);
dialog.location.setRadius(radius);
dialog.colors.body = Bitmap::makeColor(0,0,0);
dialog.colors.bodyAlpha = 200;
dialog.colors.border = Bitmap::makeColor(255,255,255);
dialog.colors.borderAlpha = 255;
Bitmap temp = Bitmap::temporaryBitmap(width,height);
dialog.render(temp);
vFont.printf( 5, 5, Bitmap::makeColor(255,255,255), temp, message, -1);
temp.BlitToScreen(x,y);
#endif
}
diff --git a/util/gui/context-box.cpp b/util/gui/context-box.cpp
index 68f50c1f..8dbad74f 100644
--- a/util/gui/context-box.cpp
+++ b/util/gui/context-box.cpp
@@ -1,428 +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;
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, int color, const Graphics::Bitmap & where, const Font & font) const {
font.printf(x, y, color, where, getName(), 0);
}
int ContextItem::size(const Font & font) const {
return font.textLength(getName().c_str());
}
ContextBox::ContextBox():
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 ):
fadeState(NotActive),
selectedGradient(GradientMax, selectedGradientStart(), selectedGradientEnd()),
renderOnlyText(false){
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->fadeState = NotActive;
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);
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();
/*
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();
/*
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 x1 = board.getArea().getX()+(int)(board.getTransforms().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 x2 = board.getArea().getX2()-(int)(board.getTransforms().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/coordinate.cpp b/util/gui/coordinate.cpp
index b8e5c6e5..cf6cdb10 100644
--- a/util/gui/coordinate.cpp
+++ b/util/gui/coordinate.cpp
@@ -1,475 +1,470 @@
#include "util/bitmap.h"
#include "coordinate.h"
#include "globals.h"
#include "util/load_exception.h"
#include <sstream>
using namespace Gui;
namespace Gui{
namespace Space{
Point::Point(double x, double y, const Space & space):
x(x),
y(y),
space(space){
}
Point::Point(const Point & point, const Space & space):
space(space){
x = space.getLocalX(point.physicalX());
y = space.getLocalY(point.physicalY());
}
Point::Point(const Point & point):
x(point.x),
y(point.y),
space(point.space){
}
Point & Point::operator=(const Point & point){
if (!sameSpace(point)){
/* FIXME: throw an error */
}
this->x = point.x;
this->y = point.y;
return *this;
}
Point & Point::operator+=(const Point & point){
*this = *this + point;
return *this;
}
Point Point::operator+(const Point & point){
if (sameSpace(point)){
x += point.x;
y += point.y;
return *this;
} else {
return *this + Point(point, space);
}
}
bool Point::sameSpace(const Point & point){
return space == point.space;
}
int Point::physicalX() const {
return (x * space.sizeX() / 2) + space.centerX();
}
int Point::physicalY() const {
return (y * space.sizeY() / 2) + space.centerY();
}
Space::Space(double minX, double minY, double maxX, double maxY):
minX(minX),
minY(minY),
maxX(maxX),
maxY(maxY){
}
bool Space::operator==(const Space & space) const {
if (this == &space){
return true;
}
return minX == space.minX &&
minY == space.minY &&
maxX == space.maxX &&
maxY == space.maxY;
}
Point Space::fromPhysical(int x, int y){
return Point(getLocalX(x), getLocalY(y), *this);
}
double Space::sizeX() const {
return maxX - minX;
}
double Space::sizeY() const {
return maxY - minY;
}
double Space::centerX() const {
return (maxX - minX) / 2;
}
double Space::centerY() const {
return (maxY - minY) / 2;
}
double Space::getLocalX(int physicalX) const {
return (physicalX - centerX()) / sizeX();
}
double Space::getLocalY(int physicalY) const {
return (physicalY - centerY()) / sizeY();
}
}
}
static int relativeToAbsolute(double x, int center){
return (int)(center + (center * x));
}
static int amountFromCenterX(int x){
return x - (640 / 2);
}
static int amountFromCenterY(int y){
return y - (480 / 2);
}
/* scale an absolute distance to a relative distance
* distance / absolute = X / relative
* absolute space = 0 to 640
* relative space = -1 to 1
* X = distance * relative / absolute
*/
static double scaleAbsoluteToRelativeDistanceX(int distance){
return distance * (1.0 - (-1.0)) / (640.0 - 0);
}
static double scaleAbsoluteToRelativeDistanceY(int distance){
return distance * (1.0 - (-1.0)) / (480.0 - 0);
}
/* convert a point in absolute space to relative space */
static double absoluteToRelative(int x, int center){
return (double)(x-center)/center;
}
static double relativeToAbsoluteX(double x){
// return relativeToAbsolute(x, Global::getScreenWidth() / 2);
return relativeToAbsolute(x, 640 / 2);
}
static double relativeToAbsoluteY(double y){
// return relativeToAbsolute(y, Global::getScreenHeight() / 2);
return relativeToAbsolute(y, 480 / 2);
}
static double absoluteToRelativeX(int x){
return absoluteToRelative(x, 640/2);
}
static double absoluteToRelativeY(int y){
return absoluteToRelative(y, 480/2);
}
AbsolutePoint::AbsolutePoint():
x(0),
y(0){
}
AbsolutePoint::AbsolutePoint(int x, int y):
x(x),
y(y){
}
AbsolutePoint::AbsolutePoint(const AbsolutePoint & copy):
x(copy.x),
y(copy.y){
}
AbsolutePoint::~AbsolutePoint(){
}
const AbsolutePoint & AbsolutePoint::operator=(const AbsolutePoint & copy){
this->x = copy.x;
this->y = copy.y;
return *this;
}
int AbsolutePoint::getX() const {
return x;
}
int AbsolutePoint::getY() const {
return y;
}
RelativePoint::RelativePoint():
x(0),
y(0){
}
RelativePoint::RelativePoint(double x, double y):
x(x),
y(y){
}
RelativePoint::RelativePoint(const RelativePoint & copy):
x(copy.x),
y(copy.y){
}
RelativePoint::RelativePoint(const AbsolutePoint & point):
x(absoluteToRelativeX(point.getX())),
y(absoluteToRelativeY(point.getY())){
}
RelativePoint::~RelativePoint(){
}
const RelativePoint & RelativePoint::operator=(const RelativePoint & copy){
this->x = copy.x;
this->y = copy.y;
return *this;
}
const RelativePoint & RelativePoint::operator=(const AbsolutePoint & point){
this->x = absoluteToRelativeX(point.getX());
this->y = absoluteToRelativeY(point.getY());
return *this;
}
bool RelativePoint::operator==(const RelativePoint & point){
return (this->x == point.x && this->y == point.y);
}
bool RelativePoint::operator!=(const RelativePoint & point){
return !(*this == point);
}
int RelativePoint::getX() const{
return relativeToAbsoluteX(x);
}
int RelativePoint::getY() const{
return relativeToAbsoluteY(y);
}
int RelativePoint::getDistanceFromCenterX(){
return amountFromCenterX(getX());
}
int RelativePoint::getDistanceFromCenterY(){
return amountFromCenterY(getY());
}
void RelativePoint::moveX(double percent){
x += percent;
}
void RelativePoint::moveY(double percent){
y += percent;
}
void RelativePoint::moveBy(double x, double y){
moveX(x);
moveY(y);
}
AbsolutePoint RelativePoint::getAbsolute(){
return AbsolutePoint(relativeToAbsoluteX(x), relativeToAbsoluteY(y));
}
double RelativePoint::getRelativeX() const{
return x;
}
double RelativePoint::getRelativeY() const{
return y;
}
Coordinate::Coordinate():
-z(0),
-radius(0){
+z(0){
}
Coordinate::Coordinate(AbsolutePoint & position, AbsolutePoint & position2):
position(position),
position2(position2),
-z(0),
-radius(0){
+z(0){
}
Coordinate::Coordinate(const RelativePoint & position, const RelativePoint & position2):
position(position),
position2(position2),
-z(0),
-radius(0){
+z(0){
}
Coordinate::Coordinate(const Coordinate & copy):
position(copy.position),
position2(copy.position2),
-z(copy.z),
-radius(copy.radius){
+z(copy.z){
}
Coordinate::~Coordinate(){
}
const Coordinate & Coordinate::operator=(const Coordinate & copy){
this->position = copy.position;
this->position2 = copy.position2;
this->z = copy.z;
- this->radius = copy.radius;
return *this;
}
int Coordinate::getX() const{
return position.getX();
}
int Coordinate::getY() const{
return position.getY();
}
int Coordinate::getWidth() const {
return position2.getX() - position.getX();
}
int Coordinate::getHeight() const {
return position2.getY() - position.getY();
}
int Coordinate::getX2() const{
return position2.getX();
}
int Coordinate::getY2() const{
return position2.getY();
}
void Coordinate::growHorizontal(double by){
position.moveX(-(by));
position2.moveX(by);
}
void Coordinate::growHorizontalAbsolute(int distance){
growHorizontal(scaleAbsoluteToRelativeDistanceX(distance));
}
void Coordinate::growVerticalAbsolute(int distance){
growVertical(scaleAbsoluteToRelativeDistanceY(distance));
}
void Coordinate::growVertical(double by){
position.moveY(-(by));
position2.moveY(by);
}
void Coordinate::growTo(const Coordinate & coord, double percent){
if (position.getRelativeX() > coord.position.getRelativeX()){
position.moveX(-(percent));
if (position.getRelativeX() < coord.position.getRelativeX()){
position.setX(coord.position.getRelativeX());
}
} else if (position.getRelativeX() < coord.position.getRelativeX()){
position.moveX(percent);
if (position.getRelativeX() > coord.position.getRelativeX()){
position.setX(coord.position.getRelativeX());
}
}
if (position.getRelativeY() > coord.position.getRelativeY()){
position.moveY(-(percent));
if (position.getRelativeY() < coord.position.getRelativeY()){
position.setY(coord.position.getRelativeY());
}
} else if (position.getRelativeY() < coord.position.getRelativeY()){
position.moveY(percent);
if (position.getRelativeY() > coord.position.getRelativeY()){
position.setY(coord.position.getRelativeY());
}
}
if (position2.getRelativeX() > coord.position2.getRelativeX()){
position2.moveX(-(percent));
if (position2.getRelativeX() < coord.position2.getRelativeX()){
position2.setX(coord.position2.getRelativeX());
}
} else if (position2.getRelativeX() < coord.position2.getRelativeX()){
position2.moveX(percent);
if (position2.getRelativeX() > coord.position2.getRelativeX()){
position2.setX(coord.position2.getRelativeX());
}
}
if (position2.getRelativeY() > coord.position2.getRelativeY()){
position2.moveY(-(percent));
if (position2.getRelativeY() < coord.position2.getRelativeY()){
position2.setY(coord.position2.getRelativeY());
}
} else if (position2.getRelativeY() < coord.position2.getRelativeY()){
position2.moveY(percent);
if (position2.getRelativeY() > coord.position2.getRelativeY()){
position2.setY(coord.position2.getRelativeY());
}
}
}
void Coordinate::center(const Coordinate & coord){
const double centerx = (coord.getRelativeX1() + coord.getRelativeX2())/2;
const double centery = (coord.getRelativeY1() + coord.getRelativeY2())/2;
set(centerx, centery, centerx, centery);
}
void Coordinate::moveBy(double x, double y){
position.moveBy(x, y);
position2.moveBy(x, y);
}
bool Coordinate::operator==( const Coordinate & coord){
return ( (position == coord.position) &&
(position2 == coord.position2));
}
bool Coordinate::operator!=( const Coordinate & coord){
return ( !(position == coord.position) ||
!(position2 == coord.position2));
}
bool Coordinate::operator==( const Graphics::Bitmap & bmp){
return ( (getWidth() == bmp.getWidth()) &&
(getHeight() == bmp.getHeight()));
}
bool Coordinate::operator!=( const Graphics::Bitmap & bmp){
return !(*this == bmp);
}
void Coordinate::setPosition(const RelativePoint & point){
position = point;
}
void Coordinate::setPosition(const AbsolutePoint & point){
position = RelativePoint(point);
}
void Coordinate::setPosition2(const RelativePoint & point){
position2 = point;
}
void Coordinate::setPosition2(const AbsolutePoint & point){
position2 = RelativePoint(point);
}
void Coordinate::moveTo(const AbsolutePoint & where){
double dx = position2.getRelativeX() - position.getRelativeX();
double dy = position2.getRelativeY() - position.getRelativeY();
setPosition(where);
/* sort of ugly, use operator+ for RelativePosition */
setPosition2(RelativePoint(position.getRelativeX() + dx, position.getRelativeY() + dy));
}
void Coordinate::checkDimensions(){
if (getWidth() < 0 || getHeight() < 0){
std::ostringstream out;
out << "Cannot have a negative coordinate dimension " << getWidth() << ", " << getHeight();
throw LoadException(__FILE__, __LINE__, out.str());
}
}
void Coordinate::setDimensions(int width, int height){
position2 = RelativePoint(AbsolutePoint(getX() + width, getY() + height));
}
void Coordinate::setCenterPosition(const RelativePoint & center){
int width = getWidth();
int height = getHeight();
this->position = center;
this->position2 = center;
growHorizontalAbsolute(width / 2.0);
growVerticalAbsolute(height / 2.0);
}
diff --git a/util/gui/coordinate.h b/util/gui/coordinate.h
index 8b0498fc..5a567967 100644
--- a/util/gui/coordinate.h
+++ b/util/gui/coordinate.h
@@ -1,233 +1,226 @@
#ifndef _paintown_gui_coordinate_h
#define _paintown_gui_coordinate_h
namespace Graphics{
class Bitmap;
}
namespace Gui {
namespace Space{
class Space;
/* a 2-d point */
class Point{
public:
Point(double x, double y, const Space & space);
Point(const Point & point, const Space & space);
Point(const Point & point);
Point operator+(const Point &);
Point & operator+=(const Point &);
Point & operator=(const Point &);
/* convert to physical space */
int physicalX() const;
int physicalY() const;
double x;
double y;
const Space & space;
private:
/* true if points use the same space system */
bool sameSpace(const Point & point);
};
/* mapping from coordinate space to physical space */
class Space{
public:
Space(double minX, double minY, double maxX, double maxY);
Point fromPhysical(int x, int y);
bool operator==(const Space & space) const;
double sizeX() const;
double sizeY() const;
double centerX() const;
double centerY() const;
double getLocalX(int physicalX) const;
double getLocalY(int physicalY) const;
private:
double minX, minY, maxX, maxY;
};
}
/* Coordinate system for handling scalable graphics */
class AbsolutePoint {
public:
AbsolutePoint();
explicit AbsolutePoint(int x, int y);
AbsolutePoint(const AbsolutePoint &);
virtual ~AbsolutePoint();
const AbsolutePoint & operator=(const AbsolutePoint &);
virtual inline void setX(int x){
this->x = x;
}
virtual int getX() const;
virtual inline void setY(int y){
this->y = y;
}
virtual int getY() const;
private:
int x;
int y;
};
class RelativePoint {
public:
RelativePoint();
explicit RelativePoint(double x, double y);
RelativePoint(const RelativePoint &);
RelativePoint(const AbsolutePoint &);
virtual ~RelativePoint();
const RelativePoint & operator=(const RelativePoint &);
const RelativePoint & operator=(const AbsolutePoint &);
bool operator==(const RelativePoint &);
bool operator!=(const RelativePoint &);
virtual inline void setX(double x){
this->x = x;
}
virtual int getX() const;
virtual inline void setY(double y){
this->y = y;
}
virtual int getY() const;
virtual inline void set(double x, double y){
this->x = x;
this->y = y;
}
virtual int getDistanceFromCenterX();
virtual int getDistanceFromCenterY();
virtual void moveX(double percent);
virtual void moveY(double percent);
virtual void moveBy(double x, double y);
virtual AbsolutePoint getAbsolute();
virtual double getRelativeX() const;
virtual double getRelativeY() const;
private:
double x;
double y;
};
class Coordinate {
public:
Coordinate();
Coordinate(AbsolutePoint &, AbsolutePoint &);
Coordinate(const RelativePoint &, const RelativePoint &);
Coordinate(const Coordinate &);
virtual ~Coordinate();
const Coordinate & operator=(const Coordinate &);
virtual inline void setZ(double z){
this->z = z;
}
virtual inline double getZ() const{
return this->z;
}
- virtual inline void setRadius(double radius){
- this->radius = radius;
- }
- virtual inline double getRadius() const{
- return this->radius;
- }
virtual int getX() const;
virtual int getY() const;
virtual int getWidth() const;
virtual int getHeight() const;
virtual int getX2() const;
virtual int getY2() const;
/* give a relative quantity */
virtual void growHorizontal(double by);
/* give an absolute quantity */
virtual void growHorizontalAbsolute(int by);
/* give a relative quantity */
virtual void growVertical(double by);
/* give an absolute quantity */
virtual void growVerticalAbsolute(int by);
virtual void growTo(const Coordinate &, double percent = 0.005);
virtual void center(const Coordinate &);
virtual void moveBy(double x, double y);
virtual inline double getRelativeX1() const{
return this->position.getRelativeX();
}
virtual inline double getRelativeX2() const{
return this->position2.getRelativeX();
}
virtual inline double getRelativeY1() const{
return this->position.getRelativeY();
}
virtual inline double getRelativeY2() const{
return this->position2.getRelativeY();
}
virtual inline void set(double x1, double y1, double x2, double y2){
this->position.setX(x1);
this->position.setY(y1);
this->position2.setX(x2);
this->position2.setY(y2);
}
virtual inline void setX1(double x){
this->position.setX(x);
}
virtual inline void setX2(double x){
this->position2.setX(x);
}
virtual inline void setY1(double y){
this->position.setY(y);
}
virtual inline void setY2(double y){
this->position2.setY(y);
}
bool operator==( const Coordinate &);
bool operator!=( const Coordinate &);
bool operator==( const Graphics::Bitmap &);
bool operator!=( const Graphics::Bitmap &);
/* moves the positions so that `center' is in the middle but the
* width/height is maintained
*/
virtual void setCenterPosition(const RelativePoint & center);
virtual void setPosition(const RelativePoint &);
virtual void setPosition(const AbsolutePoint &);
virtual void setPosition2(const RelativePoint &);
virtual void setPosition2(const AbsolutePoint &);
virtual void moveTo(const AbsolutePoint &);
virtual void setDimensions(int width, int height);
virtual inline RelativePoint & getPosition(){
return this->position;
}
virtual inline RelativePoint & getPosition2(){
return this->position2;
}
virtual inline bool empty(){
return (getWidth() == 0 && getHeight() == 0);
}
private:
void checkDimensions();
RelativePoint position;
RelativePoint position2;
double z;
- double radius;
};
}
#endif
diff --git a/util/gui/lineedit.cpp b/util/gui/lineedit.cpp
index 1a722364..744ed82d 100644
--- a/util/gui/lineedit.cpp
+++ b/util/gui/lineedit.cpp
@@ -1,362 +1,362 @@
#include "util/bitmap.h"
#include "util/trans-bitmap.h"
#include "util/font.h"
#include "lineedit.h"
#include "keys.h"
#include "globals.h"
#include "util/debug.h"
#include <iostream>
using namespace Gui;
static std::ostream & debug( int level ){
Global::debug(level) << "[line edit] ";
return Global::debug(level);
}
LineEdit::LineEdit() :
currentSetFont(0),
hAlignment(T_Middle),
hAlignMod(T_Middle),
vAlignment(T_Middle),
inputTypeValue(inputGeneral),
changed_(0),
autoResizable(0),
textX(0),
textY(0),
cursorX(0),
cursorY(0),
cursorIndex(0),
textColor(0),
textSizeH(0),
limit(0),
blinkRate(500),
blink(false),
focused(false),
changeCounter(0){
cursorTime.reset();
}
LineEdit::~LineEdit(){
if (focused){
input.disable();
}
}
void LineEdit::hookKey(int key, void (*callback)(void *), void * arg){
input.addBlockingHandle(key, callback, arg);
}
bool LineEdit::didChanged(unsigned long long & counter){
bool did = counter < changeCounter;
counter = changeCounter;
return did;
}
// If the font size changes
void LineEdit::fontChange(){
changed();
}
// Update
void LineEdit::act(const Font & font){
if (cursorTime.msecs() >= blinkRate){
cursorTime.reset();
blink = !blink;
changed();
}
/*
if ((blinkRate * 2) <= cursorTime.msecs()){
cursorTime.reset();
changed();
}
*/
if (input.doInput()){
changed();
cursorIndex = input.getText().size();
}
if (changed_){
textSizeH = currentSetFont->getHeight();
if (autoResizable) {
location.setDimensions(textSizeH+2, currentSetFont->textLength(input.getText().c_str()) + 4);
} else {
if (hAlignMod==T_Left){
if (currentSetFont->textLength(input.getText().c_str())>location.getWidth()){
hAlignment = T_Right;
} else {
hAlignment = T_Left;
}
}
}
switch (hAlignment) {
case T_Left:
textX = 2;
cursorX = textX + currentSetFont->textLength(input.getText().substr(0,cursorIndex).c_str()) + 1;
break;
case T_Middle:
textX = (location.getWidth()/2) - (currentSetFont->textLength(input.getText().c_str())/2);
cursorX = (textX) + currentSetFont->textLength(input.getText().substr(0,cursorIndex).c_str()) + 1;
break;
case T_Right:
textX = location.getWidth() - currentSetFont->textLength(input.getText().c_str());//(position.width - 1)-2;
cursorX = location.getWidth() - currentSetFont->textLength(input.getText().substr(0, input.getText().length()-cursorIndex).c_str());
break;
case T_Bottom:
case T_Top:
break;
}
switch (vAlignment) {
case T_Top:
textY = 1;
cursorY = 1;
break;
case T_Middle:
textY = cursorY = (location.getHeight() - textSizeH-(5))/2;
break;
case T_Bottom:
textY = (location.getHeight() - 1) - textSizeH - 1;
cursorY = textY - textSizeH;
break;
case T_Right:
case T_Left:
break;
}
//textY++;
//textX++;
stable();
}
}
// Draw
void LineEdit::render(const Graphics::Bitmap & work){
checkWorkArea();
// Check if we are using a rounded box
- if (location.getRadius()>0) {
+ if (transforms.getRadius()>0) {
Graphics::Bitmap::transBlender( 0, 0, 0, colors.bodyAlpha );
- roundRectFill( *workArea, (int)location.getRadius(), 0, 0, location.getWidth()-1, location.getHeight()-1, colors.body );
+ roundRectFill( *workArea, (int)transforms.getRadius(), 0, 0, location.getWidth()-1, location.getHeight()-1, colors.body );
workArea->translucent().draw(location.getX(),location.getY(),work);
workArea->fill(Graphics::makeColor(255,0,255));
Graphics::Bitmap::transBlender( 0, 0, 0, colors.borderAlpha );
- roundRect( *workArea, (int)location.getRadius(), 0, 0, location.getWidth()-1, location.getHeight()-1, colors.border );
+ roundRect( *workArea, (int)transforms.getRadius(), 0, 0, location.getWidth()-1, location.getHeight()-1, colors.border );
workArea->translucent().draw(location.getX(),location.getY(),work);
} else {
Graphics::Bitmap::transBlender( 0, 0, 0, colors.bodyAlpha );
workArea->rectangleFill( 0, 0, location.getWidth()-1, location.getHeight()-1, colors.body );
workArea->translucent().draw(location.getX(),location.getY(),work);
workArea->fill(Graphics::makeColor(255,0,255));
Graphics::Bitmap::transBlender( 0, 0, 0, colors.borderAlpha );
workArea->rectangle( 0, 0, location.getWidth()-1, location.getHeight()-1, colors.border );
workArea->translucent().draw(location.getX(),location.getY(),work);
}
// work.drawingMode( Bitmap::MODE_SOLID );
workArea->fill(Graphics::makeColor(255,0,255));
if (currentSetFont){
currentSetFont->printf(textX,textY,textColor,*workArea, input.getText(), 0);
}
if (focused){
/*
if (cursorTime.msecs() <= blinkRate){
workArea->line(cursorX,cursorY,cursorX,cursorY+textSizeH-5,textColor);
}
*/
if (blink){
workArea->line(cursorX,cursorY,cursorX,cursorY+textSizeH-5,textColor);
}
}
workArea->draw(location.getX(), location.getY(), work);
}
#if 0
// Keypresses
sigslot::slot LineEdit::keyPress(const keys &k)
{
debug( 5 ) << "Received key press " << k.getValue() << std::endl;
if(focused)
{
if(k.isCharacter())
{
char keyValue = k.getValue();
bool addValue = false;
switch(inputTypeValue){
case inputNumerical:
if ( k.isNumber() ) addValue = !addValue;
break;
case inputNoCaps:
keyValue = tolower(keyValue);
addValue = !addValue;
break;
case inputAllCaps:
keyValue = toupper(keyValue);
addValue = !addValue;
break;
case inputGeneral:
default:
addValue = !addValue;
break;
}
if(addValue){
if(limit!=0)
{
if(currentSetText.length()<limit)
{
//currentSetText += k.getValue();
currentSetText.insert(cursorIndex, std::string(1,keyValue));
++cursorIndex;
changed();
}
}
else
{
//currentSetText += k.getValue();
currentSetText.insert(cursorIndex, std::string(1,keyValue));
++cursorIndex;
changed();
}
}
}
else
{
switch(k.getValue())
{
case keys::DEL:
if(cursorIndex<currentSetText.length())
{
currentSetText.erase(cursorIndex,1);
}
break;
case keys::BACKSPACE:
if(cursorIndex>0)
{
currentSetText.erase(cursorIndex - 1, 1);
--cursorIndex;
}
break;
case keys::RIGHT:
if(cursorIndex<currentSetText.length())++cursorIndex;
break;
case keys::LEFT:
if(cursorIndex>0)--cursorIndex;
break;
case keys::INSERT:
break;
}
changed();
}
}
}
#endif
// Set text
void LineEdit::setText(const std::string & text){
input.setText(text);
if (limit!=0) {
if (input.getText().length() > limit) {
while (input.getText().length() > limit){
// currentSetText.erase(currentSetText.begin()+currentSetText.length()-1);
}
}
}
cursorIndex = input.getText().length();
changed();
}
//! Get text
const std::string LineEdit::getText(){
return input.getText();
}
//! Clear text
void LineEdit::clearText(){
input.clearInput();
cursorIndex=0;
changed();
}
//! Set text limit
void LineEdit::setLimit(unsigned int l){
limit = l;
if (limit!=0){
if (input.getText().length()>limit){
while (input.getText().length()>limit){
// currentSetText.erase(currentSetText.begin()+currentSetText.length()-1);
}
}
}
cursorIndex = input.getText().length();
changed();
}
// Set Horizontal Alignment
void LineEdit::setHorizontalAlign(const textAlign & a){
hAlignment = hAlignMod = a;
changed();
}
// Set Vertical Alignment
void LineEdit::setVerticalAlign(const textAlign & a){
vAlignment = a;
changed();
}
//! Set the type of input default general
void LineEdit::setInputType(const inputType i){
inputTypeValue = i;
}
// Set textColor
void LineEdit::setTextColor(const int color){
textColor = color;
}
//! Set textColor
void LineEdit::setCursorColor(const int color){
textColor = color;
}
// Set font
void LineEdit::setFont(const Font *f){
currentSetFont = f;
if (currentSetFont) changed();
}
// Set autoResizeable
void LineEdit::setAutoResize(bool r){
autoResizable = r;
}
// Set the cursor blink rate in miliseconds (default 500)
void LineEdit::setCursorBlinkRate(unsigned int msecs){
blinkRate = msecs;
}
//! set Focus
void LineEdit::setFocused(bool focus){
focused = focus;
if (focus){
input.enable();
} else {
input.disable();
}
}
//! check Focus
bool LineEdit::isFocused(){
return focused;
}
diff --git a/util/gui/popup-box.h b/util/gui/popup-box.h
index d887bcfd..849808fa 100644
--- a/util/gui/popup-box.h
+++ b/util/gui/popup-box.h
@@ -1,72 +1,76 @@
#ifndef _paintown_gui_popup_box_h
#define _paintown_gui_popup_box_h
#include <string>
#include <vector>
#include "widget.h"
#include "box.h"
#include "../gradient.h"
namespace Gui{
class PopupBox : public Widget {
public:
PopupBox();
PopupBox(const PopupBox &);
virtual ~PopupBox();
//! copy
PopupBox &operator=(const PopupBox &);
//! Logic
virtual void act(const Font &);
//! Render
using Widget::render;
virtual void render(const Graphics::Bitmap &);
//! Open box
virtual void open();
//! Close box
virtual void close();
//! Is active?
virtual inline bool isActive(){
return (this->fadeState != Closed);
}
virtual inline bool isOpen(){
return this->fadeState == Open ||
this->fadeState == FadeIn;
}
//!set fadespeed
virtual inline void setFadeSpeed(int speed){
this->fadeSpeed = speed;
}
//! Get current box coordinates
virtual inline const Coordinate & getArea(){
return this->board.location;
}
+ //! Get current box transformations
+ virtual inline const Gui::Transformations & getTransforms(){
+ return this->board.transforms;
+ }
private:
void doFade();
enum FadeState{
Closed,
FadeIn,
Open,
FadeOut,
};
//! Current fade state
FadeState fadeState;
//! Fade speed
int fadeSpeed;
//! Board
Box board;
};
}
#endif
diff --git a/util/gui/tabbed-box.cpp b/util/gui/tabbed-box.cpp
index 0f31267d..8c417f18 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 );
+ if (transforms.getRadius() > 0){
+ //roundRectFill( *workArea, (int)transforms.getRadius(), 0, 0, location.getWidth()-1, location.getHeight()-1, colors.body );
+ //roundRect( *workArea, (int)transforms.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<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){
+ if (tab->context->transforms.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/widget.cpp b/util/gui/widget.cpp
index 30797767..8adc5980 100644
--- a/util/gui/widget.cpp
+++ b/util/gui/widget.cpp
@@ -1,249 +1,265 @@
#include "util/bitmap.h"
#include "widget.h"
#include <math.h>
#include "globals.h"
#include "util/token.h"
#include "coordinate.h"
#include "util/load_exception.h"
#include <sstream>
using namespace Gui;
static const double S_PI = 3.14159265358979323846;
static const double DEG_TO_RAD = 180.0/S_PI;
static const double RAD_TO_DEG = S_PI/180.0;
static void round_double (double dbl_to_round , int &rounded_num) {
rounded_num = static_cast<int>(dbl_to_round);
if ((dbl_to_round - static_cast<double>(rounded_num)) >= 0.5) {rounded_num++;}
}
//! min (borrowed from allegro)
static inline int Min(int x, int y){ return (((x) < (y)) ? (x) : (y)); }
//! max (borrowed from allegro)
static inline int Max(int x, int y){ return (((x) > (y)) ? (x) : (y)); }
//! mid (borrowed from allegro)
static inline int Mid(int x,int y,int z){ return (Max((x), Min((y), (z)))); }
+Transformations::Transformations():
+radius(0){
+}
+
+Transformations::Transformations(const Transformations & transforms):
+radius(transforms.radius){
+}
+
+Transformations::~Transformations(){
+}
+
+Transformations & Transformations::operator=(const Transformations & transforms){
+ this->radius = transforms.radius;
+ return *this;
+}
+
Widget::Widget() : workArea(0)
{
// Nothing yet
}
Widget::Widget( const Widget & w ){
this->location = w.location;
this->workArea = w.workArea;
}
Widget::~Widget(){
if ( workArea ){
delete workArea;
}
}
// copy
Widget &Widget::operator=( const Widget &copy){
location = copy.location;
workArea = copy.workArea;
return *this;
}
void Widget::setCoordinates(const Token * token){
if ( *token == "position" ){
int x, y, width, height;
token->view() >> x >> y >> width >> height;
AbsolutePoint pos(x, y);
AbsolutePoint dimensions(x + width, y + height);
location.setPosition(pos);
location.setPosition2(dimensions);
} else if ( *token == "relative-position" ){
double x1, y1, x2, y2;
token->view() >> x1 >> y1 >> x2 >> y2;
RelativePoint pos(x1,y1);
RelativePoint dimensions(x2,y2);
location = Coordinate(pos, dimensions);
} else if ( *token == "coordinate" ){
TokenView view = token->view();
while (view.hasMore()){
const Token * coordToken;
view >> coordToken;
if (*coordToken == "absolute"){
int x, y, width, height;
coordToken->view() >> x >> y >> width >> height;
AbsolutePoint pos(x, y);
AbsolutePoint dimensions(x + width, y + height);
location = Coordinate(pos, dimensions);
} else if (*coordToken == "relative"){
double x1, y1, x2, y2;
coordToken->view() >> x1 >> y1 >> x2 >> y2;
RelativePoint pos(x1,y1);
RelativePoint dimensions(x2,y2);
location = Coordinate(pos, dimensions);
} else if (*coordToken == "radius"){
- double radius;
+ double radius = 0;
coordToken->view() >> radius;
- location.setRadius(radius);
+ transforms.setRadius(radius);
} else if (*coordToken == "z"){
double z;
coordToken->view() >> z;
location.setZ(z);
}
}
}
if (location.getWidth() < 0 || location.getHeight() < 0){
std::ostringstream out;
out << "Invalid location dimension (cannot have a negative size). Width " << location.getWidth() << " Height " << location.getHeight() << ". From token: ";
token->toString(out, "");
throw LoadException(__FILE__, __LINE__, out.str());
}
}
void Widget::setColors(const Token * token){
if ( *token == "position-body" ) {
// This handles the body color of the widget
int r,g,b;
token->view() >> r >> g >> b >> colors.bodyAlpha;
colors.body = Graphics::makeColor(r,g,b);
} else if ( *token == "position-border" ) {
// This handles the border color of the widget
int r,g,b;
token->view() >> r >> g >> b >> colors.borderAlpha;
colors.border = Graphics::makeColor(r,g,b);
}
}
void Widget::render(const Graphics::Bitmap & bitmap, const Font & font){
render(bitmap);
}
void Widget::arc( const Graphics::Bitmap & work, int x, int y, double startAngle, int radius, int color ){
int q = 0;// for counters
double d_q = 0.0;// for percentage of loop completed
double d_q_plus_one = 0.0;
const double d_angular_length_deg = 0.030;
const double d_start_angle_rad = startAngle*DEG_TO_RAD;
const double d_angular_length_rad = d_angular_length_deg*DEG_TO_RAD;
const double d_arc_distance_between_points = 0.25*pow(2.0 , static_cast<double>(10) / 10.0);
double d_angular_length_rad_per_segment = 0.0;
double arc_length = radius*d_angular_length_rad;
if (arc_length < 0.0) {arc_length *= -1.0;}
const double d_num_segments = arc_length / d_arc_distance_between_points;
int num_segments = 0;
round_double(d_num_segments , num_segments);
if (num_segments == 0) {num_segments += 1;} // need at least one segment (two points)
const int num_points = num_segments + 1;
const double d_num_points_minus_one = static_cast<double>(num_points - 1);
int arc_point_x;//[num_points];
int arc_point_y;//[num_points];
int arc_point2_x;//[num_points];
int arc_point2_y;//[num_points];
double d_arc_point_x = 0.0;
double d_arc_point_y = 0.0;
double d_arc_point2_x = 0.0;
double d_arc_point2_y = 0.0;
double current_angle_rad = 0.0;
double current_angle2_rad = 0.0;
if (d_arc_distance_between_points <= 1.0) {
for (q = 0 ; q < num_points ; q++) {
d_q = static_cast<double>(q);
current_angle_rad = d_start_angle_rad + (d_q / d_num_points_minus_one)*d_angular_length_rad;
d_arc_point_x = x + radius*cos(current_angle_rad);
d_arc_point_y = y + radius*sin(current_angle_rad);
round_double(d_arc_point_x , arc_point_x);
round_double(d_arc_point_y , arc_point_y);
work.putPixel(arc_point_x,arc_point_y,color);
}
}
if (d_arc_distance_between_points > 1.0) {
d_angular_length_rad_per_segment = d_angular_length_rad / d_num_points_minus_one;
for (q = 0 ; q < num_segments ; q++) {
d_q = static_cast<double>(q);
d_q_plus_one = static_cast<double>(q + 1);
current_angle_rad = d_start_angle_rad + d_q*d_angular_length_rad_per_segment;
current_angle2_rad = d_start_angle_rad + d_q_plus_one*d_angular_length_rad_per_segment;
d_arc_point_x = x + radius*cos(current_angle_rad);
d_arc_point_y = y + radius*sin(current_angle_rad);
round_double(d_arc_point_x , arc_point_x);
round_double(d_arc_point_y , arc_point_y);
d_arc_point2_x = x + radius*cos(current_angle2_rad);
d_arc_point2_y = y + radius*sin(current_angle2_rad);
round_double(d_arc_point2_x , arc_point2_x);
round_double(d_arc_point2_y , arc_point2_y);
work.line(arc_point_x,arc_point_y, arc_point2_x, arc_point2_y,color);
}
}
}
void Widget::roundRect( const Graphics::Bitmap & work, int radius, int x1, int y1, int x2, int y2, int color ){
const int width = x2 - x1;
const int height = y2 - y1;
radius = Mid(0, radius, Min((x1+width - x1)/2, (y1+height - y1)/2));
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);
}
void Widget::roundRectFill( const Graphics::Bitmap & work, int radius, int x1, int y1, int x2, int y2, int color ){
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);
}
static void foobar(int a, int b){
a = a + b;
}
void Widget::checkWorkArea(){
/*
if (location.getWidth() < 0 || location.getHeight() < 0){
foobar(location.getWidth(), location.getHeight());
}
*/
if ( ! workArea ){
workArea = new Graphics::Bitmap(location.getWidth(), location.getHeight());
} else if (location.getWidth() < workArea->getWidth() || location.getHeight() < workArea->getHeight()){
delete workArea;
workArea = new Graphics::Bitmap(location.getWidth(), location.getHeight());
} else if (location.getWidth() > workArea->getWidth() || location.getHeight() > workArea->getHeight()){
delete workArea;
workArea = new Graphics::Bitmap(location.getWidth(), location.getHeight());
}
if (workArea){
workArea->fill(Graphics::makeColor(255,0,255));
}
}
diff --git a/util/gui/widget.h b/util/gui/widget.h
index 4aad408c..372e2345 100644
--- a/util/gui/widget.h
+++ b/util/gui/widget.h
@@ -1,68 +1,94 @@
#ifndef _paintown_gui_widget_h
#define _paintown_gui_widget_h
#include "rectarea.h"
#include "coordinate.h"
namespace Graphics{
class Bitmap;
}
class Token;
class Font;
namespace Gui{
struct ColorInfo{
ColorInfo():
body(0),
/* alpha 0 is invisible, 255 is opaque. set something in the middle as default */
bodyAlpha(128),
border(0),
borderAlpha(128){
}
int body;
int bodyAlpha;
int border;
int borderAlpha;
};
+/*! Trasformations for widgets
+ * Eventually this could be expanded and used as something to perform changes on widgets but for now it remains to be just a place holder
+ * ************************
+ * radius - rounded corners
+ */
+class Transformations{
+public:
+ Transformations();
+ Transformations(const Transformations &);
+ virtual ~Transformations();
+
+ Transformations & operator=(const Transformations &);
+
+ virtual inline void setRadius(double radius){
+ this->radius = radius;
+ }
+ virtual inline double getRadius() const{
+ return this->radius;
+ }
+private:
+ double radius;
+};
+
class Widget{
public:
Widget();
- Widget( const Widget & w );
+ Widget( const Widget &);
virtual ~Widget();
// copy
Widget &operator=( const Widget &);
void setCoordinates(const Token * token);
void setColors(const Token * token);
//! New position data
Coordinate location;
//! Colors
ColorInfo colors;
+
+ //! Transformations
+ Transformations transforms;
// Logic
virtual void act(const Font &)=0;
// Render
virtual void render(const Graphics::Bitmap &) = 0;
/* default behavior is just to call render() */
virtual void render(const Graphics::Bitmap &, const Font &);
protected:
void arc( const Graphics::Bitmap &, int x, int y, double startAngle, int radius, int color );
void roundRect( const Graphics::Bitmap &, int radius, int x1, int y1, int x2, int y2, int color );
void roundRectFill( const Graphics::Bitmap &, int radius, int x1, int y1, int x2, int y2, int color );
void checkWorkArea();
Graphics::Bitmap *workArea;
};
}
#endif

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 11:07 AM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68640
Default Alt Text
(70 KB)

Event Timeline