Root/
| 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 "settingsdialog.h" |
| 22 | |
| 23 | #include "gmenu2x.h" |
| 24 | #include "menusetting.h" |
| 25 | |
| 26 | #include <SDL.h> |
| 27 | #include <SDL_gfxPrimitives.h> |
| 28 | |
| 29 | using namespace std; |
| 30 | |
| 31 | SettingsDialog::SettingsDialog( |
| 32 | GMenu2X *gmenu2x_, InputManager &inputMgr_, Touchscreen &ts_, |
| 33 | const string &text_, const string &icon) |
| 34 | : Dialog(gmenu2x_) |
| 35 | , inputMgr(inputMgr_) |
| 36 | , ts(ts_) |
| 37 | , text(text_) |
| 38 | { |
| 39 | if (!icon.empty() && gmenu2x->sc[icon] != NULL) { |
| 40 | this->icon = icon; |
| 41 | } else { |
| 42 | this->icon = "icons/generic.png"; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | SettingsDialog::~SettingsDialog() { |
| 47 | for (vector<MenuSetting *>::iterator it = voices.begin(); |
| 48 | it != voices.end(); ++it) { |
| 49 | delete *it; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | bool SettingsDialog::exec() { |
| 54 | Surface bg(gmenu2x->bg); |
| 55 | bg.convertToDisplayFormat(); |
| 56 | |
| 57 | bool close = false, ts_pressed = false; |
| 58 | uint i, sel = 0, firstElement = 0; |
| 59 | |
| 60 | const int topBarHeight = gmenu2x->skinConfInt["topBarHeight"]; |
| 61 | SDL_Rect clipRect = { |
| 62 | 0, |
| 63 | static_cast<Sint16>(topBarHeight + 1), |
| 64 | static_cast<Uint16>(gmenu2x->resX - 9), |
| 65 | static_cast<Uint16>(gmenu2x->resY - topBarHeight - 25) |
| 66 | }; |
| 67 | SDL_Rect touchRect = { |
| 68 | 2, |
| 69 | static_cast<Sint16>(topBarHeight + 4), |
| 70 | static_cast<Uint16>(gmenu2x->resX - 12), |
| 71 | static_cast<Uint16>(clipRect.h) |
| 72 | }; |
| 73 | uint rowHeight = gmenu2x->font->getHeight() + 1; // gp2x=15+1 / pandora=19+1 |
| 74 | uint numRows = (gmenu2x->resY - topBarHeight - 20) / rowHeight; |
| 75 | |
| 76 | while (!close) { |
| 77 | if (ts.available()) ts.poll(); |
| 78 | |
| 79 | bg.blit(gmenu2x->s,0,0); |
| 80 | |
| 81 | gmenu2x->drawTopBar(gmenu2x->s); |
| 82 | //link icon |
| 83 | drawTitleIcon(icon); |
| 84 | writeTitle(text); |
| 85 | |
| 86 | gmenu2x->drawBottomBar(gmenu2x->s); |
| 87 | |
| 88 | if (sel>firstElement+numRows-1) firstElement=sel-numRows+1; |
| 89 | if (sel<firstElement) firstElement=sel; |
| 90 | |
| 91 | //selection |
| 92 | uint iY = topBarHeight + 2 + (sel - firstElement) * rowHeight; |
| 93 | gmenu2x->s->setClipRect(clipRect); |
| 94 | if (sel<voices.size()) { |
| 95 | gmenu2x->s->box( |
| 96 | 1, iY, 148, rowHeight - 2, |
| 97 | gmenu2x->skinConfColors[COLOR_SELECTION_BG] |
| 98 | ); |
| 99 | } |
| 100 | gmenu2x->s->clearClipRect(); |
| 101 | |
| 102 | //selected option |
| 103 | voices[sel]->drawSelected(iY); |
| 104 | |
| 105 | gmenu2x->s->setClipRect(clipRect); |
| 106 | if (ts_pressed && !ts.pressed()) { |
| 107 | ts_pressed = false; |
| 108 | } |
| 109 | if (ts.available() && ts.pressed() && !ts.inRect(touchRect)) { |
| 110 | ts_pressed = false; |
| 111 | } |
| 112 | for (i=firstElement; i<voices.size() && i<firstElement+numRows; i++) { |
| 113 | iY = i-firstElement; |
| 114 | voices[i]->draw(iY * rowHeight + topBarHeight + 2); |
| 115 | if (ts.available() && ts.pressed() && ts.inRect( |
| 116 | touchRect.x, touchRect.y + (iY * rowHeight), |
| 117 | touchRect.w, rowHeight |
| 118 | )) { |
| 119 | ts_pressed = true; |
| 120 | sel = i; |
| 121 | } |
| 122 | } |
| 123 | gmenu2x->s->clearClipRect(); |
| 124 | |
| 125 | gmenu2x->drawScrollBar(numRows, voices.size(), firstElement); |
| 126 | |
| 127 | //description |
| 128 | writeSubTitle(voices[sel]->getDescription()); |
| 129 | |
| 130 | gmenu2x->s->flip(); |
| 131 | voices[sel]->handleTS(); |
| 132 | |
| 133 | InputManager::Button button = inputMgr.waitForPressedButton(); |
| 134 | if (!voices[sel]->handleButtonPress(button)) { |
| 135 | switch (button) { |
| 136 | case InputManager::SETTINGS: |
| 137 | close = true; |
| 138 | break; |
| 139 | case InputManager::UP: |
| 140 | if (sel == 0) { |
| 141 | sel = voices.size() - 1; |
| 142 | } else { |
| 143 | sel -= 1; |
| 144 | } |
| 145 | break; |
| 146 | case InputManager::DOWN: |
| 147 | sel += 1; |
| 148 | if (sel>=voices.size()) sel = 0; |
| 149 | default: |
| 150 | break; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | return true; |
| 156 | } |
| 157 | |
| 158 | void SettingsDialog::addSetting(MenuSetting *set) { |
| 159 | voices.push_back(set); |
| 160 | } |
| 161 | |
| 162 | bool SettingsDialog::edited() { |
| 163 | for (uint i=0; i < voices.size(); i++) { |
| 164 | if (voices[i]->edited()) return true; |
| 165 | } |
| 166 | return false; |
| 167 | } |
| 168 |
Branches:
install_locations
master
opkrun
packages
