Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
54 KB
Referenced Files
None
Subscribers
None
diff --git a/util/gui/context-box.cpp b/util/gui/context-box.cpp
index 3202c213..950b50c4 100644
--- a/util/gui/context-box.cpp
+++ b/util/gui/context-box.cpp
@@ -1,449 +1,453 @@
#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{
Effects::Gradient standardGradient(){
Effects::Gradient standard(GradientMax, selectedGradientStart(), selectedGradientEnd());
return standard;
}
ContextItem::ContextItem(const ContextBox & parent):
parent(parent){
}
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, int distance) const {
if (distance == 0){
Graphics::Bitmap::transBlender(0, 0, 0, parent.getFadeAlpha());
font.printf(x, y, parent.getSelectedColor(), where.translucent(), getName(), 0);
} else {
int alpha = parent.getFadeAlpha() - fabs((double) distance) * 35;
if (alpha < 0){
alpha = 0;
}
Graphics::Bitmap::transBlender(0, 0, 0, alpha);
font.printf(x, y, Graphics::makeColor(255, 255, 255), where.translucent(), 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(standardGradient()),
useGradient(true),
renderOnlyText(false){
}
ContextBox::ContextBox( const ContextBox & copy ):
fadeState(NotActive),
selectedGradient(standardGradient()),
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;
}
int ContextBox::getSelectedColor() const {
return useGradient ? selectedGradient.current() : selectedGradientStart();
}
void ContextBox::adjustLeft(){
}
void ContextBox::adjustRight(){
}
void ContextBox::open(){
// Set the fade stuff
fadeState = FadeIn;
//board.position = position;
board.location = location;
board.transforms = transforms;
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::addItem(const Util::ReferenceCount<ContextItem> & item){
+ 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.getTransforms().getRadius()/2);
const int y1 = board.getArea().getY()+2;//(board.getArea().radius/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/context-box.h b/util/gui/context-box.h
index 406a2520..de19eed7 100644
--- a/util/gui/context-box.h
+++ b/util/gui/context-box.h
@@ -1,165 +1,166 @@
#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{
Effects::Gradient standardGradient();
class ContextBox;
class ContextItem: public ScrollItem {
public:
ContextItem(const ContextBox & parent);
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, int distance) const;
virtual int size(const Font & font) const;
protected:
const ContextBox & parent;
};
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 void setList(const std::vector<Util::ReferenceCount<ContextItem> > & list);
+ virtual void addItem(const Util::ReferenceCount<ContextItem> & item);
virtual int getSelectedColor() const;
/*
//! 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->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;
}
virtual inline int getFadeAlpha() const {
return this->fadeAlpha;
}
//! 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;
//! Current fade state
FadeState fadeState;
//! Context list
// 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 ae89040d..9b5688a8 100644
--- a/util/gui/scroll-list.cpp
+++ b/util/gui/scroll-list.cpp
@@ -1,199 +1,204 @@
#include "../bitmap.h"
#include "../trans-bitmap.h"
#include "scroll-list.h"
#include "../font.h"
#include <math.h>
#include "../debug.h"
namespace Gui{
static const double FONT_SPACER = 1.3;
// static const int GradientMax = 50;
const double EPSILON = 0.01;
/*
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),
scrollWaitTime(4),
scrollMotion(1.2),
// selectedGradient(GradientMax, selectedGradientStart(), selectedGradientEnd()),
// useGradient(false),
useHighlight(false),
allowWrap(true),
scroll(0),
justification(CenterJustify){}
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),
scroll(0){}
ScrollList::~ScrollList(){}
ScrollList & ScrollList::operator=(const ScrollList & copy){
return *this;
}
void ScrollList::act(){
if (scrollWait == 0){
if (scroll > EPSILON){
// scroll -= SCROLL_MOTION;
scroll /= scrollMotion;
} else if (scroll < -EPSILON){
// scroll += SCROLL_MOTION;
scroll /= scrollMotion;
} else {
scroll = 0;
currentPosition = currentIndex;
}
} else {
scrollWait -= 1;
}
/*
if (scrollWait > 0){
scrollWait -= 1;
} else {
currentPosition = currentIndex;
}
*/
}
int ScrollList::justify(int left, int right, int size) const {
switch (justification){
case LeftJustify: return left;
case RightJustify: return right - size;
case CenterJustify: return (left + right) / 2 - size / 2;
}
return 0;
}
/* this is the smooth scroll stuff from context-box */
void ScrollList::doDraw(int x, int y, int min_y, int max_y, const Font & font, int current, int selected, const Graphics::Bitmap & area, int direction) const {
+ /* sanity check */
+ if (text.size() == 0){
+ return;
+ }
+
while (y < max_y && y > min_y){
/* circuluar */
int pick = current;
while (pick < 0){
pick += text.size();
}
pick = pick % text.size();
Util::ReferenceCount<ScrollItem> option = text[pick];
/* center justification */
const int startx = justify(1, area.getWidth() - 1, option->size(font));
/* the selected option will have a distance of 0 */
int distance = current - selected;
option->draw(x + startx, y, area, font, distance);
if (text.size() == 1){
return;
}
current += direction;
y += direction * font.getHeight() / FONT_SPACER;
}
}
void ScrollList::render(const Graphics::Bitmap & where, const Font & font) const {
/* middle of the bitmap offset by the scroll amount. */
int y = where.getHeight() / 2 + scroll * font.getHeight() / 2 - font.getHeight() / 2;
/* allow options to be drawn a little off the bitmap */
int min_y = 0 - font.getHeight() / FONT_SPACER;
int max_y = where.getHeight();
/* draw down starting from the current selection */
doDraw(0, y, min_y, max_y, font, currentIndex, currentIndex, where, 1);
/* then draw up, skipping the current selection */
doDraw(0, y - font.getHeight() / FONT_SPACER, min_y, max_y, font, currentIndex - 1, currentIndex, where, -1);
}
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(){
/* FIXME: probably if the current index goes past the boundary we shouldn't scroll */
currentIndex++;
scroll = 1;
if (scrollWait == 0){
scrollWait = scrollWaitTime;
}
if (currentIndex >= text.size()){
if (allowWrap){
currentIndex = 0;
return true;
} else {
currentIndex = text.size()-1;
return false;
}
}
return true;
}
bool ScrollList::previous(){
scroll = -1;
if (scrollWait == 0){
scrollWait = scrollWaitTime;
}
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/tabbed-box.cpp b/util/gui/tabbed-box.cpp
index 099de93a..69ec9d09 100644
--- a/util/gui/tabbed-box.cpp
+++ b/util/gui/tabbed-box.cpp
@@ -1,312 +1,316 @@
#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;
}
+
+void Tab::addOption(const Util::ReferenceCount<ContextItem> & item){
+ context.addItem(item);
+}
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 (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);
addTab(tab);
/*
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::addTab(Tab * tab){
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.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/tabbed-box.h b/util/gui/tabbed-box.h
index d19644e9..f6cd2dc0 100644
--- a/util/gui/tabbed-box.h
+++ b/util/gui/tabbed-box.h
@@ -1,136 +1,139 @@
#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"
#include "context-box.h"
class Token;
namespace Gui{
class ContextBox;
class ContextItem;
class Tab{
- public:
- Tab();
- virtual ~Tab();
- std::string name;
- Gui::ContextBox context;
- bool active;
+public:
+ Tab();
+ virtual ~Tab();
+
+ void addOption(const Util::ReferenceCount<ContextItem> & item);
+
+ 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<Util::ReferenceCount<ContextItem> > & list);
virtual void addTab(Tab * tab);
//! 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/init.cpp b/util/init.cpp
index ef94dad8..71eb033b 100644
--- a/util/init.cpp
+++ b/util/init.cpp
@@ -1,585 +1,585 @@
#ifdef USE_ALLEGRO
#include <allegro.h>
#ifdef ALLEGRO_WINDOWS
#include <winalleg.h>
#endif
#endif
#ifdef USE_ALLEGRO5
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#endif
#ifdef USE_SDL
#include <SDL.h>
#endif
#ifndef WINDOWS
#include <signal.h>
#include <string.h>
#include <unistd.h>
#endif
#ifdef LINUX
#include <execinfo.h>
#endif
/* don't be a boring tuna */
// #warning you are ugly
#include "globals.h"
#include "init.h"
#include "network/network.h"
#include "thread.h"
#include <time.h>
#include <ostream>
#include "dumb/include/dumb.h"
#ifdef USE_ALLEGRO
#include "dumb/include/aldumb.h"
#include "loadpng/loadpng.h"
#include "gif/algif.h"
#endif
#include "bitmap.h"
#include "funcs.h"
#include "file-system.h"
#include "font.h"
#include "sound.h"
#include "configuration.h"
#include "music.h"
#include "loading.h"
#include "input/keyboard.h"
#include "message-queue.h"
#ifdef WII
#include <fat.h>
#endif
using namespace std;
volatile int Global::speed_counter4 = 0;
/* enough seconds for 136 years */
volatile unsigned int Global::second_counter = 0;
/* the original engine was running at 90 ticks per second, but we dont
* need to render that fast, so TICS_PER_SECOND is really fps and
* LOGIC_MULTIPLIER will be used to adjust the speed counter to its
* original value.
*/
const int Global::TICS_PER_SECOND = 40;
const double Global::LOGIC_MULTIPLIER = (double) 90 / (double) Global::TICS_PER_SECOND;
#ifdef USE_ALLEGRO
const int Global::WINDOWED = GFX_AUTODETECT_WINDOWED;
const int Global::FULLSCREEN = GFX_AUTODETECT_FULLSCREEN;
#else
/* FIXME: use enums here or something */
const int Global::WINDOWED = 0;
const int Global::FULLSCREEN = 1;
#endif
/* game counter, controls FPS */
static void inc_speed_counter(){
/* probably put input polling here, InputManager::poll(). no, don't do that.
* polling is done in the standardLoop now.
*/
Global::speed_counter4 += 1;
}
#ifdef USE_ALLEGRO
END_OF_FUNCTION(inc_speed_counter)
#endif
/* if you need to count seconds for some reason.. */
static void inc_second_counter() {
Global::second_counter += 1;
}
#ifdef USE_ALLEGRO
END_OF_FUNCTION(inc_second_counter)
#endif
#if !defined(WINDOWS) && !defined(WII) && !defined(MINPSPW) && !defined(PS3) && !defined(NDS)
#ifdef LINUX
static void print_stack_trace(){
/* use addr2line on these addresses to get a filename and line number */
void *trace[128];
int frames = backtrace(trace, 128);
printf("Stack trace\n");
for (int i = 0; i < frames; i++){
printf(" %p\n", trace[i]);
}
}
#endif
static void handleSigSegV(int i, siginfo_t * sig, void * data){
const char * message = "Bug! Caught a memory violation. Shutting down..\n";
int dont_care = write(1, message, 48);
dont_care = dont_care;
#ifdef LINUX
print_stack_trace();
#endif
// Global::shutdown_message = "Bug! Caught a memory violation. Shutting down..";
Graphics::setGfxModeText();
#ifdef USE_ALLEGRO
allegro_exit();
#endif
#ifdef USE_SDL
SDL_Quit();
#endif
/* write to a log file or something because sigsegv shouldn't
* normally happen.
*/
exit(1);
}
#else
#endif
/* catch a socket being closed prematurely on unix */
#if !defined(WINDOWS) && !defined(WII) && !defined(MINPSPW) && !defined(PS3) && !defined(NDS)
static void handleSigPipe( int i, siginfo_t * sig, void * data ){
}
/*
static void handleSigUsr1( int i, siginfo_t * sig, void * data ){
pthread_exit( NULL );
}
*/
#endif
static void registerSignals(){
#if !defined(WINDOWS) && !defined(WII) && !defined(MINPSPW) && !defined(PS3) && !defined(NDS)
struct sigaction action;
memset( &action, 0, sizeof(struct sigaction) );
action.sa_sigaction = handleSigPipe;
sigaction( SIGPIPE, &action, NULL );
memset( &action, 0, sizeof(struct sigaction) );
action.sa_sigaction = handleSigSegV;
sigaction( SIGSEGV, &action, NULL );
/*
action.sa_sigaction = handleSigUsr1;
sigaction( SIGUSR1, &action, NULL );
*/
#endif
}
/* should probably call the janitor here or something */
static void close_paintown(){
Music::pause();
Graphics::setGfxModeText();
#ifdef USE_ALLEGRO
allegro_exit();
#endif
exit(0);
}
namespace Global{
extern int do_shutdown;
}
static void close_window(){
/* when do_shutdown is 1 the game will attempt to throw ShutdownException
* wherever it is. If the game is stuck or the code doesn't throw
* ShutdownException then when the user tries to close the window
* twice we just forcifully shutdown.
*/
Global::do_shutdown += 1;
if (Global::do_shutdown == 2){
close_paintown();
}
}
#ifdef USE_ALLEGRO
END_OF_FUNCTION(close_window)
#endif
#ifdef USE_ALLEGRO5
struct TimerInfo{
TimerInfo(void (*x)(), ALLEGRO_TIMER * y):
tick(x), timer(y){}
void (*tick)();
ALLEGRO_TIMER * timer;
};
static void * do_timer(void * info){
TimerInfo * timerInfo = (TimerInfo*) info;
ALLEGRO_EVENT_SOURCE * source = al_get_timer_event_source(timerInfo->timer);
ALLEGRO_EVENT_QUEUE * queue = al_create_event_queue();
al_register_event_source(queue, source);
while (true){
ALLEGRO_EVENT event;
al_wait_for_event(queue, &event);
timerInfo->tick();
}
al_destroy_event_queue(queue);
al_destroy_timer(timerInfo->timer);
delete timerInfo;
}
static Util::Thread::Id start_timer(void (*func)(), int frequency){
ALLEGRO_TIMER * timer = al_create_timer(ALLEGRO_BPS_TO_SECS(frequency));
if (timer == NULL){
Global::debug(0) << "Could not create timer" << endl;
}
al_start_timer(timer);
TimerInfo * info = new TimerInfo(func, timer);
Util::Thread::Id thread;
Util::Thread::createThread(&thread, NULL, (Util::Thread::ThreadFunction) do_timer, (void*) info);
return thread;
}
static void initSystem(ostream & out){
out << "Allegro5 initialize " << (al_init() ? "Ok" : "Failed") << endl;
uint32_t version = al_get_allegro_version();
int major = version >> 24;
int minor = (version >> 16) & 255;
int revision = (version >> 8) & 255;
int release = version & 255;
out << "Allegro5 version " << major << "." << minor << "." << revision << "." << release << endl;
al_init_image_addon();
al_install_keyboard();
al_set_app_name("Paintown");
start_timer(inc_speed_counter, Global::TICS_PER_SECOND);
// start_timer(inc_second_counter, 1);
}
#endif
#ifdef USE_ALLEGRO
static void initSystem(ostream & out){
out << "Allegro version: " << ALLEGRO_VERSION_STR << endl;
out << "Allegro init: " <<allegro_init()<<endl;
out << "Install timer: " <<install_timer()<<endl;
/* png */
loadpng_init();
algif_init();
out<<"Install keyboard: "<<install_keyboard()<<endl;
/* do we need the mouse?? */
// out<<"Install mouse: "<<install_mouse()<<endl;
out<<"Install joystick: "<<install_joystick(JOY_TYPE_AUTODETECT)<<endl;
/* 16 bit color depth */
set_color_depth(16);
LOCK_VARIABLE( speed_counter4 );
LOCK_VARIABLE( second_counter );
LOCK_FUNCTION( (void *)inc_speed_counter );
LOCK_FUNCTION( (void *)inc_second_counter );
/* set up the timers */
out<<"Install game timer: "<< install_int_ex(inc_speed_counter, BPS_TO_TIMER(Global::TICS_PER_SECOND))<<endl;
out<<"Install second timer: "<<install_int_ex(inc_second_counter, BPS_TO_TIMER(1))<<endl;
/* keep running in the background */
set_display_switch_mode(SWITCH_BACKGROUND);
/* close window when the X is pressed */
LOCK_FUNCTION(close_window);
set_close_button_callback(close_window);
}
#endif
#ifdef USE_SDL
// static pthread_t events;
struct TimerInfo{
TimerInfo(void (*x)(), int y):
tick(x), frequency(y){}
void (*tick)();
int frequency;
};
static void * do_timer(void * arg){
TimerInfo info = *(TimerInfo *) arg;
uint32_t delay = (uint32_t)(1000.0 / (double) info.frequency);
/* assuming SDL_GetTicks() starts at 0, this should last for about 50 days
* before overflowing. overflow should work out fine. Assuming activate occurs
* when the difference between now and ticks is at least 6, the following will happen.
* ticks now now-ticks
* 4294967294 4294967294 0
* 4294967294 4294967295 1
* 4294967294 0 2
* 4294967294 1 3
* 4294967294 2 4
* 4294967294 3 5
* 4294967294 4 6
* Activate
* 3 5 2
* 3 6 3
* 3 7 4
* 3 8 5
* 3 9 6
* Activate
*
* Can 'now' ever be much larger than 'ticks' due to overflow?
* It doesn't seem like it.
*/
uint32_t ticks = SDL_GetTicks();
/* TODO: pass in some variable that tells this loop to quit */
while (true){
uint32_t now = SDL_GetTicks();
while (now - ticks >= delay){
// Global::debug(0) << "Tick!" << endl;
info.tick();
ticks += delay;
}
SDL_Delay(1);
}
delete (TimerInfo *) arg;
return NULL;
}
static Util::Thread::Id start_timer(void (*func)(), int frequency){
TimerInfo * speed = new TimerInfo(func, frequency);
/*
speed.tick = func;
speed.frequency = frequency;
*/
Util::Thread::Id thread;
Util::Thread::createThread(&thread, NULL, (Util::Thread::ThreadFunction) do_timer, (void*) speed);
return thread;
}
#if 0
static void * handleEvents(void * arg){
bool done = false;
while (!done){
SDL_Event event;
int ok = SDL_WaitEvent(&event);
if (ok){
switch (event.type){
case SDL_QUIT : {
done = true;
close_window();
break;
}
default : {
// Global::debug(0) << "Ignoring SDL event " << event.type << endl;
break;
}
}
}
}
return NULL;
}
#endif
/*
static void doSDLQuit(){
SDL_Event quit;
quit.type = SDL_QUIT;
SDL_PushEvent(&quit);
Global::debug(0) << "Waiting for SDL event handler to finish" << endl;
pthread_join(events, NULL);
SDL_Quit();
}
*/
static void initSystem(ostream & out){
out << "SDL Init: ";
int ok = SDL_Init(SDL_INIT_VIDEO |
SDL_INIT_AUDIO |
SDL_INIT_TIMER |
SDL_INIT_JOYSTICK |
SDL_INIT_NOPARACHUTE);
if (ok == 0){
out << "Ok" << endl;
} else {
out << "Failed (" << ok << ") - " << SDL_GetError() << endl;
exit(ok);
}
/* Just do SDL thread init
#ifdef MINPSPW
pthread_init();
#endif
*/
start_timer(inc_speed_counter, Global::TICS_PER_SECOND);
start_timer(inc_second_counter, 1);
try{
SDL_Surface * icon = SDL_LoadBMP(Filesystem::find(Filesystem::RelativePath("menu/icon.bmp")).path().c_str());
if (icon != NULL){
SDL_WM_SetIcon(icon, NULL);
}
} catch (const Filesystem::NotFound & failed){
Global::debug(0) << "Could not find window icon: " << failed.getTrace() << endl;
}
SDL_WM_SetCaption("Paintown", NULL);
SDL_EnableUNICODE(1);
SDL_JoystickEventState(1);
atexit(SDL_Quit);
// atexit(doSDLQuit);
}
#endif
/* mostly used for testing purposes */
bool Global::initNoGraphics(){
/* copy/pasting the init code isn't ideal, maybe fix it later */
ostream & out = Global::debug(0);
out << "-- BEGIN init --" << endl;
out << "Data path is " << Util::getDataPath2().path() << endl;
out << "Paintown version " << Global::getVersionString() << endl;
out << "Build date " << __DATE__ << " " << __TIME__ << endl;
#ifdef WII
/* <WinterMute> fatInitDefault will set working dir to argv[0] passed by launcher,
* or root of first device mounted
*/
- out << "Fat init " << (fatInitDefault() != 0 ? "Ok" : "Failed") << endl;
+ out << "Fat init " << (fatInitDefault() == true ? "Ok" : "Failed") << endl;
#endif
/*
char buffer[512];
if (getcwd(buffer, 512) != 0){
printf("Working directory '%s'\n", buffer);
}
*/
if (!Filesystem::exists(Util::getDataPath2())){
Global::debug(0) << "Cannot find data path '" << Util::getDataPath2().path() << "'! Either use the -d switch to specify the data directory or find the data directory and move it to that path" << endl;
return false;
}
/* do implementation specific setup */
initSystem(out);
dumb_register_stdfiles();
// Sound::initialize();
Filesystem::initialize();
Graphics::SCALE_X = GFX_X;
Graphics::SCALE_Y = GFX_Y;
Configuration::loadConfigurations();
const int sx = Configuration::getScreenWidth();
const int sy = Configuration::getScreenHeight();
Graphics::Bitmap::setFakeGraphicsMode(sx, sy);
/* music */
atexit(&dumb_exit);
out << "Initialize random number generator" << endl;
/* initialize random number generator */
srand(time(NULL));
registerSignals();
#ifdef HAVE_NETWORKING
out << "Initialize network" << endl;
Network::init();
atexit(Network::closeAll);
#endif
/* this mutex is used to show the loading screen while the game loads */
// Util::Thread::initializeLock(&Loader::loading_screen_mutex);
out << "-- END init --" << endl;
return true;
}
bool Global::init(int gfx){
ostream & out = Global::debug( 0 );
out << "-- BEGIN init --" << endl;
out << "Data path is " << Util::getDataPath2().path() << endl;
out << "Paintown version " << Global::getVersionString() << endl;
out << "Build date " << __DATE__ << " " << __TIME__ << endl;
#ifdef WII
/* <WinterMute> fatInitDefault will set working dir to argv[0] passed by launcher,
* or root of first device mounted
*/
out << "Fat init " << (fatInitDefault() == 0 ? "Ok" : "Failed") << endl;
#endif
/*
char buffer[512];
if (getcwd(buffer, 512) != 0){
printf("Working directory '%s'\n", buffer);
}
*/
if (!Filesystem::exists(Util::getDataPath2())){
Global::debug(0) << "Cannot find data path '" << Util::getDataPath2().path() << "'! Either use the -d switch to specify the data directory or find the data directory and move it to that path" << endl;
return false;
}
/* do implementation specific setup */
initSystem(out);
dumb_register_stdfiles();
Sound::initialize();
Filesystem::initialize();
Graphics::SCALE_X = GFX_X;
Graphics::SCALE_Y = GFX_Y;
Configuration::loadConfigurations();
const int sx = Configuration::getScreenWidth();
const int sy = Configuration::getScreenHeight();
if (gfx == -1){
gfx = Configuration::getFullscreen() ? Global::FULLSCREEN : Global::WINDOWED;
} else {
Configuration::setFullscreen(gfx == Global::FULLSCREEN);
}
/* set up the screen */
int gfxCode = Graphics::setGraphicsMode(gfx, sx, sy);
if (gfxCode == 0){
out << "Set graphics mode: Ok" << endl;
} else {
out << "Set graphics mode: Failed! (" << gfxCode << ")" << endl;
return false;
}
/* music */
atexit(&dumb_exit);
out << "Initialize random number generator" << endl;
/* initialize random number generator */
srand(time(NULL));
registerSignals();
#ifdef HAVE_NETWORKING
out << "Initialize network" << endl;
Network::init();
atexit(Network::closeAll);
#endif
/* this mutex is used to show the loading screen while the game loads */
Util::Thread::initializeLock(&Global::messageLock);
out << "-- END init --" << endl;
/*
const Font & font = Font::getDefaultFont();
// font.setSize(30, 30);
Bitmap temp(font.textLength("Loading") + 1, font.getHeight("Loading") + 1);
font.printf(0, 0, Bitmap::makeColor(255, 255, 255), temp, "Loading", 0);
temp.BlitToScreen(sx / 2, sy / 2);
*/
Graphics::Bitmap white(sx, sy);
white.fill(Graphics::makeColor(255, 255, 255));
white.BlitToScreen();
return true;
}

File Metadata

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

Event Timeline