Example #1
0
        public void OnRender(Canvas c)
        {
            if (State != WindowState.HIDE)
            {
                _shade_btn        = _caption_bar;
                _shade_btn.Width  = 12;
                _shade_btn.Height = 12;
                _shade_btn.X      = _caption_bar.Right - 28;
                _shade_btn.Y     += 7;

                _v_scroll_rect.X      = _client_area.Right - ScrollWidth;
                _v_scroll_rect.Y      = _caption_bar.Bottom;
                _v_scroll_rect.Height = _client_area.Height - (ScrollWidth + _caption_bar.Height);
                _v_scroll_rect.Width  = ScrollWidth - 1;

                _h_scroll_rect.X      = _client_area.X;
                _h_scroll_rect.Y      = _client_area.Bottom - ScrollWidth;
                _h_scroll_rect.Width  = _client_area.Width - ScrollWidth;
                _h_scroll_rect.Height = ScrollWidth - 1;

                _v_scroll_thumb = _v_scroll_rect;
                _h_scroll_thumb = _h_scroll_rect;


                c.DrawFillRect(_main_panel.ClientArea, _background_color_material);

                _main_panel.OnRender(c);

                if (HasScrollBars)
                {
                    if (this._ShowHorizontalScroll)
                    {
                        DrawHorizontalScroll(c);
                    }
                    if (this._ShowVerticalScroll)
                    {
                        DrawVerticalScroll(c);
                    }
                }

                c.DrawRect(_client_area, BorderColor);


                if (CaptionText != string.Empty)
                {
                    c.DrawFillRect(_caption_bar, _caption_color_material);
                    if (Font != null)
                    {
                        Font.DrawText(null, CaptionText, _caption_bar, DrawTextFormat.VerticalCenter | DrawTextFormat.Center, CaptionForeground);
                    }

                    if (AllowShade)
                    {
                        switch (State)
                        {
                        case WindowState.MINIMIZED:
                            c.DrawFillTri(_shade_btn, _caption_foreground_material, DIRECTION.UP);
                            c.DrawTri(_shade_btn, BorderColor, DIRECTION.UP);
                            break;

                        case WindowState.MAXIMIZED:
                            c.DrawFillTri(_shade_btn, _caption_foreground_material, DIRECTION.DOWN);
                            c.DrawTri(_shade_btn, BorderColor, DIRECTION.DOWN);
                            break;
                        }
                    }

                    if (Selected)
                    {
                        c.DrawRect(_caption_bar, Color.White);
                    }
                    else
                    {
                        c.DrawRect(_caption_bar, BorderColor);
                    }
                }


                if (AllowResize)
                {
                    _resize_btn.X      = _client_area.Right - 15;
                    _resize_btn.Y      = _client_area.Bottom - 15;
                    _resize_btn.Width  = 10;
                    _resize_btn.Height = 10;

                    c.DrawFillRect(_resize_btn, _caption_color_material);
                    c.DrawRect(_resize_btn, BorderColor);
                }
            }
        }
