Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
30 KB
Referenced Files
None
Subscribers
None
diff --git a/util/gradient.cpp b/util/gradient.cpp
index 5501d3f8..3b9b50e8 100644
--- a/util/gradient.cpp
+++ b/util/gradient.cpp
@@ -1,44 +1,54 @@
#include "gradient.h"
#include "funcs.h"
namespace Effects{
/* this class does virtually no error checking. great job */
Gradient::Gradient(int size, int startColor, int endColor):
colors(0),
size(size),
index(0){
colors = new int[size];
Util::blend_palette(colors, size / 2, startColor, endColor);
Util::blend_palette(colors + size / 2, size / 2, endColor, startColor);
}
+
+Gradient::Gradient(const Gradient & copy):
+colors(NULL),
+size(copy.size),
+index(copy.index){
+ colors = new int[size];
+ for (int i = 0; i < size; i++){
+ colors[i] = copy.colors[i];
+ }
+}
void Gradient::forward(){
index = (index + 1) % size;
}
void Gradient::backward(){
index = (index - 1 + size) % size;
}
void Gradient::update(){
forward();
}
void Gradient::reset(){
index = 0;
}
int Gradient::current() const {
return colors[index];
}
int Gradient::current(int offset) const {
return colors[(index + offset + size) % size];
}
Gradient::~Gradient(){
delete[] colors;
}
}
diff --git a/util/gradient.h b/util/gradient.h
index cb0b19b2..f4e91b09 100644
--- a/util/gradient.h
+++ b/util/gradient.h
@@ -1,32 +1,33 @@
#ifndef _paintown_gradient_h
#define _paintown_gradient_h
namespace Effects{
class Gradient{
public:
Gradient(int size, int startColor, int endColor);
+ Gradient(const Gradient & copy);
/* move to next color. update is an alias for `forward' */
void update();
void forward();
void backward();
/* start at startColor */
void reset();
/* get current color */
int current() const;
int current(int offset) const;
virtual ~Gradient();
protected:
int * colors;
unsigned int size;
unsigned int index;
};
}
#endif
diff --git a/util/gui/context-box.cpp b/util/gui/context-box.cpp
index 54f3365b..3202c213 100644
--- a/util/gui/context-box.cpp
+++ b/util/gui/context-box.cpp
@@ -1,444 +1,449 @@
#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(GradientMax, selectedGradientStart(), selectedGradientEnd()),
+selectedGradient(standardGradient()),
useGradient(true),
renderOnlyText(false){
}
ContextBox::ContextBox( const ContextBox & copy ):
fadeState(NotActive),
-selectedGradient(GradientMax, selectedGradientStart(), selectedGradientEnd()),
+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::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 ba23f98f..406a2520 100644
--- a/util/gui/context-box.h
+++ b/util/gui/context-box.h
@@ -1,163 +1,165 @@
#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 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 4f5974d5..ae89040d 100644
--- a/util/gui/scroll-list.cpp
+++ b/util/gui/scroll-list.cpp
@@ -1,199 +1,199 @@
#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;
-const int SCROLL_WAIT = 4;
/*
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 {
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 = SCROLL_WAIT;
+ 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 = SCROLL_WAIT;
+ 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/scroll-list.h b/util/gui/scroll-list.h
index e5a3ae1e..0a5ff844 100644
--- a/util/gui/scroll-list.h
+++ b/util/gui/scroll-list.h
@@ -1,186 +1,195 @@
#ifndef _gui_scroll_list_h
#define _gui_scroll_list_h
#include <string>
#include <vector>
#include "coordinate.h"
#include "../pointer.h"
class Font;
namespace Gui{
/* pure virtual class */
class ScrollItem{
public:
ScrollItem();
/* distance is how far from the selected item we are. 0 means we are the selected item.
* distance can be positive or negative.
*/
virtual void draw(int x, int y, const Graphics::Bitmap & where, const Font & font, int distance) const = 0;
/* size in pixels, used for justification */
virtual int size(const Font & font) const = 0;
virtual ~ScrollItem();
};
class ScrollList {
public:
ScrollList();
ScrollList(const ScrollList &);
virtual ~ScrollList();
enum Justify{
LeftJustify,
RightJustify,
CenterJustify
};
//! copy
ScrollList & operator=(const ScrollList &);
//! Logic
virtual void act();
//! Render
virtual void render(const Graphics::Bitmap &, const Font & font) const;
//! Add item
virtual void addItem(const Util::ReferenceCount<ScrollItem> & item);
//! Add vector of text
virtual void addItems(const std::vector<Util::ReferenceCount<ScrollItem> > & items);
//! Set Position
virtual void setPosition(const Gui::Coordinate &);
//! Set font spacing
inline virtual void setFontSpacing(int x, int y){
this->fontSpacingX = x;
this->fontSpacingY = y;
}
//! Set font spacing X
inline virtual void setFontSpacingX(int x){
this->fontSpacingX = x;
}
//! Set font spacing X
inline virtual void setFontSpacingY(int y){
this->fontSpacingY = y;
}
//! Next
virtual bool next();
//! Previous
virtual bool previous();
//! Set current index
virtual bool setCurrentIndex(unsigned int index);
//! Get current index
virtual inline unsigned int getCurrentIndex() const {
return this->currentIndex;
}
/*
//! Set gradient
virtual inline void setGradient(bool use){
this->useGradient = use;
}
//! Get gradient
virtual inline bool gradientActive() const {
return this->useGradient;
}
*/
virtual inline double getScrollMotion() const {
return scrollMotion;
}
virtual inline void setScrollMotion(double what){
if (what < 1.01){
what = 1.01;
}
scrollMotion = what;
}
+
+ virtual inline void setScrollWaitTime(int what){
+ scrollWaitTime = what;
+ }
+
+ virtual inline int getScrollWaitTime() const {
+ return scrollWaitTime;
+ }
//! Set highlight
virtual inline void setHighlight(bool use){
this->useHighlight = use;
}
//! Get highlight
virtual inline bool highlightActive() const {
return this->useHighlight;
}
//! Set wrap
virtual inline void setWrap(bool wrap){
this->allowWrap = wrap;
}
//! Get wrap
virtual inline bool getWrap() const {
return this->allowWrap;
}
virtual inline void setJustification(Justify what){
this->justification = what;
}
private:
int justify(int left, int right, int size) const;
/* smooth drawing */
void 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;
//! Text
std::vector<Util::ReferenceCount<ScrollItem> > text;
//! Current index
unsigned int currentIndex;
//! Coordinates (size of)
Gui::Coordinate position;
//! Font Spacing
int fontSpacingX, fontSpacingY;
//! Current position for smooth scrolling
int currentPosition;
//! Scroll wait
int scrollWait;
+ int scrollWaitTime;
/* speed at which the menu scrolls */
double scrollMotion;
//! Gradient for selected cursor
// Effects::Gradient selectedGradient;
//! Use gradient
// bool useGradient;
//! Use highlight
bool useHighlight;
//! Is wrappable
bool allowWrap;
/* how much to scroll by */
double scroll;
Justify justification;
};
}
#endif

File Metadata

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

Event Timeline