| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- /*
- Copyright (C) 2012 by Ivan Safrin
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- */
- #include "PolycodeFrame.h"
- EditorHolder::EditorHolder() : UIElement() {
- currentEditor = NULL;
- }
- EditorHolder::~EditorHolder() {
- }
-
- void EditorHolder::Resize(Number width, Number height) {
- if(currentEditor) {
- currentEditor->Resize(width, height);
- }
- }
- PolycodeFrame::PolycodeFrame() : ScreenEntity() {
- modalChild = NULL;
-
- welcomeEntity = new ScreenEntity();
- addChild(welcomeEntity);
- welcomeImage = new ScreenImage("welcome.png");
- welcomeEntity->addChild(welcomeImage);
- welcomeEntity->snapToPixels = true;
-
- newProjectButton = new UIButton("Create A New Project!", 220);
- newProjectButton->setPosition(230,80);
- newProjectButton->addEventListener(this, UIEvent::CLICK_EVENT);
-
- examplesButton = new UIButton("Browse Example Projects!", 220);
- examplesButton->setPosition(460,80);
- examplesButton->addEventListener(this, UIEvent::CLICK_EVENT);
-
- welcomeEntity->addChild(newProjectButton);
- welcomeEntity->addChild(examplesButton);
-
- mainSizer = new UIHSizer(100,100,200);
- mainSizer->setPosition(0, 45);
- addChild(mainSizer);
-
-
- projectBrowser = new PolycodeProjectBrowser();
- mainSizer->addLeftChild(projectBrowser);
- consoleSizer = new UIVSizer(100,100,400);
- mainSizer->addRightChild(consoleSizer);
- editorHolder = new EditorHolder();
- consoleSizer->addTopChild(editorHolder);
-
- // REPLACE WITH CONSOLE CLASS
- UITextInput *textInput = new UITextInput(true, 100, 100);
- consoleSizer->addBottomChild(textInput);
-
-
- projectBrowser->treeContainer->getRootNode()->addEventListener(this, UITreeEvent::DRAG_START_EVENT);
-
- topBarBg = new ScreenShape(ScreenShape::SHAPE_RECT, 2,2);
- topBarBg->setColor(0,0,0,1);
- topBarBg->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
- addChild(topBarBg);
-
- logo = new ScreenImage("barlogo.png");
- addChild(logo);
-
-
- playButton = new UIImageButton("play_button.png");
- addChild(playButton);
- playButton->setPosition(10,8);
-
- resizer = new ScreenImage("corner_resize.png");
- addChild(resizer);
- resizer->setColor(0,0,0,0.4);
-
- modalBlocker = new ScreenShape(ScreenShape::SHAPE_RECT, 10,10);
- modalBlocker->setColor(0,0,0,0.5);
- modalBlocker->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
- modalBlocker->enabled = false;
- modalBlocker->blockMouseInput = true;
- addChild(modalBlocker);
-
- newProjectWindow = new NewProjectWindow();
- newProjectWindow->visible = false;
-
- exampleBrowserWindow = new ExampleBrowserWindow();
- exampleBrowserWindow->visible = false;
-
- newFileWindow = new NewFileWindow();
- newFileWindow->visible = false;
-
- textInputPopup = new TextInputPopup();
- textInputPopup->visible = false;
-
-
- isDragging = false;
- dragLabel = new ScreenLabel("NONE", 11, "sans");
- dragLabel->setPosition(0,-15);
-
- dragEntity = new ScreenEntity();
- dragEntity->addChild(dragLabel);
- addChild(dragEntity);
- dragEntity->visible = false;
-
- CoreServices::getInstance()->getCore()->getInput()->addEventListener(this, InputEvent::EVENT_MOUSEUP);
- CoreServices::getInstance()->getCore()->getInput()->addEventListener(this, InputEvent::EVENT_MOUSEMOVE);
- }
- void PolycodeFrame::showModal(UIWindow *modalChild) {
- modalBlocker->enabled = true;
-
- this->modalChild = modalChild;
- addChild(modalChild);
- modalChild->showWindow();
- modalChild->addEventListener(this, UIEvent::CLOSE_EVENT);
- Resize(frameSizeX, frameSizeY);
- }
- PolycodeProjectBrowser *PolycodeFrame::getProjectBrowser() {
- return projectBrowser;
- }
- void PolycodeFrame::addEditor(PolycodeEditor *editor) {
- editors.push_back(editor);
- editorHolder->addChild(editor);
- editor->enabled = false;
- }
- void PolycodeFrame::showEditor(PolycodeEditor *editor) {
- if(editorHolder->currentEditor) {
- editorHolder->currentEditor->enabled = false;
- editorHolder->currentEditor = NULL;
- }
-
- editorHolder->currentEditor = editor;
- editorHolder->currentEditor->enabled = true;
-
- Resize(frameSizeX, frameSizeY);
- }
- void PolycodeFrame::hideModal() {
- if(modalChild) {
- removeChild(modalChild);
- modalChild->removeEventListener(this, UIEvent::CLOSE_EVENT);
- modalChild->hideWindow();
- modalChild = NULL;
- }
- modalBlocker->enabled = false;
- }
- void PolycodeFrame::handleEvent(Event *event) {
-
- if(event->getDispatcher() == CoreServices::getInstance()->getCore()->getInput()) {
- switch(event->getEventCode()) {
- case InputEvent::EVENT_MOUSEUP:
- if(isDragging) {
- if(editorHolder->currentEditor) {
- InputEvent *inputEvent = (InputEvent*) event;
- Number posX = inputEvent->mousePosition.x - editorHolder->getPosition2D().x;
- Number posY = inputEvent->mousePosition.y - editorHolder->getPosition2D().y;
- editorHolder->currentEditor->handleDroppedFile(draggedFile, posX, posY);
- }
- }
- isDragging = false;
- dragEntity->visible = false;
- break;
- case InputEvent::EVENT_MOUSEMOVE:
- if(isDragging) {
- dragEntity->setPosition(((InputEvent*)event)->mousePosition);
- }
- break;
- }
- }
- if(event->getDispatcher() == projectBrowser->treeContainer->getRootNode()) {
- switch (event->getEventCode()) {
- case UITreeEvent::DRAG_START_EVENT:
- {
- UITreeEvent *treeEvent = (UITreeEvent*) event;
- BrowserUserData *data = (BrowserUserData*)treeEvent->selection->getUserData();
- draggedFile = data->fileEntry;
- dragLabel->setText(data->fileEntry.name);
- dragEntity->visible = true;
- isDragging = true;
- // printf("START DRAG: %s\n", data->fileEntry.name.c_str());
- }
- break;
- }
- }
- if(event->getDispatcher() == modalChild) {
- if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLOSE_EVENT) {
- hideModal();
- }
- } else {
- if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT && event->getDispatcher() == newProjectButton) {
- newProjectWindow->ResetForm();
- showModal(newProjectWindow);
- }
-
- if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT && event->getDispatcher() == examplesButton) {
- newProjectWindow->ResetForm();
- showModal(exampleBrowserWindow);
- }
-
- }
- }
- void PolycodeFrame::Resize(int x, int y) {
-
- frameSizeX = x;
- frameSizeY = y;
-
- welcomeEntity->setPosition((x-welcomeImage->getWidth()) / 2,
- (y-welcomeImage->getHeight()) / 2);
-
- topBarBg->setShapeSize(x, 45);
- logo->setPosition(x-logo->getWidth()-2, 2);
- resizer->setPosition(x-resizer->getWidth()-1, y-resizer->getHeight()-1);
- mainSizer->Resize(x,y-45);
-
- modalBlocker->setShapeSize(x, y);
-
-
- if(this->modalChild) {
- modalChild->setPosition((x-modalChild->getWidth())/2.0f, (y-modalChild->getHeight())/2.0f);
- }
- }
- PolycodeFrame::~PolycodeFrame() {
-
- }
|