-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathFileDialog.cpp
More file actions
143 lines (115 loc) · 3.63 KB
/
Copy pathFileDialog.cpp
File metadata and controls
143 lines (115 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Framework.h"
#include "Bitmap.h"
#include "Action.h"
#include "Table.h"
#include "StringVectorModel.h"
#include "PicButton.h"
#define ART_BANNER "gfx/shell/head_touchoptions"
#define ART_GAMMA "gfx/shell/gamma"
uiFileDialogGlobal_t uiFileDialogGlobal;
class CMenuFileDialog : public CMenuFramework
{
public:
CMenuFileDialog() : CMenuFramework("CMenuFileDialog") { }
private:
void _Init( void ) override;
void _VidInit( void ) override;
void SaveAndPopMenu() override;
void RejectChanges();
void ApplyChanges( const char *fileName );
void UpdateExtra();
class CFileListModel : public CStringVectorModel
{
public:
CFileListModel() : CStringVectorModel() {}
void Update() override;
} model;
CMenuTable fileList;
class CPreview : public CMenuAction
{
public:
void Draw() override;
HIMAGE image;
} preview;
};
void CMenuFileDialog::CPreview::Draw()
{
UI_FillRect( m_scPos.x - 2, m_scPos.y - 2, m_scSize.w + 4, m_scSize.h + 4, 0xFFC0C0C0 );
UI_FillRect( m_scPos.x, m_scPos.y, m_scSize.w, m_scSize.h, 0xFF808080 );
EngFuncs::PIC_Set( image, 255, 255, 255, 255 );
EngFuncs::PIC_DrawTrans( m_scPos, m_scSize );
}
void CMenuFileDialog::CFileListModel::Update( void )
{
char **filenames;
int i = 0, numFiles, j, k;
for( k = 0; k < uiFileDialogGlobal.npatterns; k++)
{
filenames = EngFuncs::GetFilesList( uiFileDialogGlobal.patterns[k], &numFiles, true );
for ( j = 0; j < numFiles; i++, j++ )
AddToTail( filenames[j] );
}
}
void CMenuFileDialog::ApplyChanges(const char *fileName)
{
Q_strncpy( uiFileDialogGlobal.result, fileName, sizeof( uiFileDialogGlobal.result ) );
uiFileDialogGlobal.result[255] = 0;
uiFileDialogGlobal.valid = false;
uiFileDialogGlobal.callback( fileName[0] != 0 );
}
void CMenuFileDialog::RejectChanges()
{
ApplyChanges( "" );
Hide();
}
void CMenuFileDialog::SaveAndPopMenu()
{
const char *fileName = model.GetText( fileList.GetCurrentIndex() );
ApplyChanges( fileName );
Hide();
}
void CMenuFileDialog::UpdateExtra()
{
const char *fileName = model.GetText( fileList.GetCurrentIndex() );
if( uiFileDialogGlobal.preview )
preview.image = EngFuncs::PIC_Load( fileName );
}
/*
=================
UI_FileDialog_Init
=================
*/
void CMenuFileDialog::_Init( void )
{
// banner.SetPicture( ART_BANNER );
fileList.iFlags |= QMF_DROPSHADOW;
fileList.SetModel( &model );
fileList.onChanged = VoidCb( &CMenuFileDialog::UpdateExtra );
fileList.SetRect( 360, 230, -20, 465 );
UpdateExtra();
preview.SetRect( 72, 380, 196, 196 );
// AddItem( banner );
AddButton( L( "Done" ), L( "Use selected file" ), PC_DONE, VoidCb( &CMenuFileDialog::SaveAndPopMenu ) );
AddButton( L( "GameUI_Cancel" ), L( "Cancel file selection" ), PC_CANCEL, VoidCb( &CMenuFileDialog::RejectChanges ) );
AddItem( preview );
AddItem( fileList );
}
void CMenuFileDialog::_VidInit()
{
preview.SetVisibility( uiFileDialogGlobal.preview );
}
ADD_MENU( menu_filedialog, CMenuFileDialog, UI_FileDialog_Menu );