GearFontSize.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections.Generic;
  2. using FairyGUI.Utils;
  3. namespace FairyGUI
  4. {
  5. /// <summary>
  6. /// Gear is a connection between object and controller.
  7. /// </summary>
  8. public class GearFontSize : GearBase
  9. {
  10. Dictionary<string, int> _storage;
  11. int _default;
  12. public GearFontSize(GObject owner)
  13. : base(owner)
  14. {
  15. }
  16. protected override void Init()
  17. {
  18. _default = ((GTextField)_owner).textFormat.size;
  19. _storage = new Dictionary<string, int>();
  20. }
  21. override protected void AddStatus(string pageId, ByteBuffer buffer)
  22. {
  23. if (pageId == null)
  24. _default = buffer.ReadInt();
  25. else
  26. _storage[pageId] = buffer.ReadInt();
  27. }
  28. override public void Apply()
  29. {
  30. _owner._gearLocked = true;
  31. int cv;
  32. if (!_storage.TryGetValue(_controller.selectedPageId, out cv))
  33. cv = _default;
  34. TextFormat tf = ((GTextField)_owner).textFormat;
  35. tf.size = cv;
  36. ((GTextField)_owner).textFormat = tf;
  37. _owner._gearLocked = false;
  38. }
  39. override public void UpdateState()
  40. {
  41. _storage[_controller.selectedPageId] = ((GTextField)_owner).textFormat.size;
  42. }
  43. }
  44. }