public override void Draw() { DrawX.DrawFilledRect(Area, BackGroundColor); if (HasFocus) { DrawX.DrawShapeOutline(Area, BorderColor); } Font.Draw(DrawString, Position + 1f, TextColor, Alignment.TopLeft, -5); }
public override void Draw() { DrawX.DrawFilledRect(ScrollbarRect, BackgroundColor, Depth); DrawX.DrawFilledRect(SliderRect, Dragging ? SliderColorDragging : Hovering ? SliderColorHovering : SliderColor, Depth); }
private static void Draw() { //collect drawjobs foreach (LogicalObject obj in Resources.Objects) { if (!obj.Destroyed) { obj.Draw(); } } DrawX.DrawJobs.OrderBy((job) => job.Depth); SDL.SetRenderDrawColor(RendererHandle, DrawX.BackgroundColor.R, DrawX.BackgroundColor.G, DrawX.BackgroundColor.B, DrawX.BackgroundColor.A); SDL.RenderClear(RendererHandle); foreach (View view in Resources.Views.Values) { if (!view.Active) { continue; } Rectangle absoluteGameArea = view.GetAbsoluteGameArea(); Rectangle absoluteViewport = view.GetAbsoluteViewport(); Point scale = view.GetScale(); SDL.RenderSetScale(RendererHandle, scale.X, scale.Y); //viewport is affected by scale for whatever reason, correct it Rectangle scaledViewport = new Rectangle(absoluteViewport); scaledViewport.Position /= scale; scaledViewport.Size /= scale; SDL.Rect sdlViewport = (SDL.Rect)scaledViewport; SDL.RenderSetViewport(RendererHandle, ref sdlViewport); //get all jobs that will draw inside this view foreach (IDrawJob job in DrawX.GetDrawJobsByArea(absoluteGameArea)) { Type jobType = job.GetType(); if (jobType == typeof(TextureDrawJob)) //draw a texture { TextureDrawJob textureDrawJob = (TextureDrawJob)job; SDL.Rect sourceRect = (SDL.Rect)textureDrawJob.SourceRect; SDL.Rect destRect = (SDL.Rect) new Rectangle(textureDrawJob.DestRect.Position - absoluteGameArea.Position - textureDrawJob.DestRect.Origin, textureDrawJob.DestRect.Size); if (textureDrawJob.DestRect.Rotation == 0f) { SDL.RenderCopy(RendererHandle, textureDrawJob.Texture, ref sourceRect, ref destRect); } else { SDL.Point origin = (SDL.Point)textureDrawJob.DestRect.Origin; SDL.RenderCopyEx(RendererHandle, textureDrawJob.Texture, ref sourceRect, ref destRect, textureDrawJob.DestRect.Rotation, ref origin, SDL.RendererFlip.FLIP_NONE); } } else if (jobType == typeof(LineDrawJob)) //draw line(s) { LineDrawJob lineDrawJob = (LineDrawJob)job; //transform all points according to view and cast em SDL.Point[] sdlPoints = Array.ConvertAll <Point, SDL.Point>(lineDrawJob.Points, point => (SDL.Point)(point - absoluteGameArea.Position)); SDL.SetRenderDrawColor(RendererHandle, lineDrawJob.Color.R, lineDrawJob.Color.G, lineDrawJob.Color.B, lineDrawJob.Color.A); SDL.RenderDrawLines(RendererHandle, sdlPoints, lineDrawJob.PointCount); } else //draw filledrect { FilledRectDrawJob rectDrawJob = (FilledRectDrawJob)job; SDL.Rect rect = (SDL.Rect)(rectDrawJob.Area - absoluteGameArea.Position); SDL.SetRenderDrawColor(RendererHandle, rectDrawJob.Color.R, rectDrawJob.Color.G, rectDrawJob.Color.B, rectDrawJob.Color.A); SDL.RenderFillRect(RendererHandle, ref rect); } } } DrawX.DrawJobs.Clear(); //threadpool should take care of actually swapping the frames (RenderPresent may wait for things like Fraps or VSync) RenderframeReady = true; ThreadPool.QueueUserWorkItem(new WaitCallback(PresentRender)); }