3e9add9a43a6324b0953c9975c398abb32f3ac42
11 /*******************************************************************************
12 * GUI : Abstract Graphic User Interface
13 * Provides additional macchanismes to synchronize widgets and zones. Widgets
14 * should both reflect the value of a zone and allow to change this value.
15 ******************************************************************************/
18 typedef void (*uiCallback
)(float val
, void* data
);
22 typedef list
<uiItem
*> clist
;
23 typedef map
<float*, clist
*> zmap
;
26 static list
<GUI
*> fGuiList
;
32 GUI() : fStopped(false) {
33 fGuiList
.push_back(this);
37 // suppression de this dans fGuiList
40 // -- registerZone(z,c) : zone management
42 void registerZone(float* z
, uiItem
* c
)
44 if (fZoneMap
.find(z
) == fZoneMap
.end()) fZoneMap
[z
] = new clist();
45 fZoneMap
[z
]->push_back(c
);
48 void updateAllZones();
50 void updateZone(float* z
);
52 static void updateAllGuis()
54 list
<GUI
*>::iterator g
;
55 for (g
= fGuiList
.begin(); g
!= fGuiList
.end(); g
++) {
56 (*g
)->updateAllZones();
59 void addCallback(float* zone
, uiCallback foo
, void* data
);
60 virtual void show() {};
61 virtual void run() {};
63 void stop() { fStopped
= true; }
64 bool stopped() { return fStopped
; }
66 virtual void declare(float* , const char* , const char* ) {}
72 * User Interface Item: abstract definition
83 uiItem (GUI
* ui
, float* zone
) : fGUI(ui
), fZone(zone
), fCache(-123456.654321)
85 ui
->registerZone(zone
, this);
92 void modifyZone(float v
)
97 fGUI
->updateZone(fZone
);
101 float cache() { return fCache
; }
102 virtual void reflectZone() = 0;
110 struct uiCallbackItem
: public uiItem
112 uiCallback fCallback
;
115 uiCallbackItem(GUI
* ui
, float* zone
, uiCallback foo
, void* data
)
116 : uiItem(ui
, zone
), fCallback(foo
), fData(data
) {}
118 virtual void reflectZone() {
125 // en cours d'installation de call back. a finir!!!!!
128 * Update all user items reflecting zone z
131 inline void GUI::updateZone(float* z
)
134 clist
* l
= fZoneMap
[z
];
135 for (clist::iterator c
= l
->begin(); c
!= l
->end(); c
++) {
136 if ((*c
)->cache() != v
) (*c
)->reflectZone();
142 * Update all user items not up to date
145 inline void GUI::updateAllZones()
147 for (zmap::iterator m
= fZoneMap
.begin(); m
!= fZoneMap
.end(); m
++) {
149 clist
* l
= m
->second
;
151 for (clist::iterator c
= l
->begin(); c
!= l
->end(); c
++) {
152 if ((*c
)->cache() != v
) (*c
)->reflectZone();
157 inline void GUI::addCallback(float* zone
, uiCallback foo
, void* data
)
159 new uiCallbackItem(this, zone
, foo
, data
);