-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuimenu_CustomMenu.cpp
More file actions
114 lines (87 loc) · 2.96 KB
/
uimenu_CustomMenu.cpp
File metadata and controls
114 lines (87 loc) · 2.96 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
/*
Copyright (C) 2008 Will Franklin
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 "uicore_Global.h"
#include "uimenu_CustomMenu.h"
#include "uiwsw_Export.h"
#include "uiwsw_SysCalls.h"
#include "uiwsw_Utils.h"
using namespace UICore;
using namespace UIMenu;
using namespace UIWsw;
CustomMenu *custommenu = NULL;
void UIMenu::M_Menu_Custom_f( void )
{
if( !custommenu )
custommenu = new CustomMenu;
custommenu->Show();
}
ALLOCATOR_DEFINITION( CustomMenu )
DELETER_DEFINITION( CustomMenu )
CustomMenu::CustomMenu( void )
{
panel = Factory::newPanel( rootPanel, 0, 0, 0, 0 );
title = Factory::newLabel( panel, 0, 20, 0, 0 );
title->setFont( Local::getFontBig() );
title->setAlign( ALIGN_TOP_CENTER );
}
void CustomMenu::Show( void )
{
int maxw;
setActiveMenu( this );
if( !buttons.empty() )
{
for( std::list<ButtonPair>::iterator it = buttons.begin() ; it != buttons.end() ; it++ )
{
delete (*it).first;
(*it).second.clear();
}
buttons.clear();
}
title->setCaption( Trap::Cmd_Argv( 1 ) );
maxw = Importer::StringWidth( title->getCaption().c_str(), title->getFont() );
for( int i = 2 ; i < Trap::Cmd_Argc() ; i += 2 )
{
Button *button;
button = Factory::newButton( panel, 20, 50 + buttons.size() * 40, 0, 0, Trap::Cmd_Argv( i ) );
buttons.push_front( std::make_pair( button, Trap::Cmd_Argv( i + 1 ) ) );
maxw = max( maxw, Importer::StringWidth( button->getCaption().c_str(), button->getFont() ) );
}
panel->setSize( maxw + 40 + 20, buttons.size() * 40 + 60 );
panel->setPosition( ( REL_WIDTH - panel->getWidth() ) / 2.0f, ( REL_HEIGHT - panel->getHeight() ) / 2.0f );
title->setSize( panel->getWidth(), 40 );
for( std::list<ButtonPair>::iterator it = buttons.begin() ; it != buttons.end() ; it++ )
{
(*it).first->setSize( maxw + 20, 30 );
(*it).first->setClickHandler( clickHandler );
}
panel->setVisible( true );
}
void CustomMenu::clickHandler( BaseObject *btn )
{
for( std::list<ButtonPair>::iterator it = custommenu->buttons.begin() ; it != custommenu->buttons.end() ; it++ )
{
if( btn == (*it).first )
{
Trap::Cmd_ExecuteText( EXEC_APPEND, (*it).second.c_str() );
UI_ForceMenuOff();
break;
}
}
custommenu->Hide();
}
void CustomMenu::Hide( void )
{
panel->setVisible( false );
}