Mercurial > projects > mde
comparison mde/lookup/Options.d @ 80:ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Moved contents of mde/gui/WidgetData.d elsewhere; new gui/WidgetDataSet.d and gui/types.d modules.
Changes to widget/createWidget.d
Partially implemented FloatingAreaWidget to provide an area for floating "window" widgets.
New DebugWidget and some uses of it (e.g. bad widget data).
Decoupled OptionChanges from Options.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 07 Aug 2008 11:25:27 +0100 |
parents | 61ea26abe4dd |
children | d8fccaa45d5f |
comparison
equal
deleted
inserted
replaced
79:61ea26abe4dd | 80:ea58f277f487 |
---|---|
367 } | 367 } |
368 } | 368 } |
369 //END Templates: impl & optionsThis | 369 //END Templates: impl & optionsThis |
370 } | 370 } |
371 | 371 |
372 /* Special class to store all locally changed options, whatever the section. */ | 372 /** Special class to store all locally changed options, whatever the section. */ |
373 class OptionChanges : Options { | 373 class OptionChanges : IDataSection |
374 { | |
374 //BEGIN Templates | 375 //BEGIN Templates |
375 private { | 376 private { |
377 alias Options.TName TName; | |
378 alias Options.TYPES TYPES; | |
376 template Vars(A...) { | 379 template Vars(A...) { |
377 static if (A.length) { | 380 static if (A.length) { |
378 const char[] Vars = A[0].stringof~`[] `~TName!(A[0])~`s;` ~ Vars!(A[1..$]); | 381 const char[] Vars = A[0].stringof~`[ID] `~TName!(A[0])~`s;` ~ Vars!(A[1..$]); |
379 } else | 382 } else |
380 const char[] Vars = ``; | 383 const char[] Vars = ``; |
381 } | 384 } |
382 | 385 |
383 // For addTag; different to Options.addTag(). | 386 // For addTag |
384 // Reverse priority: only load symbols not currently existing | |
385 template addTagMixin(T, A...) { | 387 template addTagMixin(T, A...) { |
386 const char[] ifBlock = `if (tp == "`~T.stringof~`") { | 388 const char[] ifBlock = `if (tp == "`~T.stringof~`") { |
387 if ((id in opts`~TName!(T)~`) is null) { | 389 if ((id in `~TName!(T)~`s) is null) |
388 `~TName!(T)~`s ~= parseTo!(`~T.stringof~`) (dt); | 390 `~TName!(T)~`s[id] = parseTo!(`~T.stringof~`) (dt); |
389 opts`~TName!(T)~`[id] = &`~TName!(T)~`s[$-1]; | |
390 } | |
391 }`; | 391 }`; |
392 static if (A.length) | 392 static if (A.length) |
393 const char[] addTagMixin = ifBlock~` else `~addTagMixin!(A).addTagMixin; | 393 const char[] addTagMixin = ifBlock~` else `~addTagMixin!(A).addTagMixin; |
394 else | 394 else |
395 const char[] addTagMixin = ifBlock; | 395 const char[] addTagMixin = ifBlock; |
396 } | 396 } |
397 | 397 // For writeAll |
398 template writeAllMixin(A...) { | |
399 static if (A.length) { | |
400 const char[] writeAllMixin = | |
401 `foreach (id, val; `~TName!(A[0])~`s) | |
402 dlg ("`~A[0].stringof~`", id, serialize (val)); | |
403 ` ~ writeAllMixin!(A[1..$]); | |
404 } else | |
405 const char[] writeAllMixin = ``; | |
406 } | |
407 | |
398 } | 408 } |
399 //END Templates | 409 //END Templates |
400 // These store the actual values, but are never accessed directly except when initially added. | 410 // These store the actual values, but are never accessed directly except when initially added. |
401 // optsX store pointers to each item added along with the ID and are used for access. | 411 // optsX store pointers to each item added along with the ID and are used for access. |
402 mixin(Vars!(TYPES)); | 412 mixin(Vars!(TYPES)); |
403 | 413 |
404 this () {} | 414 this () {} |
405 | 415 |
406 void set(T) (ID id, T x) { | 416 void set(T) (ID id, T x) { |
407 static assert (TIsIn!(T,TYPES), "Options does not support type "~T.stringof); | 417 static assert (Options.TIsIn!(T,TYPES), "Options does not support type "~T.stringof); |
408 | 418 |
409 mixin (`alias opts`~TName!(T)~` optsVars;`); | |
410 mixin (`alias `~TName!(T)~`s vars;`); | 419 mixin (`alias `~TName!(T)~`s vars;`); |
411 | 420 vars[id] = x; |
412 T** p = id in optsVars; | |
413 if (p !is null) **p = x; | |
414 else { | |
415 vars ~= x; | |
416 optsVars[id] = &vars[$-1]; | |
417 } | |
418 } | 421 } |
419 | 422 |
420 //BEGIN Mergetag loading/saving code | 423 //BEGIN Mergetag loading/saving code |
421 // Reverse priority: only load symbols not currently existing | 424 // HIGH_LOW priority: only load symbols not currently existing |
422 void addTag (char[] tp, ID id, char[] dt) { | 425 void addTag (char[] tp, ID id, char[] dt) { |
423 mixin (addTagMixin!(TYPES).addTagMixin); | 426 mixin (addTagMixin!(TYPES).addTagMixin); |
427 } | |
428 void writeAll (ItemDelg dlg) { | |
429 mixin(writeAllMixin!(TYPES)); | |
424 } | 430 } |
425 //END Mergetag loading/saving code | 431 //END Mergetag loading/saving code |
426 } | 432 } |
427 | 433 |
428 /* NOTE: Options sub-classes are expected to use a template to ease inserting contents and | 434 /* NOTE: Options sub-classes are expected to use a template to ease inserting contents and |