public override bool parseXml(XElement xml)
        {
            if (xml == null || xml.Name != "ActionIntervalAnimate")
            {
                return(false);
            }

            if (!base.parseXml(xml))
            {
                return(false);
            }

            try {
                XElement xmlFrames = xml.Element("Frames");
                IEnumerable <XElement> xmlFrameList = xmlFrames.Elements();
                foreach (XElement xmlFrame in xmlFrameList)
                {
                    string image    = TUtil.parseStringXElement(xmlFrame.Element("Image"), "");
                    long   duration = TUtil.parseLongXElement(xmlFrame.Element("Duration"), -1);
                    if (string.IsNullOrEmpty(image) || duration == -1)
                    {
                        return(false);
                    }

                    frames.Add(new TAnimateFrame {
                        image = image, duration = duration
                    });
                }
                return(true);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
        public override bool parseXml(XElement xml, TLayer parentLayer)
        {
            if (xml == null || xml.Name != "TextActor")
                return false;

            if (!base.parseXml(xml, parentLayer))
                return false;

            try {
                text = xml.Element("Text").Value;
                FontFamily family = Program.findFontFamily(xml.Element("FontFamilyName").Value);
                float fontSize = TUtil.parseFloatXElement(xml.Element("FontSize"), 12);
                FontStyle fontStyle = (FontStyle)TUtil.parseIntXElement(xml.Element("FontStyle"), 0);
                if (family != null)
                    font = new Font(family, fontSize, fontStyle, GraphicsUnit.Point);
                else
                    font = new Font("Arial", fontSize, fontStyle, GraphicsUnit.Point);
                color = Color.FromArgb(int.Parse(xml.Element("Color").Value));
                BoxSize.Width = float.Parse(xml.Element("SizeWidth").Value);
                BoxSize.Height = float.Parse(xml.Element("SizeHeight").Value);

                refreshMatrix();
                return true;
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                return false;
            }
        }
Example #3
0
        private void startDocument()
        {
            // default values
            bgmOn    = true;
            effectOn = true;
            voiceOn  = true;

            transitionDelegate  = null;
            transitionStartTime = 0;

            // sound emulator
            soundEmulator = new TSoundEmulator(document.libraryManager);

            // play document background
            playBGM(document.backgroundMusic, document.backgroundMusicVolume);


            // load prev button image
            try {
                int prevSceneButtonIndex = document.libraryManager.imageIndex(document.prevSceneButton);
                if (prevSceneButtonIndex == -1)
                {
                    imgPrevButton = TUtil.resizedImage(Properties.Resources.emulator_img_nav_prev, new Size(Program.NAVBUTTON_WIDTH, Program.NAVBUTTON_HEIGHT), Program.NAVBUTTON_STRETCH);
                }
                else
                {
                    imgPrevButton = TUtil.resizedImage(Image.FromFile(document.libraryManager.imageFilePath(prevSceneButtonIndex)), new Size(Program.NAVBUTTON_WIDTH, Program.NAVBUTTON_HEIGHT), Program.NAVBUTTON_STRETCH);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                imgPrevButton = TUtil.resizedImage(Properties.Resources.emulator_img_nav_prev, new Size(Program.NAVBUTTON_WIDTH, Program.NAVBUTTON_HEIGHT), Program.NAVBUTTON_STRETCH);
            }

            // load next button image
            try {
                int nextSceneButtonIndex = document.libraryManager.imageIndex(document.nextSceneButton);
                if (nextSceneButtonIndex == -1)
                {
                    imgNextButton = TUtil.resizedImage(Properties.Resources.emulator_img_nav_next, new Size(Program.NAVBUTTON_WIDTH, Program.NAVBUTTON_HEIGHT), Program.NAVBUTTON_STRETCH);
                }
                else
                {
                    imgNextButton = TUtil.resizedImage(Image.FromFile(document.libraryManager.imageFilePath(nextSceneButtonIndex)), new Size(Program.NAVBUTTON_WIDTH, Program.NAVBUTTON_HEIGHT), Program.NAVBUTTON_STRETCH);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                imgNextButton = TUtil.resizedImage(Properties.Resources.emulator_img_nav_next, new Size(Program.NAVBUTTON_WIDTH, Program.NAVBUTTON_HEIGHT), Program.NAVBUTTON_STRETCH);
            }


            // initial scene
            changeScene(document.currentScene());

            // start timer
            bStepFlag  = true;
            threadStep = new Thread(new ThreadStart(step));
            threadStep.SetApartmentState(System.Threading.ApartmentState.STA);
            threadStep.Start();
        }
Example #4
0
        public virtual bool parseXml(XElement xml, TLayer parentLayer)
        {
            if (xml == null)
            {
                return(false);
            }

            try {
                name            = xml.Element("Name").Value;
                parent          = parentLayer;
                locked          = TUtil.parseBoolXElement(xml.Element("Locked"), false);
                backgroundColor = Color.FromArgb(TUtil.parseIntXElement(xml.Element("BackgroundColor"), 0));
                alpha           = float.Parse(xml.Element("Alpha").Value);

                XElement xmlEvents = xml.Element("Events");
                IEnumerable <XElement> xmlEventList = xmlEvents.Elements("Event");
                foreach (XElement xmlEvent in xmlEventList)
                {
                    events.Add(xmlEvent.Value);
                }

                XElement xmlStates = xml.Element("States");
                IEnumerable <XElement> xmlStateList = xmlStates.Elements("State");
                foreach (XElement xmlState in xmlStateList)
                {
                    states.Add(xmlState.Value);
                }

                XElement xmlAnimations = xml.Element("Animations");
                IEnumerable <XElement> xmlAnimationList = xmlAnimations.Elements("Animation");
                foreach (XElement xmlAnimation in xmlAnimationList)
                {
                    TAnimation animation = new TAnimation(this);
                    if (!animation.parseXml(xmlAnimation))
                    {
                        return(false);
                    }
                    animations.Add(animation);
                }

                XElement xmlChilds = xml.Element("Childs");
                IEnumerable <XElement> xmlChildList = xmlChilds.Elements();
                foreach (XElement xmlChild in xmlChildList)
                {
                    TLayer layer = (TLayer)Activator.CreateInstance(Type.GetType(GetType().Namespace + ".T" + xmlChild.Name.ToString()), new Object[] { document });
                    if (!layer.parseXml(xmlChild, this))
                    {
                        return(false);
                    }
                    childs.Add(layer);
                }

                return(true);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
        public TransferActorAction(TDocument doc, TActor actor, TLayer parent)
        {
            this.document  = doc;
            this.actor     = actor;
            this.oldData   = new ActorMatrixData();
            this.newData   = new ActorMatrixData();
            this.oldParent = actor.parent;
            this.newParent = parent;

            this.oldData.position = actor.position;
            this.oldData.scale    = actor.scale;
            this.oldData.skew     = actor.skew;
            this.oldData.rotation = actor.rotation;

            // actor's position based on new parent
            PointF pt = actor.parent.logicalToScreen(actor.position);

            pt = parent.screenToLogical(pt);

            // actor's rotation based on new parent
            float angle = actor.rotationOnScreen();

            if (parent is TActor)
            {
                angle -= ((TActor)parent).rotationOnScreen();
            }
            TUtil.normalizeDegreeAngle(angle);

            // for scale
            RectangleF bound = actor.bound();
            PointF     s     = actor.logicalVectorToScreen(new PointF(bound.Width, bound.Height));
            SizeF      scale = new SizeF(1, 1);

            Matrix m2 = new Matrix();

            m2.Translate(pt.X, pt.Y);
            m2.Rotate((float)(angle * 180 / Math.PI));
            m2.Translate(-actor.anchor.X * actor.bound().Width, -actor.anchor.Y * actor.bound().Height);

            Matrix m = parent.matrixFromScreen();

            m.Multiply(m2);
            if (m.IsInvertible)
            {
                PointF[] aPos = { s };
                m.Invert();
                m.TransformVectors(aPos);
                s     = aPos[0];
                scale = new SizeF(s.X / bound.Width, s.Y / bound.Height);
            }

            this.newData.position = pt;
            this.newData.scale    = scale;
            this.newData.skew     = actor.skew;
            this.newData.rotation = angle;

            oldIndex = actor.parent.childs.IndexOf(actor);
        }
Example #6
0
        private void pnlDisplayBox_MouseUp(object sender, MouseEventArgs e)
        {
            if (currentScene == null)
            {
                return;
            }

            if (e.Button == MouseButtons.Left && MousePressed)
            {
                // fire drop event
                if (MouseDownActor != null)
                {
                    MouseDownActor.fireEvent(Program.DEFAULT_EVENT_DROP, false);

                    // check this actor is puzzle actor
                    if (MouseDownActor.puzzle && !MouseDownActor.isMoving())
                    {
                        PointF[] bound1 = MouseDownActor.interactionBoundOnScreen();

                        // check if the puzzle actor went the correct puzzle area
                        if (TUtil.isPolygonsIntersect(bound1, MouseDownActor.puzzleAreaOnScreen()))
                        {
                            // turn off the puzzle function after success
                            MouseDownActor.puzzle = false;

                            // fire puzzle success event
                            MouseDownActor.fireEvent(Program.DEFAULT_EVENT_PUZZLE_SUCCESS, false);
                        }
                        else
                        {
                            // if puzzle is failed, actor return to original position
                            TAnimation animation = new TAnimation(MouseDownActor);
                            TSequence  sequence  = animation.addSequence();
                            sequence.addAction(new TActionIntervalMove()
                            {
                                duration = 300, position = MouseDownActor.backupActor.position
                            });
                            sequence.addAction(new TActionInstantDispatchEvent()
                            {
                                actor = MouseDownActor.name, eventu = Program.DEFAULT_EVENT_PUZZLE_FAIL, recursive = false
                            });

                            animation.start();
                            extraAnimations.Add(animation);
                        }
                    }
                }

                MousePressed   = false;
                MouseDownActor = null;

                // redraw workspace
                this.pnlDisplayBox.Refresh();
            }
        }
Example #7
0
        public override bool parseXml(XElement xml, TLayer parentLayer)
        {
            if (xml == null)
            {
                return(false);
            }

            if (!base.parseXml(xml, parentLayer))
            {
                return(false);
            }

            try {
                Anchor.X     = float.Parse(xml.Element("AnchorX").Value);
                Anchor.Y     = float.Parse(xml.Element("AnchorY").Value);
                Position.X   = float.Parse(xml.Element("PositionX").Value);
                Position.Y   = float.Parse(xml.Element("PositionY").Value);
                Scale.Width  = float.Parse(xml.Element("ScaleWidth").Value);
                Scale.Height = float.Parse(xml.Element("ScaleHeight").Value);
                Skew.Width   = float.Parse(xml.Element("SkewWidth").Value);
                Skew.Height  = float.Parse(xml.Element("SkewHeight").Value);
                Rotation     = float.Parse(xml.Element("Rotation").Value);
                refreshMatrix();

                zIndex    = int.Parse(xml.Element("ZIndex").Value);
                draggable = bool.Parse(xml.Element("Draggable").Value);
                acceleratorSensibility = bool.Parse(xml.Element("AcceleratorSensibility").Value);
                autoInteractionBound   = bool.Parse(xml.Element("AutoInteractionBound").Value);
                InteractionBound       = new RectangleF(float.Parse(xml.Element("InteractionBoundX").Value),
                                                        float.Parse(xml.Element("InteractionBoundY").Value),
                                                        float.Parse(xml.Element("InteractionBoundWidth").Value),
                                                        float.Parse(xml.Element("InteractionBoundHeight").Value));

                puzzle     = bool.Parse(xml.Element("Puzzle").Value);
                PuzzleArea = new RectangleF(TUtil.parseFloatXElement(xml.Element("PuzzleAreaX"), 0),
                                            TUtil.parseFloatXElement(xml.Element("PuzzleAreaY"), 0),
                                            TUtil.parseFloatXElement(xml.Element("PuzzleAreaWidth"), Program.BOOK_WIDTH),
                                            TUtil.parseFloatXElement(xml.Element("PuzzleAreaHeight"), Program.BOOK_HEIGHT));

                return(true);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
        // execute action for every frame
        // if action is finished, return true;
        public override bool step(FrmEmulator emulator, long time)
        {
            float elapsed = time - run_startTime;

            if (elapsed > duration)
            {
                elapsed = duration;
            }

            TLayer layer = sequence.animation.layer;

            if (layer is TActor)
            {
                TActor target = (TActor)layer;
                target.rotation = TUtil.normalizeDegreeAngle(run_easingFunction.ease(easingType, easingMode, duration, elapsed, run_startAngle, run_endAngle));
            }

            return(base.step(emulator, time));
        }
Example #9
0
        public void transferLayer(TActor item, TLayer target)
        {
            // item's position based on new parent
            PointF pt = item.parent.logicalToScreen(item.position);

            pt = target.screenToLogical(pt);

            // item's rotation based on new parent
            float angle = item.rotationOnScreen();

            if (target is TActor)
            {
                angle -= ((TActor)target).rotationOnScreen();
            }
            TUtil.normalizeDegreeAngle(angle);

            // for scale
            RectangleF bound = item.bound();
            PointF     s     = item.logicalVectorToScreen(new PointF(bound.Width, bound.Height));

            // new properties
            item.position = pt;
            item.rotation = angle;
            item.scale    = new Size(1, 1);

            Matrix m = target.matrixFromScreen();

            m.Multiply(item.matrix);
            if (m.IsInvertible)
            {
                PointF[] aPos = { s };
                m.Invert();
                m.TransformVectors(aPos);
                s          = aPos[0];
                item.scale = new SizeF(s.X / bound.Width, s.Y / bound.Height);
            }

            item.parent.childs.Remove(item);
            target.childs.Add(item);
            item.parent = target;
        }
Example #10
0
        public override bool parseXml(XElement xml)
        {
            if (xml == null || xml.Name != "ActionInstantChangeBGM")
            {
                return(false);
            }

            if (!base.parseXml(xml))
            {
                return(false);
            }

            try {
                sound  = xml.Element("Sound").Value;
                volume = TUtil.parseIntXElement(xml.Element("Volume"), 100);
                return(true);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
Example #11
0
        public override bool parseXml(XElement xml)
        {
            if (xml == null || xml.Name != "ActionInstantStopAllSounds")
            {
                return(false);
            }

            if (!base.parseXml(xml))
            {
                return(false);
            }

            try {
                bgm    = TUtil.parseBoolXElement(xml.Element("BGM"), true);
                effect = TUtil.parseBoolXElement(xml.Element("Effect"), true);
                voice  = TUtil.parseBoolXElement(xml.Element("Voice"), true);
                return(true);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
Example #12
0
        // rotate the selected item the specified angle, the angle is degree
        public void rotateSelectedItems(float angle, bool fixedAngle)
        {
            if (selectedItems.Count == 0)
            {
                return;
            }

            if (fixedAngle)
            {
                angle = (float)(Math.Floor(angle / 15) + 1) * 15;
            }

            if (selectedItems.Count == 1)
            {
                TActor item   = (TActor)this.selectedItems[0];
                TActor origin = item.backupActor;
                item.rotation = TUtil.normalizeDegreeAngle(origin.rotation + angle);
            }
            else
            {
                // center of selection
                PointF[] bound = this.selectedBound();
                PointF   c     = new PointF((bound[0].X + bound[2].X) / 2, (bound[0].Y + bound[2].Y) / 2);

                // rotate each selected item
                for (int i = 0; i < selectedItems.Count; i++)
                {
                    // adjust rotation value
                    TActor item   = this.selectedItems[0];
                    TActor origin = item.backupActor;
                    item.rotation = TUtil.normalizeDegreeAngle(origin.rotation + angle);

                    // item position
                    PointF p = item.parent.logicalToScreen(item.position);
                    p             = TUtil.rotatePositionAround(c, p, angle);
                    item.position = item.parent.screenToLogical(p);
                }
            }
        }
Example #13
0
        public bool parseXml(XElement xml)
        {
            if (xml == null || xml.Name != "Document")
            {
                return(false);
            }

            identifier                  = TUtil.parseStringXElement(xml.Element("Identifier"), "");
            backgroundMusic             = xml.Element("BackgroundMusic").Value;
            backgroundMusicVolume       = TUtil.parseIntXElement(xml.Element("BackgroundMusicVolume"), 100);
            navigationButtonDelayTime   = TUtil.parseIntXElement(xml.Element("NavigationButtonDelayTime"), 5);
            navigationLeftButtonRender  = TUtil.parseBoolXElement(xml.Element("NavigationLeftButtonRender"), true);
            navigationRightButtonRender = TUtil.parseBoolXElement(xml.Element("NavigationRightButtonRender"), true);
            prevSceneButton             = xml.Element("PrevSceneButton").Value;
            nextSceneButton             = xml.Element("NextSceneButton").Value;
            avatarDefault               = xml.Element("AvatarDefault").Value;
            avatarFrame                 = xml.Element("AvatarFrame").Value;
            avatarMask                  = xml.Element("AvatarMask").Value;

            return
                (libraryManager.parseXml(xml.Element("Libraries")) &&
                 sceneManager.parseXml(xml.Element("Scenes")));
        }
Example #14
0
        public override bool parseXml(XElement xml, TLayer parentLayer)
        {
            if (xml == null || xml.Name != "Scene")
            {
                return(false);
            }

            if (!base.parseXml(xml, null))
            {
                return(false);
            }

            try {
                touchIndication       = bool.Parse(xml.Element("TouchIndication").Value);
                prevButtonVisible     = bool.Parse(xml.Element("PrevButtonVisible").Value);
                nextButtonVisible     = bool.Parse(xml.Element("NextButtonVisible").Value);
                backgroundMusic       = xml.Element("BackgroundMusic").Value;
                backgroundMusicVolume = TUtil.parseIntXElement(xml.Element("BackgroundMusicVolume"), 100);
                return(true);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
        private void pnlWorkspace_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.document.currentScene() == null)
            {
                return;
            }

            if (e.Button == MouseButtons.Left && MousePressed)
            {
                if (MouseDownTool == TDocument.TOOL_SELECT)
                {
                    // if have selection, move it
                    if (this.document.haveSelection())
                    {
                        if (MouseDownPart == 0)
                        {
                            // move selection items
                            this.document.moveSelectedItems(e.X - MouseDownPos.X, e.Y - MouseDownPos.Y, (Control.ModifierKeys & Keys.Shift) != 0);
                        }
                        else if (MouseDownPart >= 1 && MouseDownPart <= 8)
                        {
                            // scale selection items
                            this.document.scaleSelectedItems(MouseDownPart, e.X - MouseDownPos.X, e.Y - MouseDownPos.Y, (Control.ModifierKeys & Keys.Shift) != 0);
                        }
                        else if (MouseDownPart == 10)
                        {
                            // move anchor point
                            this.document.moveAnchorOfSelectedItem(e.X - MouseDownPos.X, e.Y - MouseDownPos.Y, (Control.ModifierKeys & Keys.Shift) != 0);
                        }
                        else if (MouseDownPart == 9)
                        {
                            // rotate
                            TActor item = this.document.selectedItems[0];
                            PointF p    = item.parent.logicalToScreen(item.position);
                            float  a    = TUtil.angleBetweenVectors(new PointF(MouseDownPos.X - p.X, MouseDownPos.Y - p.Y), new PointF(e.X - p.X, e.Y - p.Y));
                            this.document.rotateSelectedItems((float)(a * 180 / Math.PI), (Control.ModifierKeys & Keys.Shift) != 0);
                        }
                    }
                }
                else if (MouseDownTool == TDocument.TOOL_HAND)
                {
                    PointF offset = this.document.offset;
                    offset.X += e.X - MouseDownPos.X;
                    offset.Y += e.Y - MouseDownPos.Y;

                    this.document.offset = offset;

                    // update mouse position
                    MouseDownPos.X = e.X; MouseDownPos.Y = e.Y;
                }
                else if (MouseDownTool == TDocument.TOOL_TEXT || MouseDownTool == TDocument.TOOL_AVATAR)
                {
                    // if have selection, move it
                    if (!this.document.haveSelection() || MouseDownPart == -1 || MouseDownPart == 9)
                    {
                        this.SelectRegion.Width  = e.X - this.SelectRegion.X;
                        this.SelectRegion.Height = e.Y - this.SelectRegion.Y;
                    }
                    else if (MouseDownPart >= 1 && MouseDownPart <= 8 && MouseDownTool == TDocument.TOOL_TEXT)
                    {
                        // resize text actor
                        if (this.document.resizeSelectedTextActor(MouseDownPart, e.X - MouseDownPos.X, e.Y - MouseDownPos.Y))
                        {
                            // update mouse position
                            MouseDownPos.X = e.X; MouseDownPos.Y = e.Y;
                        }
                    }
                }
                else if (MouseDownTool == TDocument.TOOL_BOUNDING)
                {
                    if (this.document.haveSelection())
                    {
                        if (MouseDownPart == 0)
                        {
                            // move the interaction bound
                            this.document.moveInteractionBound(e.X - MouseDownPos.X, e.Y - MouseDownPos.Y, (Control.ModifierKeys & Keys.Shift) != 0);
                        }
                        else if (MouseDownPart >= 1 && MouseDownPart <= 8)
                        {
                            // scale the interaction bound
                            this.document.scaleInteractionBound(MouseDownPart, e.X - MouseDownPos.X, e.Y - MouseDownPos.Y, (Control.ModifierKeys & Keys.Shift) != 0);
                        }
                    }
                }
                else if (MouseDownTool == TDocument.TOOL_PUZZLE)
                {
                    if (this.document.haveSelection())
                    {
                        if (MouseDownPart == 0)
                        {
                            // move the puzzle area
                            this.document.movePuzzleArea(e.X - MouseDownPos.X, e.Y - MouseDownPos.Y, (Control.ModifierKeys & Keys.Shift) != 0);
                        }
                        else if (MouseDownPart >= 1 && MouseDownPart <= 8)
                        {
                            // scale the puzzle area
                            this.document.scalePuzzleArea(MouseDownPart, e.X - MouseDownPos.X, e.Y - MouseDownPos.Y, (Control.ModifierKeys & Keys.Shift) != 0);
                        }
                    }
                }

                // redraw workspace
                this.pnlWorkspace.Refresh();
            }
            else
            {
                if (this.document.activeTool() == TDocument.TOOL_SELECT)
                {
                    if (this.document.haveSelection())
                    {
                        // calc which part of selection is mouse position
                        int cursor;
                        int part = this.document.partOfSelection(e.X, e.Y, out cursor);
                        if (part == -1)
                        {
                            this.Cursor = Cursors.Default;
                        }
                        else if (part == 0)
                        {
                            this.Cursor = Cursors.SizeAll;
                        }
                        else if (part == 9)
                        {
                            this.Cursor = new Cursor(Properties.Resources.cursor_rotation.Handle);
                        }
                        else if (part == 10)
                        {
                            this.Cursor = Cursors.NoMove2D;
                        }
                        else if (cursor == 0)
                        {
                            this.Cursor = Cursors.SizeNS;
                        }
                        else if (cursor == 1)
                        {
                            this.Cursor = Cursors.SizeNWSE;
                        }
                        else if (cursor == 2)
                        {
                            this.Cursor = Cursors.SizeWE;
                        }
                        else if (cursor == 3)
                        {
                            this.Cursor = Cursors.SizeNESW;
                        }
                    }
                }
                else if (this.document.activeTool() == TDocument.TOOL_TEXT)
                {
                    if (this.document.haveSelection() && (this.document.selectedItems[0] is TTextActor))
                    {
                        // calc which part of selection is mouse position
                        int cursor;
                        int part = this.document.partOfSelection(e.X, e.Y, out cursor);
                        if (part == -1 || part == 9)
                        {
                            this.Cursor = Cursors.Cross;
                        }
                        else if (part == 0)
                        {
                            this.Cursor = Cursors.IBeam;
                        }
                        else if (cursor == 0)
                        {
                            this.Cursor = Cursors.SizeNS;
                        }
                        else if (cursor == 1)
                        {
                            this.Cursor = Cursors.SizeNWSE;
                        }
                        else if (cursor == 2)
                        {
                            this.Cursor = Cursors.SizeWE;
                        }
                        else if (cursor == 3)
                        {
                            this.Cursor = Cursors.SizeNESW;
                        }
                    }
                }
                else if (this.document.activeTool() == TDocument.TOOL_BOUNDING || this.document.activeTool() == TDocument.TOOL_PUZZLE)
                {
                    if (this.document.haveSelection())
                    {
                        // calc which part of selection is mouse position
                        int cursor;
                        int part = this.document.partOfSelection(e.X, e.Y, out cursor);
                        if (part == -1)
                        {
                            this.Cursor = Cursors.Default;
                        }
                        else if (part == 0)
                        {
                            this.Cursor = Cursors.SizeAll;
                        }
                        else if (cursor == 0)
                        {
                            this.Cursor = Cursors.SizeNS;
                        }
                        else if (cursor == 1)
                        {
                            this.Cursor = Cursors.SizeNWSE;
                        }
                        else if (cursor == 2)
                        {
                            this.Cursor = Cursors.SizeWE;
                        }
                        else if (cursor == 3)
                        {
                            this.Cursor = Cursors.SizeNESW;
                        }
                    }
                }
                else if (this.document.activeTool() == TDocument.TOOL_AVATAR)
                {
                    this.Cursor = Cursors.Cross;
                }
            }
        }
Example #16
0
        //============== return value ===============//
        //
        //                    -1
        //      9                           9
        //        ┌───────────────────────┐
        //        │ 1         8         4 │
        //        │                       │
        //  -1    │ 5         0         7 │    -1
        //        │                       │
        //        │ 2         6         3 │
        //        └───────────────────────┘
        //      9                           9
        //                    -1
        //
        //
        // Anchor Point : 10
        //============================================//
        public int partOfSelection(float x, float y, out int cursor)
        {
            cursor = -1;

            if (selectedItems.Count == 0)
            {
                return(-1);
            }
            if (selectedItems.Count > 1)
            {
                return(containsInSelection(x, y) ? 0 : 9);
            }

            TActor actor = selectedItems[0];

            if (currentTool == TDocument.TOOL_PUZZLE && !actor.puzzle)
            {
                return(-1);
            }

            PointF screenPos  = new PointF(x, y);
            PointF logicalPos = currentTool != TDocument.TOOL_PUZZLE ? actor.screenToLogical(new PointF(x, y)) : actor.ownerScene().screenToLogical(new PointF(x, y));

            RectangleF actorBound        = actor.bound();
            PointF     anchorPosOnScreen = actor.logicalToScreen(new PointF(actorBound.Width * actor.anchor.X, actorBound.Height * actor.anchor.Y));

            RectangleF bound;

            if (currentTool == TDocument.TOOL_BOUNDING)
            {
                bound = actor.interactionBound;
            }
            else if (currentTool == TDocument.TOOL_PUZZLE)
            {
                bound = actor.puzzleArea;
            }
            else
            {
                bound = actorBound;
            }

            PointF[] boundOnScreen;
            if (currentTool == TDocument.TOOL_BOUNDING)
            {
                boundOnScreen = actor.interactionBoundOnScreen();
            }
            else if (currentTool == TDocument.TOOL_PUZZLE)
            {
                boundOnScreen = actor.puzzleAreaOnScreen();
            }
            else
            {
                boundOnScreen = actor.boundOnScreen();
            }
            int ctrl_size = 6;

            bool leftEdge    = TUtil.distanceBetweenPointLine(screenPos, boundOnScreen[0], boundOnScreen[1]) <= ctrl_size;
            bool bottomEdge  = TUtil.distanceBetweenPointLine(screenPos, boundOnScreen[1], boundOnScreen[2]) <= ctrl_size;
            bool rightEdge   = TUtil.distanceBetweenPointLine(screenPos, boundOnScreen[2], boundOnScreen[3]) <= ctrl_size;
            bool topEdge     = TUtil.distanceBetweenPointLine(screenPos, boundOnScreen[3], boundOnScreen[0]) <= ctrl_size;
            bool insideBound = bound.Contains(logicalPos);

            int    first_cursor = 0; // cursor form part 5
            double angle        = -Math.Atan2(boundOnScreen[1].Y - boundOnScreen[0].Y, boundOnScreen[1].X - boundOnScreen[0].X) * 180 / Math.PI;

            if (angle < 0)
            {
                angle += 360;
            }
            first_cursor = (int)((angle + 22.5) / 45) % 4;

            int part = -1;

            if (leftEdge && topEdge)
            {
                part = 1; cursor = (first_cursor - 1) % 4;
            }
            else if (leftEdge && bottomEdge)
            {
                part = 2; cursor = (first_cursor + 1) % 4;
            }
            else if (rightEdge && bottomEdge)
            {
                part = 3; cursor = (first_cursor + 3) % 4;
            }
            else if (rightEdge && topEdge)
            {
                part = 4; cursor = (first_cursor + 5) % 4;
            }
            else if (leftEdge && TUtil.isPointProjectionInLineSegment(screenPos, boundOnScreen[0], boundOnScreen[1]))
            {
                part = 5; cursor = (first_cursor + 0) % 4;
            }
            else if (bottomEdge && TUtil.isPointProjectionInLineSegment(screenPos, boundOnScreen[1], boundOnScreen[2]))
            {
                part = 6; cursor = (first_cursor + 2) % 4;
            }
            else if (rightEdge && TUtil.isPointProjectionInLineSegment(screenPos, boundOnScreen[2], boundOnScreen[3]))
            {
                part = 7; cursor = (first_cursor + 4) % 4;
            }
            else if (topEdge && TUtil.isPointProjectionInLineSegment(screenPos, boundOnScreen[3], boundOnScreen[0]))
            {
                part = 8; cursor = (first_cursor + 6) % 4;
            }
            else if (TUtil.distanceBetweenPoints(screenPos, anchorPosOnScreen) <= ctrl_size)
            {
                part = 10;
            }
            else if (insideBound)
            {
                part = 0;
            }
            else if (currentTool != TDocument.TOOL_BOUNDING && currentTool != TDocument.TOOL_PUZZLE)
            {
                if (TUtil.distanceBetweenPoints(screenPos, boundOnScreen[0]) <= ctrl_size * 3 ||
                    TUtil.distanceBetweenPoints(screenPos, boundOnScreen[1]) <= ctrl_size * 3 ||
                    TUtil.distanceBetweenPoints(screenPos, boundOnScreen[2]) <= ctrl_size * 3 ||
                    TUtil.distanceBetweenPoints(screenPos, boundOnScreen[3]) <= ctrl_size * 3)
                {
                    part = 9;
                }
            }

            return(part);
        }
Example #17
0
 public bool containsInSelection(float x, float y)
 {
     return(TUtil.isInPolygon(this.selectedBound(), new PointF(x, y)));
 }
        private void pnlWorkspace_MouseUp(object sender, MouseEventArgs e)
        {
            if (this.document.currentScene() == null)
            {
                return;
            }

            // main form
            FrmMainContainer mainForm = (FrmMainContainer)this.MdiParent;

            if (e.Button == MouseButtons.Left && MousePressed)
            {
                if (MouseDownTool == TDocument.TOOL_TEXT)
                {
                    if (this.document.haveSelection() && MouseDownPart == 0)
                    {
                        mainForm.focusTextActorContent();
                    }
                    else if (!this.document.haveSelection() || MouseDownPart == -1)
                    {
                        // positivation
                        RectangleF bound = TUtil.positiveRectangle(SelectRegion);
                        if (bound.Width > 1 && bound.Height > 1)
                        {
                            // item to current scene
                            TTextActor actor = this.document.currentScene().pushText("", bound);
                            this.document.actionManager.RecordAction(new AddActorAction(this.document, actor));

                            // set the document modified flag
                            this.document.modified = true;

                            // select new added text actor
                            this.document.clearSelectedItems();
                            this.document.toggleSelectedItem(actor);

                            // update panels
                            mainForm.updateScenesPanel(this.document.sceneManager.currentSceneIndex);
                            mainForm.updateOutlinePanel();
                            mainForm.updateHistoryPanel();

                            // fire mainform's selected item changed event
                            mainForm.selectedItemChanged();

                            // show textbox of ribbon bar and make let user to edit content
                            mainForm.focusTextActorContent();

                            // record modify action
                            modifyActorAction = new ModifyActorAction(document, actor);
                        }
                    }
                    else if (this.document.haveSelection() && modifyActorAction != null)
                    {
                        // this is the case when text box was resized with text tool
                        modifyActorAction.setFinalData(this.document.selectedActor());
                        if (modifyActorAction.isModified())
                        {
                            this.document.actionManager.RecordAction(modifyActorAction);

                            // set the document modified flag
                            this.document.modified = true;

                            // ready to new modification action
                            modifyActorAction = new ModifyActorAction(document, document.selectedActor());

                            // update history
                            mainForm.updateHistoryPanel();
                        }

                        // update panels
                        this.document.sceneManager.updateThumbnail(this.document.sceneManager.currentSceneIndex);
                        mainForm.updateScenesPanel(this.document.sceneManager.currentSceneIndex);
                        mainForm.updateToolbarSceneSettings();
                        mainForm.updateOutlinePanel();
                    }
                }
                else if (MouseDownTool == TDocument.TOOL_AVATAR)
                {
                    if (!this.document.haveSelection() || MouseDownPart == -1)
                    {
                        // positivation
                        RectangleF bound = TUtil.positiveRectangle(SelectRegion);
                        if (bound.Width > 1 && bound.Height > 1)
                        {
                            // item to current scene
                            TAvatarActor actor = this.document.currentScene().pushAvatar(bound);
                            this.document.actionManager.RecordAction(new AddActorAction(this.document, actor));

                            // set the document modified flag
                            this.document.modified = true;

                            // select new added avatar actor
                            this.document.clearSelectedItems();
                            this.document.toggleSelectedItem(actor);

                            // update panels
                            mainForm.updateScenesPanel(this.document.sceneManager.currentSceneIndex);
                            mainForm.updateOutlinePanel();
                            mainForm.updateHistoryPanel();

                            // fire mainform's selected item changed event
                            mainForm.selectedItemChanged();

                            // record modify action
                            modifyActorAction = new ModifyActorAction(document, actor);
                        }
                    }
                }
                else
                {
                    if (this.document.haveSelection() && modifyActorAction != null)
                    {
                        // this is the case when text box was resized with text tool
                        modifyActorAction.setFinalData(this.document.selectedActor());
                        if (modifyActorAction.isModified())
                        {
                            this.document.actionManager.RecordAction(modifyActorAction);

                            // set the document modified flag
                            this.document.modified = true;

                            // ready to new modification action
                            modifyActorAction = new ModifyActorAction(document, document.selectedActor());

                            // update history
                            mainForm.updateHistoryPanel();
                        }
                    }

                    // update panels
                    this.document.sceneManager.updateThumbnail(this.document.sceneManager.currentSceneIndex);
                    mainForm.updateScenesPanel(this.document.sceneManager.currentSceneIndex);
                    mainForm.updateToolbarSceneSettings();
                    mainForm.updateOutlinePanel();
                }

                foreach (TActor actor in this.document.selectedItems)
                {
                    actor.deleteBackup();
                }

                MousePressed  = false;
                MouseDownTool = TDocument.TOOL_NONE;
                MouseDownPart = -1;
                SelectRegion  = RectangleF.Empty;

                // reset cursor
                this.updateCursor();

                // redraw workspace
                this.pnlWorkspace.Refresh();
            }
        }