| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- /*
- 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.
- */
-
- #pragma once
- #include "PolycodeEditor.h"
- #include <Polycode.h>
- #include <PolycodeUI.h>
- #include "PolycodeProps.h"
- #if defined(__APPLE__) && defined(__MACH__)
- #define COPYMOD_1 KEY_RALT
- #define COPYMOD_2 KEY_LALT
- #elif defined _WINDOWS
- #define COPYMOD_1 KEY_RCTRL
- #define COPYMOD_2 KEY_LCTRL
- #else
- #define COPYMOD_1 KEY_RCTRL
- #define COPYMOD_2 KEY_LCTRL
- #endif
- using namespace Polycode;
- #ifdef _WINDOWS
- #define round (int)
- #endif
- class EntityBrowserData {
- public:
- Entity *entity;
- };
- class EntityTreeView : public UIElement {
- public:
- EntityTreeView(Entity *rootEntity);
- ~EntityTreeView();
-
- void Resize(Number width, Number height);
- void handleEvent(Event *event);
-
- void syncNodeToEntity(UITree *node, Entity *entity);
-
- void Refresh();
- Entity *selectedEntity;
- Entity *targetLayer;
-
- UIImageButton *newLayerButton;
- UIImageButton *targetLayerButton;
-
- Entity *rootEntity;
-
- protected:
-
- bool dontSendSelectionEvent;
-
- UITreeContainer *treeContainer;
-
- ScreenShape *headerBg;
- ScreenShape *bg;
-
- };
- class PropertiesSizer : public UIElement {
- public:
- PropertiesSizer();
- ~PropertiesSizer();
-
- void Resize(Number width, Number height);
-
- UIVSizer *sizer;
- };
- class ScreenEntityNameDisplay : public ScreenEntity {
- public:
- ScreenEntityNameDisplay(ScreenEntity *targetEntity);
- ~ScreenEntityNameDisplay();
-
- void Update();
-
- ScreenLabel *label;
- ScreenLabel *tagsLabel;
- ScreenEntity *targetEntity;
- };
- class PolycodeScreenEditorMain : public UIElement {
- public:
-
- PolycodeScreenEditorMain();
- virtual ~PolycodeScreenEditorMain();
-
- void Resize(Number width, Number height);
- void syncTransformToSelected();
- ScreenEntity *addNewLayer(String layerName);
- void updateCursor();
- void selectEntity(ScreenEntity *entity);
- void resetSelectedEntityTransforms();
- void setMode(int newMode);
- void handleEvent(Event *event);
- void resizePreviewScreen();
- void handleDroppedFile(OSFileEntry file, Number x, Number y);
- bool hasSelected(ScreenEntity *entity);
-
- void applyEditorOnly(ScreenEntity *entity);
- void applyEditorProperties(ScreenEntity *entity);
-
- void processEventForEntity(ScreenEntity *childEntity, InputEvent *inputEvent);
-
- void createParticleRef(ScreenParticleEmitter *target);
- void createSoundRef(ScreenSound *target);
- void createEntityRef(ScreenEntity *entity);
-
- void getCenterAndSizeForSelected(Vector2 *center, Number *width, Number *height);
-
- void handleMouseDown(Vector2 position);
- void handleMouseMove(Vector2 position);
- void handleMouseUp(Vector2 position);
-
- void setGrid(int gridSize);
-
- String Copy(void **data);
- void Paste(void *data, String clipboardType);
- void destroyClipboardData(void *data, String type);
-
- static const int MODE_SELECT = 0;
- static const int MODE_SHAPE = 1;
- static const int MODE_ZOOM = 2;
- static const int MODE_PAN = 3;
- static const int MODE_IMAGE = 4;
- static const int MODE_TEXT = 5;
- static const int MODE_PARENT = 6;
- static const int MODE_ENTITY = 7;
- static const int MODE_SOUND = 8;
- static const int MODE_LINK = 9;
- static const int MODE_SPRITE = 10;
- static const int MODE_PARTICLES = 11;
-
- std::vector<ScreenEntity*> layers;
-
- ScreenEntity *currentLayer;
-
- PropList *entityProps;
-
- ScreenEntity *layerBaseEntity;
-
- ScreenEntity *selectedEntity;
- std::vector<ScreenEntity*> selectedEntities;
-
- Transform2DSheet *transform2dSheet;
- EntitySheet *entitySheet;
- ShapeSheet *shapeSheet;
- ScreenImageSheet *imageSheet;
- ScreenLabelSheet *labelSheet;
- SoundSheet *soundSheet;
- EntityPropSheet *entityPropSheet;
- ScreenEntityInstanceSheet *instanceSheet;
- ScreenSpriteSheet *spriteSheet;
- ScreenParticleSheet *particleSheet;
-
- EntityTreeView *treeView;
-
- ScreenEntity *objectBaseEntity;
- ScreenEntity *placingPreviewEntity;
- bool multiSelect;
- protected:
-
-
- int gridSize;
- bool gridSnap;
-
- ScreenShape *previewShape;
- ScreenImage *previewImage;
- ScreenEntityInstance *previewInstance;
- ScreenLabel *previewLabel;
- ScreenEntity *previewEntity;
- ScreenParticleEmitter *previewEmitter;
-
- ScreenSound *previewSound;
- ScreenSprite *previewSprite;
-
- ScreenMesh *grid;
- bool firstResize;
-
- bool firstMove;
- int placementCount;
-
-
- Number previewAspectRatio;
- bool placing;
- bool moving;
- bool scalingY;
- bool scalingX;
- bool rotating;
- bool panning;
- bool zooming;
-
- bool parenting;
- ScreenEntity *parentingChild;
- ScreenLine *parentingLine;
-
-
- int lastMode;
-
- Vector2 basePanPosition;
-
- Number baseZoomScale;
-
- Number baseRotateAngle;
-
- int selectedEntityPositionMode;
-
- Vector3 baseScale;
-
- Vector2 mouseBase;
- std::vector<Vector2> baseEntityPositions;
- std::vector<Vector2> baseEntityScales;
- std::vector<Number> baseRotateAngles;
- Vector2 groupCenterPoint;
- Number groupRoll;
- Number baseAngle;
-
- ScreenShape *placingShape;
- Vector2 placingAnchor;
-
- ScreenShape *screenPreviewShape;
-
- Vector2 dragOffset;
- bool isDraggingEntity;
- bool isScalingEntity;
-
- ScreenEntity *baseEntity;
-
- ScreenEntity *screenTransform;
- ScreenShape *screenTransformShape;
- ScreenImage *transformRotator;
- ScreenImage *transformScalerY;
- ScreenImage *transformScalerX;
-
- ScreenImage *centerImage;
-
- ScreenEntity *properties;
- ScreenShape *propertiesBg;
- ScreenEntity *viewOptions;
- ScreenShape *viewOptionsBg;
-
- UITextInput *gridSizeInput;
- UICheckBox *gridCheckBox;
-
- UICheckBox *pixelSnapBox;
- UICheckBox *gridSnapBox;
-
- UITextInput *scaleInput;
-
- ScreenEntity *toolPalette;
- ScreenShape *toolPaletteBg;
-
- UIImageButton *arrowToolButton;
- UIImageButton *shapeToolButton;
- UIImageButton *zoomToolButton;
- UIImageButton *panToolButton;
- UIImageButton *imageToolButton;
- UIImageButton *textToolButton;
- UIImageButton *parentToolButton;
- UIImageButton *entityToolButton;
- UIImageButton *soundToolButton;
- UIImageButton *spriteToolButton;
- UIImageButton *particlesToolButton;
-
- UIImageButton *linkToolButton;
-
- UIComboBox *aspectComboBox;
- UIComboBox *zoomComboBox;
-
- UIButton *moveUpButton;
- UIButton *moveDownButton;
- UIButton *moveTopButton;
- UIButton *moveBottomButton;
- UIButton *unparentButton;
-
- Number zooms[16];
-
- Number aspects[16];
-
- ScreenImage *selectorImage;
- int mode;
- };
- class ScreenEntityClipboardData {
- public:
- ScreenEntityClipboardData(){}
-
- std::vector<ScreenEntity*> entities;
- };
- class PolycodeScreenEditor : public PolycodeEditor {
- public:
- PolycodeScreenEditor();
- virtual ~PolycodeScreenEditor();
-
- bool openFile(OSFileEntry filePath);
- void Resize(int x, int y);
-
- String Copy(void **data);
- void Paste(void *data, String clipboardType);
- void destroyClipboardData(void *data, String type);
- void Activate();
-
- void saveCurveToObject(ObjectEntry *entry, BezierCurve *curve);
- void saveEntityToObjectEntry(ScreenEntity *entity, ObjectEntry *entry);
- void saveFile();
-
- void handleDroppedFile(OSFileEntry file, Number x, Number y);
- void handleEvent(Event *event);
- protected:
- UIHSizer *mainSizer;
- PropertiesSizer *propSizer;
- EntityTreeView *treeView;
- PolycodeScreenEditorMain *editorMain;
- };
- class PolycodeScreenEditorFactory : public PolycodeEditorFactory {
- public:
- PolycodeScreenEditorFactory() : PolycodeEditorFactory() { extensions.push_back("entity2d"); }
- PolycodeEditor *createEditor() { return new PolycodeScreenEditor(); }
- };
|