Root/
Source at commit a794a1c created 13 years 10 months ago. By Lars-Peter Clausen, Cache current icon surface. By doing so we safe a huge number of hash map lookups. | |
---|---|
1 | /*************************************************************************** |
2 | * Copyright (C) 2006 by Massimiliano Torromeo * |
3 | * massimiliano.torromeo@gmail.com * |
4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * |
6 | * it under the terms of the GNU General Public License as published by * |
7 | * the Free Software Foundation; either version 2 of the License, or * |
8 | * (at your option) any later version. * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the * |
17 | * Free Software Foundation, Inc., * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | ***************************************************************************/ |
20 | #include <fstream> |
21 | #include <sstream> |
22 | #include "link.h" |
23 | #include "menu.h" |
24 | #include "selector.h" |
25 | |
26 | using namespace std; |
27 | using namespace fastdelegate; |
28 | |
29 | Link::Link(GMenu2X *gmenu2x) : Button(gmenu2x, true) { |
30 | this->gmenu2x = gmenu2x; |
31 | action = MakeDelegate(this, &Link::run); |
32 | edited = false; |
33 | iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png"); |
34 | iconX = 0; |
35 | padding = 0; |
36 | |
37 | updateSurfaces(); |
38 | } |
39 | |
40 | void Link::run() {} |
41 | |
42 | void Link::paint() { |
43 | iconSurface->blit(gmenu2x->s, iconX, rect.y+padding, 32,32); |
44 | gmenu2x->s->write( gmenu2x->font, getTitle(), iconX+16, rect.y+gmenu2x->skinConfInt["linkHeight"]-padding, SFontHAlignCenter, SFontVAlignBottom ); |
45 | } |
46 | |
47 | bool Link::paintHover() { |
48 | if (gmenu2x->useSelectionPng) |
49 | gmenu2x->sc["imgs/selection.png"]->blit(gmenu2x->s,rect,SFontHAlignCenter,SFontVAlignMiddle); |
50 | else |
51 | gmenu2x->s->box(rect.x, rect.y, rect.w, rect.h, gmenu2x->skinConfColors["selectionBg"]); |
52 | return true; |
53 | } |
54 | |
55 | void Link::updateSurfaces() |
56 | { |
57 | iconSurface = gmenu2x->sc[getIconPath()]; |
58 | } |
59 | |
60 | string Link::getTitle() { |
61 | return title; |
62 | } |
63 | |
64 | void Link::setTitle(string title) { |
65 | this->title = title; |
66 | edited = true; |
67 | } |
68 | |
69 | string Link::getDescription() { |
70 | return description; |
71 | } |
72 | |
73 | void Link::setDescription(string description) { |
74 | this->description = description; |
75 | edited = true; |
76 | } |
77 | |
78 | string Link::getIcon() { |
79 | return icon; |
80 | } |
81 | |
82 | void Link::setIcon(string icon) { |
83 | string skinpath = gmenu2x->getExePath()+"skins/"+gmenu2x->confStr["skin"]; |
84 | if (icon.substr(0,skinpath.length()) == skinpath) { |
85 | string tempIcon = icon.substr(skinpath.length(), icon.length()); |
86 | string::size_type pos = tempIcon.find("/"); |
87 | if (pos != string::npos) |
88 | icon = "skin:"+tempIcon.substr(pos+1,icon.length()); |
89 | } |
90 | |
91 | iconPath = strreplace(icon,"skin:",skinpath+"/"); |
92 | if (iconPath.empty() || !fileExists(iconPath)) { |
93 | iconPath = strreplace(icon,"skin:",gmenu2x->getExePath()+"skins/Default/"); |
94 | if (!fileExists(iconPath)) searchIcon(); |
95 | } |
96 | |
97 | this->icon = icon; |
98 | edited = true; |
99 | updateSurfaces(); |
100 | } |
101 | |
102 | string Link::searchIcon() { |
103 | iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png"); |
104 | return iconPath; |
105 | } |
106 | |
107 | string Link::getIconPath() { |
108 | if (iconPath.empty()) searchIcon(); |
109 | return iconPath; |
110 | } |
111 | |
112 | void Link::setIconPath(string icon) { |
113 | if (fileExists(icon)) |
114 | iconPath = icon; |
115 | else |
116 | iconPath = gmenu2x->sc.getSkinFilePath("icons/generic.png"); |
117 | updateSurfaces(); |
118 | } |
119 | |
120 | void Link::setSize(int w, int h) { |
121 | Button::setSize(w,h); |
122 | recalcCoordinates(); |
123 | } |
124 | |
125 | void Link::setPosition(int x, int y) { |
126 | Button::setPosition(x,y); |
127 | recalcCoordinates(); |
128 | } |
129 | |
130 | void Link::recalcCoordinates() { |
131 | iconX = rect.x+(rect.w-32)/2; |
132 | padding = (gmenu2x->skinConfInt["linkHeight"] - 32 - gmenu2x->font->getLineHeight()) / 3; |
133 | } |
134 |
Branches:
install_locations
master
opkrun
packages