DeveloperMenu.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include "DeveloperMenu.h"
  2. #include "ColorRectSprite.h"
  3. #include "ClipRectActor.h"
  4. #include "TextField.h"
  5. #include "DebugActor.h"
  6. #include "res/Resources.h"
  7. #include "res/ResFont.h"
  8. #include "initActor.h"
  9. namespace oxygine
  10. {
  11. const Color windowColor(64, 128, 128, 255);
  12. DeveloperMenu::DeveloperMenu(): _resSystem(0)
  13. {
  14. setName(getDefaultName());
  15. setColor(windowColor);
  16. DebugActor::initialize();
  17. _resSystem = DebugActor::resSystem;
  18. setPriority(999);
  19. }
  20. DeveloperMenu::~DeveloperMenu()
  21. {
  22. }
  23. Vector2 DeveloperMenu::getBodySize() const
  24. {
  25. return _body->getSize();
  26. }
  27. void DeveloperMenu::init(const Vector2& size, const char* text, spActor data, const Color& color)
  28. {
  29. const float BORDER = 3;
  30. float offset = 24;
  31. setSize(size);
  32. setWidth(data->getWidth() + BORDER * 2);
  33. setHeight(size.y + offset);
  34. //setSize(data->getSize() + Point(0, offset));
  35. spColorRectSprite top = new ColorRectSprite();
  36. top->setWidth(getWidth());
  37. top->setSize(size);
  38. _topDrag.init(top.get());
  39. _topDrag.setDragClient(this);
  40. addChild(top);
  41. top->setColor(windowColor);
  42. top->setSize(Vector2(getWidth(), offset));
  43. top->setPriority(100);
  44. spColorRectSprite body = new ColorRectSprite();
  45. body->setColor(color);
  46. addChild(body);
  47. body->setSize(Vector2(getWidth() - BORDER * 2, getHeight()));
  48. body->setX(BORDER);
  49. body->setY((float)offset);
  50. _body = body;
  51. TextStyle style;
  52. style.font = _resSystem->getResFont("system");
  53. style.vAlign = TextStyle::VALIGN_TOP;
  54. spButton close = initActor(new Button,
  55. arg_y = offset / 2,
  56. arg_x = offset / 2,
  57. arg_anchor = Vector2(0.5f, 0.5f),
  58. arg_resAnim = _resSystem->getResAnim("remove"),
  59. arg_attachTo = top);
  60. close->addEventListener(TouchEvent::CLICK, CLOSURE(this, &DeveloperMenu::close));
  61. spTextField title = initActor(new TextField,
  62. arg_style = style,
  63. arg_hAlign = TextStyle::HALIGN_MIDDLE,
  64. arg_vAlign = TextStyle::VALIGN_MIDDLE,
  65. arg_text = text,
  66. arg_width = top->getWidth(),
  67. arg_height = top->getHeight(),
  68. arg_input = false,
  69. arg_attachTo = top);
  70. //title->setSize(close->getTextRect().size);
  71. title->addEventListener(TouchEvent::CLICK, CLOSURE(this, &DeveloperMenu::close));
  72. data->attachTo(body);
  73. }
  74. void DeveloperMenu::close(Event* ev)
  75. {
  76. detach();
  77. //return true;
  78. }
  79. }