Root/
Source at commit 00d3c3b57008bddf8770c51271db9d766acaf854 created 8 years 5 months ago. By Maarten ter Huurne, Gave Layer class a protected constructor | |
---|---|
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 | |
21 | #include "link.h" |
22 | |
23 | #include "gmenu2x.h" |
24 | #include "menu.h" |
25 | #include "selector.h" |
26 | #include "surface.h" |
27 | #include "utilities.h" |
28 | |
29 | #include <fstream> |
30 | #include <sstream> |
31 | |
32 | using namespace std; |
33 | |
34 | |
35 | Link::Link(GMenu2X& gmenu2x, Action action) |
36 | : gmenu2x(gmenu2x) |
37 | , action(action) |
38 | , lastTick(0) |
39 | { |
40 | rect.w = gmenu2x.skinConfInt["linkWidth"]; |
41 | rect.h = gmenu2x.skinConfInt["linkHeight"]; |
42 | edited = false; |
43 | iconPath = gmenu2x.sc.getSkinFilePath("icons/generic.png"); |
44 | iconX = 0; |
45 | padding = 0; |
46 | |
47 | updateSurfaces(); |
48 | } |
49 | |
50 | void Link::paint() { |
51 | Surface& s = *gmenu2x.s; |
52 | |
53 | if (iconSurface) { |
54 | iconSurface->blit(s, iconX, rect.y+padding, 32,32); |
55 | } |
56 | gmenu2x.font->write(s, getTitle(), iconX+16, rect.y + gmenu2x.skinConfInt["linkHeight"]-padding, Font::HAlignCenter, Font::VAlignBottom); |
57 | } |
58 | |
59 | void Link::paintHover() { |
60 | Surface& s = *gmenu2x.s; |
61 | |
62 | if (gmenu2x.useSelectionPng) |
63 | gmenu2x.sc["imgs/selection.png"]->blit(s, rect, Font::HAlignCenter, Font::VAlignMiddle); |
64 | else |
65 | s.box(rect.x, rect.y, rect.w, rect.h, gmenu2x.skinConfColors[COLOR_SELECTION_BG]); |
66 | } |
67 | |
68 | void Link::updateSurfaces() |
69 | { |
70 | iconSurface = gmenu2x.sc[getIconPath()]; |
71 | } |
72 | |
73 | const string &Link::getTitle() { |
74 | return title; |
75 | } |
76 | |
77 | void Link::setTitle(const string &title) { |
78 | this->title = title; |
79 | edited = true; |
80 | } |
81 | |
82 | const string &Link::getDescription() { |
83 | return description; |
84 | } |
85 | |
86 | void Link::setDescription(const string &description) { |
87 | this->description = description; |
88 | edited = true; |
89 | } |
90 | |
91 | const string &Link::getLaunchMsg() { |
92 | return launchMsg; |
93 | } |
94 | |
95 | const string &Link::getIcon() { |
96 | return icon; |
97 | } |
98 | |
99 | void Link::loadIcon() { |
100 | if (icon.compare(0, 5, "skin:") == 0) { |
101 | setIconPath(gmenu2x.sc.getSkinFilePath(icon.substr(5, string::npos))); |
102 | } |
103 | } |
104 | |
105 | void Link::setIcon(const string &icon) { |
106 | this->icon = icon; |
107 | |
108 | if (icon.compare(0, 5, "skin:") == 0) |
109 | this->iconPath = gmenu2x.sc.getSkinFilePath( |
110 | icon.substr(5, string::npos)); |
111 | else |
112 | this->iconPath = icon; |
113 | |
114 | edited = true; |
115 | updateSurfaces(); |
116 | } |
117 | |
118 | const string &Link::searchIcon() { |
119 | iconPath = gmenu2x.sc.getSkinFilePath("icons/generic.png"); |
120 | return iconPath; |
121 | } |
122 | |
123 | const string &Link::getIconPath() { |
124 | if (iconPath.empty()) searchIcon(); |
125 | return iconPath; |
126 | } |
127 | |
128 | void Link::setIconPath(const string &icon) { |
129 | if (fileExists(icon)) |
130 | iconPath = icon; |
131 | else |
132 | iconPath = gmenu2x.sc.getSkinFilePath("icons/generic.png"); |
133 | updateSurfaces(); |
134 | } |
135 | |
136 | void Link::setSize(int w, int h) { |
137 | rect.w = w; |
138 | rect.h = h; |
139 | recalcCoordinates(); |
140 | } |
141 | |
142 | void Link::setPosition(int x, int y) { |
143 | rect.x = x; |
144 | rect.y = y; |
145 | recalcCoordinates(); |
146 | } |
147 | |
148 | void Link::recalcCoordinates() { |
149 | iconX = rect.x+(rect.w-32)/2; |
150 | padding = (gmenu2x.skinConfInt["linkHeight"] - 32 - gmenu2x.font->getLineSpacing()) / 3; |
151 | } |
152 | |
153 | void Link::run() { |
154 | this->action(); |
155 | } |
156 |
Branches:
install_locations
master
opkrun
packages