Example #1
0
        /// <summary>
        /// Converts the (A,B) coordinates to (X,Y,Z) coordinates.
        /// </summary>
        public Location fromABToXYZ(int a, int b, IModalController controller)
        {
            int t = 2 * b - 16;

            int x = (a - t) >> 5;
            int y = (a + t) >> 5;

            x += (world.Size.y - 1) / 2;

            // (x,y,0) is the base location. disambiguate the location.
            // TODO: use height-cut here to force the specified z-level
            if (controller != null)
            {
                ILocationDisambiguator disambiguator = controller.Disambiguator;
                for (int z = HeightCutHeight; z >= 0; z--)
                {
                    Location loc = new Location(x - z, y + z, z);
                    if (disambiguator != null && disambiguator.IsSelectable(loc))
                    {
                        return(loc);
                    }
                }
            }

            return(new Location(x, y, 0));
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        protected override void OnMouseDown(MouseEventArgs arg)
        {
            IModalController controller = MainWindow.mainWindow.CurrentController;

            // start the drag mode
            dragMode           = true;
            dragStartMousePos  = getPoint(arg);
            dragStartScrollPos = this.AutoScrollPosition;
            dragAccel          = ((SdlDotNet.Input.Keyboard.IsKeyPressed(SdlDotNet.Input.Key.LeftControl) || SdlDotNet.Input.Keyboard.IsKeyPressed(SdlDotNet.Input.Key.RightControl)) ? 2 : 1) * ((SdlDotNet.Input.Keyboard.IsKeyPressed(SdlDotNet.Input.Key.LeftShift) || SdlDotNet.Input.Keyboard.IsKeyPressed(SdlDotNet.Input.Key.RightShift)) ? 2 : 1);
            this.Capture       = true;
        }
Example #3
0
        IEnumerator DoPop(IModalController ctrl)
        {
            ctrl.SetActive(false);

            ctrl.Close();

            yield return(ctrl.Closing());

            ctrl.Pop();

            ctrl.SetShow(false);
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        protected override void OnMouseUp(MouseEventArgs arg)
        {
            IModalController controller = MainWindow.mainWindow.CurrentController;

            if (dragMode)
            {
                bool r = scrollByDrag(arg);

                // end the drag mode
                dragMode     = false;
                this.Capture = false;
                this.Cursor  = null;

                if (r)
                {
                    return;     // if the scroll-by-drag was successful, don't process the click event
                }
            }

            if (controller != null)
            {
                //Point ab = drawer.fromClientToAB( arg.X, arg.Y );
                //Location xyz = drawer.fromABToXYZ( ab, controller );

                //if( arg.Button == MouseButtons.Left )
                //	controller.onClick( this, xyz, ab );
                //if( arg.Button == MouseButtons.Right )
                //	controller.onRightClick( this, xyz, ab );
            }
            else
            {
                if (arg.Button == MouseButtons.Left)
                {
                    // dispatch this click event to the appropriate voxel.

                    //Location loc = drawer.fromClientToXYZ(arg,null); {
                    // print debug information
                    //	Debug.WriteLine("mouse clicked on MapViewWindow. (x,y,z)="+loc);
                    //	int h,v;
                    //	World.world.toHV( loc.x, loc.y, out h, out v );
                    //	Debug.WriteLine(string.Format(" (h,v)=({0},{1})",h,v) );
                    //}

                    // look for voxels that can process this event
                    //for( int z=drawer.heightCutHeight; z>=0; z-- ) {
                    //	Voxel v = World.world[ loc.x-z, loc.y+z, z ];
                    //	if(v!=null && v.onClick())
                    //		return;
                    //}
                }
            }
        }
Example #5
0
        /// <summary>
        /// Deactivates the current ModalController, if any.
        /// </summary>
        public void DetachController()
        {
            if (controller == null)
            {
                return;
            }

            controller.OnDetached();
            controller = null;

            // update all the views
            // TODO: update voxels correctly
            WorldDefinition.World.OnVoxelUpdated(World.Location.Unplaced);
        }
Example #6
0
 private void Tick(object sender, TickEventArgs e)
 {
     if (qView != null)
     {
         controller = MainWindow.mainWindow.CurrentController;
         qView.UpdateScreen();
         if (WorldDefinition.World.Satellite == null ||
             WorldDefinition.World.Satellite.surface.w != 150 ||
             WorldDefinition.World.Satellite.surface.h != 150)
         {
             WorldDefinition.World.Satellite = new Surface(150, 150, 32);
             WorldDefinition.World.Satellite.SourceColorKey = Color.Magenta;
             WorldDefinition.World.Satellite.Fill(Color.FromArgb(222, 195, 132));
         }
     }
     Application.DoEvents();
 }
Example #7
0
        /// <summary>
        /// Activates a new ModalController.
        /// </summary>
        public void AttachController(IModalController newHandler)
        {
            if (controller == newHandler)
            {
                return; // already activated
            }
            if (controller != null)
            {
                DetachController();     // deactive the current handler first
            }

            controller = newHandler;
            controller.OnAttached();

            // update all the views
            // TODO: update voxels correctly
            WorldDefinition.World.OnAllVoxelUpdated();
        }
Example #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        protected override void OnMouseMove(MouseEventArgs arg)
        {
            IModalController controller = MainWindow.mainWindow.CurrentController;

            if (dragMode)
            {
                scrollByDrag(arg);
            }
            else
            {
                if (controller != null)
                {
                    //Point ab = drawer.fromClientToAB( arg.X, arg.Y );

                    //controller.onMouseMove( this,
                    //	drawer.fromABToXYZ(ab,controller),
                    //	ab );
                }
            }
        }
Example #9
0
        internal void EndModal(IModalController controller)
        {
            if (controller != _currentModalController)
                return;

            if (!InModalMode)
                throw new InvalidOperationException("Cannot end modal mode because the Ribbon is not in Modal Mode");

            _modalControllerStack.RemoveAt(_modalControllerStack.Count - 1);
            _currentModalController = null;
            if (_modalControllerStack.Count > 0)
            {
                _currentModalController =
                    (IModalController)_modalControllerStack[_modalControllerStack.Count - 1];
            }

            if (CUIUtility.IsNullOrUndefined(_currentModalController))
                EnsureEndModal();
        }
Example #10
0
        internal bool BeginModal(IModalController controller, HtmlElement _elmTrigger)
        {
            if (CUIUtility.IsNullOrUndefined(_modalControllerStack))
                _modalControllerStack = new List<IModalController>();

            _modalControllerStack.Add(controller);
            _currentModalController = controller;

            if (_modal)
                return false;

            // This div covers the whole window and will essentially block any elements
            // behind it from receiving click/mouseover/mouseout events etc.
            Div modalDiv = ModalDiv;
            modalDiv.Style.Visibility = "hidden";
            Browser.Document.Body.AppendChild(modalDiv);
            modalDiv.Style.Visibility = "visible";
            _modal = true;
            return true;
        }
Example #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cx"></param>
 /// <param name="cy"></param>
 /// <param name="controller"></param>
 /// <returns></returns>
 public Location fromClientToXYZ(int cx, int cy, IModalController controller)
 {
     return(fromABToXYZ(fromClientToAB(cx, cy), controller));
 }
Example #12
0
 /// <summary>
 /// Converts the mouse coordinate (which is client coordinate)
 /// to (X,Y) coordinates.
 /// </summary>
 public Location fromClientToXYZ(MouseEventArgs mea, IModalController controller)
 {
     return(fromABToXYZ(fromClientToAB(mea.X, mea.Y), controller));
 }
Example #13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="pt"></param>
 /// <param name="controller"></param>
 /// <returns></returns>
 public Location fromABToXYZ(Point pt, IModalController controller)
 {
     return(fromABToXYZ(pt.X, pt.Y, controller));
 }
Example #14
0
        /// <summary>
        /// Update the surface by redrawing necessary parts.
        /// </summary>
        public void UpdateScreen()
        {
            if (dirtyRect.isEmpty || offscreenBuffer == null)
            {
                return;                                                 // no need for draw.
            }
            DateTime start = DateTime.Now;

            IMapOverlay      overlay    = null;
            IModalController controller = MainWindow.mainWindow.CurrentController;

            if (controller != null)
            {
                overlay = controller.Overlay;
            }

            if (overlay != null)
            {
                overlay.DrawBefore(this, drawContext);
            }

            // draw the rect
            Rectangle dr = dirtyRect.rect;

            if (dr.Top < 0)
            {
                dr.Y = 0;               // clipping. higher voxel on the northen edge could make top<0
            }
            Draw(dr, overlay);
            dirtyRect.clear();

            // allow MapOverlay to do the wrap-up
            if (overlay != null)
            {
                overlay.DrawAfter(this, drawContext);
            }

            if (Core.Options.drawStationNames)
            {
                // REVISIT: I don't want these code inside this method.
                //  it needs to be extensible.

                /*Graphics graphics = drawContext.graphics;
                 *
                 * foreach( freetrain.world.rail.Station st in world.stations )
                 * {
                 *  Point pt = fromXYZToClient( st.baseLocation );
                 *  pt.Y -= 16;	// display the string above the station
                 *
                 *  SizeF sz = graphics.MeasureString( st.name, drawFont );
                 *  pt.X -= (int)sz.Width/2;
                 *
                 *  graphics.DrawString( st.name, drawFont, drawBrush1, pt.X+1, pt.Y+1 );
                 *  graphics.DrawString( st.name, drawFont, drawBrush2, pt.X  , pt.Y   );
                 * }*/
            }

            drawContext.Tag = null;             // reset the attached tag

            Debug.WriteLine("update took " + (DateTime.Now - start).TotalMilliseconds + "ms");
        }