TORCS  1.3.9
The Open Racing Car Simulator
fileselect.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  file : fileselect.cpp
4  created : Sun Feb 16 13:09:23 CET 2003
5  copyright : (C) 2003-2014 by Eric Espie, Bernhard Wymann
6  email : eric.espie@torcs.org
7  version : $Id$
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <sys/stat.h>
30 #ifdef WIN32
31 #include <windows.h>
32 #endif
33 #include <tgfclient.h>
34 #include <racescreens.h>
35 
36 static void *scrHandle = NULL;
37 static int fileScrollList;
39 static tFList *FileList = NULL;
41 
42 
43 static void rmActivate(void * /* dummy */ )
44 {
45 }
46 
47 
48 static void rmClickOnFile(void * /*dummy*/)
49 {
51 }
52 
53 
54 static void rmSelect(void * /* dummy */ )
55 {
56  if (FileList) {
58  GfDirFreeList(FileList, NULL, true, false);
59  FileList = NULL;
60  } else {
61  rmFs->select(NULL);
62  }
63 }
64 
65 static void rmDeactivate(void * /* dummy */ )
66 {
67  if (FileList) {
68  GfDirFreeList(FileList, NULL, true, false);
69  FileList = NULL;
70  }
72 }
73 
74 
81 void RmFileSelect(void *vs)
82 {
83  tFList *FileCur;
84 
85  rmFs = (tRmFileSelect*)vs;
86 
87  if (scrHandle) {
89  }
90  scrHandle = GfuiScreenCreateEx((float*)NULL, NULL, rmActivate, NULL, (tfuiCallback)NULL, 1);
91  GfuiScreenAddBgImg(scrHandle, "data/img/splash-filesel.png");
93 
94  /* Scroll List containing the File list */
96  400, 310, GFUI_SB_RIGHT, NULL, rmClickOnFile);
97 
99  if (FileList == NULL) {
101  return;
102  }
103 
105  FileCur = FileList;
106  do {
107  FileCur = FileCur->next;
108  GfuiScrollListInsertElement(scrHandle, fileScrollList, FileCur->name, 1000, (void*)FileCur);
109  } while (FileCur != FileList);
110 
111  /* Bottom buttons */
113  NULL, rmSelect, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL);
114 
116  NULL, rmDeactivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL);
117 
118  /* Default menu keyboard actions */
121 }
static tRmFileSelect * rmFs
Definition: fileselect.cpp:38
static void * scrHandle
Definition: fileselect.cpp:36
#define GFUI_MOUSE_UP
Definition: tgfclient.h:80
char * path
Directory containing the files to list.
Definition: racescreens.h:79
static tFList * FileList
Definition: fileselect.cpp:39
int GfuiButtonCreate(void *scr, const char *text, int font, int x, int y, int width, int align, int mouse, void *userDataOnPush, tfuiCallback onPush, void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost)
Add a button to a screen.
Definition: guibutton.cpp:248
int GfuiScrollListInsertElement(void *scr, int Id, char *element, int index, void *userData)
Insert an element in a scroll list.
char * GfuiScrollListGetSelectedElement(void *scr, int Id, void **userData)
Get the selected element from the scroll list.
static void rmSelect(void *)
Definition: fileselect.cpp:54
void GfuiScreenRelease(void *scr)
Release the given screen.
Definition: gui.cpp:618
static tFList * FileSelected
Definition: fileselect.cpp:40
void GfuiScreenAddBgImg(void *scr, const char *filename)
Add an image background to a screen.
Definition: gui.cpp:961
List of (DLL) files for a Directory.
Definition: tgf.h:229
#define GFUI_SB_RIGHT
Definition: tgfclient.h:89
const char * title
Title for file selection (for screen title)
Definition: racescreens.h:78
void * prevScreen
Link to previous screen.
Definition: racescreens.h:80
static void rmClickOnFile(void *)
Definition: fileselect.cpp:48
The Gaming Framework API (client part).
Structure for file selection.
Definition: racescreens.h:76
#define GFUI_FONT_LARGE
Definition: tgfclient.h:168
void * GfuiScreenCreateEx(float *bgColor, void *userDataOnActivate, tfuiCallback onActivate, void *userDataOnDeactivate, tfuiCallback onDeactivate, int mouseAllowed)
Create a screen.
Definition: gui.cpp:578
struct FList * next
Next entry.
Definition: tgf.h:231
void GfuiMenuDefaultKeysAdd(void *scr)
Add the default menu keyboard callback to a screen.
Definition: guimenu.cpp:55
void(* tfuiCallback)(void *)
Definition: tgfclient.h:105
void GfuiScreenActivate(void *screen)
Activate a screen and make it current.
Definition: gui.cpp:467
void GfDirFreeList(tFList *list, tfDirfreeUserData freeUserData, bool freename, bool freedispname)
Free a directory list.
Definition: directory.cpp:76
#define GFUI_ALIGN_HC_VB
Definition: tgfclient.h:72
static int fileScrollList
Definition: fileselect.cpp:37
tfSelectFile select
Callback function to handle the selection (store the selection in the caller)
Definition: racescreens.h:81
int GfuiTitleCreate(void *scr, const char *text, int maxlen)
Add a Title to the screen.
Definition: guilabel.cpp:170
static void rmActivate(void *)
Definition: fileselect.cpp:43
int GfuiScrollListCreate(void *scr, int font, int x, int y, int align, int width, int height, int scrollBarPos, void *userDataOnSelect, tfuiCallback onSelect)
Create a new scroll list.
#define GFUI_FONT_MEDIUM_C
Definition: tgfclient.h:173
char * name
File name.
Definition: tgf.h:233
void RmFileSelect(void *vs)
File selection.
Definition: fileselect.cpp:81
static void rmDeactivate(void *)
Definition: fileselect.cpp:65
tFList * GfDirGetList(const char *dir)
Get the list of files of a given directory.
Definition: directory.cpp:43