Example #2
0
        public override void OnRender(Canvas canvas)
        {
            if (!PauseRendering)
            {
                Rectangle PlayfieldRect = canvas.TargetControl.ClientRectangle;
                _playfield.ClientArea = PlayfieldRect;

                int bottom_left = (PlayfieldRect.Y + PlayfieldRect.Height);

                Rectangle SpriteRect = Rectangle.Empty;

                if (Map != null)
                {
                    SpriteRect = Map.ToRectangle();

                    // Prevent black from appearing on sides of map.
                    if (!SpriteRect.Contains(PlayfieldRect))
                    {
                        int right = (int)(Map.Position.X + (Map.TextureWidth * _playfield.Scale));
                        int bottom = (int)(Map.Position.Y + (Map.TextureHeight * _playfield.Scale));
                        if (right < PlayfieldRect.Width)
                        {
                            Pan(PlayfieldRect.Width - right, 0);
                        }
                        if (bottom < PlayfieldRect.Height)
                        {
                            Pan(0, PlayfieldRect.Height - bottom);
                        }
                        if (Map.Position.Y > PlayfieldRect.Y)
                        {
                            Pan(0, -(Map.Position.Y));
                        }
                        if (Map.Position.X > PlayfieldRect.X)
                        {
                            Pan(-(Map.Position.X), 0);
                        }
                    }
                }

                switch (MapScrollState)
                {
                    case MapPlayfieldScrollState.UP:
                        Pan(0, -10);
                        break;
                    case MapPlayfieldScrollState.DOWN:
                        Pan(0, 10);
                        break;
                    case MapPlayfieldScrollState.LEFT:
                        Pan(-10, 0);
                        break;
                    case MapPlayfieldScrollState.RIGHT:
                        Pan(10, 0);
                        break;
                }

                _playfield.OnRender(canvas);

                if (WBRoom != null)
                {
                    // Draw Whiteboard information from other selected rooms
                    List<string> otherWBNames = WBRoom.GetOtherWBRoomNames();
                    if (otherWBNames != null)
                    {
                        foreach (string otherWBName in otherWBNames)
                        {
                            DrawWhiteboardRoomObjects(WBRoom.GetOtherWBRoom(otherWBName), canvas);
                        }
                    }

                    // Draw Whiteboard information from current room
                    DrawWhiteboardRoomObjects(WBRoom, canvas);

                    // Draw any commands in progress
                    if ((WBRoom.DrawMode == DrawModes.Line) &&
                        (DrawDistanceLine == true) && (WhiteboardDrawing == true))
                    {
                        if ((WBRoom.DrawText != null) && (WBRoom.DrawText.Length > 0))
                        {
                            int lineTextSize = LineTextSize;

                            DrawShortenedLine(canvas, WBRoom.DrawColor, WBRoom.DrawPointSize, LineStartLocation.X, LineStartLocation.Y,
                                LineEndLocation.X, LineEndLocation.Y, 1f);

                            if (lineTextSize > MaxFontSize)
                            {
                                lineTextSize = MaxFontSize;
                            }
                            if (lineTextSize < 1)
                            {
                                lineTextSize = 1;
                            }
                            if (wbFonts[lineTextSize] == null)
                            {
                                wbFonts[lineTextSize] = canvas.CreateFont(new System.Drawing.Font("Arial", lineTextSize, FontStyle.Bold, GraphicsUnit.Pixel));
                            }
                            DrawCenteredText(wbFonts[lineTextSize], WBRoom.DrawText, LineEndLocation.X, LineEndLocation.Y, WBRoom.DrawColor);
                        }
                        else
                        {
                            canvas.DrawLine(WBRoom.DrawColor, WBRoom.DrawPointSize, LineStartLocation.X, LineStartLocation.Y,
                                LineEndLocation.X, LineEndLocation.Y);
                        }
                    }
                    else if ((WBRoom.DrawMode == DrawModes.Circle) &&
                        (DrawDistanceLine == true) && (WhiteboardDrawing == true))
                    {
                        canvas.DrawCircle(WBRoom.DrawColor, WBRoom.DrawPointSize, LineStartLocation.X, LineStartLocation.Y,
                            LineEndLocation.X, LineEndLocation.Y);
                    }
                    else if ((WBRoom.DrawMode == DrawModes.Arrow) &&
                        (DrawDistanceLine == true) && (WhiteboardDrawing == true))
                    {
                        canvas.DrawArrow(WBRoom.DrawColor, WBRoom.DrawPointSize, LineStartLocation.X, LineStartLocation.Y,
                            LineEndLocation.X, LineEndLocation.Y);
                    }
                    else if ((WBRoom.DrawMode == DrawModes.Text) &&
                        (DrawDistanceLine == true) && (WhiteboardDrawing == true))
                    {
                        if ((WBRoom.DrawText != null) && (WBRoom.DrawText.Length > 0))
                        {
                            int drawPointSize = WBRoom.DrawPointSize + 7;

                            if (drawPointSize > MaxFontSize)
                            {
                                drawPointSize = MaxFontSize;
                            }
                            if (wbFonts[drawPointSize] == null)
                            {
                                wbFonts[drawPointSize] = canvas.CreateFont(new System.Drawing.Font("Arial", drawPointSize, FontStyle.Bold, GraphicsUnit.Pixel));
                            }
                            DrawCenteredText(wbFonts[drawPointSize], WBRoom.DrawText, LineEndLocation.X, LineEndLocation.Y, WBRoom.DrawColor);
                        }
                    }
                    else if ((WBRoom.DrawMode == DrawModes.Selection) &&
                        (DrawDistanceLine == true) && (WhiteboardDrawing == true))
                    {
                        RectangleF selectionRect;

                        int selectionX = Math.Min(LineStartLocation.X, LineEndLocation.X);
                        int selectionY = Math.Min(LineStartLocation.Y, LineEndLocation.Y);

                        selectionRect = new RectangleF((float)selectionX, (float)selectionY,
                            (float)Math.Abs(LineStartLocation.X - LineEndLocation.X),
                            (float)Math.Abs(LineStartLocation.Y - LineEndLocation.Y));
                        canvas.DrawRect(selectionRect, Color.Orange);
                    }
                }

                // Draw Mini map
                _bottom_status_bar.Height = 35;
                _bottom_status_bar.Width = PlayfieldRect.Width;
                _bottom_status_bar.X = PlayfieldRect.X;
                _bottom_status_bar.Y = bottom_left - _bottom_status_bar.Height;
                canvas.DrawFillRect(_bottom_status_bar, _mini_map_background);
                
                if (true) //check DDD_Global or playfield
                {
                    if (_rangeFinderFont == null && this.Fonts.ContainsKey("RangeRing"))
                    {
                        _rangeFinderFont = this.Fonts["RangeRing"];
                    }
                    string rangeText = DDD_Global.Instance.GetRangeFinderDisplayString();

                    if (_rangeFinderFont != null && rangeText.Trim() != string.Empty)
                    {
                        _mouseoverRangeFinderDisplay = _rangeFinderFont.MeasureString(null, rangeText, DrawTextFormat.Center, Color.White);
                        _mouseoverRangeFinderDisplay.X = Convert.ToInt32(DDD_Global.Instance.RangeFinderXDisplay);// 500;
                        _mouseoverRangeFinderDisplay.Y = Convert.ToInt32(DDD_Global.Instance.RangeFinderYDisplay);// 400;
                        _mouseoverRangeFinderDisplay.Width += 10;
                        canvas.DrawFillRect(_mouseoverRangeFinderDisplay, _mini_map_background);//_rangeFinderMaterial);
                        _rangeFinderFont.DrawText(null, rangeText, _mouseoverRangeFinderDisplay, DrawTextFormat.Center, Color.White);

                        //DRAW LINE FROM OBJECT TO CURSOR

                        float objX = 0f;
                        float objY = 0f;
                        DDDObjects obj = _playfield.GetSelectedObject();
                        if (obj != null)
                        {
                            objX = obj.ScreenCoordinates.X;
                            objY = obj.ScreenCoordinates.Y;

                            canvas.DrawLine(Color.Black, 3, _mouseoverRangeFinderDisplay.X - 10, _mouseoverRangeFinderDisplay.Y - 15, objX, objY);
                        }
                    }
                }

                if (!MiniMapOverride)
                {
                    if ((!Map_IsContained_Horizontal(PlayfieldRect)) && (!Map_IsContained_Vertical(PlayfieldRect)))
                    {
                        ShowMiniMap = false;
                    }
                    else
                    {
                        ShowMiniMap = true;
                    }

                    if (WBRoom != null)
                    {
                        ShowMiniMap = true;
                    }
     
                    if (ShowMiniMap)
                    {
                        _mini_map.X = (PlayfieldRect.X + PlayfieldRect.Width) - _mini_map.Width;
                        _mini_map.Y = 0;
                        _mini_map.Height = (int)((Map.TextureHeight / Map.TextureWidth) * (float)_mini_map.Width);

                        _mini_map_thumb.X = (int)(-(Map.Position.X / (Map.TextureWidth * _playfield.Scale)) * (float)_mini_map.Width) + _mini_map.X;
                        _mini_map_thumb.Y = (int)(-(Map.Position.Y / (Map.TextureHeight * _playfield.Scale)) * (float)_mini_map.Height) + _mini_map.Y;
                        _mini_map_thumb.Width = (int)(_mini_map.Width * ((float)PlayfieldRect.Width / (Map.TextureWidth * _playfield.Scale)));
                        _mini_map_thumb.Height = (int)(_mini_map.Height * ((float)PlayfieldRect.Height / (Map.TextureHeight * _playfield.Scale)));

                        canvas.DrawFillRect(_mini_map, _mini_map_background);

                        // Draw rect for other users in a whiteboard room
                        if (wbRoom != null)
                        {
                            int originX = 0;
                            int originY = 0;
                            int screenSizeWidth = 0;
                            int screenSizeHeight = 0;
                            double screenZoom = 0.0;

                            foreach (string wbUser in wbRoom.MembershipList)
                            {
                                if (string.Compare(wbUser, DDD_Global.Instance.PlayerID) == 0)
                                {
                                    continue;
                                }

                                if (wbRoom.GetScreenViewInfo(wbUser, ref originX, ref originY, ref screenSizeWidth, ref screenSizeHeight,
                                        ref screenZoom))
                                {
                                    Rectangle userMiniMapRect = Rectangle.Empty;
                                    Vector2 _metersPerPixelValues = new Vector2();
                                    Vector2 userPosition = new Vector2();
                                    _metersPerPixelValues.X = UTM_Mapping.HorizonalMetersPerPixel;
                                    _metersPerPixelValues.Y = UTM_Mapping.VerticalMetersPerPixel;

                                    userPosition.X = (float) originX / _metersPerPixelValues.X;
                                    userPosition.Y = (float)originY  / _metersPerPixelValues.Y;
                                    userMiniMapRect.X = (int)((userPosition.X / (Map.TextureWidth)) * (float)_mini_map.Width) + _mini_map.X;
                                    userMiniMapRect.Y = (int)((userPosition.Y / (Map.TextureHeight)) * (float)_mini_map.Height) + _mini_map.Y;
                                    userMiniMapRect.Width = (int)((float)screenSizeWidth / _metersPerPixelValues.X /
                                        Map.TextureWidth * (float)_mini_map.Width);
                                    userMiniMapRect.Height = (int)((float)screenSizeHeight / _metersPerPixelValues.Y /
                                        Map.TextureHeight * (float)_mini_map.Height);

                                    // Draw rect for this a whiteboard user
                                    if (DMColorMap.ContainsKey(wbUser))
                                    {
                                        canvas.DrawRect(userMiniMapRect, Color.FromArgb(DMColorMap[wbUser]));
                                    }
                                    else
                                    {
                                        canvas.DrawRect(userMiniMapRect, Color.DarkBlue);
                                    }
                                }

                            }
                        }

                        // Draw rect for this user
                        if ((wbRoom != null) && DMColorMap.ContainsKey(DDD_Global.Instance.PlayerID))
                        {
                            canvas.DrawRect(_mini_map_thumb, Color.FromArgb(DMColorMap[DDD_Global.Instance.PlayerID]));
                        }
                        else
                        {
                            canvas.DrawRect(_mini_map_thumb, Color.Red);
                        }

                        lock (this)
                        {
                            DDDObjects selected = GetSelectedObject();
                            foreach (string obj_name in _playfield.PlayfieldObjects)
                            {
                                DDDObjects obj = (DDDObjects)_playfield.GetMappableObject(obj_name);
                                if (obj != null)
                                {
                                    _mini_map_track.X = (int)(((_mini_map.Width / Map.TextureWidth) * obj.Position.X) + _mini_map.X) - (int)(.5 * _mini_map_track.Width);
                                    _mini_map_track.Y = (int)(((_mini_map.Height / Map.TextureHeight) * obj.Position.Y) + _mini_map.Y) - (int)(.5 * _mini_map_track.Height);
                                    if (selected != null)
                                    {
                                        if ((selected.ID == obj.ID) && !ShowUnitColorOnMiniMap)
                                        {
                                            canvas.DrawTri(_mini_map_track, Color.Yellow, DIRECTION.UP);
                                            continue;
                                        }
                                    }

                                    if (!ShowUnitColorOnMiniMap)
                                    {
                                        canvas.DrawTri(_mini_map_track, Color.DodgerBlue, DIRECTION.UP);
                                    }
                                    else
                                    {
                                        canvas.DrawTri(_mini_map_track, obj.TextBoxColor, DIRECTION.UP);
                                    }

                                }
                            }


                            foreach (string obj_name in _playfield.PlayfieldObjects)
                            {
                                DDDObjects obj = (DDDObjects)_playfield.GetMappableObject(obj_name);
                                if (obj != null)
                                {
                                    _mini_map_track.X = (int)(((_mini_map.Width / Map.TextureWidth) * obj.Position.X) + _mini_map.X) - (int)(.5 * _mini_map_track.Width);
                                    _mini_map_track.Y = (int)(((_mini_map.Height / Map.TextureHeight) * obj.Position.Y) + _mini_map.Y) - (int)(.5 * _mini_map_track.Height);

                                    if (obj.IsBeingAttacked)
                                    {
                                        if (GameFramework.ElapsedSeconds(AnimationTimer, AnimationCycle))
                                        {
                                            AnimationTimer = GameFramework.QueryPerformanceTimer();
                                        }
                                        if (GameFramework.ElapsedSeconds(AnimationTimer, BlinkCycle))
                                        {
                                            canvas.DrawTri(_mini_map_track, Color.White, DIRECTION.UP);
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }



                if (ShowPosition)
                {

                    DDDObjects obj = _playfield.GetSelectedObject();
                    if (obj != null)
                    {
                        if (obj.IsPathCalculatorRunning())
                        {
                            canvas.DrawFillRect(_bottom_status_bar, _mini_map_background);
                            SizeF size = obj.DrawIcon(canvas, PlayfieldRect.X, _bottom_status_bar.Y, 30, 30);

                            int font_height = (Fonts["Arial8B"].MeasureString(null, obj.FullVelocityStr, DrawTextFormat.None, Color.White)).Height;

                            Fonts["Arial8B"].DrawText(null, obj.FullVelocityStr, PlayfieldRect.X + (int)size.Width + 2, _bottom_status_bar.Y, Color.White);
                            Fonts["Arial8B"].DrawText(null, obj.FullTTDStr, PlayfieldRect.X + (int)size.Width + 2, (_bottom_status_bar.Y + font_height), Color.White);
                            Fonts["Arial8B"].DrawText(null, obj.FullDestinationStr, PlayfieldRect.X + (int)size.Width + 2, (_bottom_status_bar.Y + (2 * font_height)), Color.White);
                        }
                        else
                        {
                            SizeF size = obj.DrawIcon(canvas, PlayfieldRect.X, _bottom_status_bar.Y, 30, 30);

                            int font_height = (Fonts["Arial10B"].MeasureString(null, obj.ObjectID, DrawTextFormat.None, Color.White)).Height;
                            Fonts["Arial10B"].DrawText(null, obj.ObjectID, PlayfieldRect.X + (int)size.Width, (_bottom_status_bar.Bottom - font_height), Color.White);
                        }
                    }
                }


                int width;
                String str = String.Empty;
                if (!IsPaused)
                {
                    if (DDD_Global.Instance.IsForkReplay)
                    {
                        str = String.Format("Fork Replay {0}", Time);
                    }
                    else
                    {
                        str = Time;
                    }
                }
                else
                {
                    str = "Paused";
                }
                width = (Fonts["Arial10B"].MeasureString(null, str, DrawTextFormat.None, Color.Yellow)).Width + 5;
                Fonts["Arial10B"].DrawText(null, str, _bottom_status_bar.X + (_bottom_status_bar.Width - width), _bottom_status_bar.Y + 5, Color.Yellow);
                //if (!IsPaused)
                //{
                //    if (DDD_Global.Instance.IsForkReplay)
                //    {
                //        width = (Fonts["Arial10B"].MeasureString(null, Time, DrawTextFormat.None, Color.Yellow)).Width + 5;
                //        Fonts["Arial10B"].DrawText(null, String.Format("Fork Replay {0}",Time), _bottom_status_bar.X + (_bottom_status_bar.Width - width), _bottom_status_bar.Y + 5, Color.Yellow);
                //    }
                //    else
                //    {
                //        width = (Fonts["Arial10B"].MeasureString(null, Time, DrawTextFormat.None, Color.Yellow)).Width + 5;
                //        Fonts["Arial10B"].DrawText(null, Time, _bottom_status_bar.X + (_bottom_status_bar.Width - width), _bottom_status_bar.Y + 5, Color.Yellow);
                //    }
                //}
                //else
                //{
                //    width = (Fonts["Arial10B"].MeasureString(null, Time, DrawTextFormat.None, Color.Yellow)).Width + 5;
                //    Fonts["Arial10B"].DrawText(null, "Paused", _bottom_status_bar.X + (_bottom_status_bar.Width - width), _bottom_status_bar.Y + 5, Color.Yellow);
                //}

            }

        }
Example #3
0
        public void OnRender(Canvas c)
        {
            if (State != WindowState.HIDE)
            {

                _shade_btn = _caption_bar;
                _shade_btn.Width = 12;
                _shade_btn.Height = 12;
                _shade_btn.X = _caption_bar.Right - 28;
                _shade_btn.Y += 7;

                _v_scroll_rect.X = _client_area.Right - ScrollWidth;
                _v_scroll_rect.Y = _caption_bar.Bottom;
                _v_scroll_rect.Height = _client_area.Height - (ScrollWidth + _caption_bar.Height);
                _v_scroll_rect.Width = ScrollWidth - 1;

                _h_scroll_rect.X = _client_area.X;
                _h_scroll_rect.Y = _client_area.Bottom - ScrollWidth;
                _h_scroll_rect.Width = _client_area.Width - ScrollWidth;
                _h_scroll_rect.Height = ScrollWidth - 1;

                _v_scroll_thumb = _v_scroll_rect;
                _h_scroll_thumb = _h_scroll_rect;


                c.DrawFillRect(_main_panel.ClientArea, _background_color_material);

                _main_panel.OnRender(c);

                if (HasScrollBars)
                {
                    if (this._ShowHorizontalScroll)
                    {
                        DrawHorizontalScroll(c);
                    }
                    if (this._ShowVerticalScroll)
                    {
                        DrawVerticalScroll(c);
                    }
                }

                c.DrawRect(_client_area, BorderColor);


                if (CaptionText != string.Empty)
                {
                    c.DrawFillRect(_caption_bar, _caption_color_material);
                    if (Font != null)
                    {
                        Font.DrawText(null, CaptionText, _caption_bar, DrawTextFormat.VerticalCenter | DrawTextFormat.Center, CaptionForeground);
                    }

                    if (AllowShade)
                    {
                        switch (State)
                        {
                            case WindowState.MINIMIZED:
                                c.DrawFillTri(_shade_btn, _caption_foreground_material, DIRECTION.UP);
                                c.DrawTri(_shade_btn, BorderColor, DIRECTION.UP);
                                break;
                            case WindowState.MAXIMIZED:
                                c.DrawFillTri(_shade_btn, _caption_foreground_material, DIRECTION.DOWN);
                                c.DrawTri(_shade_btn, BorderColor, DIRECTION.DOWN);
                                break;
                        }
                    }
                    
                    if (Selected)
                    {
                        c.DrawRect(_caption_bar, Color.White);
                    }
                    else
                    {
                        c.DrawRect(_caption_bar, BorderColor);
                    }
                }


                if (AllowResize)
                {
                    _resize_btn.X = _client_area.Right - 15;
                    _resize_btn.Y = _client_area.Bottom - 15;
                    _resize_btn.Width = 10;
                    _resize_btn.Height = 10;

                    c.DrawFillRect(_resize_btn, _caption_color_material);
                    c.DrawRect(_resize_btn, BorderColor);
                }


            }
        }