mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-26 00:02:29 +02:00
Merge branch 'master' of projects.qi-hardware.com:gmenu2x into install_locations
Conflicts: data/platform/nanonote/sections/terminals/ash src/gmenu2x.cpp src/surface.cpp
This commit is contained in:
commit
ef4b012026
@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
source /etc/profile
|
source /etc/profile
|
||||||
|
|
||||||
setfont2 /usr/share/setfont2/un-fuzzy-6x10-font.pnm
|
#setfont2 /usr/share/setfont2/un-fuzzy-6x10-font.pnm
|
||||||
loadunimap /usr/share/setfont2/ben_uni.trans
|
#loadunimap /usr/share/setfont2/ben_uni.trans
|
||||||
clear
|
|
||||||
|
|
||||||
cd /usr/share/gmenu2x
|
setfont /usr/share/kbd/consolefonts/kernel-6x11-font
|
||||||
./gmenu2x
|
|
||||||
|
clear
|
||||||
|
cd /usr/share/gmenu2x && ./gmenu2x
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
title=ash(Default)
|
|
||||||
icon=skin:icons/utilities-terminal.png
|
|
||||||
exec=/bin/ash
|
|
||||||
params=--login
|
|
4
data/platform/nanonote/sections/terminals/ash-color
Normal file
4
data/platform/nanonote/sections/terminals/ash-color
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
title=ash(Color)
|
||||||
|
icon=skin:icons/utilities-terminal.png
|
||||||
|
exec=/usr/bin/setfont
|
||||||
|
params=/usr/share/kbd/consolefonts/kernel-6x11-font; /bin/ash --login
|
4
data/platform/nanonote/sections/terminals/ash-default
Normal file
4
data/platform/nanonote/sections/terminals/ash-default
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
title=ash(Default)
|
||||||
|
icon=skin:icons/utilities-terminal.png
|
||||||
|
exec=/usr/sbin/setfont2
|
||||||
|
params=/usr/share/setfont2/un-fuzzy-6x10-font.pnm; /usr/bin/loadunimap /usr/share/setfont2/ben_uni.trans; /bin/ash --login
|
@ -1 +1 @@
|
|||||||
open.png
|
a.png
|
@ -8,10 +8,11 @@ gmenu2x_SOURCES = asfont.cpp button.cpp cpu.cpp dirdialog.cpp filedialog.cpp \
|
|||||||
menusettingmultistring.cpp menusettingrgba.cpp menusettingstring.cpp \
|
menusettingmultistring.cpp menusettingrgba.cpp menusettingstring.cpp \
|
||||||
menusettingstringbase.cpp \
|
menusettingstringbase.cpp \
|
||||||
messagebox.cpp selector.cpp \
|
messagebox.cpp selector.cpp \
|
||||||
settingsdialog.cpp sfontplus.cpp surfacecollection.cpp surface.cpp \
|
settingsdialog.cpp surfacecollection.cpp surface.cpp \
|
||||||
textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp \
|
textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp \
|
||||||
utilities.cpp wallpaperdialog.cpp \
|
utilities.cpp wallpaperdialog.cpp \
|
||||||
browsedialog.cpp buttonbox.cpp dialog.cpp
|
browsedialog.cpp buttonbox.cpp dialog.cpp \
|
||||||
|
imageio.cpp powersaver.cpp
|
||||||
|
|
||||||
noinst_HEADERS = asfont.h button.h cpu.h dirdialog.h FastDelegate.h \
|
noinst_HEADERS = asfont.h button.h cpu.h dirdialog.h FastDelegate.h \
|
||||||
filedialog.h filelister.h gmenu2x.h gp2x.h iconbutton.h imagedialog.h \
|
filedialog.h filelister.h gmenu2x.h gp2x.h iconbutton.h imagedialog.h \
|
||||||
@ -21,9 +22,10 @@ noinst_HEADERS = asfont.h button.h cpu.h dirdialog.h FastDelegate.h \
|
|||||||
menusettingmultistring.h menusettingrgba.h menusettingstring.h \
|
menusettingmultistring.h menusettingrgba.h menusettingstring.h \
|
||||||
menusettingstringbase.h \
|
menusettingstringbase.h \
|
||||||
messagebox.h selector.h settingsdialog.h \
|
messagebox.h selector.h settingsdialog.h \
|
||||||
sfontplus.h surfacecollection.h surface.h textdialog.h textmanualdialog.h \
|
surfacecollection.h surface.h textdialog.h textmanualdialog.h \
|
||||||
touchscreen.h translator.h utilities.h wallpaperdialog.h \
|
touchscreen.h translator.h utilities.h wallpaperdialog.h \
|
||||||
browsedialog.h buttonbox.h dialog.h
|
browsedialog.h buttonbox.h dialog.h \
|
||||||
|
imageio.h powersaver.h
|
||||||
|
|
||||||
AM_CFLAGS= @CFLAGS@ @SDL_CFLAGS@
|
AM_CFLAGS= @CFLAGS@ @SDL_CFLAGS@
|
||||||
|
|
||||||
|
240
src/asfont.cpp
240
src/asfont.cpp
@ -1,124 +1,196 @@
|
|||||||
#include "asfont.h"
|
#include "asfont.h"
|
||||||
|
#include "imageio.h"
|
||||||
#include "surface.h"
|
#include "surface.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <cassert>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
using namespace std;
|
#define SFONTPLUS_CHARSET "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~¡¿ÀÁÈÉÌÍÒÓÙÚÝÄËÏÖÜŸÂÊÎÔÛÅÃÕÑÆÇČĎĚĽĹŇÔŘŔŠŤŮŽàáèéìíòóùúýäëïöüÿâêîôûåãõñæçčďěľĺňôřŕšťžůðßÐÞþАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюяØøąćęłńśżźĄĆĘŁŃŚŻŹ"
|
||||||
|
|
||||||
ASFont::ASFont(SDL_Surface* font) {
|
ASFont::ASFont(const std::string &fontImagePath)
|
||||||
this->font.initFont(font);
|
: characters(SFONTPLUS_CHARSET)
|
||||||
halfHeight = getHeight()/2;
|
{
|
||||||
halfLineHeight = getLineHeight()/2;
|
surface = loadPNG(fontImagePath);
|
||||||
}
|
if (!surface) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assert(surface->format->BytesPerPixel == 4);
|
||||||
|
|
||||||
ASFont::ASFont(Surface* font) {
|
SDL_LockSurface(surface);
|
||||||
this->font.initFont(font->raw);
|
|
||||||
halfHeight = getHeight()/2;
|
|
||||||
halfLineHeight = getLineHeight()/2;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASFont::ASFont(const string &font) {
|
// Determine character widths.
|
||||||
this->font.initFont(font);
|
Uint32 pink = SDL_MapRGB(surface->format, 255, 0, 255);
|
||||||
halfHeight = getHeight()/2;
|
Uint32 *topLine = static_cast<Uint32 *>(surface->pixels);
|
||||||
halfLineHeight = getLineHeight()/2;
|
const unsigned width = surface->w;
|
||||||
|
unsigned x = 0;
|
||||||
|
unsigned c = 0;
|
||||||
|
while (c < characters.length()) {
|
||||||
|
while (x < width && topLine[x] != pink) x++;
|
||||||
|
unsigned startx = x;
|
||||||
|
x++;
|
||||||
|
while (x < width && topLine[x] == pink) x++;
|
||||||
|
|
||||||
|
charpos.push_back(startx);
|
||||||
|
charpos.push_back(x);
|
||||||
|
if (c > 0 && utf8Code(characters[c - 1])) {
|
||||||
|
// UTF8 character
|
||||||
|
charpos.push_back(startx);
|
||||||
|
charpos.push_back(x);
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan height of "0" glyph.
|
||||||
|
std::string::size_type pos = characters.find("0") * 2;
|
||||||
|
SDL_Rect srcrect = {
|
||||||
|
charpos[pos], 1, charpos[pos + 2] - charpos[pos], surface->h - 1
|
||||||
|
};
|
||||||
|
const unsigned alphaMask = surface->format->Amask;
|
||||||
|
unsigned y = srcrect.h;
|
||||||
|
bool nonTransparentFound = false;
|
||||||
|
while (!nonTransparentFound && y-- > 0) {
|
||||||
|
Uint32 *line = reinterpret_cast<Uint32 *>(
|
||||||
|
reinterpret_cast<Uint8 *>(surface->pixels)
|
||||||
|
+ (srcrect.y + y) * surface->pitch
|
||||||
|
);
|
||||||
|
for (unsigned x = 0; !nonTransparentFound && x < srcrect.w; x++) {
|
||||||
|
nonTransparentFound = (line[srcrect.x + x] & alphaMask) != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lineHeight = y + 1;
|
||||||
|
|
||||||
|
SDL_UnlockSurface(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASFont::~ASFont() {
|
ASFont::~ASFont() {
|
||||||
font.freeFont();
|
if (surface) {
|
||||||
|
SDL_FreeSurface(surface);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ASFont::utf8Code(unsigned char c) {
|
bool ASFont::utf8Code(unsigned char c) {
|
||||||
return font.utf8Code(c);
|
return (c>=194 && c<=198) || c==208 || c==209;
|
||||||
|
//return c>=194;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASFont::write(SDL_Surface* surface, const char* text, int x, int y) {
|
void ASFont::writeLine(Surface *s, const std::string &text, int x, int y) {
|
||||||
font.write(surface, text, x, y);
|
if (text.empty()) return;
|
||||||
|
|
||||||
|
std::string::size_type pos;
|
||||||
|
SDL_Rect srcrect, dstrect;
|
||||||
|
|
||||||
|
// these values won't change in the loop
|
||||||
|
srcrect.y = 1;
|
||||||
|
dstrect.y = y;
|
||||||
|
srcrect.h = dstrect.h = surface->h-1;
|
||||||
|
|
||||||
|
for(unsigned i=0; i<text.length() && x<surface->w; i++) {
|
||||||
|
//Utf8 characters
|
||||||
|
if (utf8Code(text[i]) && i+1<text.length()) {
|
||||||
|
pos = characters.find(text.substr(i,2));
|
||||||
|
i++;
|
||||||
|
} else
|
||||||
|
pos = characters.find(text[i]);
|
||||||
|
if (pos == std::string::npos) {
|
||||||
|
x += charpos[2]-charpos[1];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos *= 2;
|
||||||
|
|
||||||
|
srcrect.x = charpos[pos];
|
||||||
|
srcrect.w = charpos[pos+2] - charpos[pos];
|
||||||
|
dstrect.x = x - charpos[pos+1] + charpos[pos];
|
||||||
|
|
||||||
|
SDL_BlitSurface(surface, &srcrect, s->raw, &dstrect);
|
||||||
|
|
||||||
|
x += charpos[pos+2] - charpos[pos+1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, const unsigned short halign, const unsigned short valign) {
|
int ASFont::getTextWidth(const char *text) {
|
||||||
|
int maxWidth = 0, width = 0;
|
||||||
|
while (char ch = *text++) {
|
||||||
|
if (ch == '\n') {
|
||||||
|
// New line.
|
||||||
|
maxWidth = max(width, maxWidth);
|
||||||
|
width = 0;
|
||||||
|
} else {
|
||||||
|
std::string::size_type pos;
|
||||||
|
if (utf8Code(ch) && *text) {
|
||||||
|
// 2-byte character.
|
||||||
|
pos = characters.find(std::string(&text[-1], 2));
|
||||||
|
text++;
|
||||||
|
} else {
|
||||||
|
// 1-byte character.
|
||||||
|
pos = characters.find(ch);
|
||||||
|
}
|
||||||
|
if (pos == std::string::npos) {
|
||||||
|
pos = 0;
|
||||||
|
}
|
||||||
|
width += charpos[pos * 2 + 2] - charpos[pos * 2 + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max(width, maxWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ASFont::getTextWidth(const std::string& text) {
|
||||||
|
return getTextWidth(text.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ASFont::writeLine(Surface* surface, const std::string& text, int x, int y, HAlign halign) {
|
||||||
switch (halign) {
|
switch (halign) {
|
||||||
case SFontHAlignCenter:
|
case HAlignLeft:
|
||||||
x -= getTextWidth(text)/2;
|
|
||||||
break;
|
break;
|
||||||
case SFontHAlignRight:
|
case HAlignCenter:
|
||||||
|
x -= getTextWidth(text) / 2;
|
||||||
|
break;
|
||||||
|
case HAlignRight:
|
||||||
x -= getTextWidth(text);
|
x -= getTextWidth(text);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
writeLine(surface, text, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ASFont::writeLine(Surface* surface, const std::string& text, int x, int y, HAlign halign, VAlign valign) {
|
||||||
switch (valign) {
|
switch (valign) {
|
||||||
case SFontVAlignMiddle:
|
case VAlignTop:
|
||||||
y -= getHalfHeight();
|
|
||||||
break;
|
break;
|
||||||
case SFontVAlignBottom:
|
case VAlignMiddle:
|
||||||
|
y -= getHeight() / 2;
|
||||||
|
break;
|
||||||
|
case VAlignBottom:
|
||||||
y -= getHeight();
|
y -= getHeight();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
writeLine(surface, text, x, y, halign);
|
||||||
font.write(surface, text, x, y);
|
|
||||||
}
|
}
|
||||||
void ASFont::write(SDL_Surface* surface, vector<string> *text, int x, int y, const unsigned short halign, const unsigned short valign) {
|
|
||||||
|
void ASFont::writeLine(Surface* surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign) {
|
||||||
switch (valign) {
|
switch (valign) {
|
||||||
case SFontVAlignMiddle:
|
case VAlignTop:
|
||||||
y -= getHalfHeight()*text->size();
|
|
||||||
break;
|
break;
|
||||||
case SFontVAlignBottom:
|
case VAlignMiddle:
|
||||||
y -= getHeight()*text->size();
|
y -= (getHeight() / 2) * text.size();
|
||||||
|
break;
|
||||||
|
case VAlignBottom:
|
||||||
|
y -= getHeight() * text.size();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint i=0; i<text->size(); i++) {
|
for (std::vector<std::string>::const_iterator it = text.begin(); it != text.end(); ++it) {
|
||||||
int ix = x;
|
write(surface, *it, x, y, halign);
|
||||||
switch (halign) {
|
y += getHeight();
|
||||||
case SFontHAlignCenter:
|
|
||||||
ix -= getTextWidth(text->at(i))/2;
|
|
||||||
break;
|
|
||||||
case SFontHAlignRight:
|
|
||||||
ix -= getTextWidth(text->at(i));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
font.write(surface, text->at(i), x, y+getHeight()*i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)!=string::npos) {
|
if (text.find("\n", 0) != std::string::npos) {
|
||||||
vector<string> textArr;
|
std::vector<std::string> textArr;
|
||||||
split(textArr,text,"\n");
|
split(textArr, text, "\n");
|
||||||
write(surface->raw, &textArr, x, y, halign, valign);
|
writeLine(surface, textArr, x, y, halign, valign);
|
||||||
} else
|
} else
|
||||||
write(surface->raw, text, x, y, halign, valign);
|
writeLine(surface, text, x, y, halign, valign);
|
||||||
}
|
|
||||||
|
|
||||||
int ASFont::getHeight() {
|
|
||||||
return font.getHeight();
|
|
||||||
}
|
|
||||||
int ASFont::getHalfHeight() {
|
|
||||||
return halfHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ASFont::getLineHeight() {
|
|
||||||
return font.getLineHeight();
|
|
||||||
}
|
|
||||||
int ASFont::getHalfLineHeight() {
|
|
||||||
return halfLineHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ASFont::getTextWidth(const char* text) {
|
|
||||||
return font.getTextWidth(text);
|
|
||||||
}
|
|
||||||
int ASFont::getTextWidth(const std::string& text) {
|
|
||||||
if (text.find("\n",0)!=string::npos) {
|
|
||||||
vector<string> textArr;
|
|
||||||
split(textArr,text,"\n");
|
|
||||||
return getTextWidth(&textArr);
|
|
||||||
} else
|
|
||||||
return getTextWidth(text.c_str());
|
|
||||||
}
|
|
||||||
int ASFont::getTextWidth(vector<string> *text) {
|
|
||||||
int w = 0;
|
|
||||||
for (uint i=0; i<text->size(); i++)
|
|
||||||
w = max( getTextWidth(text->at(i).c_str()), w );
|
|
||||||
return w;
|
|
||||||
}
|
}
|
||||||
|
58
src/asfont.h
58
src/asfont.h
@ -1,49 +1,49 @@
|
|||||||
//Advanced SFont by Massimiliano Torromeo (cpp wrapper around SFont)
|
// Based on SFont by Karl Bartel.
|
||||||
|
// Adapted to C++ by Massimiliano Torromeo.
|
||||||
|
// Refactored by Maarten ter Huurne and several others (see git log).
|
||||||
|
// License: GPL version 2 or later.
|
||||||
|
|
||||||
#ifndef ASFONT_H
|
#ifndef ASFONT_H
|
||||||
#define ASFONT_H
|
#define ASFONT_H
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <SDL.h>
|
|
||||||
#include "sfontplus.h"
|
|
||||||
|
|
||||||
using std::string;
|
|
||||||
using std::vector;
|
|
||||||
|
|
||||||
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 Surface;
|
class Surface;
|
||||||
|
|
||||||
class ASFont {
|
class ASFont {
|
||||||
public:
|
public:
|
||||||
ASFont(SDL_Surface* font);
|
enum HAlign { HAlignLeft, HAlignRight, HAlignCenter };
|
||||||
ASFont(Surface* font);
|
enum VAlign { VAlignTop, VAlignBottom, VAlignMiddle };
|
||||||
ASFont(const string &font);
|
|
||||||
|
ASFont(const std::string &font);
|
||||||
~ASFont();
|
~ASFont();
|
||||||
|
|
||||||
bool utf8Code(unsigned char c);
|
bool utf8Code(unsigned char c);
|
||||||
|
|
||||||
int getHeight();
|
int getTextWidth(const char *text);
|
||||||
int getHalfHeight();
|
int getTextWidth(const std::string& text);
|
||||||
int getLineHeight();
|
|
||||||
int getHalfLineHeight();
|
int getHeight() {
|
||||||
int getTextWidth(const char* text);
|
return surface->h - 1;
|
||||||
int getTextWidth(const string& text);
|
}
|
||||||
int getTextWidth(vector<string> *text);
|
int getLineHeight() {
|
||||||
void write(SDL_Surface* surface, const char* text, int x, int y);
|
return lineHeight;
|
||||||
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, vector<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, 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;
|
void writeLine(Surface *surface, const std::string &text, int x, int y);
|
||||||
int halfHeight, halfLineHeight;
|
void writeLine(Surface *surface, const std::string &text, int x, int y, HAlign halign);
|
||||||
|
void writeLine(Surface *surface, const std::string &text, int x, int y, HAlign halign, VAlign valign);
|
||||||
|
void writeLine(Surface *surface, const std::vector<std::string> &text, int x, int y, HAlign halign, VAlign valign);
|
||||||
|
|
||||||
|
SDL_Surface *surface;
|
||||||
|
std::vector<unsigned> charpos;
|
||||||
|
std::string characters;
|
||||||
|
int lineHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* ASFONT_H */
|
#endif /* ASFONT_H */
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +48,6 @@
|
|||||||
#include "linkaction.h"
|
#include "linkaction.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "asfont.h"
|
#include "asfont.h"
|
||||||
#include "sfontplus.h"
|
|
||||||
#include "surface.h"
|
#include "surface.h"
|
||||||
#include "filedialog.h"
|
#include "filedialog.h"
|
||||||
#include "gmenu2x.h"
|
#include "gmenu2x.h"
|
||||||
@ -215,6 +214,7 @@ void GMenu2X::gp2x_tvout_off() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GMenu2X::GMenu2X() {
|
GMenu2X::GMenu2X() {
|
||||||
//Detect firmware version and type
|
//Detect firmware version and type
|
||||||
if (fileExists("/etc/open2x")) {
|
if (fileExists("/etc/open2x")) {
|
||||||
@ -292,7 +292,7 @@ GMenu2X::GMenu2X() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Screen
|
//Screen
|
||||||
if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK)<0 ) {
|
if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK|SDL_INIT_TIMER)<0 ) {
|
||||||
ERROR("Could not initialize SDL: %s\n", SDL_GetError());
|
ERROR("Could not initialize SDL: %s\n", SDL_GetError());
|
||||||
quit();
|
quit();
|
||||||
}
|
}
|
||||||
@ -334,7 +334,7 @@ GMenu2X::GMenu2X() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
input.init(input_file);
|
input.init(input_file);
|
||||||
|
PowerSaver::getInstance()->setScreenTimeout( confInt["backlightTimeout"] );
|
||||||
setInputSpeed();
|
setInputSpeed();
|
||||||
initServices();
|
initServices();
|
||||||
setBacklight(confInt["backlight"]);
|
setBacklight(confInt["backlight"]);
|
||||||
@ -345,6 +345,7 @@ GMenu2X::GMenu2X() {
|
|||||||
readTmp();
|
readTmp();
|
||||||
if (lastSelectorElement>-1 && menu->selLinkApp()!=NULL && (!menu->selLinkApp()->getSelectorDir().empty() || !lastSelectorDir.empty()))
|
if (lastSelectorElement>-1 && menu->selLinkApp()!=NULL && (!menu->selLinkApp()->getSelectorDir().empty() || !lastSelectorDir.empty()))
|
||||||
menu->selLinkApp()->selector(lastSelectorElement,lastSelectorDir);
|
menu->selLinkApp()->selector(lastSelectorElement,lastSelectorDir);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GMenu2X::~GMenu2X() {
|
GMenu2X::~GMenu2X() {
|
||||||
@ -384,7 +385,8 @@ void GMenu2X::initBG() {
|
|||||||
bg = new Surface(s);
|
bg = new Surface(s);
|
||||||
bg->box(0,0,resX,resY,0,0,0);
|
bg->box(0,0,resX,resY,0,0,0);
|
||||||
} else {
|
} else {
|
||||||
bg = new Surface(confStr["wallpaper"],false);
|
// Note: Copy constructor converts to display format.
|
||||||
|
bg = new Surface(Surface(confStr["wallpaper"]));
|
||||||
}
|
}
|
||||||
|
|
||||||
drawTopBar(bg);
|
drawTopBar(bg);
|
||||||
@ -399,7 +401,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;
|
||||||
@ -587,6 +589,7 @@ void GMenu2X::readConfig() {
|
|||||||
evalIntConf( &confInt["maxClock"], 430, 30, 500 );
|
evalIntConf( &confInt["maxClock"], 430, 30, 500 );
|
||||||
evalIntConf( &confInt["menuClock"], 200, 30, 430 );
|
evalIntConf( &confInt["menuClock"], 200, 30, 430 );
|
||||||
evalIntConf( &confInt["globalVolume"], 67, 0,100 );
|
evalIntConf( &confInt["globalVolume"], 67, 0,100 );
|
||||||
|
evalIntConf( &confInt["backlightTimeout"], 15, 0,120 );
|
||||||
evalIntConf( &confInt["backlight"], 100, 5,100 );
|
evalIntConf( &confInt["backlight"], 100, 5,100 );
|
||||||
evalIntConf( &confInt["videoBpp"], 32,32,32 ); // 8,16
|
evalIntConf( &confInt["videoBpp"], 32,32,32 ); // 8,16
|
||||||
|
|
||||||
@ -850,7 +853,6 @@ void GMenu2X::main() {
|
|||||||
if (!fileExists(CARD_ROOT))
|
if (!fileExists(CARD_ROOT))
|
||||||
CARD_ROOT = "/";
|
CARD_ROOT = "/";
|
||||||
|
|
||||||
|
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
tickNow = SDL_GetTicks();
|
tickNow = SDL_GetTicks();
|
||||||
|
|
||||||
@ -878,7 +880,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
|
||||||
@ -907,10 +909,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);
|
||||||
@ -964,7 +966,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();
|
||||||
@ -1149,6 +1151,7 @@ void GMenu2X::options() {
|
|||||||
sd.addSetting(new MenuSettingBool(this,tr["Output logs"],tr["Logs the output of the links. Use the Log Viewer to read them."],&confInt["outputLogs"]));
|
sd.addSetting(new MenuSettingBool(this,tr["Output logs"],tr["Logs the output of the links. Use the Log Viewer to read them."],&confInt["outputLogs"]));
|
||||||
//G
|
//G
|
||||||
sd.addSetting(new MenuSettingInt(this,tr["Lcd Backlight"],tr["Set dingoo's Lcd Backlight value (default: 100)"],&confInt["backlight"],5,100));
|
sd.addSetting(new MenuSettingInt(this,tr["Lcd Backlight"],tr["Set dingoo's Lcd Backlight value (default: 100)"],&confInt["backlight"],5,100));
|
||||||
|
sd.addSetting(new MenuSettingInt(this,tr["Screen Timeout"],tr["Set screen's backlight timeout in seconds"],&confInt["backlightTimeout"],0,120));
|
||||||
// sd.addSetting(new MenuSettingMultiString(this,tr["Tv-Out encoding"],tr["Encoding of the tv-out signal"],&confStr["tvoutEncoding"],&encodings));
|
// sd.addSetting(new MenuSettingMultiString(this,tr["Tv-Out encoding"],tr["Encoding of the tv-out signal"],&confStr["tvoutEncoding"],&encodings));
|
||||||
sd.addSetting(new MenuSettingBool(this,tr["Show root"],tr["Show root folder in the file selection dialogs"],&showRootFolder));
|
sd.addSetting(new MenuSettingBool(this,tr["Show root"],tr["Show root folder in the file selection dialogs"],&showRootFolder));
|
||||||
|
|
||||||
@ -1157,6 +1160,7 @@ void GMenu2X::options() {
|
|||||||
if (prevbacklight != confInt["backlight"]) setBacklight(confInt["backlight"]);
|
if (prevbacklight != confInt["backlight"]) setBacklight(confInt["backlight"]);
|
||||||
if (curMenuClock!=confInt["menuClock"]) setClock(confInt["menuClock"]);
|
if (curMenuClock!=confInt["menuClock"]) setClock(confInt["menuClock"]);
|
||||||
if (curGlobalVolume!=confInt["globalVolume"]) setVolume(confInt["globalVolume"]);
|
if (curGlobalVolume!=confInt["globalVolume"]) setVolume(confInt["globalVolume"]);
|
||||||
|
PowerSaver::getInstance()->setScreenTimeout( confInt["backlightTimeout"] );
|
||||||
if (lang == "English") lang = "";
|
if (lang == "English") lang = "";
|
||||||
if (lang != tr.lang()) {
|
if (lang != tr.lang()) {
|
||||||
tr.setLang(lang);
|
tr.setLang(lang);
|
||||||
@ -1377,7 +1381,6 @@ void GMenu2X::contextMenu() {
|
|||||||
uint i, sel=0, fadeAlpha=0;
|
uint i, sel=0, fadeAlpha=0;
|
||||||
|
|
||||||
int h = font->getHeight();
|
int h = font->getHeight();
|
||||||
int h2 = font->getHalfHeight();
|
|
||||||
SDL_Rect box;
|
SDL_Rect box;
|
||||||
box.h = (h+2)*voices.size()+8;
|
box.h = (h+2)*voices.size()+8;
|
||||||
box.w = 0;
|
box.w = 0;
|
||||||
@ -1414,7 +1417,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+5+(h+2)*i, ASFont::HAlignLeft, ASFont::VAlignTop );
|
||||||
s->flip();
|
s->flip();
|
||||||
|
|
||||||
//touchscreen
|
//touchscreen
|
||||||
@ -1693,7 +1696,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;
|
||||||
|
|
||||||
@ -2039,7 +2042,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;
|
||||||
@ -2051,7 +2054,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;
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "inputmanager.h"
|
#include "inputmanager.h"
|
||||||
#include "asfont.h"
|
#include "asfont.h"
|
||||||
#include "surface.h"
|
#include "surface.h"
|
||||||
|
#include "powersaver.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -131,6 +132,7 @@ private:
|
|||||||
usbnet,
|
usbnet,
|
||||||
samba,
|
samba,
|
||||||
web;
|
web;
|
||||||
|
|
||||||
string ip, defaultgw, lastSelectorDir;
|
string ip, defaultgw, lastSelectorDir;
|
||||||
int lastSelectorElement;
|
int lastSelectorElement;
|
||||||
void readConfig();
|
void readConfig();
|
||||||
|
@ -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) {
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
36
src/imageio.cpp
Normal file
36
src/imageio.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include "imageio.h"
|
||||||
|
|
||||||
|
#include <SDL_image.h>
|
||||||
|
|
||||||
|
SDL_Surface *loadPNG(const std::string &path) {
|
||||||
|
// Load PNG file into an SDL surface.
|
||||||
|
SDL_Surface *surface = IMG_Load(path.c_str());
|
||||||
|
if (!surface) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure we have a surface that can be blitted using alpha blending.
|
||||||
|
if (surface->format->BytesPerPixel == 4) {
|
||||||
|
SDL_SetAlpha(surface, SDL_SRCALPHA, 255);
|
||||||
|
return surface;
|
||||||
|
} else {
|
||||||
|
SDL_PixelFormat format32;
|
||||||
|
memset(&format32, 0, sizeof(format32));
|
||||||
|
format32.BitsPerPixel = 32;
|
||||||
|
format32.BytesPerPixel = 4;
|
||||||
|
format32.Rmask =
|
||||||
|
SDL_BYTEORDER == SDL_BIG_ENDIAN ? 0x00FF0000 : 0x000000FF;
|
||||||
|
format32.Gmask = 0x0000FF00;
|
||||||
|
format32.Bmask =
|
||||||
|
SDL_BYTEORDER == SDL_BIG_ENDIAN ? 0x000000FF : 0x00FF0000;
|
||||||
|
format32.Amask = 0xFF000000;
|
||||||
|
format32.Rshift = SDL_BYTEORDER == SDL_BIG_ENDIAN ? 16 : 0;
|
||||||
|
format32.Gshift = 8;
|
||||||
|
format32.Bshift = SDL_BYTEORDER == SDL_BIG_ENDIAN ? 0 : 16;
|
||||||
|
format32.Ashift = 24;
|
||||||
|
SDL_Surface *surface32 =
|
||||||
|
SDL_ConvertSurface(surface, &format32, SDL_SRCALPHA);
|
||||||
|
SDL_FreeSurface(surface);
|
||||||
|
return surface32;
|
||||||
|
}
|
||||||
|
}
|
12
src/imageio.h
Normal file
12
src/imageio.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef IMAGEIO_H
|
||||||
|
#define IMAGEIO_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
struct SDL_Surface;
|
||||||
|
|
||||||
|
/** Loads an image from a PNG file into a newly allocated 32bpp RGBA surface.
|
||||||
|
*/
|
||||||
|
SDL_Surface *loadPNG(const std::string &path);
|
||||||
|
|
||||||
|
#endif
|
@ -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)) {
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "inputmanager.h"
|
#include "inputmanager.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
#include "powersaver.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -179,6 +180,8 @@ bool InputManager::getEvent(bevent_t *bevent, bool wait) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( wait ) {
|
||||||
|
PowerSaver::getInstance()->resetScreenTimer();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +301,8 @@ void LinkApp::showManual() {
|
|||||||
gmenu2x->setClock(336);
|
gmenu2x->setClock(336);
|
||||||
|
|
||||||
Surface pngman(manual);
|
Surface pngman(manual);
|
||||||
Surface bg(gmenu2x->confStr["wallpaper"],false);
|
// Note: Copy constructor converts to display format.
|
||||||
|
Surface bg(Surface(gmenu2x->confStr["wallpaper"]));
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
string pageStatus;
|
string pageStatus;
|
||||||
|
|
||||||
@ -329,7 +330,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;
|
||||||
|
@ -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, ASFont::HAlignLeft, ASFont::VAlignTop );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSetting::handleTS()
|
void MenuSetting::handleTS()
|
||||||
|
@ -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, ASFont::HAlignLeft, ASFont::VAlignTop );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSettingBool::manageInput(bevent_t *event)
|
void MenuSettingBool::manageInput(bevent_t *event)
|
||||||
|
@ -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, ASFont::HAlignLeft, ASFont::VAlignTop );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSettingInt::manageInput(bevent_t *event)
|
void MenuSettingInt::manageInput(bevent_t *event)
|
||||||
|
@ -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, ASFont::HAlignLeft, ASFont::VAlignTop );
|
||||||
gmenu2x->s->write( gmenu2x->font, "G: "+strG, 205, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle );
|
gmenu2x->s->write( gmenu2x->font, "G: "+strG, 205, y, ASFont::HAlignLeft, ASFont::VAlignTop );
|
||||||
gmenu2x->s->write( gmenu2x->font, "B: "+strB, 241, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle );
|
gmenu2x->s->write( gmenu2x->font, "B: "+strB, 241, y, ASFont::HAlignLeft, ASFont::VAlignTop );
|
||||||
gmenu2x->s->write( gmenu2x->font, "A: "+strA, 277, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle );
|
gmenu2x->s->write( gmenu2x->font, "A: "+strA, 277, y, ASFont::HAlignLeft, ASFont::VAlignTop );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSettingRGBA::handleTS() {
|
void MenuSettingRGBA::handleTS() {
|
||||||
@ -90,6 +90,12 @@ void MenuSettingRGBA::manageInput(bevent_t *event) {
|
|||||||
case CLEAR:
|
case CLEAR:
|
||||||
dec();
|
dec();
|
||||||
break;
|
break;
|
||||||
|
case ALTLEFT:
|
||||||
|
update_value(-10);
|
||||||
|
break;
|
||||||
|
case ALTRIGHT:
|
||||||
|
update_value(10);
|
||||||
|
break;
|
||||||
case LEFT:
|
case LEFT:
|
||||||
leftComponent();
|
leftComponent();
|
||||||
break;
|
break;
|
||||||
@ -101,14 +107,19 @@ void MenuSettingRGBA::manageInput(bevent_t *event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MenuSettingRGBA::update_value(int value)
|
||||||
|
{
|
||||||
|
setSelPart(constrain(getSelPart() + value, 0, 255));
|
||||||
|
}
|
||||||
|
|
||||||
void MenuSettingRGBA::dec()
|
void MenuSettingRGBA::dec()
|
||||||
{
|
{
|
||||||
setSelPart(constrain(getSelPart()-1,0,255));
|
update_value(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSettingRGBA::inc()
|
void MenuSettingRGBA::inc()
|
||||||
{
|
{
|
||||||
setSelPart(constrain(getSelPart()+1,0,255));
|
update_value(+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSettingRGBA::leftComponent()
|
void MenuSettingRGBA::leftComponent()
|
||||||
|
@ -34,6 +34,7 @@ private:
|
|||||||
RGBAColor originalValue;
|
RGBAColor originalValue;
|
||||||
RGBAColor *_value;
|
RGBAColor *_value;
|
||||||
|
|
||||||
|
void update_value(int value);
|
||||||
void dec();
|
void dec();
|
||||||
void inc();
|
void inc();
|
||||||
void leftComponent();
|
void leftComponent();
|
||||||
|
@ -38,10 +38,8 @@ MenuSettingStringBase::~MenuSettingStringBase()
|
|||||||
void MenuSettingStringBase::draw(int y)
|
void MenuSettingStringBase::draw(int y)
|
||||||
{
|
{
|
||||||
MenuSetting::draw(y);
|
MenuSetting::draw(y);
|
||||||
gmenu2x->s->write(
|
gmenu2x->s->write(gmenu2x->font, value(), 155, y,
|
||||||
gmenu2x->font, value(),
|
ASFont::HAlignLeft, ASFont::VAlignTop);
|
||||||
155, y + gmenu2x->font->getHalfHeight(),
|
|
||||||
SFontHAlignLeft, SFontVAlignMiddle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSettingStringBase::manageInput(bevent_t *event)
|
void MenuSettingStringBase::manageInput(bevent_t *event)
|
||||||
|
@ -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++) {
|
||||||
|
90
src/powersaver.cpp
Normal file
90
src/powersaver.cpp
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "powersaver.h"
|
||||||
|
#include "debug.h"
|
||||||
|
PowerSaver* PowerSaver::instance = NULL;
|
||||||
|
Uint32 screenTimerCallback(Uint32 interval, void *param)
|
||||||
|
{
|
||||||
|
DEBUG("Disable Backlight Event\n");
|
||||||
|
PowerSaver::getInstance()->disableScreen();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
PowerSaver* PowerSaver::getInstance() {
|
||||||
|
if ( instance == NULL ) {
|
||||||
|
instance = new PowerSaver();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
PowerSaver::PowerSaver( ) {
|
||||||
|
setScreenTimeout(0);
|
||||||
|
screenTimer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
PowerSaver::~PowerSaver() {
|
||||||
|
SDL_RemoveTimer(screenTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PowerSaver::setScreenTimeout( unsigned int seconds ) {
|
||||||
|
screenTimeout = seconds;
|
||||||
|
resetScreenTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PowerSaver::resetScreenTimer() {
|
||||||
|
if ( screenTimer != NULL ) {
|
||||||
|
SDL_RemoveTimer(screenTimer);
|
||||||
|
}
|
||||||
|
addScreenTimer();
|
||||||
|
//If display is off, turn on it
|
||||||
|
if ( !screenState ) {
|
||||||
|
enableScreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PowerSaver::addScreenTimer() {
|
||||||
|
//if timeout is zero, don't set timeout
|
||||||
|
if ( screenTimeout == 0 ) {
|
||||||
|
screenTimer = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
screenTimer = SDL_AddTimer(screenTimeout*1000, screenTimerCallback,NULL);
|
||||||
|
if ( screenTimer == NULL ) {
|
||||||
|
ERROR("Could not initialize SDLTimer: %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SCREEN_BLANK_PATH "/sys/class/graphics/fb0/blank"
|
||||||
|
void PowerSaver::setScreenBlanking( bool state ) {
|
||||||
|
const char* path = SCREEN_BLANK_PATH;
|
||||||
|
const char* blank = state ? "0" : "1";
|
||||||
|
|
||||||
|
int fd = open(path, O_RDWR);
|
||||||
|
if (fd == -1) {
|
||||||
|
WARNING("Failed to open '%s': %s\n", path, strerror(errno));
|
||||||
|
} else {
|
||||||
|
ssize_t written = write(fd, blank, strlen(blank));
|
||||||
|
if (written == -1) {
|
||||||
|
WARNING("Error writing '%s': %s\n", path, strerror(errno));
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
screenState = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PowerSaver::enableScreen() {
|
||||||
|
if ( !screenState ) {
|
||||||
|
setScreenBlanking(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void PowerSaver::disableScreen() {
|
||||||
|
if ( screenState ) {
|
||||||
|
setScreenBlanking(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
25
src/powersaver.h
Normal file
25
src/powersaver.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef POWERSAVER_H
|
||||||
|
#define POWERSAVER_H
|
||||||
|
#include <SDL.h>
|
||||||
|
class PowerSaver {
|
||||||
|
|
||||||
|
public:
|
||||||
|
static PowerSaver* getInstance();
|
||||||
|
~PowerSaver();
|
||||||
|
void addScreenTimer();
|
||||||
|
void resetScreenTimer();
|
||||||
|
|
||||||
|
void enableScreen();
|
||||||
|
void disableScreen();
|
||||||
|
|
||||||
|
void setScreenTimeout( unsigned int seconds );
|
||||||
|
private:
|
||||||
|
PowerSaver( );
|
||||||
|
static PowerSaver* instance;
|
||||||
|
bool screenState;
|
||||||
|
unsigned int screenTimeout;
|
||||||
|
SDL_TimerID screenTimer;
|
||||||
|
|
||||||
|
void setScreenBlanking( bool state );
|
||||||
|
};
|
||||||
|
#endif
|
@ -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();
|
||||||
|
|
||||||
|
@ -1,195 +0,0 @@
|
|||||||
#include "sfontplus.h"
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <SDL_image.h>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
Uint32 SFontPlus::getPixel(Sint32 x, Sint32 y) {
|
|
||||||
assert(x>=0);
|
|
||||||
assert(x<surface->w);
|
|
||||||
assert(y>=0);
|
|
||||||
assert(y<surface->h);
|
|
||||||
|
|
||||||
Uint32 Bpp = surface->format->BytesPerPixel;
|
|
||||||
|
|
||||||
// Get the pixel
|
|
||||||
switch(Bpp) {
|
|
||||||
case 1:
|
|
||||||
return *((Uint8 *)surface->pixels + y * surface->pitch + x);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
return *((Uint16 *)surface->pixels + y * surface->pitch/2 + x);
|
|
||||||
break;
|
|
||||||
case 3: { // Format/endian independent
|
|
||||||
Uint8 *bits = ((Uint8 *)surface->pixels)+y*surface->pitch+x*Bpp;
|
|
||||||
Uint8 r, g, b;
|
|
||||||
r = *((bits)+surface->format->Rshift/8);
|
|
||||||
g = *((bits)+surface->format->Gshift/8);
|
|
||||||
b = *((bits)+surface->format->Bshift/8);
|
|
||||||
return SDL_MapRGB(surface->format, r, g, b);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
return *((Uint32 *)surface->pixels + y * surface->pitch/4 + x);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SFontPlus::SFontPlus() {
|
|
||||||
surface = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SFontPlus::SFontPlus(SDL_Surface* font) {
|
|
||||||
surface = NULL;
|
|
||||||
initFont(font);
|
|
||||||
}
|
|
||||||
|
|
||||||
SFontPlus::SFontPlus(const string &font) {
|
|
||||||
surface = NULL;
|
|
||||||
initFont(font);
|
|
||||||
}
|
|
||||||
|
|
||||||
SFontPlus::~SFontPlus() {
|
|
||||||
freeFont();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SFontPlus::utf8Code(unsigned char c) {
|
|
||||||
return (c>=194 && c<=198) || c==208 || c==209;
|
|
||||||
//return c>=194;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SFontPlus::initFont(const string &font, const string &characters) {
|
|
||||||
SDL_Surface *buf = IMG_Load(font.c_str());
|
|
||||||
if (buf!=NULL) {
|
|
||||||
initFont( SDL_DisplayFormatAlpha(buf), characters );
|
|
||||||
SDL_FreeSurface(buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SFontPlus::initFont(SDL_Surface *font, const string &characters) {
|
|
||||||
freeFont();
|
|
||||||
this->characters = characters;
|
|
||||||
if (font==NULL) return;
|
|
||||||
surface = font;
|
|
||||||
Uint32 pink = SDL_MapRGB(surface->format, 255,0,255);
|
|
||||||
#ifdef DEBUG
|
|
||||||
bool utf8 = false;
|
|
||||||
for (uint x=0; x<characters.length(); x++) {
|
|
||||||
if (!utf8) utf8 = (unsigned char)characters[x]>128;
|
|
||||||
if (utf8) DEBUG("%d\n", (unsigned char)characters[x]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uint c = 0;
|
|
||||||
|
|
||||||
SDL_LockSurface(surface);
|
|
||||||
for (uint x=0; x<(uint)surface->w && c<characters.length(); x++) {
|
|
||||||
if (getPixel(x,0) == pink) {
|
|
||||||
uint startx = x;
|
|
||||||
charpos.push_back(x);
|
|
||||||
|
|
||||||
x++;
|
|
||||||
while (x<(uint)surface->w && getPixel(x,0) == pink) x++;
|
|
||||||
charpos.push_back(x);
|
|
||||||
|
|
||||||
//utf8 characters
|
|
||||||
if (c>0 && utf8Code(characters[c-1])) {
|
|
||||||
charpos.push_back(startx);
|
|
||||||
charpos.push_back(x);
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SDL_UnlockSurface(surface);
|
|
||||||
Uint32 colKey = getPixel(0,surface->h-1);
|
|
||||||
SDL_SetColorKey(surface, SDL_SRCCOLORKEY, colKey);
|
|
||||||
string::size_type pos = characters.find("0")*2;
|
|
||||||
SDL_Rect srcrect = {charpos[pos], 1, charpos[pos+2] - charpos[pos], surface->h - 1};
|
|
||||||
uint y = srcrect.h;
|
|
||||||
bool nonKeyFound = false;
|
|
||||||
while (y-- > 0 && !nonKeyFound) {
|
|
||||||
uint x = srcrect.w;
|
|
||||||
while (x-- > 0 && !nonKeyFound)
|
|
||||||
nonKeyFound = getPixel(x+srcrect.x,y+srcrect.y) != colKey;
|
|
||||||
}
|
|
||||||
lineHeight = y+1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SFontPlus::freeFont() {
|
|
||||||
if (surface!=NULL) {
|
|
||||||
SDL_FreeSurface(surface);
|
|
||||||
surface = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SFontPlus::write(SDL_Surface *s, const string &text, int x, int y) {
|
|
||||||
if (text.empty()) return;
|
|
||||||
|
|
||||||
string::size_type pos;
|
|
||||||
SDL_Rect srcrect, dstrect;
|
|
||||||
|
|
||||||
// these values won't change in the loop
|
|
||||||
srcrect.y = 1;
|
|
||||||
dstrect.y = y;
|
|
||||||
srcrect.h = dstrect.h = surface->h-1;
|
|
||||||
|
|
||||||
for(uint i=0; i<text.length() && x<surface->w; i++) {
|
|
||||||
//Utf8 characters
|
|
||||||
if (utf8Code(text[i]) && i+1<text.length()) {
|
|
||||||
pos = characters.find(text.substr(i,2));
|
|
||||||
i++;
|
|
||||||
} else
|
|
||||||
pos = characters.find(text[i]);
|
|
||||||
if (pos == string::npos) {
|
|
||||||
x += charpos[2]-charpos[1];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos *= 2;
|
|
||||||
|
|
||||||
srcrect.x = charpos[pos];
|
|
||||||
srcrect.w = charpos[pos+2] - charpos[pos];
|
|
||||||
dstrect.x = x - charpos[pos+1] + charpos[pos];
|
|
||||||
|
|
||||||
SDL_BlitSurface(surface, &srcrect, s, &dstrect);
|
|
||||||
|
|
||||||
x += charpos[pos+2] - charpos[pos+1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint SFontPlus::getTextWidth(const string &text) {
|
|
||||||
string::size_type pos;
|
|
||||||
int width = 0;
|
|
||||||
|
|
||||||
for(uint x=0; x<text.length(); x++) {
|
|
||||||
//Utf8 characters
|
|
||||||
if (utf8Code(text[x]) && x+1<text.length()) {
|
|
||||||
pos = characters.find(text.substr(x,2));
|
|
||||||
x++;
|
|
||||||
} else
|
|
||||||
pos = characters.find(text[x]);
|
|
||||||
if (pos == string::npos) {
|
|
||||||
width += charpos[2]-charpos[1];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos *= 2;
|
|
||||||
width += charpos[pos+2] - charpos[pos+1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint SFontPlus::getHeight() {
|
|
||||||
return surface->h - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint SFontPlus::getLineHeight() {
|
|
||||||
return lineHeight;
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
#ifndef SFONTPLUS_H
|
|
||||||
#define SFONTPLUS_H
|
|
||||||
|
|
||||||
#include <SDL.h>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#define SFONTPLUS_CHARSET "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~¡¿ÀÁÈÉÌÍÒÓÙÚÝÄËÏÖÜŸÂÊÎÔÛÅÃÕÑÆÇČĎĚĽĹŇÔŘŔŠŤŮŽàáèéìíòóùúýäëïöüÿâêîôûåãõñæçčďěľĺňôřŕšťžůðßÐÞþАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюяØøąćęłńśżźĄĆĘŁŃŚŻŹ"
|
|
||||||
#ifdef _WIN32
|
|
||||||
typedef unsigned int uint;
|
|
||||||
#endif
|
|
||||||
using std::vector;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
class SFontPlus {
|
|
||||||
private:
|
|
||||||
Uint32 getPixel(Sint32 x, Sint32 y);
|
|
||||||
|
|
||||||
SDL_Surface *surface;
|
|
||||||
vector<uint> charpos;
|
|
||||||
string characters;
|
|
||||||
uint height, lineHeight;
|
|
||||||
|
|
||||||
public:
|
|
||||||
SFontPlus();
|
|
||||||
SFontPlus(SDL_Surface *font);
|
|
||||||
SFontPlus(const string &font);
|
|
||||||
~SFontPlus();
|
|
||||||
|
|
||||||
bool utf8Code(unsigned char c);
|
|
||||||
|
|
||||||
void initFont(SDL_Surface *font, const string &characters = SFONTPLUS_CHARSET);
|
|
||||||
void initFont(const string &font, const string &characters = SFONTPLUS_CHARSET);
|
|
||||||
void freeFont();
|
|
||||||
|
|
||||||
void write(SDL_Surface *s, const string &text, int x, int y);
|
|
||||||
|
|
||||||
uint getTextWidth(const string &text);
|
|
||||||
uint getHeight();
|
|
||||||
uint getLineHeight();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* SFONTPLUS_H */
|
|
213
src/surface.cpp
213
src/surface.cpp
@ -18,16 +18,17 @@
|
|||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "surface.h"
|
||||||
|
#include "imageio.h"
|
||||||
|
#include "utilities.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "surfacecollection.h"
|
||||||
|
|
||||||
#include <SDL_gfxPrimitives.h>
|
#include <SDL_gfxPrimitives.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#include "surface.h"
|
|
||||||
#include "utilities.h"
|
|
||||||
#include "debug.h"
|
|
||||||
#include "surfacecollection.h"
|
|
||||||
|
|
||||||
RGBAColor strtorgba(const string &strColor) {
|
RGBAColor strtorgba(const string &strColor) {
|
||||||
RGBAColor c = {0,0,0,255};
|
RGBAColor c = {0,0,0,255};
|
||||||
c.r = constrain( strtol( strColor.substr(0,2).c_str(), NULL, 16 ), 0, 255 );
|
c.r = constrain( strtol( strColor.substr(0,2).c_str(), NULL, 16 ), 0, 255 );
|
||||||
@ -42,54 +43,19 @@ Surface::Surface() {
|
|||||||
dblbuffer = NULL;
|
dblbuffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface::Surface(const string &img, bool alpha, const string &skin) {
|
|
||||||
raw = NULL;
|
|
||||||
dblbuffer = NULL;
|
|
||||||
load(img, alpha, skin);
|
|
||||||
halfW = raw->w/2;
|
|
||||||
halfH = raw->h/2;
|
|
||||||
}
|
|
||||||
|
|
||||||
Surface::Surface(const string &img, const string &skin, bool alpha) {
|
|
||||||
raw = NULL;
|
|
||||||
dblbuffer = NULL;
|
|
||||||
load(img, alpha, skin);
|
|
||||||
halfW = raw->w/2;
|
|
||||||
halfH = raw->h/2;
|
|
||||||
}
|
|
||||||
|
|
||||||
Surface::Surface(SDL_Surface *s, SDL_PixelFormat *fmt, Uint32 flags) {
|
|
||||||
dblbuffer = NULL;
|
|
||||||
this->operator =(s);
|
|
||||||
if (fmt!=NULL || flags!=0) {
|
|
||||||
if (fmt==NULL) fmt = s->format;
|
|
||||||
if (flags==0) flags = s->flags;
|
|
||||||
raw = SDL_ConvertSurface( s, fmt, flags );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Surface::Surface(Surface *s) {
|
Surface::Surface(Surface *s) {
|
||||||
dblbuffer = NULL;
|
dblbuffer = NULL;
|
||||||
this->operator =(s->raw);
|
raw = SDL_DisplayFormat(s->raw);
|
||||||
|
halfW = raw->w/2;
|
||||||
|
halfH = raw->h/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface::Surface(int w, int h, Uint32 flags) {
|
Surface::Surface(const string &img, const string &skin) {
|
||||||
|
raw = NULL;
|
||||||
dblbuffer = NULL;
|
dblbuffer = NULL;
|
||||||
Uint32 rmask, gmask, bmask, amask;
|
load(img, skin);
|
||||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
halfW = raw->w/2;
|
||||||
rmask = 0xff000000;
|
halfH = raw->h/2;
|
||||||
gmask = 0x00ff0000;
|
|
||||||
bmask = 0x0000ff00;
|
|
||||||
amask = 0x000000ff;
|
|
||||||
#else
|
|
||||||
rmask = 0x000000ff;
|
|
||||||
gmask = 0x0000ff00;
|
|
||||||
bmask = 0x00ff0000;
|
|
||||||
amask = 0xff000000;
|
|
||||||
#endif
|
|
||||||
raw = SDL_CreateRGBSurface( flags, w, h, 16, rmask, gmask, bmask, amask );
|
|
||||||
halfW = w/2;
|
|
||||||
halfH = h/2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface::~Surface() {
|
Surface::~Surface() {
|
||||||
@ -113,7 +79,7 @@ SDL_PixelFormat *Surface::format() {
|
|||||||
return raw->format;
|
return raw->format;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Surface::load(const string &img, bool alpha, const string &skin) {
|
void Surface::load(const string &img, const string &skin) {
|
||||||
free();
|
free();
|
||||||
|
|
||||||
string skinpath;
|
string skinpath;
|
||||||
@ -122,35 +88,12 @@ void Surface::load(const string &img, bool alpha, const string &skin) {
|
|||||||
else
|
else
|
||||||
skinpath = img;
|
skinpath = img;
|
||||||
|
|
||||||
SDL_Surface *buf = IMG_Load(skinpath.c_str());
|
raw = loadPNG(skinpath);
|
||||||
if (buf!=NULL) {
|
if (!raw) {
|
||||||
if (alpha)
|
|
||||||
raw = SDL_DisplayFormatAlpha(buf);
|
|
||||||
else
|
|
||||||
raw = SDL_DisplayFormat(buf);
|
|
||||||
SDL_FreeSurface(buf);
|
|
||||||
} else {
|
|
||||||
ERROR("Couldn't load surface '%s'\n", img.c_str());
|
ERROR("Couldn't load surface '%s'\n", img.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Surface::lock() {
|
|
||||||
if ( SDL_MUSTLOCK(raw) && !locked ) {
|
|
||||||
if ( SDL_LockSurface(raw) < 0 ) {
|
|
||||||
ERROR("Can't lock surface: '%s'\n", SDL_GetError());
|
|
||||||
SDL_Quit();
|
|
||||||
}
|
|
||||||
locked = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Surface::unlock() {
|
|
||||||
if ( SDL_MUSTLOCK(raw) && locked ) {
|
|
||||||
SDL_UnlockSurface(raw);
|
|
||||||
locked = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Surface::flip() {
|
void Surface::flip() {
|
||||||
if (dblbuffer!=NULL) {
|
if (dblbuffer!=NULL) {
|
||||||
this->blit(dblbuffer,0,0);
|
this->blit(dblbuffer,0,0);
|
||||||
@ -194,122 +137,25 @@ bool Surface::blitRight(Surface *destination, int x, int y, int w, int h, int a)
|
|||||||
return blitRight(destination->raw,x,y,w,h,a);
|
return blitRight(destination->raw,x,y,w,h,a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Surface::putPixel(int x, int y, SDL_Color color) {
|
|
||||||
putPixel(x,y, SDL_MapRGB( raw->format , color.r , color.g , color.b ));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Surface::putPixel(int x, int y, Uint32 color) {
|
|
||||||
//determine position
|
|
||||||
char* pPosition = ( char* ) raw->pixels ;
|
|
||||||
//offset by y
|
|
||||||
pPosition += ( raw->pitch * y ) ;
|
|
||||||
//offset by x
|
|
||||||
pPosition += ( raw->format->BytesPerPixel * x ) ;
|
|
||||||
//copy pixel data
|
|
||||||
memcpy ( pPosition , &color , raw->format->BytesPerPixel ) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Color Surface::pixelColor(int x, int y) {
|
|
||||||
SDL_Color color;
|
|
||||||
Uint32 col = pixel(x,y);
|
|
||||||
SDL_GetRGB( col, raw->format, &color.r, &color.g, &color.b );
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint32 Surface::pixel(int x, int y) {
|
|
||||||
//determine position
|
|
||||||
char* pPosition = ( char* ) raw->pixels ;
|
|
||||||
//offset by y
|
|
||||||
pPosition += ( raw->pitch * y ) ;
|
|
||||||
//offset by x
|
|
||||||
pPosition += ( raw->format->BytesPerPixel * x ) ;
|
|
||||||
//copy pixel data
|
|
||||||
Uint32 col = 0;
|
|
||||||
memcpy ( &col , pPosition , raw->format->BytesPerPixel ) ;
|
|
||||||
return col;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Surface::blendAdd(Surface *target, int x, int y) {
|
|
||||||
SDL_Color targetcol, blendcol;
|
|
||||||
for (int iy=0; iy<raw->h; iy++)
|
|
||||||
if (iy+y >= 0 && iy+y < target->raw->h)
|
|
||||||
for (int ix=0; ix<raw->w; ix++) {
|
|
||||||
if (ix+x >= 0 && ix+x < target->raw->w) {
|
|
||||||
blendcol = pixelColor(ix,iy);
|
|
||||||
targetcol = target->pixelColor(ix+x,iy+y);
|
|
||||||
targetcol.r = min(targetcol.r+blendcol.r, 255);
|
|
||||||
targetcol.g = min(targetcol.g+blendcol.g, 255);
|
|
||||||
targetcol.b = min(targetcol.b+blendcol.b, 255);
|
|
||||||
target->putPixel(ix+x,iy+y,targetcol);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Uint32 bcol, tcol;
|
|
||||||
char *pPos, *tpPos;
|
|
||||||
for (int iy=0; iy<raw->h; iy++)
|
|
||||||
if (iy+y >= 0 && iy+y < target->raw->h) {
|
|
||||||
pPos = (char*)raw->pixels + raw->pitch*iy;
|
|
||||||
tpPos = (char*)target->raw->pixels + target->raw->pitch*(iy+y);
|
|
||||||
|
|
||||||
for (int ix=0; ix<raw->w; ix++) {
|
|
||||||
memcpy(&bcol, pPos, raw->format->BytesPerPixel);
|
|
||||||
memcpy(&tcol, tpPos, target->raw->format->BytesPerPixel);
|
|
||||||
//memcpy(tpPos, &bcol, target->raw->format->BytesPerPixel);
|
|
||||||
pPos += raw->format->BytesPerPixel;
|
|
||||||
tpPos += target->raw->format->BytesPerPixel;
|
|
||||||
target->putPixel(ix+x,iy+y,bcol);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
raw = SDL_DisplayFormat(s);
|
|
||||||
halfW = raw->w/2;
|
|
||||||
halfH = raw->h/2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Surface::operator = (Surface *s) {
|
|
||||||
this->operator =(s->raw);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Surface::box(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
int Surface::box(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
||||||
return boxRGBA(raw,x,y,x+w-1,y+h-1,r,g,b,a);
|
return boxRGBA(raw,x,y,x+w-1,y+h-1,r,g,b,a);
|
||||||
}
|
}
|
||||||
int Surface::box(SDL_Rect re, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
|
||||||
return boxRGBA(raw,re.x,re.y,re.x+re.w-1,re.y+re.h-1,r,g,b,a);
|
|
||||||
}
|
|
||||||
int Surface::box(SDL_Rect re, Uint8 r, Uint8 g, Uint8 b) {
|
|
||||||
return SDL_FillRect(raw, &re, SDL_MapRGBA(format(),r,g,b,255));
|
|
||||||
}
|
|
||||||
int Surface::box(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b) {
|
int Surface::box(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b) {
|
||||||
SDL_Rect re = {x,y,w,h};
|
SDL_Rect re = {x,y,w,h};
|
||||||
return box(re,r,g,b);
|
return SDL_FillRect(raw, &re, SDL_MapRGBA(format(),r,g,b,255));
|
||||||
}
|
}
|
||||||
int Surface::box(Sint16 x, Sint16 y, Sint16 w, Sint16 h, RGBAColor c) {
|
int Surface::box(Sint16 x, Sint16 y, Sint16 w, Sint16 h, RGBAColor c) {
|
||||||
return box(x,y,w,h,c.r,c.g,c.b,c.a);
|
return box(x,y,w,h,c.r,c.g,c.b,c.a);
|
||||||
}
|
}
|
||||||
int Surface::box(SDL_Rect re, RGBAColor c) {
|
int Surface::box(SDL_Rect re, RGBAColor c) {
|
||||||
return box(re,c.r,c.g,c.b,c.a);
|
return boxRGBA(
|
||||||
|
raw, re.x, re.y, re.x + re.w - 1, re.y + re.h - 1, c.r, c.g, c.b, c.a
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::rectangle(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
int Surface::rectangle(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
||||||
return rectangleRGBA(raw,x,y,x+w-1,y+h-1,r,g,b,a);
|
return rectangleRGBA(raw,x,y,x+w-1,y+h-1,r,g,b,a);
|
||||||
}
|
}
|
||||||
int Surface::rectangle(SDL_Rect re, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
|
||||||
return rectangleRGBA(raw,re.x,re.y,re.x+re.w-1,re.y+re.h-1,r,g,b,a);
|
|
||||||
}
|
|
||||||
int Surface::rectangle(Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 r, Uint8 g, Uint8 b) {
|
|
||||||
return rectangleColor(raw, x,y,x+w-1,y+h-1, SDL_MapRGBA(format(),r,g,b,255));
|
|
||||||
}
|
|
||||||
int Surface::rectangle(SDL_Rect re, Uint8 r, Uint8 g, Uint8 b) {
|
|
||||||
return rectangleColor(raw, re.x,re.y,re.x+re.w-1,re.y+re.h-1, SDL_MapRGBA(format(),r,g,b,255));
|
|
||||||
}
|
|
||||||
int Surface::rectangle(Sint16 x, Sint16 y, Sint16 w, Sint16 h, RGBAColor c) {
|
int Surface::rectangle(Sint16 x, Sint16 y, Sint16 w, Sint16 h, RGBAColor c) {
|
||||||
return rectangle(x,y,w,h,c.r,c.g,c.b,c.a);
|
return rectangle(x,y,w,h,c.r,c.g,c.b,c.a);
|
||||||
}
|
}
|
||||||
@ -320,9 +166,6 @@ int Surface::rectangle(SDL_Rect re, RGBAColor c) {
|
|||||||
int Surface::hline(Sint16 x, Sint16 y, Sint16 w, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
int Surface::hline(Sint16 x, Sint16 y, Sint16 w, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
|
||||||
return hlineRGBA(raw,x,x+w-1,y,r,g,b,a);
|
return hlineRGBA(raw,x,x+w-1,y,r,g,b,a);
|
||||||
}
|
}
|
||||||
int Surface::hline(Sint16 x, Sint16 y, Sint16 w, RGBAColor c) {
|
|
||||||
return hline(x,y,w-1,c.r,c.g,c.b,c.a);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Surface::clearClipRect() {
|
void Surface::clearClipRect() {
|
||||||
SDL_SetClipRect(raw,NULL);
|
SDL_SetClipRect(raw,NULL);
|
||||||
@ -337,21 +180,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;
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,8 @@
|
|||||||
#ifndef SURFACE_H
|
#ifndef SURFACE_H
|
||||||
#define SURFACE_H
|
#define SURFACE_H
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_image.h>
|
#include <string>
|
||||||
|
|
||||||
#include "asfont.h"
|
#include "asfont.h"
|
||||||
|
|
||||||
@ -39,18 +38,10 @@ RGBAColor strtorgba(const string &strColor);
|
|||||||
@author Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
|
@author Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
|
||||||
*/
|
*/
|
||||||
class Surface {
|
class Surface {
|
||||||
private:
|
|
||||||
bool locked;
|
|
||||||
int halfW, halfH;
|
|
||||||
SDL_Surface *dblbuffer;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Surface();
|
Surface();
|
||||||
Surface(const string &img, const string &skin="", bool alpha=true);
|
|
||||||
Surface(const string &img, bool alpha, const string &skin="");
|
|
||||||
Surface(SDL_Surface *s, SDL_PixelFormat *fmt = NULL, Uint32 flags = 0);
|
|
||||||
Surface(Surface *s);
|
Surface(Surface *s);
|
||||||
Surface(int w, int h, Uint32 flags = SDL_HWSURFACE|SDL_SRCALPHA);
|
Surface(const string &img, const string &skin="");
|
||||||
~Surface();
|
~Surface();
|
||||||
|
|
||||||
void enableVirtualDoubleBuffer(SDL_Surface *surface);
|
void enableVirtualDoubleBuffer(SDL_Surface *surface);
|
||||||
@ -58,50 +49,40 @@ public:
|
|||||||
SDL_Surface *raw;
|
SDL_Surface *raw;
|
||||||
|
|
||||||
void free();
|
void free();
|
||||||
void load(const string &img, bool alpha=true, const string &skin="");
|
|
||||||
void lock();
|
|
||||||
void unlock();
|
|
||||||
void flip();
|
void flip();
|
||||||
SDL_PixelFormat *format();
|
|
||||||
|
|
||||||
void putPixel(int,int,SDL_Color);
|
|
||||||
void putPixel(int,int,Uint32);
|
|
||||||
SDL_Color pixelColor(int,int);
|
|
||||||
Uint32 pixel(int,int);
|
|
||||||
|
|
||||||
void blendAdd(Surface*, int,int);
|
|
||||||
|
|
||||||
void clearClipRect();
|
void clearClipRect();
|
||||||
void setClipRect(int x, int y, int w, int h);
|
void setClipRect(int x, int y, int w, int h);
|
||||||
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 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 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);
|
|
||||||
|
|
||||||
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);
|
||||||
int box(Sint16, Sint16, Sint16, Sint16, RGBAColor);
|
int box(Sint16, Sint16, Sint16, Sint16, RGBAColor);
|
||||||
int box(SDL_Rect, Uint8, Uint8, Uint8, Uint8);
|
|
||||||
int box(SDL_Rect, Uint8, Uint8, Uint8);
|
|
||||||
int box(SDL_Rect, RGBAColor);
|
int box(SDL_Rect, RGBAColor);
|
||||||
int rectangle(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
|
int rectangle(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
|
||||||
int rectangle(Sint16, Sint16, Sint16, Sint16, Uint8, Uint8, Uint8);
|
|
||||||
int rectangle(Sint16, Sint16, Sint16, Sint16, RGBAColor);
|
int rectangle(Sint16, Sint16, Sint16, Sint16, RGBAColor);
|
||||||
int rectangle(SDL_Rect, Uint8, Uint8, Uint8, Uint8);
|
|
||||||
int rectangle(SDL_Rect, Uint8, Uint8, Uint8);
|
|
||||||
int rectangle(SDL_Rect, RGBAColor);
|
int rectangle(SDL_Rect, RGBAColor);
|
||||||
int hline(Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
|
int hline(Sint16, Sint16, Sint16, Uint8, Uint8, Uint8, Uint8);
|
||||||
int hline(Sint16, Sint16, Sint16, RGBAColor);
|
|
||||||
|
|
||||||
void operator = (SDL_Surface*);
|
private:
|
||||||
void operator = (Surface*);
|
SDL_PixelFormat *format();
|
||||||
|
void load(const string &img, const string &skin);
|
||||||
|
bool blit(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(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1);
|
||||||
|
|
||||||
|
bool locked;
|
||||||
|
int halfW, halfH;
|
||||||
|
SDL_Surface *dblbuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,12 +24,14 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "gmenu2x.h"
|
#include "gmenu2x.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
SurfaceCollection::SurfaceCollection(bool defaultAlpha, const string &skin) {
|
SurfaceCollection::SurfaceCollection()
|
||||||
this->defaultAlpha = defaultAlpha;
|
: skin("default")
|
||||||
setSkin(skin);
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SurfaceCollection::~SurfaceCollection() {}
|
SurfaceCollection::~SurfaceCollection() {}
|
||||||
@ -83,7 +85,7 @@ string SurfaceCollection::getSkinFilePath(const string &skin, const string &file
|
|||||||
void SurfaceCollection::debug() {
|
void SurfaceCollection::debug() {
|
||||||
SurfaceHash::iterator end = surfaces.end();
|
SurfaceHash::iterator end = surfaces.end();
|
||||||
for(SurfaceHash::iterator curr = surfaces.begin(); curr != end; curr++){
|
for(SurfaceHash::iterator curr = surfaces.begin(); curr != end; curr++){
|
||||||
DEBUG("key: %i\n", curr->first);
|
DEBUG("key: %s\n", curr->first.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +99,7 @@ Surface *SurfaceCollection::add(Surface *s, const string &path) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface *SurfaceCollection::add(const string &path, bool alpha) {
|
Surface *SurfaceCollection::add(const string &path) {
|
||||||
DEBUG("Adding surface: '%s'\n", path.c_str());
|
DEBUG("Adding surface: '%s'\n", path.c_str());
|
||||||
|
|
||||||
if (exists(path)) del(path);
|
if (exists(path)) del(path);
|
||||||
@ -109,12 +111,12 @@ Surface *SurfaceCollection::add(const string &path, bool alpha) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
} else if (!fileExists(filePath)) return NULL;
|
} else if (!fileExists(filePath)) return NULL;
|
||||||
|
|
||||||
Surface *s = new Surface(filePath,alpha);
|
Surface *s = new Surface(filePath);
|
||||||
surfaces[path] = s;
|
surfaces[path] = s;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface *SurfaceCollection::addSkinRes(const string &path, bool alpha) {
|
Surface *SurfaceCollection::addSkinRes(const string &path) {
|
||||||
DEBUG("Adding skin surface: '%s'\n", path.c_str());
|
DEBUG("Adding skin surface: '%s'\n", path.c_str());
|
||||||
|
|
||||||
if (path.empty()) return NULL;
|
if (path.empty()) return NULL;
|
||||||
@ -123,7 +125,7 @@ Surface *SurfaceCollection::addSkinRes(const string &path, bool alpha) {
|
|||||||
string skinpath = getSkinFilePath(path);
|
string skinpath = getSkinFilePath(path);
|
||||||
if (skinpath.empty())
|
if (skinpath.empty())
|
||||||
return NULL;
|
return NULL;
|
||||||
Surface *s = new Surface(skinpath,alpha);
|
Surface *s = new Surface(skinpath);
|
||||||
if (s != NULL)
|
if (s != NULL)
|
||||||
surfaces[path] = s;
|
surfaces[path] = s;
|
||||||
return s;
|
return s;
|
||||||
@ -154,7 +156,7 @@ void SurfaceCollection::move(const string &from, const string &to) {
|
|||||||
Surface *SurfaceCollection::operator[](const string &key) {
|
Surface *SurfaceCollection::operator[](const string &key) {
|
||||||
SurfaceHash::iterator i = surfaces.find(key);
|
SurfaceHash::iterator i = surfaces.find(key);
|
||||||
if (i == surfaces.end())
|
if (i == surfaces.end())
|
||||||
return add(key, defaultAlpha);
|
return add(key);
|
||||||
else
|
else
|
||||||
return i->second;
|
return i->second;
|
||||||
}
|
}
|
||||||
@ -164,7 +166,7 @@ Surface *SurfaceCollection::skinRes(const string &key) {
|
|||||||
|
|
||||||
SurfaceHash::iterator i = surfaces.find(key);
|
SurfaceHash::iterator i = surfaces.find(key);
|
||||||
if (i == surfaces.end())
|
if (i == surfaces.end())
|
||||||
return addSkinRes(key, defaultAlpha);
|
return addSkinRes(key);
|
||||||
else
|
else
|
||||||
return i->second;
|
return i->second;
|
||||||
}
|
}
|
||||||
|
@ -33,13 +33,8 @@ Hash Map of surfaces that loads surfaces not already loaded and reuses already l
|
|||||||
@author Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
|
@author Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
|
||||||
*/
|
*/
|
||||||
class SurfaceCollection {
|
class SurfaceCollection {
|
||||||
private:
|
|
||||||
SurfaceHash surfaces;
|
|
||||||
std::string skin;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SurfaceCollection(
|
SurfaceCollection();
|
||||||
bool defaultAlpha = true, const std::string &skin = "default");
|
|
||||||
~SurfaceCollection();
|
~SurfaceCollection();
|
||||||
|
|
||||||
void setSkin(const std::string &skin);
|
void setSkin(const std::string &skin);
|
||||||
@ -51,8 +46,8 @@ public:
|
|||||||
void debug();
|
void debug();
|
||||||
|
|
||||||
Surface *add(Surface *s, const std::string &path);
|
Surface *add(Surface *s, const std::string &path);
|
||||||
Surface *add(const std::string &path, bool alpha=true);
|
Surface *add(const std::string &path);
|
||||||
Surface *addSkinRes(const std::string &path, bool alpha=true);
|
Surface *addSkinRes(const std::string &path);
|
||||||
void del(const std::string &path);
|
void del(const std::string &path);
|
||||||
void clear();
|
void clear();
|
||||||
void move(const std::string &from, const std::string &to);
|
void move(const std::string &from, const std::string &to);
|
||||||
@ -60,6 +55,10 @@ public:
|
|||||||
|
|
||||||
Surface *operator[](const std::string &);
|
Surface *operator[](const std::string &);
|
||||||
Surface *skinRes(const std::string &);
|
Surface *skinRes(const std::string &);
|
||||||
|
|
||||||
|
private:
|
||||||
|
SurfaceHash surfaces;
|
||||||
|
std::string skin;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
@ -95,7 +95,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();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user