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 "wallpaperdialog.h" |
| 22 | |
| 23 | #include "debug.h" |
| 24 | #include "buttonbox.h" |
| 25 | #include "filelister.h" |
| 26 | #include "gmenu2x.h" |
| 27 | #include "iconbutton.h" |
| 28 | #include "surface.h" |
| 29 | #include "utilities.h" |
| 30 | |
| 31 | #include <iostream> |
| 32 | |
| 33 | using namespace std; |
| 34 | |
| 35 | WallpaperDialog::WallpaperDialog(GMenu2X *gmenu2x, Touchscreen &ts_) |
| 36 | : Dialog(gmenu2x) |
| 37 | , ts(ts_) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | bool WallpaperDialog::exec() |
| 42 | { |
| 43 | bool close = false, result = true; |
| 44 | |
| 45 | FileLister fl; |
| 46 | fl.setFilter("png"); |
| 47 | |
| 48 | string filepath = GMenu2X::getHome() + "/skins/" |
| 49 | + gmenu2x->confStr["skin"] + "/wallpapers"; |
| 50 | if (fileExists(filepath)) |
| 51 | fl.setPath(filepath, true); |
| 52 | |
| 53 | filepath = GMENU2X_SYSTEM_DIR "/skins/" |
| 54 | + gmenu2x->confStr["skin"] + "/wallpapers"; |
| 55 | if (fileExists(filepath)) { |
| 56 | fl.setPath(filepath, false); |
| 57 | fl.browse(false); |
| 58 | } |
| 59 | |
| 60 | if (gmenu2x->confStr["skin"] != "Default") { |
| 61 | filepath = GMenu2X::getHome() + "/skins/Default/wallpapers"; |
| 62 | if (fileExists(filepath)) { |
| 63 | fl.setPath(filepath, false); |
| 64 | fl.browse(false); |
| 65 | } |
| 66 | |
| 67 | filepath = GMENU2X_SYSTEM_DIR "/skins/Default/wallpapers"; |
| 68 | if (fileExists(filepath)) { |
| 69 | fl.setPath(filepath, false); |
| 70 | fl.browse(false); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | vector<string> wallpapers = fl.getFiles(); |
| 75 | |
| 76 | DEBUG("Wallpapers: %i\n", wallpapers.size()); |
| 77 | |
| 78 | uint i, selected = 0, firstElement = 0, iY; |
| 79 | |
| 80 | ButtonBox buttonbox(gmenu2x); |
| 81 | buttonbox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Select wallpaper"])); |
| 82 | buttonbox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x->tr["Exit"])); |
| 83 | |
| 84 | while (!close) { |
| 85 | if (selected>firstElement+9) firstElement=selected-9; |
| 86 | if (selected<firstElement) firstElement=selected; |
| 87 | |
| 88 | //Wallpaper |
| 89 | gmenu2x->sc[((string)"skin:wallpapers/" + wallpapers[selected]).c_str()]->blit(gmenu2x->s, 0, 0); |
| 90 | |
| 91 | gmenu2x->drawTopBar(gmenu2x->s); |
| 92 | gmenu2x->drawBottomBar(gmenu2x->s); |
| 93 | |
| 94 | drawTitleIcon("icons/wallpaper.png",true); |
| 95 | writeTitle("Wallpaper selection"); |
| 96 | writeSubTitle("Select an image from the list, to use as a wallpaper"); |
| 97 | |
| 98 | buttonbox.paint(5); |
| 99 | |
| 100 | //Selection |
| 101 | iY = selected-firstElement; |
| 102 | iY = 44+(iY*17); |
| 103 | gmenu2x->s->box(2, iY, 308, 16, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); |
| 104 | |
| 105 | //Files & Directories |
| 106 | gmenu2x->s->setClipRect(0,41,311,179); |
| 107 | for (i=firstElement; i<wallpapers.size() && i<firstElement+10; i++) { |
| 108 | iY = i-firstElement; |
| 109 | gmenu2x->s->write(gmenu2x->font, wallpapers[i], 5, 52+(iY*17), Font::HAlignLeft, Font::VAlignMiddle); |
| 110 | } |
| 111 | gmenu2x->s->clearClipRect(); |
| 112 | |
| 113 | gmenu2x->drawScrollBar(10, wallpapers.size(), firstElement); |
| 114 | gmenu2x->s->flip(); |
| 115 | |
| 116 | switch(gmenu2x->input.waitForPressedButton()) { |
| 117 | case InputManager::CANCEL: |
| 118 | close = true; |
| 119 | result = false; |
| 120 | break; |
| 121 | case InputManager::UP: |
| 122 | if (selected == 0) selected = wallpapers.size()-1; |
| 123 | else selected -= 1; |
| 124 | break; |
| 125 | case InputManager::ALTLEFT: |
| 126 | if ((int)(selected-9) < 0) selected = 0; |
| 127 | else selected -= 9; |
| 128 | break; |
| 129 | case InputManager::DOWN: |
| 130 | if (selected+1 >= wallpapers.size()) selected = 0; |
| 131 | else selected += 1; |
| 132 | break; |
| 133 | case InputManager::ALTRIGHT: |
| 134 | if (selected+9 >= wallpapers.size()) selected = wallpapers.size()-1; |
| 135 | else selected += 9; |
| 136 | break; |
| 137 | case InputManager::ACCEPT: |
| 138 | close = true; |
| 139 | if (wallpapers.size() > 0) |
| 140 | wallpaper = gmenu2x->sc.getSkinFilePath("wallpapers/" + wallpapers[selected]); |
| 141 | else result = false; |
| 142 | default: |
| 143 | break; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | for (uint i=0; i<wallpapers.size(); i++) |
| 148 | gmenu2x->sc.del("skin:wallpapers/" + wallpapers[i]); |
| 149 | |
| 150 | return result; |
| 151 | } |
| 152 |
Branches:
install_locations
master
opkrun
packages
