1
0

centerlayer.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // ----------------------------------------------------------------------
  2. // centerlayer.m
  3. // ----------------------------------------------------------------------
  4. // by Brennan
  5. // Use like this :
  6. // #define CENTER_VAR MyVar
  7. // Global MyVar;
  8. // #include "centerlayer.h"
  9. // Group l = ;
  10. // MyVar = l.getObject("something");
  11. // _MyVarInit(Layer MyVar, Group l, int centerx, int centery);
  12. // ----------------------------------------------------------------------
  13. Global GuiObject _##CENTER_VAR##Layer;
  14. Global Group _##CENTER_VAR##Group; // parent Layout to center in
  15. Global Int _##CENTER_VAR##centerx; // should we center x?
  16. Global Int _##CENTER_VAR##centery; // should we center y?
  17. Global Int _##CENTER_VAR##addx = 0;
  18. Global Int _##CENTER_VAR##addy = 0;
  19. Global Int _##CENTER_VAR##addh = 0;
  20. Global Int _##CENTER_VAR##addw = 0;
  21. Function _##CENTER_VAR##Init(GuiObject _layer, Group parentLayout, int centerx, int centery);
  22. Function _##CENTER_VAR##handleResize();
  23. Function _##CENTER_VAR##setXSpace(int val);
  24. Function _##CENTER_VAR##setYSpace(int val);
  25. Function _##CENTER_VAR##setWSpace(int val);
  26. Function _##CENTER_VAR##setHSpace(int val);
  27. Function _##CENTER_VAR##sizeError(boolean iserror);
  28. _##CENTER_VAR##Init(GuiObject _layer, Group parentLayout, int centerx, int centery) {
  29. _##CENTER_VAR##Layer = _layer;
  30. _##CENTER_VAR##Group = parentLayout;
  31. _##CENTER_VAR##centerx = centerx;
  32. _##CENTER_VAR##centery = centery;
  33. _##CENTER_VAR##handleResize();
  34. }
  35. _##CENTER_VAR##setXSpace(int val)
  36. {
  37. _##CENTER_VAR##addx = val;
  38. }
  39. _##CENTER_VAR##setYSpace(int val)
  40. {
  41. _##CENTER_VAR##addy = val;
  42. }
  43. _##CENTER_VAR##setHSpace(int val)
  44. {
  45. _##CENTER_VAR##addh = val;
  46. }
  47. _##CENTER_VAR##setWSpace(int val)
  48. {
  49. _##CENTER_VAR##addw = val;
  50. }
  51. _##CENTER_VAR##handleResize() {
  52. int myw = _##CENTER_VAR##Group.getWidth();
  53. int myh = _##CENTER_VAR##Group.getHeight();
  54. int layerw = _##CENTER_VAR##Layer.getWidth();
  55. int layerh = _##CENTER_VAR##Layer.getHeight();
  56. int x = _##CENTER_VAR##Layer.getLeft();
  57. int y = _##CENTER_VAR##Layer.getTop();
  58. if (_##CENTER_VAR##centerx) _##CENTER_VAR##Layer.setXmlParam("x", integerToString((myw - layerw)/2 + _##CENTER_VAR##addx + _##CENTER_VAR##addw));
  59. if (_##CENTER_VAR##centery) _##CENTER_VAR##Layer.setXmlParam("y", integerToString((myh - layerh)/2 + _##CENTER_VAR##addy + _##CENTER_VAR##addh));
  60. if (myw < layerw + 2*_##CENTER_VAR##addx - _##CENTER_VAR##addw || myh < layerh + _##CENTER_VAR##addy - _##CENTER_VAR##addh)
  61. {
  62. _##CENTER_VAR##sizeError(TRUE);
  63. }
  64. else
  65. {
  66. _##CENTER_VAR##sizeError(FALSE);
  67. }
  68. }
  69. _##CENTER_VAR##sizeError(boolean iserror) {}
  70. _##CENTER_VAR##Group.onResize(int x, int y, int w, int h) {
  71. _##CENTER_VAR##handleResize();
  72. }