/
option.hh
71 lines (59 loc) · 1.76 KB
/
option.hh
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
#ifndef _OPTION_H_
#define _OPTION_H_
#include <string>
#include "worldfile.hh"
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Menu_Item.H>
namespace Stg {
class World;
/** option.hh
Class that encapsulates a boolean and pairs it with a string description
Used to pass settings between the GUI and the drawing classes
Author: Jeremy Asher, Richard Vaughan
SVN: $Id$
*/
class Option {
private:
friend bool compare( const Option* lhs, const Option* rhs );
std::string optName;
bool value;
/** worldfile entry string for loading and saving this value */
std::string wf_token;
std::string shortcut;
Fl_Menu_* menu;
int menuIndex;
Fl_Callback* menuCb;
Fl_Widget* menuCbWidget;
World* _world;
public:
Option( const std::string& n,
const std::string& tok,
const std::string& key,
bool v,
World *world );
const std::string name() const { return optName; }
inline bool isEnabled() const { return value; }
inline bool val() const { return value; }
inline operator bool() { return val(); }
inline bool operator<( const Option& rhs ) const
{
puts( "comparing" );
return optName<rhs.optName;
}
void set( bool val );
void invert() { set( !value ); }
// // Comparator to dereference Option pointers and compare their strings
// struct optComp {
// inline bool operator()( const Option* a, const Option* b ) const
// //{ return lhs->operator<(*rhs); }
// { return a->optName < b->optName; }
// };
void createMenuItem( Fl_Menu_Bar* menu, std::string path );
void menuCallback( Fl_Callback* cb, Fl_Widget* w );
static void toggleCb( Fl_Widget* w, void* p );
void Load( Worldfile* wf, int section );
void Save( Worldfile* wf, int section );
std::string htname;
};
}
#endif