From 9b8f289ca3cf316d04c67196b939ae6efe421e6b Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Fri, 24 Jul 2009 20:34:55 +0000 Subject: [PATCH] *Added Filebrowser from libwiigui 1.03 (modified a bit). It will be used by giantpune later. Right now its not used. *Created a function to get SVN_REV to avoid long compiling times when small changes are done in the source. --- gui.pnproj | 2 +- source/filebrowser.cpp | 235 +++++++++++++++ source/filebrowser.h | 55 ++++ source/filelist.h | 14 +- source/getrev.c | 7 + source/getrev.h | 14 + source/images/addressbar_textbox.png | Bin 0 -> 1785 bytes source/images/bg_browser.png | Bin 0 -> 1746 bytes source/images/bg_browser_selection.png | Bin 0 -> 5922 bytes source/images/folder.png | Bin 0 -> 1565 bytes source/libwiigui/gui.h | 51 ++++ source/libwiigui/gui_element.cpp | 5 + source/libwiigui/gui_filebrowser.cpp | 402 +++++++++++++++++++++++++ source/network/networkops.cpp | 4 +- source/prompts/PromptWindows.cpp | 6 +- source/svnrev.h | 4 + source/testfilebrowser.cpp | 134 +++++++++ 17 files changed, 926 insertions(+), 7 deletions(-) create mode 100644 source/filebrowser.cpp create mode 100644 source/filebrowser.h create mode 100644 source/getrev.c create mode 100644 source/getrev.h create mode 100644 source/images/addressbar_textbox.png create mode 100644 source/images/bg_browser.png create mode 100644 source/images/bg_browser_selection.png create mode 100644 source/images/folder.png create mode 100644 source/libwiigui/gui_filebrowser.cpp create mode 100644 source/svnrev.h create mode 100644 source/testfilebrowser.cpp diff --git a/gui.pnproj b/gui.pnproj index 13660541..2fdea4f9 100644 --- a/gui.pnproj +++ b/gui.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/source/filebrowser.cpp b/source/filebrowser.cpp new file mode 100644 index 00000000..790fc448 --- /dev/null +++ b/source/filebrowser.cpp @@ -0,0 +1,235 @@ +/**************************************************************************** + * libwiigui Template + * Tantric 2009 + * + * modified by dimok + * + * filebrowser.cpp + * + * Generic file routines - reading, writing, browsing + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include "filebrowser.h" +#include "menu.h" + +BROWSERINFO browser; +BROWSERENTRY * browserList = NULL; // list of files/folders in browser + +/**************************************************************************** + * ResetBrowser() + * Clears the file browser memory, and allocates one initial entry + ***************************************************************************/ +void ResetBrowser() +{ + browser.numEntries = 0; + browser.selIndex = 0; + browser.pageIndex = 0; + + // Clear any existing values + if(browserList != NULL) + { + free(browserList); + browserList = NULL; + } + // set aside space for 1 entry + browserList = (BROWSERENTRY *)malloc(sizeof(BROWSERENTRY)); + memset(browserList, 0, sizeof(BROWSERENTRY)); +} + +/**************************************************************************** + * UpdateDirName() + * Update curent directory name for file browser + ***************************************************************************/ +int UpdateDirName() +{ + int size=0; + char * test; + char temp[1024]; + + /* current directory doesn't change */ + if (strcmp(browserList[browser.selIndex].filename,".") == 0) + { + return 0; + } + /* go up to parent directory */ + else if (strcmp(browserList[browser.selIndex].filename,"..") == 0) + { + /* determine last subdirectory namelength */ + sprintf(temp,"%s",browser.dir); + test = strtok(temp,"/"); + while (test != NULL) + { + size = strlen(test); + test = strtok(NULL,"/"); + } + + /* remove last subdirectory name */ + size = strlen(browser.dir) - size - 1; + browser.dir[size] = 0; + + return 1; + } + /* Open a directory */ + else + { + /* test new directory namelength */ + if ((strlen(browser.dir)+1+strlen(browserList[browser.selIndex].filename)) < MAXPATHLEN) + { + /* update current directory name */ + sprintf(browser.dir, "%s/%s",browser.dir, browserList[browser.selIndex].filename); + return 1; + } + else + { + return -1; + } + } +} + +/**************************************************************************** + * FileSortCallback + * + * Quick sort callback to sort file entries with the following order: + * . + * .. + * + * + ***************************************************************************/ +int FileSortCallback(const void *f1, const void *f2) +{ + /* Special case for implicit directories */ + if(((BROWSERENTRY *)f1)->filename[0] == '.' || ((BROWSERENTRY *)f2)->filename[0] == '.') + { + if(strcmp(((BROWSERENTRY *)f1)->filename, ".") == 0) { return -1; } + if(strcmp(((BROWSERENTRY *)f2)->filename, ".") == 0) { return 1; } + if(strcmp(((BROWSERENTRY *)f1)->filename, "..") == 0) { return -1; } + if(strcmp(((BROWSERENTRY *)f2)->filename, "..") == 0) { return 1; } + } + + /* If one is a file and one is a directory the directory is first. */ + if(((BROWSERENTRY *)f1)->isdir && !(((BROWSERENTRY *)f2)->isdir)) return -1; + if(!(((BROWSERENTRY *)f1)->isdir) && ((BROWSERENTRY *)f2)->isdir) return 1; + + return stricmp(((BROWSERENTRY *)f1)->filename, ((BROWSERENTRY *)f2)->filename); +} + +/*************************************************************************** + * Browse subdirectories + **************************************************************************/ +int +ParseDirectory() +{ + DIR_ITER *dir = NULL; + char fulldir[MAXPATHLEN]; + char filename[MAXPATHLEN]; + struct stat filestat; + + // reset browser + ResetBrowser(); + + // open the directory + sprintf(fulldir, "%s%s", browser.rootdir, browser.dir); // add currentDevice to path + dir = diropen(fulldir); + + // if we can't open the dir, try opening the root dir + if (dir == NULL) + { + sprintf(browser.dir,"/"); + dir = diropen(browser.rootdir); + if (dir == NULL) + { + return -1; + } + } + + // index files/folders + int entryNum = 0; + + while(dirnext(dir,filename,&filestat) == 0) + { + if(strcmp(filename,".") != 0) + { + BROWSERENTRY * newBrowserList = (BROWSERENTRY *)realloc(browserList, (entryNum+1) * sizeof(BROWSERENTRY)); + + if(!newBrowserList) // failed to allocate required memory + { + ResetBrowser(); + entryNum = -1; + break; + } + else + { + browserList = newBrowserList; + } + memset(&(browserList[entryNum]), 0, sizeof(BROWSERENTRY)); // clear the new entry + + strncpy(browserList[entryNum].filename, filename, MAXJOLIET); + + if(strcmp(filename,"..") == 0) + { + sprintf(browserList[entryNum].displayname, ".."); + } + else + { + strcpy(browserList[entryNum].displayname, filename); // crop name for display + } + + browserList[entryNum].length = filestat.st_size; + browserList[entryNum].isdir = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; // flag this as a dir + + entryNum++; + } + } + + // close directory + dirclose(dir); + + // Sort the file list + qsort(browserList, entryNum, sizeof(BROWSERENTRY), FileSortCallback); + + browser.numEntries = entryNum; + return entryNum; +} + +/**************************************************************************** + * BrowserChangeFolder + * + * Update current directory and set new entry list if directory has changed + ***************************************************************************/ +int BrowserChangeFolder() +{ + if(!UpdateDirName()) + return -1; + + ParseDirectory(); + + return browser.numEntries; +} + +/**************************************************************************** + * BrowseDevice + * Displays a list of files on the selected device + ***************************************************************************/ +int BrowseDevice(int device) +{ + sprintf(browser.dir, "/"); + switch(device) + { + case SD: + sprintf(browser.rootdir, "SD:"); + break; + case USB: + sprintf(browser.rootdir, "USB:"); + break; + } + ParseDirectory(); // Parse root directory + return browser.numEntries; +} diff --git a/source/filebrowser.h b/source/filebrowser.h new file mode 100644 index 00000000..c4357047 --- /dev/null +++ b/source/filebrowser.h @@ -0,0 +1,55 @@ +/**************************************************************************** + * libwiigui Template + * Tantric 2009 + * + * modified by dimok + * + * filebrowser.h + * + * Generic file routines - reading, writing, browsing + ****************************************************************************/ + +#ifndef _FILEBROWSER_H_ +#define _FILEBROWSER_H_ + +#include +#include + +#define MAXJOLIET 255 +#define MAXDISPLAY MAXPATHLEN + + +enum { + SD, + USB +}; + +typedef struct +{ + char dir[MAXPATHLEN]; // directory path of browserList + char rootdir[10]; // directory path of browserList + int numEntries; // # of entries in browserList + int selIndex; // currently selected index of browserList + int pageIndex; // starting index of browserList page display +} BROWSERINFO; + +typedef struct +{ + u64 offset; // DVD offset + u64 length; // file length in 64 bytes for sizes higher than 4GB + char isdir; // 0 - file, 1 - directory + char filename[MAXJOLIET + 1]; // full filename + char displayname[MAXDISPLAY + 1]; // name for browser display +} BROWSERENTRY; + +extern BROWSERINFO browser; +extern BROWSERENTRY * browserList; + +int UpdateDirName(); +int FileSortCallback(const void *f1, const void *f2); +void ResetBrowser(); +int ParseDirectory(); +int BrowserChangeFolder(); +int BrowseDevice(int device); + +#endif diff --git a/source/filelist.h b/source/filelist.h index 761a8efc..54f19368 100644 --- a/source/filelist.h +++ b/source/filelist.h @@ -101,6 +101,18 @@ extern const u32 bg_options_settings_png_size; extern const u8 settings_background_png[]; extern const u32 settings_background_png_size; +extern const u8 bg_browser_png[]; +extern const u32 bg_browser_png_size; + +extern const u8 folder_png[]; +extern const u32 folder_png_size; + +extern const u8 bg_browser_selection_png[]; +extern const u32 bg_browser_selection_png_size; + +extern const u8 addressbar_textbox_png[]; +extern const u32 addressbar_textbox_png_size; + extern const u8 browser_png[]; extern const u32 browser_png_size; @@ -315,7 +327,7 @@ extern const u8 Wiimote1_png[]; extern const u32 Wiimote1_png_size; extern const u8 Wiimote2_png[]; -extern const u32 Wiimote2_png_size; +extern const u32 Wiimote2_png_size; extern const u8 wifi1_png[]; extern const u32 wifi1_png_size; diff --git a/source/getrev.c b/source/getrev.c new file mode 100644 index 00000000..3c461f77 --- /dev/null +++ b/source/getrev.c @@ -0,0 +1,7 @@ +#include "svnrev.h" + +char *GetRev() { + + return SVN_REV; + +} diff --git a/source/getrev.h b/source/getrev.h new file mode 100644 index 00000000..6138424b --- /dev/null +++ b/source/getrev.h @@ -0,0 +1,14 @@ +#ifndef GETREV_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +char *GetRev(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/source/images/addressbar_textbox.png b/source/images/addressbar_textbox.png new file mode 100644 index 0000000000000000000000000000000000000000..856be7662b3911adbf635db49ee8cec1652227e2 GIT binary patch literal 1785 zcmZXUeKgc*6vywpPfVGO$-9}QEoW;pq0o!@QO%4$(oiePYI^ZfMz4}A=7&DyI}vIYeHfZ6%~whQaLf!`Ym(^Uplb{XNgU-}|}uxj#vKMKg`8 zi~wM!k9f5|0BHcN9hr2rl5cV!MH_0k*IF-t!jtiOzYMhJZ5R8m1&I3w08arJHlY7b zfP;L1E-ApWYyk5;*;miK1fU=BS?#qU_WZWsKX!2_Y@M@$Uw;4oElVCAh!>@mmX75m z#jr{>`CHT$KxV!@oZ70En-p#CoHaf=TmfusA^)M6!V^%awZ~5$#$j8qI&o!Hzr&4k zy)he8>}e?(HVl1iO^RVQlQ1a6e;E-ExMPsCa{Obf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cX7_hWLNF>gLUxmltu$0?m>+4{neH+OCC^#A=}O5>{r*{s4;? zunm?>(U+>JV3tL$&Y{3x4VB?Z-6rT=@1+5W4mOIub}yNc7|_pWjqmE4-qPfM0je{? AG5`Po literal 0 HcmV?d00001 diff --git a/source/images/bg_browser.png b/source/images/bg_browser.png new file mode 100644 index 0000000000000000000000000000000000000000..f7796934839c3d5490cb28861884dec9ceb08a8d GIT binary patch literal 1746 zcmeAS@N?(olHy`uVBq!ia0y~yV3Gl{e{iq?$>m$@4+1I464!{5;QX|b^2DN42FH~A zq*MjZ+{E-3nbD5iypH5rJBZ7CoBpVb#C2 z)yc$oc8~6}&y5C#Gh^oMt@)Yy*`{#y)vjF^Gfb2i7VKB?ob>u%(YYNGp8Dr?jTycy zoqhG{)%bhQn+vCLx=TsPFQ2|OXyuo{tx;R=FkEPNGM+PUp4@W(`%C)2s(6}J3CUz; ztZBKh;`(d-Wy_W=+PHC}MqjcvA4Bb`n>lXm?Ccl6eJd-etNR!G>r#4V#hpFn1uZMx zR)$pV-LXT$*Uv91k>P>-LU}WD^Tl)L&i(r3{Q65TEb3nT`((Q@u>bLoua_QDV4o@y?x?9c!L)^<7ba{P=OAOA;$%Ltoa`sF1Z`;ZnWFg62Jl;FM=! zIFVISViIF_LRjWJ8$0`28HNcrFI))N;q#2MPcVKt14HGVtRXzi0#WyFfsf&+rrEsAj8lAlz>t!>|h>(Qm|lP0P;Z8K}IC1!96hVd(!HwyJ{I2 zQZBBP_OW1SIK;`v-~hC#i5W%#O$G4~6p~fHnjXJoY&bL%q5-QC3`boMKlOd@!z~dE z3akC@CLCg95b-0deO}YH^p!1tFU(!a#PFqy6Wuc$d|mV?Q zH0A&U2pS03!y+NOm|;PI8YC#O1|CFT!}0|+_ocU)u`_IXb%htG-r*sJfe43yLfocl zTlDPqx1PDVe1siu!(`pd#1Q+MNTZpeXEQUj8b8GAIj|#GpZ>nLVXGy>gwW-A20-;( z>X7t+a4RU#fIKMmKyb_5TQ)iVS)gzU2c`{>DYz6vlZ*m$`bq|(9S=0@fo8!pE`|%H zAZ`CGAr>Gx1Ca`$7C@8O5Bq{B9fkl4VNwz+FqRzjr@XH|{P7EeLl|+%0;iu@o|frv zi&}ddWabP=`mLCCu<+??5e9|+-DNvY3CmPpzkWT8kKx3dSFg62)}0oX*&i1d7iGzy zuz7b`#dLLxItweSPuijk3X=`)TG-q3`=KJy|Wv@IX;rUH#(2hYx3)nC+{4v2WYKiFGfYr)~cE^V+p(FBlkZS=rh3 zZQH*6@a3<5-;eSCjqi0^{Bcu=R;{(6p=I87CnAP!YoTzfr zKbG})Y>ADxzW!s2I#VkvsZgz{85I>4UjMf}Vz{6_>+G}KjF^}hm-O`X{r6jsU5~Vv zPycJ`B_-GV^6B9(f=o{;e@Sfo!*Id;U&p^&>5t!j`t<48p+ipV_>bTH_s5i1@IMQ~ rh4e`(CrkJLp90PDt-pgC7#U30#XOYS+-MD~q!>J1{an^LB{Ts5rzcAK literal 0 HcmV?d00001 diff --git a/source/images/bg_browser_selection.png b/source/images/bg_browser_selection.png new file mode 100644 index 0000000000000000000000000000000000000000..54e7d9d0c999f86e6bef8e0a043a321e3a50ff02 GIT binary patch literal 5922 zcmZ8kXCT{M+y5sd2x`SBElLqBHKL`I*sIiPZ4!IbDr(e zXe+2a8hez;8~4-adEWQUm*m5_&h=Z@IVZ9DcQoi>oG<_Y=(RLe4FLcQC;#T9h5`Uc zo@Q_s0AR8%Dk}Q=&Yr%WKF*$Ayjm(Myk6d(jxKHv01)sp`-T7AyW?!p1C9QV^1q0~ zg;fZR^t_GI?}k)u($8ZM6z7mq<(CS;Olqo>tV%dOXu@N@a=y4IET)w^nK!Q;12-@T zL{=F4E-W;rrQvy;Lhk1_9>_ZpLdNQV<IbH1($aaAbEC3 zVEdqXLW%**E4*rP++uQ&AG;)=#oJwml<4X2zp?0T+Bt_i%_psFO7D&yBy_BtA{c&T zr?$Xf!=(V9(9gVG$#&2_z?=sHX@all16LF&mcjg(b8c99FDQ2lJ0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YG%^x6A6@`34rUm1uVG$ql~om*cKFr#wM!4J&)mC2eXM&+EWuEhgb+F)Ry;=$NZ z38ILl6(Ca&BxNW~1t=$z2hN;1!yU(2VT_I9SG|E0C6~6TfRuLAZ**8m)l*8r!9J%e zL3Wyz1{fy*O?4=snE)&-Ea2h7?!%9}H0QX4FO;yQ5*xKIt+b-ju1s(N-HJ_#N@B)n zsklrk!R(4sWCKttl~6-QaAHZ{!?`||FvTX2Qjhxtm0g<_!7iaRGsu#@+R>iJ`hN`6 z@t|0)O=sJVv8<5NMa!}Vk;;cLwL-|KeZ5^scRikDtQ!xW9V8yTJlBJq>q%uf>&=L? z(1Za3u;Qo%PQJ*;?|=I3V0`MG%zZ#ph5&v>0D}l=N+@2qv33R8t#!;YLhUKIg%WcM zy~~){#Y#}S@aM_X=TDqlv=wg-zs%y-<0y0;x6}@X_q{bbdH6jhiOLKheT5dK-(Ut8 zj(zgk>MPG5oVs_sUbpk5xq-VLm}gPA_|M9vrTT%#m&?^k{MFafaB=Bcek`zF;88oL z7q5;@yoO19Ao1i3)P*|*pwD}ad_I4A?(F6HCl2o|J~TC0bPCmLwedsIwUs6KYxyiT zpAdA1)Mta99zS|;fAzauvH#<~{@M&4P>->=0pvEnjL82#PInr>e*z2ubc!=Z?@D#i P00000NkvXXu0mjfpLXqv literal 0 HcmV?d00001 diff --git a/source/libwiigui/gui.h b/source/libwiigui/gui.h index 0e53a304..d88dda81 100644 --- a/source/libwiigui/gui.h +++ b/source/libwiigui/gui.h @@ -232,6 +232,9 @@ class GuiElement //!Set the element's parent //!\param e Pointer to parent element void SetParent(GuiElement * e); + //!Gets the element's parent + //!\return Pointer to parent element + GuiElement * GetParent(); //!Gets the current leftmost coordinate of the element //!Considers horizontal alignment, x offset, width, and parent element's GetLeft() / GetWidth() values //!\return left coordinate @@ -1029,4 +1032,52 @@ class GuiOptionBrowser : public GuiElement GuiTrigger * trigB; GuiTrigger * trigHeldA; }; + +//!Display a list of files +class GuiFileBrowser : public GuiElement +{ + public: + GuiFileBrowser(int w, int h); + ~GuiFileBrowser(); + void DisableTriggerUpdate(bool set); + void ResetState(); + void SetFocus(int f); + void Draw(); + void TriggerUpdate(); + void Update(GuiTrigger * t); + GuiButton * fileList[PAGESIZE]; + protected: + int selectedItem; + bool listChanged; + bool triggerdisabled; + + GuiText * fileListText[PAGESIZE]; + GuiText * fileListTextOver[PAGESIZE]; + GuiImage * fileListBg[PAGESIZE]; + GuiImage * fileListFolder[PAGESIZE]; + + GuiButton * arrowUpBtn; + GuiButton * arrowDownBtn; + GuiButton * scrollbarBoxBtn; + + GuiImage * bgFileSelectionImg; + GuiImage * scrollbarImg; + GuiImage * arrowDownImg; + GuiImage * arrowUpImg; + GuiImage * scrollbarBoxImg; + + GuiImageData * bgFileSelection; + GuiImageData * bgFileSelectionEntry; + GuiImageData * fileFolder; + GuiImageData * scrollbar; + GuiImageData * arrowDown; + GuiImageData * arrowUp; + GuiImageData * scrollbarBox; + + GuiSound * btnSoundOver; + GuiSound * btnSoundClick; + GuiTrigger * trigA; + GuiTrigger * trigHeldA; +}; + #endif diff --git a/source/libwiigui/gui_element.cpp b/source/libwiigui/gui_element.cpp index 6b53f277..0fa825c7 100644 --- a/source/libwiigui/gui_element.cpp +++ b/source/libwiigui/gui_element.cpp @@ -80,6 +80,11 @@ void GuiElement::SetParent(GuiElement * e) LOCK(this); parentElement = e; } + +GuiElement * GuiElement::GetParent() +{ + return parentElement; +} /** * Get the left position of the GuiElement. * @see SetLeft() diff --git a/source/libwiigui/gui_filebrowser.cpp b/source/libwiigui/gui_filebrowser.cpp new file mode 100644 index 00000000..c7986b0e --- /dev/null +++ b/source/libwiigui/gui_filebrowser.cpp @@ -0,0 +1,402 @@ +/**************************************************************************** + * libwiigui + * + * Tantric 2009 + * + * gui_filebrowser.cpp + * + * GUI class definitions + ***************************************************************************/ + +#include "gui.h" +#include "filebrowser.h" + +#define FILEBROWSERSIZE 8 +/** + * Constructor for the GuiFileBrowser class. + */ +GuiFileBrowser::GuiFileBrowser(int w, int h) +{ + width = w; + height = h; + selectedItem = 0; + selectable = true; + listChanged = true; // trigger an initial list update + triggerdisabled = false; // trigger disable + focus = 1; // allow focus + + trigA = new GuiTrigger; + trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); + + trigHeldA = new GuiTrigger; + trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); + + btnSoundOver = new GuiSound(button_over_pcm, button_over_pcm_size, SOUND_PCM); + btnSoundClick = new GuiSound(button_click_pcm, button_click_pcm_size, SOUND_PCM); + + bgFileSelection = new GuiImageData(bg_browser_png); + bgFileSelectionImg = new GuiImage(bgFileSelection); + bgFileSelectionImg->SetParent(this); + bgFileSelectionImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); + + bgFileSelectionEntry = new GuiImageData(bg_browser_selection_png); + fileFolder = new GuiImageData(folder_png); + + scrollbar = new GuiImageData(scrollbar_png); + scrollbarImg = new GuiImage(scrollbar); + scrollbarImg->SetParent(this); + scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); + scrollbarImg->SetPosition(0, 30); + + arrowDown = new GuiImageData(scrollbar_arrowdown_png); + arrowDownImg = new GuiImage(arrowDown); + arrowUp = new GuiImageData(scrollbar_arrowup_png); + arrowUpImg = new GuiImage(arrowUp); + scrollbarBox = new GuiImageData(scrollbar_box_png); + scrollbarBoxImg = new GuiImage(scrollbarBox); + + arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight()); + arrowUpBtn->SetParent(this); + arrowUpBtn->SetImage(arrowUpImg); + arrowUpBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); + arrowUpBtn->SetSelectable(false); + arrowUpBtn->SetClickable(false); + arrowUpBtn->SetHoldable(true); + arrowUpBtn->SetTrigger(trigHeldA); + arrowUpBtn->SetSoundOver(btnSoundOver); + arrowUpBtn->SetSoundClick(btnSoundClick); + + arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight()); + arrowDownBtn->SetParent(this); + arrowDownBtn->SetImage(arrowDownImg); + arrowDownBtn->SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); + arrowDownBtn->SetSelectable(false); + arrowDownBtn->SetClickable(false); + arrowDownBtn->SetHoldable(true); + arrowDownBtn->SetTrigger(trigHeldA); + arrowDownBtn->SetSoundOver(btnSoundOver); + arrowDownBtn->SetSoundClick(btnSoundClick); + + scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight()); + scrollbarBoxBtn->SetParent(this); + scrollbarBoxBtn->SetImage(scrollbarBoxImg); + scrollbarBoxBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); + scrollbarBoxBtn->SetMinY(0); + scrollbarBoxBtn->SetMaxY(136); + scrollbarBoxBtn->SetSelectable(false); + scrollbarBoxBtn->SetClickable(false); + scrollbarBoxBtn->SetHoldable(true); + scrollbarBoxBtn->SetTrigger(trigHeldA); + + for(int i=0; iSetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); + fileListText[i]->SetPosition(5,0); + fileListText[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (arrowDownImg->GetWidth()+20), GuiText::DOTTED); + + fileListTextOver[i] = new GuiText(NULL,20, (GXColor){0, 0, 0, 0xff}); + fileListTextOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); + fileListTextOver[i]->SetPosition(5,0); + fileListTextOver[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (arrowDownImg->GetWidth()+20), GuiText::SCROLL); + + fileListBg[i] = new GuiImage(bgFileSelectionEntry); + fileListFolder[i] = new GuiImage(fileFolder); + + fileList[i] = new GuiButton(512,30); + fileList[i]->SetParent(this); + fileList[i]->SetLabel(fileListText[i]); + fileList[i]->SetLabelOver(fileListTextOver[i]); + fileList[i]->SetImageOver(fileListBg[i]); + fileList[i]->SetPosition(2,30*i+3); + fileList[i]->SetTrigger(trigA); + fileList[i]->SetRumble(false); + fileList[i]->SetSoundClick(btnSoundClick); + } +} + +/** + * Destructor for the GuiFileBrowser class. + */ +GuiFileBrowser::~GuiFileBrowser() +{ + delete arrowUpBtn; + delete arrowDownBtn; + delete scrollbarBoxBtn; + + delete bgFileSelectionImg; + delete scrollbarImg; + delete arrowDownImg; + delete arrowUpImg; + delete scrollbarBoxImg; + + delete bgFileSelection; + delete bgFileSelectionEntry; + delete fileFolder; + delete scrollbar; + delete arrowDown; + delete arrowUp; + delete scrollbarBox; + + delete btnSoundOver; + delete btnSoundClick; + delete trigHeldA; + delete trigA; + + for(int i=0; iResetState(); + + if(f == 1) + fileList[selectedItem]->SetState(STATE_SELECTED); +} + +void GuiFileBrowser::DisableTriggerUpdate(bool set) +{ + triggerdisabled = set; +} + +void GuiFileBrowser::ResetState() +{ + state = STATE_DEFAULT; + stateChan = -1; + selectedItem = 0; + + for(int i=0; iResetState(); + } +} + +void GuiFileBrowser::TriggerUpdate() +{ + listChanged = true; +} + +/** + * Draw the button on screen + */ +void GuiFileBrowser::Draw() +{ + if(!this->IsVisible()) + return; + + bgFileSelectionImg->Draw(); + + for(int i=0; iDraw(); + } + + scrollbarImg->Draw(); + arrowUpBtn->Draw(); + arrowDownBtn->Draw(); + scrollbarBoxBtn->Draw(); + + this->UpdateEffects(); +} + +void GuiFileBrowser::Update(GuiTrigger * t) +{ + if(state == STATE_DISABLED || !t || triggerdisabled) + return; + + int position = 0; + int positionWiimote = 0; + + arrowUpBtn->Update(t); + arrowDownBtn->Update(t); + scrollbarBoxBtn->Update(t); + + // move the file listing to respond to wiimote cursor movement + if(scrollbarBoxBtn->GetState() == STATE_HELD && + scrollbarBoxBtn->GetStateChan() == t->chan && + t->wpad.ir.valid && + browser.numEntries > FILEBROWSERSIZE + ) + { + scrollbarBoxBtn->SetPosition(0,0); + positionWiimote = t->wpad.ir.y - 60 - scrollbarBoxBtn->GetTop(); + + if(positionWiimote < scrollbarBoxBtn->GetMinY()) + positionWiimote = scrollbarBoxBtn->GetMinY(); + else if(positionWiimote > scrollbarBoxBtn->GetMaxY()) + positionWiimote = scrollbarBoxBtn->GetMaxY(); + + browser.pageIndex = (positionWiimote * browser.numEntries)/136.0 - selectedItem; + + if(browser.pageIndex <= 0) + { + browser.pageIndex = 0; + } + else if(browser.pageIndex+FILEBROWSERSIZE >= browser.numEntries) + { + browser.pageIndex = browser.numEntries-FILEBROWSERSIZE; + } + listChanged = true; + focus = false; + } + + if(arrowDownBtn->GetState() == STATE_HELD && arrowDownBtn->GetStateChan() == t->chan) + { + t->wpad.btns_h |= WPAD_BUTTON_DOWN; + if(!this->IsFocused()) + ((GuiWindow *)this->GetParent())->ChangeFocus(this); + } + else if(arrowUpBtn->GetState() == STATE_HELD && arrowUpBtn->GetStateChan() == t->chan) + { + t->wpad.btns_h |= WPAD_BUTTON_UP; + if(!this->IsFocused()) + ((GuiWindow *)this->GetParent())->ChangeFocus(this); + } + + // pad/joystick navigation + if(!focus) + { + goto endNavigation; // skip navigation + listChanged = false; + } + + if(t->Right()) + { + if(browser.pageIndex < browser.numEntries && browser.numEntries > FILEBROWSERSIZE) + { + browser.pageIndex += FILEBROWSERSIZE; + if(browser.pageIndex+FILEBROWSERSIZE >= browser.numEntries) + browser.pageIndex = browser.numEntries-FILEBROWSERSIZE; + listChanged = true; + } + } + else if(t->Left()) + { + if(browser.pageIndex > 0) + { + browser.pageIndex -= FILEBROWSERSIZE; + if(browser.pageIndex < 0) + browser.pageIndex = 0; + listChanged = true; + } + } + else if(t->Down()) + { + if(browser.pageIndex + selectedItem + 1 < browser.numEntries) + { + if(selectedItem == FILEBROWSERSIZE-1) + { + // move list down by 1 + browser.pageIndex++; + listChanged = true; + } + else if(fileList[selectedItem+1]->IsVisible()) + { + fileList[selectedItem]->ResetState(); + fileList[++selectedItem]->SetState(STATE_SELECTED, t->chan); + } + } + } + else if(t->Up()) + { + if(selectedItem == 0 && browser.pageIndex + selectedItem > 0) + { + // move list up by 1 + browser.pageIndex--; + listChanged = true; + } + else if(selectedItem > 0) + { + fileList[selectedItem]->ResetState(); + fileList[--selectedItem]->SetState(STATE_SELECTED, t->chan); + } + } + + endNavigation: + + for(int i=0; iGetState() == STATE_DISABLED) + fileList[i]->SetState(STATE_DEFAULT); + + fileList[i]->SetVisible(true); + + fileListText[i]->SetText(browserList[browser.pageIndex+i].displayname); + fileListTextOver[i]->SetText(browserList[browser.pageIndex+i].displayname); + + if(browserList[browser.pageIndex+i].isdir) // directory + { + fileList[i]->SetIcon(fileListFolder[i]); + fileListText[i]->SetPosition(30,0); + fileListTextOver[i]->SetPosition(30,0); + } + else + { + fileList[i]->SetIcon(NULL); + fileListText[i]->SetPosition(10,0); + fileListTextOver[i]->SetPosition(10,0); + } + } + else + { + fileList[i]->SetVisible(false); + fileList[i]->SetState(STATE_DISABLED); + } + } + + if(i != selectedItem && fileList[i]->GetState() == STATE_SELECTED) + fileList[i]->ResetState(); + else if(focus && i == selectedItem && fileList[i]->GetState() == STATE_DEFAULT) + fileList[selectedItem]->SetState(STATE_SELECTED, t->chan); + + int currChan = t->chan; + + if(t->wpad.ir.valid && !fileList[i]->IsInside(t->wpad.ir.x, t->wpad.ir.y)) + t->chan = -1; + + fileList[i]->Update(t); + t->chan = currChan; + + if(fileList[i]->GetState() == STATE_SELECTED) + { + selectedItem = i; + browser.selIndex = browser.pageIndex + i; + } + } + + // update the location of the scroll box based on the position in the file list + if(positionWiimote > 0) + { + position = positionWiimote; // follow wiimote cursor + } + else + { + position = 136*(browser.pageIndex + FILEBROWSERSIZE/2.0) / (browser.numEntries*1.0); + + if(browser.pageIndex/(FILEBROWSERSIZE/2.0) < 1) + position = 0; + else if((browser.pageIndex+FILEBROWSERSIZE)/(FILEBROWSERSIZE*1.0) >= (browser.numEntries)/(FILEBROWSERSIZE*1.0)) + position = 136; + } + + scrollbarBoxBtn->SetPosition(0,position+36); + + listChanged = false; + + if(updateCB) + updateCB(this); +} diff --git a/source/network/networkops.cpp b/source/network/networkops.cpp index b6c35564..b89b8beb 100644 --- a/source/network/networkops.cpp +++ b/source/network/networkops.cpp @@ -16,7 +16,7 @@ #include "settings/cfg.h" #include "main.h" #include "http.h" -#include "svnrev.h" +#include "getrev.h" #define PORT 4299 @@ -271,7 +271,7 @@ int CheckUpdate() return -1; int revnumber = 0; - int currentrev = atoi(SVN_REV); + int currentrev = atoi(GetRev()); #ifdef NOTFULLCHANNEL struct block file = downloadfile("http://www.techjawa.com/usbloadergx/rev.txt"); diff --git a/source/prompts/PromptWindows.cpp b/source/prompts/PromptWindows.cpp index b241fc3c..35adff89 100644 --- a/source/prompts/PromptWindows.cpp +++ b/source/prompts/PromptWindows.cpp @@ -28,7 +28,7 @@ #include "wad/wad.h" #include "unzip/unzip.h" #include "zlib.h" -#include "svnrev.h" +#include "getrev.h" /*** Variables that are also used extern ***/ @@ -174,11 +174,11 @@ void WindowCredits() #ifdef NOTFULLCHANNEL char SvnRev[30]; - snprintf(SvnRev,sizeof(SvnRev), "Rev%s IOS%u (Rev %u)", SVN_REV, IOS_GetVersion(), IOS_GetRevision()); + snprintf(SvnRev,sizeof(SvnRev), "Rev%s IOS%u (Rev %u)", GetRev(), IOS_GetVersion(), IOS_GetRevision()); #else char svnTmp[4];//did this to hide the M after the rev# that is made by altering it //to be ready to be in a full channel - snprintf(svnTmp,sizeof(svnTmp), "%s", SVN_REV); + snprintf(svnTmp,sizeof(svnTmp), "%s", GetRev()); char SvnRev[30]; snprintf(SvnRev,sizeof(SvnRev), "Rev%sc IOS%u (Rev %u)", svnTmp, IOS_GetVersion(), IOS_GetRevision()); #endif diff --git a/source/svnrev.h b/source/svnrev.h new file mode 100644 index 00000000..d4ddf560 --- /dev/null +++ b/source/svnrev.h @@ -0,0 +1,4 @@ +#ifndef SVNREV_H + #define SVNREV_H + #define SVN_REV "643M" +#endif /* SVNREV_H */ diff --git a/source/testfilebrowser.cpp b/source/testfilebrowser.cpp new file mode 100644 index 00000000..391c1ccd --- /dev/null +++ b/source/testfilebrowser.cpp @@ -0,0 +1,134 @@ +#include +#include + +#include "language/gettext.h" +#include "prompts/PromptWindows.h" +#include "libwiigui/gui.h" +#include "filebrowser.h" +#include "menu.h" +#include "sys.h" + +/*** Extern variables ***/ +extern GuiWindow * mainWindow; +extern u8 shutdown; +extern u8 reset; + +/*** Extern functions ***/ +extern void ResumeGui(); +extern void HaltGui(); + +/**************************************************************************** + * MenuBrowseDevice + ***************************************************************************/ +int MenuBrowseDevice() +{ + int i; + char currentdir[50]; + + // populate initial directory listing + if(BrowseDevice(SD) <= 0) + { + int choice = WindowPrompt("Error", + "Unable to load device.", + "Retry", + "Change Settings"); + + if(choice) { + return MENU_DISCLIST; + } + } + + int menu = MENU_NONE; + + GuiText titleTxt("Browse Files", 28, (GXColor){0, 0, 0, 230}); + titleTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); + titleTxt.SetPosition(70,20); + + GuiTrigger trigA; + trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); + GuiTrigger trigPlus; + trigPlus.SetButtonOnlyTrigger(-1, WPAD_BUTTON_PLUS | WPAD_CLASSIC_BUTTON_PLUS, 0); + GuiTrigger trigMinus; + trigMinus.SetButtonOnlyTrigger(-1, WPAD_BUTTON_MINUS | WPAD_CLASSIC_BUTTON_MINUS, 0); + + GuiFileBrowser fileBrowser(552, 248); + fileBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); + fileBrowser.SetPosition(0, 100); + + GuiImageData btnOutline(button_dialogue_box_png); + GuiText ExitBtnTxt("Exit", 24, (GXColor){0, 0, 0, 255}); + GuiImage ExitBtnImg(&btnOutline); + GuiButton ExitBtn(btnOutline.GetWidth(), btnOutline.GetHeight()); + ExitBtn.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); + ExitBtn.SetPosition(100, -35); + ExitBtn.SetLabel(&ExitBtnTxt); + ExitBtn.SetImage(&ExitBtnImg); + ExitBtn.SetTrigger(&trigA); + ExitBtn.SetEffectGrow(); + + GuiImageData Address(addressbar_textbox_png); + snprintf(currentdir, sizeof(currentdir), "%s%s", browser.rootdir, browser.dir); + GuiText AdressText(currentdir, 20, (GXColor) {0, 0, 0, 255}); + AdressText.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); + AdressText.SetPosition(20, 0); + AdressText.SetMaxWidth(Address.GetWidth()-40, GuiText::SCROLL); + GuiImage AdressbarImg(&Address); + GuiButton Adressbar(Address.GetWidth(), Address.GetHeight()); + Adressbar.SetAlignment(ALIGN_LEFT, ALIGN_TOP); + Adressbar.SetPosition(60, fileBrowser.GetTop()-45); + Adressbar.SetImage(&AdressbarImg); + Adressbar.SetLabel(&AdressText); + + HaltGui(); + GuiWindow w(screenwidth, screenheight); + w.Append(&ExitBtn); + w.Append(&titleTxt); + w.Append(&fileBrowser); + w.Append(&Adressbar); + mainWindow->Append(&w); + ResumeGui(); + + while(menu == MENU_NONE) + { + VIDEO_WaitVSync(); + + if(shutdown == 1) + Sys_Shutdown(); + + if(reset == 1) + Sys_Reboot(); + + for(i=0; iGetState() == STATE_CLICKED) + { + fileBrowser.fileList[i]->ResetState(); + // check corresponding browser entry + if(browserList[browser.selIndex].isdir) + { + if(BrowserChangeFolder()) + { + fileBrowser.ResetState(); + fileBrowser.fileList[0]->SetState(STATE_SELECTED); + fileBrowser.TriggerUpdate(); + AdressText.SetTextf("%s%s", browser.rootdir, browser.dir); + } else { + menu = MENU_DISCLIST; + break; + } + } else { + mainWindow->SetState(STATE_DISABLED); + mainWindow->SetState(STATE_DEFAULT); + } + } + } + + if(ExitBtn.GetState() == STATE_CLICKED) + menu = MENU_DISCLIST; + } + HaltGui(); + mainWindow->Remove(&w); + ResumeGui(); + + return menu; +}