2
0

PolycodeFrame.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * PolycodeFrame.cpp
  3. * Polycode
  4. *
  5. * Created by Ivan Safrin on 11/29/10.
  6. * Copyright 2010 Local Projects. All rights reserved.
  7. *
  8. */
  9. #include "PolycodeFrame.h"
  10. PolycodeFrame::PolycodeFrame() : ScreenEntity() {
  11. modalChild = NULL;
  12. editorHolder = new ScreenEntity();
  13. addChild(editorHolder);
  14. projectBrowser = new PolycodeProjectBrowser();
  15. addChild(projectBrowser);
  16. topBarBg = new ScreenShape(ScreenShape::SHAPE_RECT, 2,2);
  17. topBarBg->setColor(0,0,0,1);
  18. topBarBg->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
  19. addChild(topBarBg);
  20. logo = new ScreenImage("barlogo.png");
  21. addChild(logo);
  22. resizer = new ScreenImage("corner_resize.png");
  23. addChild(resizer);
  24. resizer->setColor(0,0,0,0.4);
  25. modalBlocker = new ScreenShape(ScreenShape::SHAPE_RECT, 10,10);
  26. modalBlocker->setColor(0,0,0,0.5);
  27. modalBlocker->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
  28. modalBlocker->enabled = false;
  29. modalBlocker->blockMouseInput = true;
  30. addChild(modalBlocker);
  31. newProjectWindow = new NewProjectWindow();
  32. newProjectWindow->visible = false;
  33. currentEditor = NULL;
  34. }
  35. void PolycodeFrame::showModal(UIWindow *modalChild) {
  36. modalBlocker->enabled = true;
  37. this->modalChild = modalChild;
  38. addChild(modalChild);
  39. modalChild->showWindow();
  40. modalChild->addEventListener(this, UIEvent::CLOSE_EVENT);
  41. Resize(frameSizeX, frameSizeY);
  42. }
  43. PolycodeProjectBrowser *PolycodeFrame::getProjectBrowser() {
  44. return projectBrowser;
  45. }
  46. void PolycodeFrame::addEditor(PolycodeEditor *editor) {
  47. editors.push_back(editor);
  48. editorHolder->addChild(editor);
  49. editor->enabled = false;
  50. }
  51. void PolycodeFrame::showEditor(PolycodeEditor *editor) {
  52. if(currentEditor) {
  53. currentEditor->enabled = false;
  54. currentEditor = NULL;
  55. }
  56. currentEditor = editor;
  57. currentEditor->enabled = true;
  58. Resize(frameSizeX, frameSizeY);
  59. }
  60. void PolycodeFrame::hideModal() {
  61. if(modalChild) {
  62. modalChild->hideWindow();
  63. modalBlocker->enabled = false;
  64. modalChild = NULL;
  65. }
  66. }
  67. void PolycodeFrame::handleEvent(Event *event) {
  68. if(event->getDispatcher() == modalChild) {
  69. if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLOSE_EVENT) {
  70. hideModal();
  71. }
  72. }
  73. }
  74. void PolycodeFrame::Resize(int x, int y) {
  75. frameSizeX = x;
  76. frameSizeY = y;
  77. topBarBg->setShapeSize(x, 45);
  78. logo->setPosition(x-logo->getWidth()-10, 6);
  79. resizer->setPosition(x-resizer->getWidth()-1, y-resizer->getHeight()-1);
  80. projectBrowser->Resize(200, y-45);
  81. modalBlocker->setShapeSize(x, y);
  82. editorHolder->setPosition(200, 45);
  83. if(currentEditor) {
  84. currentEditor->Resize(x-200, y-45);
  85. }
  86. if(this->modalChild) {
  87. modalChild->setPosition((x-modalChild->getWidth())/2.0f, (y-modalChild->getHeight())/2.0f);
  88. }
  89. }
  90. PolycodeFrame::~PolycodeFrame() {
  91. }