2010-02-04 13:33:47 +02:00
|
|
|
/***************************************************************************
|
2011-10-23 17:13:02 +03:00
|
|
|
* Copyright (C) 2006 by Massimiliano Torromeo *
|
|
|
|
* massimiliano.torromeo@gmail.com *
|
2010-02-04 13:33:47 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
2011-10-23 17:13:02 +03:00
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
#include "link.h"
|
2011-10-23 17:13:02 +03:00
|
|
|
|
|
|
|
#include "gmenu2x.h"
|
2010-02-04 13:33:47 +02:00
|
|
|
#include "menu.h"
|
|
|
|
#include "selector.h"
|
2013-08-03 23:30:12 +03:00
|
|
|
#include "surface.h"
|
2011-10-23 18:27:29 +03:00
|
|
|
#include "utilities.h"
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2011-10-23 17:13:02 +03:00
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
using namespace std;
|
|
|
|
|
2013-08-14 05:21:56 +03:00
|
|
|
|
2015-04-21 21:32:33 +03:00
|
|
|
Link::Link(GMenu2X& gmenu2x, Action action)
|
2013-08-14 05:21:56 +03:00
|
|
|
: gmenu2x(gmenu2x)
|
|
|
|
, action(action)
|
|
|
|
, lastTick(0)
|
2010-07-27 23:12:28 +03:00
|
|
|
{
|
2015-04-21 21:32:33 +03:00
|
|
|
rect.w = gmenu2x.skinConfInt["linkWidth"];
|
|
|
|
rect.h = gmenu2x.skinConfInt["linkHeight"];
|
2010-02-04 13:33:47 +02:00
|
|
|
edited = false;
|
2015-04-21 21:32:33 +03:00
|
|
|
iconPath = gmenu2x.sc.getSkinFilePath("icons/generic.png");
|
2010-02-04 13:33:47 +02:00
|
|
|
iconX = 0;
|
|
|
|
padding = 0;
|
2010-05-01 19:55:11 +03:00
|
|
|
|
|
|
|
updateSurfaces();
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Link::paint() {
|
2015-04-21 21:32:33 +03:00
|
|
|
Surface& s = *gmenu2x.s;
|
2014-08-10 05:26:59 +03:00
|
|
|
|
2013-07-31 20:13:30 +03:00
|
|
|
if (iconSurface) {
|
2014-08-10 05:26:59 +03:00
|
|
|
iconSurface->blit(s, iconX, rect.y+padding, 32,32);
|
2013-07-31 20:13:30 +03:00
|
|
|
}
|
2015-04-21 21:32:33 +03:00
|
|
|
gmenu2x.font->write(s, getTitle(), iconX+16, rect.y + gmenu2x.skinConfInt["linkHeight"]-padding, Font::HAlignCenter, Font::VAlignBottom);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2013-08-13 02:47:02 +03:00
|
|
|
void Link::paintHover() {
|
2015-04-21 21:32:33 +03:00
|
|
|
Surface& s = *gmenu2x.s;
|
2014-08-10 05:26:59 +03:00
|
|
|
|
2015-04-21 21:32:33 +03:00
|
|
|
if (gmenu2x.useSelectionPng)
|
|
|
|
gmenu2x.sc["imgs/selection.png"]->blit(s, rect, Font::HAlignCenter, Font::VAlignMiddle);
|
2010-02-04 13:33:47 +02:00
|
|
|
else
|
2015-04-21 21:32:33 +03:00
|
|
|
s.box(rect.x, rect.y, rect.w, rect.h, gmenu2x.skinConfColors[COLOR_SELECTION_BG]);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-01 19:55:11 +03:00
|
|
|
void Link::updateSurfaces()
|
|
|
|
{
|
2015-04-21 21:32:33 +03:00
|
|
|
iconSurface = gmenu2x.sc[getIconPath()];
|
2010-05-01 19:55:11 +03:00
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &Link::getTitle() {
|
2010-02-04 13:33:47 +02:00
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
void Link::setTitle(const string &title) {
|
2010-02-04 13:33:47 +02:00
|
|
|
this->title = title;
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &Link::getDescription() {
|
2010-02-04 13:33:47 +02:00
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
void Link::setDescription(const string &description) {
|
2010-02-04 13:33:47 +02:00
|
|
|
this->description = description;
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
|
2014-07-16 22:02:50 +03:00
|
|
|
const string &Link::getLaunchMsg() {
|
|
|
|
return launchMsg;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &Link::getIcon() {
|
2010-02-04 13:33:47 +02:00
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2013-08-02 22:20:10 +03:00
|
|
|
void Link::loadIcon() {
|
|
|
|
if (icon.compare(0, 5, "skin:") == 0) {
|
2015-04-21 21:32:33 +03:00
|
|
|
setIconPath(gmenu2x.sc.getSkinFilePath(icon.substr(5, string::npos)));
|
2013-08-02 22:20:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
void Link::setIcon(const string &icon) {
|
2013-07-19 00:00:18 +03:00
|
|
|
this->icon = icon;
|
|
|
|
|
|
|
|
if (icon.compare(0, 5, "skin:") == 0)
|
2015-04-21 21:32:33 +03:00
|
|
|
this->iconPath = gmenu2x.sc.getSkinFilePath(
|
2013-07-19 00:00:18 +03:00
|
|
|
icon.substr(5, string::npos));
|
|
|
|
else
|
|
|
|
this->iconPath = icon;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
edited = true;
|
2010-05-01 19:55:11 +03:00
|
|
|
updateSurfaces();
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &Link::searchIcon() {
|
2015-04-21 21:32:33 +03:00
|
|
|
iconPath = gmenu2x.sc.getSkinFilePath("icons/generic.png");
|
2010-02-04 13:33:47 +02:00
|
|
|
return iconPath;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &Link::getIconPath() {
|
2010-02-04 13:33:47 +02:00
|
|
|
if (iconPath.empty()) searchIcon();
|
|
|
|
return iconPath;
|
|
|
|
}
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
void Link::setIconPath(const string &icon) {
|
2010-02-04 13:33:47 +02:00
|
|
|
if (fileExists(icon))
|
|
|
|
iconPath = icon;
|
|
|
|
else
|
2015-04-21 21:32:33 +03:00
|
|
|
iconPath = gmenu2x.sc.getSkinFilePath("icons/generic.png");
|
2010-05-01 19:55:11 +03:00
|
|
|
updateSurfaces();
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Link::setSize(int w, int h) {
|
2013-08-14 05:21:56 +03:00
|
|
|
rect.w = w;
|
|
|
|
rect.h = h;
|
2010-02-04 13:33:47 +02:00
|
|
|
recalcCoordinates();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Link::setPosition(int x, int y) {
|
2013-08-14 05:21:56 +03:00
|
|
|
rect.x = x;
|
|
|
|
rect.y = y;
|
2010-02-04 13:33:47 +02:00
|
|
|
recalcCoordinates();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Link::recalcCoordinates() {
|
|
|
|
iconX = rect.x+(rect.w-32)/2;
|
2015-04-21 21:32:33 +03:00
|
|
|
padding = (gmenu2x.skinConfInt["linkHeight"] - 32 - gmenu2x.font->getLineSpacing()) / 3;
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
2011-12-30 17:54:36 +02:00
|
|
|
|
|
|
|
void Link::run() {
|
|
|
|
this->action();
|
|
|
|
}
|