1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-26 05:55:00 +02:00

Introduced enums for text alignment in the ASFont class.

This commit is contained in:
Maarten ter Huurne 2011-05-09 05:17:25 +02:00
parent c54dec90f5
commit a35a7e2c35
21 changed files with 81 additions and 71 deletions

View File

@ -32,33 +32,39 @@ void ASFont::write(SDL_Surface* surface, const char* text, int x, int y) {
font.write(surface, text, x, y); font.write(surface, text, x, y);
} }
void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, const unsigned short halign, const unsigned short valign) { void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) {
switch (halign) { switch (halign) {
case SFontHAlignCenter: case HAlignLeft:
break;
case HAlignCenter:
x -= getTextWidth(text)/2; x -= getTextWidth(text)/2;
break; break;
case SFontHAlignRight: case HAlignRight:
x -= getTextWidth(text); x -= getTextWidth(text);
break; break;
} }
switch (valign) { switch (valign) {
case SFontVAlignMiddle: case VAlignTop:
break;
case VAlignMiddle:
y -= getHalfHeight(); y -= getHalfHeight();
break; break;
case SFontVAlignBottom: case VAlignBottom:
y -= getHeight(); y -= getHeight();
break; break;
} }
font.write(surface, text, x, y); font.write(surface, text, x, y);
} }
void ASFont::write(SDL_Surface* surface, std::vector<std::string> *text, int x, int y, const unsigned short halign, const unsigned short valign) { void ASFont::write(SDL_Surface* surface, std::vector<std::string> *text, int x, int y, HAlign halign, VAlign valign) {
switch (valign) { switch (valign) {
case SFontVAlignMiddle: case VAlignTop:
break;
case VAlignMiddle:
y -= getHalfHeight()*text->size(); y -= getHalfHeight()*text->size();
break; break;
case SFontVAlignBottom: case VAlignBottom:
y -= getHeight()*text->size(); y -= getHeight()*text->size();
break; break;
} }
@ -66,10 +72,12 @@ void ASFont::write(SDL_Surface* surface, std::vector<std::string> *text, int x,
for (unsigned i=0; i<text->size(); i++) { for (unsigned i=0; i<text->size(); i++) {
int ix = x; int ix = x;
switch (halign) { switch (halign) {
case SFontHAlignCenter: case HAlignLeft:
break;
case HAlignCenter:
ix -= getTextWidth(text->at(i))/2; ix -= getTextWidth(text->at(i))/2;
break; break;
case SFontHAlignRight: case HAlignRight:
ix -= getTextWidth(text->at(i)); ix -= getTextWidth(text->at(i));
break; break;
} }
@ -78,7 +86,7 @@ void ASFont::write(SDL_Surface* surface, std::vector<std::string> *text, int x,
} }
} }
void ASFont::write(Surface* surface, const std::string& text, int x, int y, const unsigned short halign, const unsigned short valign) { void ASFont::write(Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) {
if (text.find("\n", 0) != std::string::npos) { if (text.find("\n", 0) != std::string::npos) {
std::vector<std::string> textArr; std::vector<std::string> textArr;
split(textArr,text,"\n"); split(textArr,text,"\n");

View File

@ -11,15 +11,12 @@
struct SDL_Surface; struct SDL_Surface;
class Surface; class Surface;
const unsigned short SFontHAlignLeft = 0;
const unsigned short SFontHAlignRight = 1;
const unsigned short SFontHAlignCenter = 2;
const unsigned short SFontVAlignTop = 0;
const unsigned short SFontVAlignBottom = 1;
const unsigned short SFontVAlignMiddle = 2;
class ASFont { class ASFont {
public: public:
enum HAlign { HAlignLeft, HAlignRight, HAlignCenter };
enum VAlign { VAlignTop, VAlignBottom, VAlignMiddle };
ASFont(SDL_Surface* font); ASFont(SDL_Surface* font);
ASFont(Surface* font); ASFont(Surface* font);
ASFont(const std::string &font); ASFont(const std::string &font);
@ -35,9 +32,9 @@ public:
int getTextWidth(const std::string& text); int getTextWidth(const std::string& text);
int getTextWidth(std::vector<std::string> *text); int getTextWidth(std::vector<std::string> *text);
void write(SDL_Surface* surface, const char* text, int x, int y); void write(SDL_Surface* surface, const char* text, int x, int y);
void write(SDL_Surface* surface, const std::string& text, int x, int y, const unsigned short halign = 0, const unsigned short valign = 0); void write(SDL_Surface* surface, const std::string& text, int x, int y, HAlign halign = HAlignLeft, VAlign valign = VAlignTop);
void write(SDL_Surface* surface, std::vector<std::string> *text, int x, int y, const unsigned short halign = 0, const unsigned short valign = 0); void write(SDL_Surface* surface, std::vector<std::string> *text, int x, int y, HAlign halign = HAlignLeft, VAlign valign = VAlignTop);
void write(Surface* surface, const std::string& text, int x, int y, const unsigned short halign = 0, const unsigned short valign = 0); void write(Surface* surface, const std::string& text, int x, int y, HAlign halign = HAlignLeft, VAlign valign = VAlignTop);
private: private:
SFontPlus font; SFontPlus font;

View File

@ -260,7 +260,7 @@ void BrowseDialog::paint()
icon = iconFile; icon = iconFile;
} }
icon->blit(gmenu2x->s, 5, offsetY); icon->blit(gmenu2x->s, 5, offsetY);
gmenu2x->s->write(gmenu2x->font, (*fl)[i], 24, offsetY + 8, SFontHAlignLeft, SFontVAlignMiddle); gmenu2x->s->write(gmenu2x->font, (*fl)[i], 24, offsetY + 8, ASFont::HAlignLeft, ASFont::VAlignMiddle);
if (gmenu2x->f200 && gmenu2x->ts.pressed() && gmenu2x->ts.inRect(touchRect.x, offsetY + 3, touchRect.w, rowHeight)) { if (gmenu2x->f200 && gmenu2x->ts.pressed() && gmenu2x->ts.inRect(touchRect.x, offsetY + 3, touchRect.w, rowHeight)) {
ts_pressed = true; ts_pressed = true;

View File

@ -31,14 +31,14 @@ void Dialog::writeTitle(const std::string &title, Surface *s)
{ {
if (s==NULL) if (s==NULL)
s = gmenu2x->s; s = gmenu2x->s;
s->write(gmenu2x->font, title, 40, gmenu2x->skinConfInt["topBarHeight"]/4, SFontHAlignLeft, SFontVAlignMiddle); s->write(gmenu2x->font, title, 40, gmenu2x->skinConfInt["topBarHeight"]/4, ASFont::HAlignLeft, ASFont::VAlignMiddle);
} }
void Dialog::writeSubTitle(const std::string &subtitle, Surface *s) void Dialog::writeSubTitle(const std::string &subtitle, Surface *s)
{ {
if (s==NULL) if (s==NULL)
s = gmenu2x->s; s = gmenu2x->s;
s->write(gmenu2x->font, subtitle, 40, gmenu2x->skinConfInt["topBarHeight"]/4*3, SFontHAlignLeft, SFontVAlignMiddle); s->write(gmenu2x->font, subtitle, 40, gmenu2x->skinConfInt["topBarHeight"]/4*3, ASFont::HAlignLeft, ASFont::VAlignMiddle);
} }

View File

@ -374,7 +374,7 @@ void GMenu2X::initBG() {
string df = getDiskFree(); string df = getDiskFree();
sd.blit( sc["bgmain"], 3, bottomBarIconY ); sd.blit( sc["bgmain"], 3, bottomBarIconY );
sc["bgmain"]->write( font, df, 22, bottomBarTextY, SFontHAlignLeft, SFontVAlignMiddle ); sc["bgmain"]->write( font, df, 22, bottomBarTextY, ASFont::HAlignLeft, ASFont::VAlignMiddle );
volumeX = 27+font->getTextWidth(df); volumeX = 27+font->getTextWidth(df);
volume.blit( sc["bgmain"], volumeX, bottomBarIconY ); volume.blit( sc["bgmain"], volumeX, bottomBarIconY );
volumeX += 19; volumeX += 19;
@ -845,7 +845,7 @@ void GMenu2X::main() {
sc[sectionIcon]->blit(s,x-16,sectionLinkPadding,32,32); sc[sectionIcon]->blit(s,x-16,sectionLinkPadding,32,32);
else else
sc.skinRes("icons/section.png")->blit(s,x-16,sectionLinkPadding); sc.skinRes("icons/section.png")->blit(s,x-16,sectionLinkPadding);
s->write( font, menu->getSections()[i], x, skinConfInt["topBarHeight"]-sectionLinkPadding, SFontHAlignCenter, SFontVAlignBottom ); s->write( font, menu->getSections()[i], x, skinConfInt["topBarHeight"]-sectionLinkPadding, ASFont::HAlignCenter, ASFont::VAlignBottom );
} }
//Links //Links
@ -874,10 +874,10 @@ void GMenu2X::main() {
*/ */
if (menu->selLink()!=NULL) { if (menu->selLink()!=NULL) {
s->write ( font, menu->selLink()->getDescription(), halfX, resY-19, SFontHAlignCenter, SFontVAlignBottom ); s->write ( font, menu->selLink()->getDescription(), halfX, resY-19, ASFont::HAlignCenter, ASFont::VAlignBottom );
if (menu->selLinkApp()!=NULL) { if (menu->selLinkApp()!=NULL) {
s->write ( font, menu->selLinkApp()->clockStr(confInt["maxClock"]), cpuX, bottomBarTextY, SFontHAlignLeft, SFontVAlignMiddle ); s->write ( font, menu->selLinkApp()->clockStr(confInt["maxClock"]), cpuX, bottomBarTextY, ASFont::HAlignLeft, ASFont::VAlignMiddle );
s->write ( font, menu->selLinkApp()->volumeStr(), volumeX, bottomBarTextY, SFontHAlignLeft, SFontVAlignMiddle ); s->write ( font, menu->selLinkApp()->volumeStr(), volumeX, bottomBarTextY, ASFont::HAlignLeft, ASFont::VAlignMiddle );
//Manual indicator //Manual indicator
if (!menu->selLinkApp()->getManual().empty()) if (!menu->selLinkApp()->getManual().empty())
sc.skinRes("imgs/manual.png")->blit(s,manualX,bottomBarIconY); sc.skinRes("imgs/manual.png")->blit(s,manualX,bottomBarIconY);
@ -931,7 +931,7 @@ void GMenu2X::main() {
tickFPS = tickNow; tickFPS = tickNow;
drawn_frames = 0; drawn_frames = 0;
} }
s->write( font, fps+" FPS", resX-1,1 ,SFontHAlignRight ); s->write( font, fps+" FPS", resX-1,1 ,ASFont::HAlignRight );
#endif #endif
s->flip(); s->flip();
@ -1371,7 +1371,7 @@ void GMenu2X::contextMenu() {
//draw selection rect //draw selection rect
s->box( selbox.x, selbox.y, selbox.w, selbox.h, skinConfColors[COLOR_MESSAGE_BOX_SELECTION] ); s->box( selbox.x, selbox.y, selbox.w, selbox.h, skinConfColors[COLOR_MESSAGE_BOX_SELECTION] );
for (i=0; i<voices.size(); i++) for (i=0; i<voices.size(); i++)
s->write( font, voices[i].text, box.x+12, box.y+h2+5+(h+2)*i, SFontHAlignLeft, SFontVAlignMiddle ); s->write( font, voices[i].text, box.x+12, box.y+h2+5+(h+2)*i, ASFont::HAlignLeft, ASFont::VAlignMiddle );
s->flip(); s->flip();
//touchscreen //touchscreen
@ -1647,7 +1647,7 @@ void GMenu2X::scanner() {
Surface scanbg(bg); Surface scanbg(bg);
drawButton(&scanbg, "x", tr["Exit"], drawButton(&scanbg, "x", tr["Exit"],
drawButton(&scanbg, "b", "", 5)-10); drawButton(&scanbg, "b", "", 5)-10);
scanbg.write(font,tr["Link Scanner"],halfX,7,SFontHAlignCenter,SFontVAlignMiddle); scanbg.write(font,tr["Link Scanner"],halfX,7,ASFont::HAlignCenter,ASFont::VAlignMiddle);
uint lineY = 42; uint lineY = 42;
@ -1993,7 +1993,7 @@ int GMenu2X::drawButton(Surface *s, const string &btn, const string &text, int x
if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) { if (sc.skinRes("imgs/buttons/"+btn+".png") != NULL) {
sc["imgs/buttons/"+btn+".png"]->blit(s, x, y-7); sc["imgs/buttons/"+btn+".png"]->blit(s, x, y-7);
re.w = sc["imgs/buttons/"+btn+".png"]->raw->w+3; re.w = sc["imgs/buttons/"+btn+".png"]->raw->w+3;
s->write(font, text, x+re.w, y, SFontHAlignLeft, SFontVAlignMiddle); s->write(font, text, x+re.w, y, ASFont::HAlignLeft, ASFont::VAlignMiddle);
re.w += font->getTextWidth(text); re.w += font->getTextWidth(text);
} }
return x+re.w+6; return x+re.w+6;
@ -2005,7 +2005,7 @@ int GMenu2X::drawButtonRight(Surface *s, const string &btn, const string &text,
x -= 16; x -= 16;
sc["imgs/buttons/"+btn+".png"]->blit(s, x, y-7); sc["imgs/buttons/"+btn+".png"]->blit(s, x, y-7);
x -= 3; x -= 3;
s->write(font, text, x, y, SFontHAlignRight, SFontVAlignMiddle); s->write(font, text, x, y, ASFont::HAlignRight, ASFont::VAlignMiddle);
return x-6-font->getTextWidth(text); return x-6-font->getTextWidth(text);
} }
return x-6; return x-6;

View File

@ -71,13 +71,13 @@ void IconButton::recalcSize() {
if (labelPosition == IconButton::DISP_LEFT || labelPosition == IconButton::DISP_RIGHT) { if (labelPosition == IconButton::DISP_LEFT || labelPosition == IconButton::DISP_RIGHT) {
w += margin + labelRect.w; w += margin + labelRect.w;
//if (labelRect.h > h) h = labelRect.h; //if (labelRect.h > h) h = labelRect.h;
labelHAlign = SFontHAlignLeft; labelHAlign = ASFont::HAlignLeft;
labelVAlign = SFontVAlignMiddle; labelVAlign = ASFont::VAlignMiddle;
} else { } else {
h += margin + labelRect.h; h += margin + labelRect.h;
//if (labelRect.w > w) w = labelRect.w; //if (labelRect.w > w) w = labelRect.w;
labelHAlign = SFontHAlignCenter; labelHAlign = ASFont::HAlignCenter;
labelVAlign = SFontVAlignTop; labelVAlign = ASFont::VAlignTop;
} }
switch (labelPosition) { switch (labelPosition) {

View File

@ -1,8 +1,10 @@
#ifndef ICONBUTTON_H #ifndef ICONBUTTON_H
#define ICONBUTTON_H #define ICONBUTTON_H
#include <string>
#include "button.h" #include "button.h"
#include "asfont.h"
#include <string>
using std::string; using std::string;
@ -14,7 +16,8 @@ protected:
GMenu2X *gmenu2x; GMenu2X *gmenu2x;
string icon, label; string icon, label;
int labelPosition, labelMargin; int labelPosition, labelMargin;
unsigned short labelHAlign, labelVAlign; ASFont::HAlign labelHAlign;
ASFont::VAlign labelVAlign;
void recalcSize(); void recalcSize();
SDL_Rect iconRect, labelRect; SDL_Rect iconRect, labelRect;

View File

@ -150,7 +150,7 @@ bool InputDialog::exec() {
gmenu2x->skinConfColors[COLOR_SELECTION_BG]); gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
gmenu2x->s->rectangle(box.x, box.y, box.w, box.h, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); gmenu2x->s->rectangle(box.x, box.y, box.w, box.h, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
gmenu2x->s->write(gmenu2x->font, input, box.x+5, box.y+box.h-2, SFontHAlignLeft, SFontVAlignBottom); gmenu2x->s->write(gmenu2x->font, input, box.x+5, box.y+box.h-2, ASFont::HAlignLeft, ASFont::VAlignBottom);
curTick = SDL_GetTicks(); curTick = SDL_GetTicks();
if (curTick-caretTick>=600) { if (curTick-caretTick>=600) {
@ -317,7 +317,7 @@ int InputDialog::drawVirtualKeyboard() {
} }
gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
gmenu2x->s->write(gmenu2x->font, charX, kbLeft+xc*KEY_WIDTH+KEY_WIDTH/2-1, KB_TOP+l*KEY_HEIGHT+KEY_HEIGHT/2, SFontHAlignCenter, SFontVAlignMiddle); gmenu2x->s->write(gmenu2x->font, charX, kbLeft+xc*KEY_WIDTH+KEY_WIDTH/2-1, KB_TOP+l*KEY_HEIGHT+KEY_HEIGHT/2, ASFont::HAlignCenter, ASFont::VAlignMiddle);
xc++; xc++;
} }
} }
@ -329,7 +329,7 @@ int InputDialog::drawVirtualKeyboard() {
selCol = 0; selCol = 0;
selRow = kb->size(); selRow = kb->size();
} }
gmenu2x->s->write(gmenu2x->font, gmenu2x->tr["Cancel"], (int)(160-kbLength*KEY_WIDTH/4), KB_TOP+kb->size()*KEY_HEIGHT+KEY_HEIGHT/2, SFontHAlignCenter, SFontVAlignMiddle); gmenu2x->s->write(gmenu2x->font, gmenu2x->tr["Cancel"], (int)(160-kbLength*KEY_WIDTH/4), KB_TOP+kb->size()*KEY_HEIGHT+KEY_HEIGHT/2, ASFont::HAlignCenter, ASFont::VAlignMiddle);
re.x = kbLeft+kbLength*KEY_WIDTH/2-1; re.x = kbLeft+kbLength*KEY_WIDTH/2-1;
gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
@ -337,7 +337,7 @@ int InputDialog::drawVirtualKeyboard() {
selCol = 1; selCol = 1;
selRow = kb->size(); selRow = kb->size();
} }
gmenu2x->s->write(gmenu2x->font, gmenu2x->tr["OK"], (int)(160+kbLength*KEY_WIDTH/4), KB_TOP+kb->size()*KEY_HEIGHT+KEY_HEIGHT/2, SFontHAlignCenter, SFontVAlignMiddle); gmenu2x->s->write(gmenu2x->font, gmenu2x->tr["OK"], (int)(160+kbLength*KEY_WIDTH/4), KB_TOP+kb->size()*KEY_HEIGHT+KEY_HEIGHT/2, ASFont::HAlignCenter, ASFont::VAlignMiddle);
//if ts released //if ts released
if (gmenu2x->f200 && ts.released() && ts.inRect(kbRect)) { if (gmenu2x->f200 && ts.released() && ts.inRect(kbRect)) {

View File

@ -43,12 +43,12 @@ void Link::run() {}
void Link::paint() { void Link::paint() {
iconSurface->blit(gmenu2x->s, iconX, rect.y+padding, 32,32); iconSurface->blit(gmenu2x->s, iconX, rect.y+padding, 32,32);
gmenu2x->s->write( gmenu2x->font, getTitle(), iconX+16, rect.y+gmenu2x->skinConfInt["linkHeight"]-padding, SFontHAlignCenter, SFontVAlignBottom ); gmenu2x->s->write( gmenu2x->font, getTitle(), iconX+16, rect.y+gmenu2x->skinConfInt["linkHeight"]-padding, ASFont::HAlignCenter, ASFont::VAlignBottom );
} }
bool Link::paintHover() { bool Link::paintHover() {
if (gmenu2x->useSelectionPng) if (gmenu2x->useSelectionPng)
gmenu2x->sc["imgs/selection.png"]->blit(gmenu2x->s,rect,SFontHAlignCenter,SFontVAlignMiddle); gmenu2x->sc["imgs/selection.png"]->blit(gmenu2x->s,rect,ASFont::HAlignCenter,ASFont::VAlignMiddle);
else else
gmenu2x->s->box(rect.x, rect.y, rect.w, rect.h, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); gmenu2x->s->box(rect.x, rect.y, rect.w, rect.h, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
return true; return true;

View File

@ -280,7 +280,7 @@ void LinkApp::drawRun() {
else else
gmenu2x->sc["icons/generic.png"]->blit(gmenu2x->s,x,104);*/ gmenu2x->sc["icons/generic.png"]->blit(gmenu2x->s,x,104);*/
gmenu2x->sc[getIconPath()]->blit(gmenu2x->s,x,gmenu2x->halfY-16); gmenu2x->sc[getIconPath()]->blit(gmenu2x->s,x,gmenu2x->halfY-16);
gmenu2x->s->write( gmenu2x->font, text, x+42, gmenu2x->halfY+1, SFontHAlignLeft, SFontVAlignMiddle ); gmenu2x->s->write( gmenu2x->font, text, x+42, gmenu2x->halfY+1, ASFont::HAlignLeft, ASFont::VAlignMiddle );
gmenu2x->s->flip(); gmenu2x->s->flip();
} }
@ -329,7 +329,7 @@ void LinkApp::showManual() {
ss << page+1; ss << page+1;
ss >> pageStatus; ss >> pageStatus;
pageStatus = gmenu2x->tr["Page"]+": "+pageStatus+"/"+spagecount; pageStatus = gmenu2x->tr["Page"]+": "+pageStatus+"/"+spagecount;
gmenu2x->s->write(gmenu2x->font, pageStatus, 310, 230, SFontHAlignRight, SFontVAlignMiddle); gmenu2x->s->write(gmenu2x->font, pageStatus, 310, 230, ASFont::HAlignRight, ASFont::VAlignMiddle);
gmenu2x->s->flip(); gmenu2x->s->flip();
repaint = false; repaint = false;

View File

@ -36,7 +36,7 @@ MenuSetting::~MenuSetting()
void MenuSetting::draw(int y) void MenuSetting::draw(int y)
{ {
gmenu2x->s->write( gmenu2x->font, name, 5, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle ); gmenu2x->s->write( gmenu2x->font, name, 5, y+gmenu2x->font->getHalfHeight(), ASFont::HAlignLeft, ASFont::VAlignMiddle );
} }
void MenuSetting::handleTS() void MenuSetting::handleTS()

View File

@ -61,7 +61,7 @@ void MenuSettingBool::initButton()
void MenuSettingBool::draw(int y) void MenuSettingBool::draw(int y)
{ {
MenuSetting::draw(y); MenuSetting::draw(y);
gmenu2x->s->write( gmenu2x->font, strvalue, 155, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle ); gmenu2x->s->write( gmenu2x->font, strvalue, 155, y+gmenu2x->font->getHalfHeight(), ASFont::HAlignLeft, ASFont::VAlignMiddle );
} }
void MenuSettingBool::manageInput(bevent_t *event) void MenuSettingBool::manageInput(bevent_t *event)

View File

@ -62,7 +62,7 @@ MenuSettingInt::MenuSettingInt(GMenu2X *gmenu2x, const string &name, const strin
void MenuSettingInt::draw(int y) void MenuSettingInt::draw(int y)
{ {
MenuSetting::draw(y); MenuSetting::draw(y);
gmenu2x->s->write( gmenu2x->font, strvalue, 155, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle ); gmenu2x->s->write( gmenu2x->font, strvalue, 155, y+gmenu2x->font->getHalfHeight(), ASFont::HAlignLeft, ASFont::VAlignMiddle );
} }
void MenuSettingInt::manageInput(bevent_t *event) void MenuSettingInt::manageInput(bevent_t *event)

View File

@ -63,10 +63,10 @@ void MenuSettingRGBA::draw(int y) {
MenuSetting::draw(y); MenuSetting::draw(y);
gmenu2x->s->rectangle( 153, y+1, 11, 11, 0,0,0,255 ); gmenu2x->s->rectangle( 153, y+1, 11, 11, 0,0,0,255 );
gmenu2x->s->box( 154, y+2, 9, 9, value() ); gmenu2x->s->box( 154, y+2, 9, 9, value() );
gmenu2x->s->write( gmenu2x->font, "R: "+strR, 169, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle ); gmenu2x->s->write( gmenu2x->font, "R: "+strR, 169, y+gmenu2x->font->getHalfHeight(), ASFont::HAlignLeft, ASFont::VAlignMiddle );
gmenu2x->s->write( gmenu2x->font, "G: "+strG, 205, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle ); gmenu2x->s->write( gmenu2x->font, "G: "+strG, 205, y+gmenu2x->font->getHalfHeight(), ASFont::HAlignLeft, ASFont::VAlignMiddle );
gmenu2x->s->write( gmenu2x->font, "B: "+strB, 241, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle ); gmenu2x->s->write( gmenu2x->font, "B: "+strB, 241, y+gmenu2x->font->getHalfHeight(), ASFont::HAlignLeft, ASFont::VAlignMiddle );
gmenu2x->s->write( gmenu2x->font, "A: "+strA, 277, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle ); gmenu2x->s->write( gmenu2x->font, "A: "+strA, 277, y+gmenu2x->font->getHalfHeight(), ASFont::HAlignLeft, ASFont::VAlignMiddle );
} }
void MenuSettingRGBA::handleTS() { void MenuSettingRGBA::handleTS() {

View File

@ -41,7 +41,7 @@ void MenuSettingStringBase::draw(int y)
gmenu2x->s->write( gmenu2x->s->write(
gmenu2x->font, value(), gmenu2x->font, value(),
155, y + gmenu2x->font->getHalfHeight(), 155, y + gmenu2x->font->getHalfHeight(),
SFontHAlignLeft, SFontVAlignMiddle); ASFont::HAlignLeft, ASFont::VAlignMiddle);
} }
void MenuSettingStringBase::manageInput(bevent_t *event) void MenuSettingStringBase::manageInput(bevent_t *event)

View File

@ -84,7 +84,7 @@ int MessageBox::exec() {
//icon+text //icon+text
if (gmenu2x->sc[icon] != NULL) if (gmenu2x->sc[icon] != NULL)
gmenu2x->sc[icon]->blitCenter( &bg, box.x+25, box.y+gmenu2x->font->getHeight()+3 ); gmenu2x->sc[icon]->blitCenter( &bg, box.x+25, box.y+gmenu2x->font->getHeight()+3 );
bg.write( gmenu2x->font, text, box.x+(gmenu2x->sc[icon] != NULL ? 47 : 10), box.y+gmenu2x->font->getHeight()+3, SFontHAlignLeft, SFontVAlignMiddle ); bg.write( gmenu2x->font, text, box.x+(gmenu2x->sc[icon] != NULL ? 47 : 10), box.y+gmenu2x->font->getHeight()+3, ASFont::HAlignLeft, ASFont::VAlignMiddle );
int btnX = gmenu2x->halfX+box.w/2-6; int btnX = gmenu2x->halfX+box.w/2-6;
for (uint i=0; i<buttons.size(); i++) { for (uint i=0; i<buttons.size(); i++) {

View File

@ -106,9 +106,9 @@ int Selector::exec(int startSelection) {
iY = i-firstElement; iY = i-firstElement;
if (fl.isDirectory(i)) { if (fl.isDirectory(i)) {
gmenu2x->sc["imgs/folder.png"]->blit(gmenu2x->s, 4, 42+(iY*16)); gmenu2x->sc["imgs/folder.png"]->blit(gmenu2x->s, 4, 42+(iY*16));
gmenu2x->s->write(gmenu2x->font, fl[i], 21, 49+(iY*16), SFontHAlignLeft, SFontVAlignMiddle); gmenu2x->s->write(gmenu2x->font, fl[i], 21, 49+(iY*16), ASFont::HAlignLeft, ASFont::VAlignMiddle);
} else } else
gmenu2x->s->write(gmenu2x->font, titles[i-fl.dirCount()], 4, 49+(iY*16), SFontHAlignLeft, SFontVAlignMiddle); gmenu2x->s->write(gmenu2x->font, titles[i-fl.dirCount()], 4, 49+(iY*16), ASFont::HAlignLeft, ASFont::VAlignMiddle);
} }
gmenu2x->s->clearClipRect(); gmenu2x->s->clearClipRect();

View File

@ -267,10 +267,6 @@ void Surface::blendAdd(Surface *target, int x, int y) {
*/ */
} }
void Surface::write(ASFont *font, const string &text, int x, int y, const unsigned short halign, const unsigned short valign) {
font->write(this,text,x,y,halign,valign);
}
void Surface::operator = (SDL_Surface *s) { void Surface::operator = (SDL_Surface *s) {
raw = SDL_DisplayFormat(s); raw = SDL_DisplayFormat(s);
halfW = raw->w/2; halfW = raw->w/2;
@ -340,21 +336,25 @@ void Surface::setClipRect(SDL_Rect rect) {
SDL_SetClipRect(raw,&rect); SDL_SetClipRect(raw,&rect);
} }
bool Surface::blit(Surface *destination, SDL_Rect container, const unsigned short halign, const unsigned short valign) { bool Surface::blit(Surface *destination, SDL_Rect container, ASFont::HAlign halign, ASFont::VAlign valign) {
switch (halign) { switch (halign) {
case SFontHAlignCenter: case ASFont::HAlignLeft:
break;
case ASFont::HAlignCenter:
container.x += container.w/2-halfW; container.x += container.w/2-halfW;
break; break;
case SFontHAlignRight: case ASFont::HAlignRight:
container.x += container.w-raw->w; container.x += container.w-raw->w;
break; break;
} }
switch (valign) { switch (valign) {
case SFontVAlignMiddle: case ASFont::VAlignTop:
break;
case ASFont::VAlignMiddle:
container.y += container.h/2-halfH; container.y += container.h/2-halfH;
break; break;
case SFontVAlignBottom: case ASFont::VAlignBottom:
container.y += container.h-raw->h; container.y += container.h-raw->h;
break; break;
} }

View File

@ -75,14 +75,16 @@ public:
void setClipRect(SDL_Rect rect); void setClipRect(SDL_Rect rect);
bool blit(Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blit(Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
bool blit(Surface *destination, SDL_Rect container, const unsigned short halign=0, const unsigned short valign=0); bool blit(Surface *destination, SDL_Rect container, ASFont::HAlign halign = ASFont::HAlignLeft, ASFont::VAlign valign = ASFont::VAlignTop);
bool blit(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blit(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
bool blitCenter(Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blitCenter(Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
bool blitCenter(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blitCenter(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
bool blitRight(Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blitRight(Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
bool blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1); bool blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
void write(ASFont *font, const string &text, int x, int y, const unsigned short halign=0, const unsigned short valign=0); void write(ASFont *font, const string &text, int x, int y, ASFont::HAlign halign = ASFont::HAlignLeft, ASFont::VAlign valign = ASFont::VAlignTop) {
font->write(this, text, x, y, halign, valign);
}
int box(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8); int box(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
int box(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8); int box(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8);

View File

@ -96,7 +96,7 @@ void TextManualDialog::exec() {
ss << page+1; ss << page+1;
ss >> pageStatus; ss >> pageStatus;
pageStatus = gmenu2x->tr["Page"]+": "+pageStatus+"/"+spagecount; pageStatus = gmenu2x->tr["Page"]+": "+pageStatus+"/"+spagecount;
gmenu2x->s->write(gmenu2x->font, pageStatus, 310, 230, SFontHAlignRight, SFontVAlignMiddle); gmenu2x->s->write(gmenu2x->font, pageStatus, 310, 230, ASFont::HAlignRight, ASFont::VAlignMiddle);
gmenu2x->s->flip(); gmenu2x->s->flip();

View File

@ -80,7 +80,7 @@ bool WallpaperDialog::exec()
gmenu2x->s->setClipRect(0,41,311,179); gmenu2x->s->setClipRect(0,41,311,179);
for (i=firstElement; i<wallpapers.size() && i<firstElement+10; i++) { for (i=firstElement; i<wallpapers.size() && i<firstElement+10; i++) {
iY = i-firstElement; iY = i-firstElement;
gmenu2x->s->write(gmenu2x->font, wallpapers[i], 5, 52+(iY*17), SFontHAlignLeft, SFontVAlignMiddle); gmenu2x->s->write(gmenu2x->font, wallpapers[i], 5, 52+(iY*17), ASFont::HAlignLeft, ASFont::VAlignMiddle);
} }
gmenu2x->s->clearClipRect(); gmenu2x->s->clearClipRect();