public static Cairo.Rectangle PointsToRectangle (Cairo.PointD p1, Cairo.PointD p2, bool constrain) { // We want to create a rectangle that always has positive width/height double x, y, w, h; if (p1.Y <= p2.Y) { y = p1.Y; h = p2.Y - y + 1; } else { y = p2.Y; h = p1.Y - y + 1; } if (p1.X <= p2.X) { x = p1.X; if (constrain) w = h; else w = p2.X - x + 1; } else { x = p2.X; if (constrain) { w = h; x = p1.X - w; } else w = p1.X - x + 1; } return new Cairo.Rectangle (x, y, w, h); }
protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point) { if (!is_drawing) return; double x = Utility.Clamp (point.X, 0, PintaCore.Workspace.ImageSize.X - 1); double y = Utility.Clamp (point.Y, 0, PintaCore.Workspace.ImageSize.Y - 1); PintaCore.Layers.ShowSelection = true; ImageSurface surf = PintaCore.Layers.ToolLayer.Surface; using (Context g = new Context (surf)) { g.Antialias = Antialias.Subpixel; if (path != null) { g.AppendPath (path); (path as IDisposable).Dispose (); } g.LineTo (x, y); path = g.CopyPath (); g.FillRule = FillRule.EvenOdd; g.ClosePath (); Path old = PintaCore.Layers.SelectionPath; PintaCore.Layers.SelectionPath = g.CopyPath (); (old as IDisposable).Dispose (); } PintaCore.Workspace.Invalidate (); }
internal unsafe static void Setup(Process aParent) { Server = new Pipe(PACKET_SIZE, 1000); Clients = new IList <Pipe>(); Windows = new IList <Window>(); Stacking = new IList <Window>(); RedrawRects = new IQueue <uint>(); /* Mouse Surfaces */ MouseIdleSurface = Cairo.ImageSurfaceFromPng(Marshal.C_String("disk0/cursor_idle.png")); MouseHelpSurface = Cairo.ImageSurfaceFromPng(Marshal.C_String("disk0/cursor_help.png")); MouseClipSurface = Cairo.ImageSurfaceFromPng(Marshal.C_String("disk0/cursor_clip.png")); MouseSurface = MouseIdleSurface; int stride = Cairo.FormatStrideForWidth(VBE.Xres, ColorFormat.ARGB32); MainSurface = Cairo.ImageSurfaceCreateForData(stride, VBE.Yres, VBE.Xres, ColorFormat.ARGB32, VBE.SecondaryBuffer); VideoSurface = Cairo.ImageSurfaceCreateForData(stride, VBE.Yres, VBE.Xres, ColorFormat.ARGB32, VBE.VirtualFrameBuffer); MainContext = Cairo.Create(MainSurface); VideoContext = Cairo.Create(VideoSurface); new Thread(aParent, HandleRequest).Start(); new Thread(aParent, HandleMouse).Start(); new Thread(aParent, Renderer).Start(); }
internal protected override void Draw (Cairo.Context cr, Cairo.Rectangle area, LineSegment lineSegment, int line, double x, double y, double lineHeight) { cr.MoveTo (x + 0.5, y); cr.LineTo (x + 0.5, y + lineHeight); cr.Color = color; cr.Stroke (); }
static void Test_Cairo() { Stopwatch sw = new Stopwatch(); sw.Start(); var surface = Cairo.cairo_image_surface_create(CairoFormat.CairoFormatArgb32, 800, 600); var cr = Cairo.cairo_create(surface); Cairo.cairo_set_source_rgb(cr, 0, 0, 0); Cairo.cairo_select_font_face(cr, "Sans", CairoFontSlant.CairoFontSlantNormal, CairoFontWeight.CairoFontWeightNormal); Cairo.cairo_set_font_size(cr, 40.0); Cairo.cairo_move_to(cr, 10.0, 50.0); Cairo.cairo_show_text(cr, "Myvar"); //we will use thos for now later we can implment the opengl stuff Cairo.cairo_surface_write_to_png(surface, "image.png"); //Cairo.cairo_surface_flush(cr); //var data = Cairo.cairo_image_surface_get_data(surface); //load into texture using //glTexImage2D(GL_TEXTURE_2D, 0, 4, tex_w,tex_h, 0,GL_BGRA, GL_UNSIGNED_BYTE, data); //when you create the texture. Use glTexSubImage2D(...) to update th texture when the image content changes //. For speed set the filters for the texture to GL_NEAREST Cairo.cairo_destroy(cr); Cairo.cairo_surface_destroy(surface); sw.Stop(); Console.WriteLine($"Time: {sw.Elapsed}"); }
protected override void DrawContents(Gdk.Drawable d, Cairo.Context g, int width, int height, bool screenChanged) { g.SelectFontFace(Text.MONOSPACE_FONT, FontSlant.Normal, FontWeight.Bold); g.SetFontSize(Text.FONT_SIZE_LABEL); Text.ShadowedText(g, "Equip", X + 20, Y + 25); }
protected override void onDraw(Cairo.Context gr) { Rectangle rBack = new Rectangle (Slot.Size); //rBack.Inflate (-Margin); // if (BorderWidth > 0) // rBack.Inflate (-BorderWidth / 2); Background.SetAsSource (gr, rBack); CairoHelpers.CairoRectangle(gr, rBack, CornerRadius); gr.Fill (); if (BorderWidth > 0) { Foreground.SetAsSource (gr, rBack); CairoHelpers.CairoRectangle(gr, rBack, CornerRadius, BorderWidth); } gr.Save (); if (ClipToClientRect) { //clip to client zone CairoHelpers.CairoRectangle (gr, ClientRectangle,Math.Max(0.0, CornerRadius-Margin)); gr.Clip (); } if (child != null) child.Paint (ref gr); gr.Restore (); }
public override void Draw (TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos) { int markerStart = LineSegment.Offset + System.Math.Max (StartCol - 1, 0); int markerEnd = LineSegment.Offset + (EndCol < 1 ? LineSegment.Length : EndCol - 1); if (markerEnd < startOffset || markerStart > endOffset) return; bool drawOverlay = result.InspectionMark == IssueMarker.GrayOut; if (drawOverlay && editor.IsSomethingSelected) { var selectionRange = editor.SelectionRange; if (selectionRange.Contains (markerStart) && selectionRange.Contains (markerEnd)) return; if (selectionRange.Contains (markerEnd)) markerEnd = selectionRange.Offset; if (selectionRange.Contains (markerStart)) markerStart = selectionRange.EndOffset; if (markerEnd <= markerStart) return; } double drawFrom; double drawTo; if (markerStart < startOffset && endOffset < markerEnd) { drawFrom = startXPos; drawTo = endXPos; } else { int start = startOffset < markerStart ? markerStart : startOffset; int end = endOffset < markerEnd ? endOffset : markerEnd; int /*lineNr,*/ x_pos; x_pos = layout.IndexToPos (start - startOffset).X; drawFrom = startXPos + (int)(x_pos / Pango.Scale.PangoScale); x_pos = layout.IndexToPos (end - startOffset).X; drawTo = startXPos + (int)(x_pos / Pango.Scale.PangoScale); } drawFrom = System.Math.Max (drawFrom, editor.TextViewMargin.XOffset); drawTo = System.Math.Max (drawTo, editor.TextViewMargin.XOffset); if (drawFrom >= drawTo) return; double height = editor.LineHeight / 5; cr.Color = ColorName == null ? Color : editor.ColorStyle.GetColorFromDefinition (ColorName); if (drawOverlay) { cr.Rectangle (drawFrom, y, drawTo - drawFrom, editor.LineHeight); var color = editor.ColorStyle.Default.CairoBackgroundColor; color.A = 0.6; cr.Color = color; cr.Fill (); } else if (Wave) { Pango.CairoHelper.ShowErrorUnderline (cr, drawFrom, y + editor.LineHeight - height, drawTo - drawFrom, height); } else { cr.MoveTo (drawFrom, y + editor.LineHeight - 1); cr.LineTo (drawTo, y + editor.LineHeight - 1); cr.Stroke (); } }
public override void DrawColumnHeaderFocus(Cairo.Context cr, Gdk.Rectangle alloc) { double top_offset = 2.0; double right_offset = 2.0; double margin = 0.5; double line_width = 0.7; Cairo.Color stroke_color = CairoExtensions.ColorShade ( CairoExtensions.GdkRGBAToCairoColor ( Widget.StyleContext.GetBackgroundColor (StateFlags.Selected)), 0.8); stroke_color.A = 0.1; cr.Color = stroke_color; CairoExtensions.RoundedRectangle (cr, alloc.X + margin + line_width + right_offset, alloc.Y + margin + line_width + top_offset, alloc.Width - (margin + line_width)*2.0 - right_offset, alloc.Height - (margin + line_width)*2.0 - top_offset, Context.Radius/2.0, CairoCorners.None); cr.Fill (); stroke_color.A = 1.0; cr.LineWidth = line_width; cr.Color = stroke_color; CairoExtensions.RoundedRectangle (cr, alloc.X + margin + line_width + right_offset, alloc.Y + margin + line_width + top_offset, alloc.Width - (line_width + margin)*2.0 - right_offset, alloc.Height - (line_width + margin)*2.0 - right_offset, Context.Radius/2.0, CairoCorners.All); cr.Stroke (); }
protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point) { origin_offset = point; is_dragging = true; hist = new MovePixelsHistoryItem (Icon, Name); hist.TakeSnapshot (); if (!PintaCore.Layers.ShowSelectionLayer) { // Copy the selection to the temp layer PintaCore.Layers.CreateSelectionLayer (); PintaCore.Layers.ShowSelectionLayer = true; using (Cairo.Context g = new Cairo.Context (PintaCore.Layers.SelectionLayer.Surface)) { g.AppendPath (PintaCore.Layers.SelectionPath); g.FillRule = FillRule.EvenOdd; g.SetSource (PintaCore.Layers.CurrentLayer.Surface); g.Clip (); g.Paint (); } Cairo.ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface; using (Cairo.Context g = new Cairo.Context (surf)) { g.AppendPath (PintaCore.Layers.SelectionPath); g.FillRule = FillRule.EvenOdd; g.Operator = Cairo.Operator.Clear; g.Fill (); } } canvas.GdkWindow.Invalidate (); }
protected override bool OnDrawn(Cairo.Context cr) { double step_width = Allocation.Width / (double)steps; double step_height = Allocation.Height / (double)steps; double h = 1.0; double s = 0.0; for (int xi = 0, i = 0; xi < steps; xi++) { for (int yi = 0; yi < steps; yi++, i++) { double bg_b = (double)(i / 255.0); double fg_b = 1.0 - bg_b; double x = xi * step_width; double y = yi * step_height; cr.Rectangle (x, y, step_width, step_height); cr.Color = CairoExtensions.ColorFromHsb (h, s, bg_b); cr.Fill (); int tw, th; Pango.Layout layout = new Pango.Layout (PangoContext); layout.SetText (((int)(bg_b * 255.0)).ToString ()); layout.GetPixelSize (out tw, out th); cr.Translate (0.5, 0.5); cr.MoveTo (x + (step_width - tw) / 2.0, y + (step_height - th) / 2.0); cr.Color = CairoExtensions.ColorFromHsb (h, s, fg_b); PangoCairoHelper.ShowLayout (cr, layout); cr.Translate (-0.5, -0.5); } } return true; }
static void draw (Cairo.Context gr, int width, int height) { gr.Scale (width, height); gr.LineWidth = 0.04; gr.MoveTo ( new PointD (0.5, 0.1) ); gr.LineTo ( new PointD (0.9, 0.9) ); gr.RelLineTo ( new Distance (-0.4, 0.0) ); gr.CurveTo ( new PointD (0.2, 0.9), new PointD ( 0.2, 0.5), new PointD (0.5, 0.5) ); gr.ClosePath (); gr.MoveTo ( new PointD (0.25, 0.1) ); gr.RelLineTo ( new Distance (0.2, 0.2) ); gr.RelLineTo ( new Distance ( -0.2, 0.2) ); gr.RelLineTo ( new Distance (-0.2, -0.2) ); gr.ClosePath (); gr.Color = new Color (0, 0, 1, 1); gr.FillPreserve (); gr.Color = new Color ( 0, 0, 0, 1); gr.Stroke (); }
public DrawInRegionVisitor(Gdk.Region region, Cairo.Context context, IDrawingView view) { this.context = context; this.region = region; this.view = view; this.figures = new List<Figure> (); }
public void Draw (Cairo.Context g, double scale, bool fillSelection) { g.Save (); g.Translate (0.5, 0.5); g.Scale (scale, scale); g.AppendPath (SelectionPath); if (fillSelection) { g.SetSourceColor (new Cairo.Color (0.7, 0.8, 0.9, 0.2)); g.FillRule = Cairo.FillRule.EvenOdd; g.FillPreserve (); } g.LineWidth = 1 / scale; // Draw a white line first so it shows up on dark backgrounds g.SetSourceColor (new Cairo.Color (1, 1, 1)); g.StrokePreserve (); // Draw a black dashed line over the white line g.SetDash (new double[] { 2 / scale, 4 / scale }, 0); g.SetSourceColor (new Cairo.Color (0, 0, 0)); g.Stroke (); g.Restore (); }
public override void DrawContent (Cairo.Context Context, Cairo.Rectangle Area) { Context.Color = new Color (0, 0, 0); Pango.CairoHelper.UpdateLayout (Context, textLayout); Context.MoveTo (Area.X, Area.Y); Pango.CairoHelper.ShowLayout (Context, textLayout); }
public CairoImageCellRenderer(int width, int height, Cairo.ImageSurface default_surface, RequestThumbnailEventHandler request_thumbnail) { this.width = width; this.height = height; this.default_surface = default_surface; this.request_thumbnail = request_thumbnail; }
public static Cairo.Color AlphaBlend (Cairo.Color ca, Cairo.Color cb, double alpha) { return new Cairo.Color ( (1.0 - alpha) * ca.R + alpha * cb.R, (1.0 - alpha) * ca.G + alpha * cb.G, (1.0 - alpha) * ca.B + alpha * cb.B); }
protected void DrawHorizontalSectionIndicator(string text, Cairo.Context cr, Pango.Layout layout, double x, double y, double w, out double h) { cr.MoveTo(x,y); cr.LineTo(x,y+SectionSerifeWidth*2); cr.MoveTo(x,y+SectionSerifeWidth); cr.LineTo(x+w,y+SectionSerifeWidth); cr.MoveTo(x+w,y); cr.LineTo(x+w,y+SectionSerifeWidth*2); cr.Color = new Cairo.Color(0, 0, 0); cr.LineWidth = 1; cr.Stroke(); layout.Width = (int)(w*Pango.Scale.PangoScale); layout.Alignment = Pango.Alignment.Center; layout.SetText (text); layout.Ellipsize = EllipsizeMode.Middle; layout.Justify = true; cr.Color = new Cairo.Color(0, 0, 0); cr.MoveTo(x,y+SectionSerifeWidth*2); Pango.CairoHelper.ShowLayout (cr, layout); int lw,lh; layout.GetPixelSize(out lw, out lh); h=(double)lh+SectionSerifeWidth*2; }
static void DrawIcon (MonoTextEditor editor, Cairo.Context cr, DocumentLine lineSegment, double x, double y, double width, double height) { if (lineSegment.IsBookmarked) { var color1 = editor.ColorStyle.Bookmarks.Color; var color2 = editor.ColorStyle.Bookmarks.SecondColor; DrawRoundRectangle (cr, x + 1, y + 1, 8, width - 4, height - 4); // FIXME: VV: Remove gradient features using (var pat = new Cairo.LinearGradient (x + width / 4, y, x + width / 2, y + height - 4)) { pat.AddColorStop (0, color1); pat.AddColorStop (1, color2); cr.SetSource (pat); cr.FillPreserve (); } // FIXME: VV: Remove gradient features using (var pat = new Cairo.LinearGradient (x, y + height, x + width, y)) { pat.AddColorStop (0, color2); //pat.AddColorStop (1, color1); cr.SetSource (pat); cr.Stroke (); } } }
public static void DrawRoundRectangle (Cairo.Context cr, double x, double y, double r, double w, double h) { const double ARC_TO_BEZIER = 0.55228475; double radius_x = r; double radius_y = r / 4; if (radius_x > w - radius_x) radius_x = w / 2; if (radius_y > h - radius_y) radius_y = h / 2; double c1 = ARC_TO_BEZIER * radius_x; double c2 = ARC_TO_BEZIER * radius_y; cr.NewPath (); cr.MoveTo (x + radius_x, y); cr.RelLineTo (w - 2 * radius_x, 0.0); cr.RelCurveTo (c1, 0.0, radius_x, c2, radius_x, radius_y); cr.RelLineTo (0, h - 2 * radius_y); cr.RelCurveTo (0.0, c2, c1 - radius_x, radius_y, -radius_x, radius_y); cr.RelLineTo (-w + 2 * radius_x, 0); cr.RelCurveTo (-c1, 0, -radius_x, -c2, -radius_x, -radius_y); cr.RelLineTo (0, -h + 2 * radius_y); cr.RelCurveTo (0.0, -c2, radius_x - c1, -radius_y, radius_x, -radius_y); cr.ClosePath (); }
public static Cairo.Color ColorAdjustBrightness(Cairo.Color @base, double br) { double h, s, b; HsbFromColor(@base, out h, out s, out b); b = Math.Max(Math.Min(br, 1), 0); return ColorFromHsb(h, s, b); }
protected override void DrawContents(Gdk.Drawable d, Cairo.Context g, int width, int height, bool screenChanged) { g.SelectFontFace(Text.MONOSPACE_FONT, FontSlant.Normal, FontWeight.Bold); g.SetFontSize(24); Text.ShadowedText(g, MenuState.ConfigScreen.Control.Info, X + 20, Y + 27); }
static void draw (Cairo.Context gr, int width, int height) { int w, h; ImageSurface image; gr.Scale (width, height); gr.LineWidth = 0.04; gr.Arc (0.5, 0.5, 0.3, 0, 2*M_PI); gr.Clip (); gr.NewPath (); image = new ImageSurface("data/e.png"); w = image.Width; h = image.Height; gr.Scale (1.0/w, 1.0/h); image.Show (gr, 0, 0); image.Destroy(); gr.Arc (0.5, 0.5, 0.3, 0, 2 * M_PI); gr.Clip (); gr.NewPath (); gr.Rectangle (new PointD (0, 0), 1, 1); gr.Fill (); gr.Color = new Color (0, 1, 0, 1); gr.MoveTo ( new PointD (0, 0) ); gr.LineTo ( new PointD (1, 1) ); gr.MoveTo ( new PointD (1, 0) ); gr.LineTo ( new PointD (0, 1) ); gr.Stroke (); }
protected override void DrawContents(Gdk.Drawable d, Cairo.Context g, int width, int height, bool screenChanged) { g.SelectFontFace(Text.MONOSPACE_FONT, FontSlant.Normal, FontWeight.Bold); g.SetFontSize(24); TextExtents te; Text.ShadowedText(g, "Time", X + x1, Y + y1); Text.ShadowedText(g, "Gil", X + x1, Y + y2); g.SelectFontFace("Courier New", FontSlant.Normal, FontWeight.Bold); long s, m, h; s = GameClock.Seconds; m = GameClock.Minutes; h = GameClock.Hours; string time = String.Format("{0:D2}:{1:D2}:{2:D2}", h, m, s); te = g.TextExtents(time); Text.ShadowedText(g, time, X + x2 - te.Width, Y + y1); te = g.TextExtents(Gil); Text.ShadowedText(g, Gil, X + x2 - te.Width, Y + y2); }
static void draw (Cairo.Context gr, int width, int height) { double xc = 0.5; double yc = 0.5; double radius = 0.4; double angle1 = 45.0 * (M_PI/180.0); /* angles are specified */ double angle2 = 180.0 * (M_PI/180.0); /* in radians */ gr.Scale (width, height); gr.LineWidth = 0.04; gr.Arc (xc, yc, radius, angle1, angle2); gr.Stroke (); /* draw helping lines */ gr.Color = new Color(1, 0.2, 0.2, 0.6); gr.Arc (xc, yc, 0.05, 0, 2*M_PI); gr.Fill (); gr.LineWidth = 0.03; gr.Arc (xc, yc, radius, angle1, angle1); gr.LineTo (new PointD(xc, yc)); gr.Arc (xc, yc, radius, angle2, angle2); gr.LineTo (new PointD(xc, yc)); gr.Stroke (); }
public UnderlineMarker (Cairo.Color color, int start, int end) { this.Color = color; this.StartCol = start; this.EndCol = end; this.Wave = false; }
public override void Paint(Cairo.Context gr, Rectangle rect, string subPart = "") { float widthRatio = 1f; float heightRatio = 1f; if (Scaled) { widthRatio = (float)rect.Width / Dimensions.Width; heightRatio = (float)rect.Height / Dimensions.Height; } if (KeepProportions) { if (widthRatio < heightRatio) heightRatio = widthRatio; else widthRatio = heightRatio; } gr.Save (); gr.Translate (rect.Left,rect.Top); gr.Scale (widthRatio, heightRatio); gr.Translate (((float)rect.Width/widthRatio - Dimensions.Width)/2f, ((float)rect.Height/heightRatio - Dimensions.Height)/2f); if (string.IsNullOrEmpty (subPart)) hSVG.RenderCairo (gr); else hSVG.RenderCairoSub (gr, "#" + subPart); gr.Restore (); }
static void draw (Cairo.Context gr, int width, int height) { double x=0.1, y=0.5; double x1=0.4, y1=0.9, x2=0.6, y2=0.1, x3=0.9, y3=0.5; gr.Scale (width, height); gr.LineWidth = 0.04; gr.MoveTo ( new PointD (x, y) ); gr.CurveTo ( new PointD (x1, y1), new PointD (x2, y2), new PointD (x3, y3) ); gr.Stroke (); gr.Color = new Color (1, 0.2, 0.2, 0.6); gr.LineWidth = 0.03; gr.MoveTo ( new PointD (x, y) ); gr.LineTo ( new PointD (x1, y1) ); gr.MoveTo ( new PointD (x2, y2) ); gr.LineTo ( new PointD (x3, y3) ); gr.Stroke (); }
public ImageSurface (IntPtr data, Cairo.Format format, int width, int height, int stride) { surface = NativeMethods.cairo_image_surface_create_for_data (data, format, width, height, stride); lock (surfaces.SyncRoot){ surfaces [surface] = this; } }
protected override bool OnDrawn(Cairo.Context cr) { bool ret = true; var rect = this.Allocation; if (rect.Width > 0 && rect.Height > 0) { var arrowWidth = popupButton.Allocation.Width; var arrowPos = rect.Width - arrowWidth; var arrowSize = 10; StyleContext.Save(); StyleContext.AddClass("entry"); StyleContext.RenderBackground(cr, 0, 0, rect.Width, rect.Height); ret = base.OnDrawn(cr); StyleContext.RenderArrow(cr, Math.PI, arrowPos, (rect.Height - arrowSize) / 2, arrowSize); cr.SetSourceColor(new Cairo.Color(.8, .8, .8)); cr.Rectangle(arrowPos - 5, 2, 1, rect.Height - 4); cr.Fill(); Entry.StyleContext.RenderFrame(cr, 0, 0, rect.Width, rect.Height); StyleContext.Restore(); } return ret; }
protected override void ClippedRender (Cairo.Context cr) { Brush brush = Background; if (!brush.IsValid) { return; } double x = Double.IsNaN (brush.Width) ? 0 : (RenderSize.Width - brush.Width) * XAlign; double y = Double.IsNaN (brush.Height) ? 0 : (RenderSize.Height - brush.Height) * YAlign; cr.Rectangle (0, 0, RenderSize.Width, RenderSize.Height); cr.ClipPreserve (); if (x != 0 || y != 0) { cr.Translate (x, y); } cr.Antialias = Cairo.Antialias.None; brush.Apply (cr); cr.Fill (); }
protected void DrawCircle (Cairo.Context cr, double x, double y, double size) { x += 0.5; y += 0.5; cr.NewPath (); cr.Arc (x + size/2, y + size / 2, (size-4)/2, 0, 2 * Math.PI); cr.ClosePath (); }
private static void Taskbar() { var Data = new byte[Compositor.PACKET_SIZE]; var Request = (GuiRequest *)Data.GetDataOffset(); Request->ClientID = 0; Request->Type = RequestType.NewWindow; var Window = (NewWindow *)Request; Window->X = 0; Window->Y = 0; Window->Width = VBE.Xres; Window->Height = 30; Compositor.Server.Write(Data); Client.Read(Data); string HashCode = new string(Window->Buffer); var aBuffer = SHM.Obtain(HashCode, 0, false); TaskbarID = Window->WindowID; uint surface = Cairo.ImageSurfaceCreateForData(Window->Width * 4, Window->Height, Window->Width, ColorFormat.ARGB32, aBuffer); uint context = Cairo.Create(surface); uint pattern = Cairo.PatternCreateLinear(30, 0, 0, 0); Cairo.PatternAddColorStopRgba(0.7, 0.42, 0.42, 0.42, 0, pattern); Cairo.PatternAddColorStopRgba(0.6, 0.36, 0.36, 0.36, 0.5, pattern); Cairo.PatternAddColorStopRgba(0.7, 0.42, 0.42, 0.42, 1, pattern); Cairo.SetOperator(Operator.Over, context); Cairo.Rectangle(30, VBE.Xres, 0, 0, context); Cairo.SetSource(pattern, context); Cairo.Fill(context); Cairo.Rectangle(2, VBE.Xres, 30 - 2, 0, context); Cairo.SetSourceRGBA(0.7, 0.41, 0.41, 0.41, context); Cairo.Fill(context); Cairo.PatternDestroy(pattern); Cairo.Destroy(context); Cairo.SurfaceDestroy(surface); Request->Type = RequestType.Redraw; var Redraw = (Redraw *)Request; Redraw->WindowID = TaskbarID; Redraw->X = 0; Redraw->Y = 0; Redraw->Width = VBE.Xres; Redraw->Height = 40; Compositor.Server.Write(Data); TaskbarSurface = surface; TaskbarContext = context; Heap.Free(Data); }
public void Render(MudleObject root) { var(width, height) = root.CalualteBounds(); Surface = Cairo.cairo_image_surface_create(CairoFormat.CairoFormatArgb32, width, height); Cr = Cairo.cairo_create(Surface); Internalrender(root, Cr, 0, 0); }
internal Window(int aClientID, int aXpos, int aYpos, int aWidth, int aHeight) { ClientID = aClientID; X = aXpos; Y = aYpos; Width = aWidth; Height = aHeight; HashID = GenerateNewHashID(); Buffer = SHM.Obtain(HashID, (uint)(aWidth * aHeight * 4), true); Surface = Cairo.ImageSurfaceCreateForData(aWidth * 4, aHeight, aWidth, ColorFormat.ARGB32, Buffer); }
private static void Desktop() { var Data = new byte[Compositor.PACKET_SIZE]; var Request = (GuiRequest *)Data.GetDataOffset(); Request->ClientID = 0; Request->Type = RequestType.NewWindow; var Window = (NewWindow *)Request; Window->X = 0; Window->Y = 0; Window->Width = VBE.Xres; Window->Height = VBE.Yres; Compositor.Server.Write(Data); Client.Read(Data); string HashCode = new string(Window->Buffer); var aBuffer = SHM.Obtain(HashCode, 0, false); DesktopID = Window->WindowID; uint surface = Cairo.ImageSurfaceCreateForData(Window->Width * 4, Window->Height, Window->Width, ColorFormat.ARGB32, aBuffer); uint context = Cairo.Create(surface); uint wallpaper = Cairo.ImageSurfaceFromPng(Marshal.C_String("disk0/wallpaper.png")); Cairo.SetSourceSurface(0, 0, wallpaper, context); Cairo.Paint(context); Cairo.SurfaceDestroy(wallpaper); Request->Type = RequestType.Redraw; var Redraw = (Redraw *)Request; Redraw->WindowID = DesktopID; Redraw->X = 0; Redraw->Y = 0; Redraw->Width = VBE.Xres; Redraw->Height = VBE.Yres; Compositor.Server.Write(Data); DesktopSurface = surface; DesktopContext = context; Heap.Free(Data); }
private void Internalrender(MudleObject root, IntPtr cr, int x, int y) { var(width, height) = root.CalualteBounds(); Cairo.cairo_move_to(cr, x, y); //apply bg color var color = root.GetBackgroundColor(); Cairo.cairo_set_source_rgb(Cr, color.R, color.G, color.B); //drawbg switch (root.Implments) { case "rectangle": Cairo.cairo_rectangle(cr, x, y, width, height); Cairo.cairo_fill(cr); break; case "text": var fgcolor = root.GetColor("foreground-color"); Cairo.cairo_set_source_rgb(Cr, fgcolor.R, fgcolor.G, fgcolor.B); Cairo.cairo_select_font_face(cr, "Sans", CairoFontSlant.CairoFontSlantNormal, CairoFontWeight.CairoFontWeightNormal); Cairo.cairo_set_font_size(cr, 10.0); Cairo.cairo_show_text(cr, root.Properties["value"].Value.Trim('"').Trim('"')); break; } foreach (var mudleObject in root.Children) { var(x1, y1) = mudleObject.Value.CalualteLocation(); Internalrender(mudleObject.Value, cr, x1, y1); } }
private static unsafe void DrawTaskbar(GuiRequest *request, byte[] xData) { request->Type = RequestType.NewWindow; request->Error = ErrorType.None; var taskbar = (NewWindow *)request; int height = 30; taskbar->X = 0; taskbar->Y = 0; taskbar->Width = VBE.Xres; taskbar->Height = height; Compositor.Server.Write(xData); SystemClient.Read(xData); if (request->Error != ErrorType.None) { Debug.Write("Error4: %d\n", (int)request->Error); return; } string HashCode = new string(taskbar->Buffer); var aBuffer = SHM.Obtain(HashCode, 0, false); int winID = taskbar->WindowID; Debug.Write("winID: %d\n", winID); uint surface = Cairo.ImageSurfaceCreateForData(VBE.Xres * 4, height, VBE.Xres, ColorFormat.ARGB32, aBuffer); uint cr = Cairo.Create(surface); uint pattern = Cairo.PatternCreateLinear(height, 0, 0, 0); Cairo.PatternAddColorStopRgba(0.7, 0.42, 0.42, 0.42, 0, pattern); Cairo.PatternAddColorStopRgba(0.6, 0.36, 0.36, 0.36, 0.5, pattern); Cairo.PatternAddColorStopRgba(0.7, 0.42, 0.42, 0.42, 1, pattern); Cairo.SetOperator(Operator.Over, cr); Cairo.Rectangle(height, VBE.Xres, 0, 0, cr); Cairo.SetSource(pattern, cr); Cairo.Fill(cr); Cairo.Rectangle(2, VBE.Xres, height - 2, 0, cr); Cairo.SetSourceRGBA(0.7, 0.41, 0.41, 0.41, cr); Cairo.Fill(cr); Cairo.SetSourceRGBA(1, 1, 1, 1, cr); Cairo.SelectFontFace(FontWeight.Bold, FontSlant.Normal, Marshal.C_String(""), cr); Cairo.SetFontSize(20, cr); Cairo.MoveTo(20, 1215, cr); Cairo.ShowText(Marshal.C_String("20:10"), cr); Cairo.PatternDestroy(pattern); Cairo.Destroy(cr); Cairo.SurfaceDestroy(surface); request->Type = RequestType.Redraw; var req = (Redraw *)request; req->WindowID = winID; req->X = 0; req->Y = 0; req->Width = VBE.Xres; req->Height = height; Compositor.Server.Write(xData); }
private static unsafe void Renderer() { int tmp_mouse_X, tmp_mouse_Y; int old_mouse_X = -1, old_mouse_Y = -1; bool update; while (true) { tmp_mouse_X = Mouse_X; tmp_mouse_Y = Mouse_Y; update = false; Cairo.Save(MainContext); Cairo.Save(VideoContext); if (tmp_mouse_X != old_mouse_X || tmp_mouse_Y != old_mouse_Y) { update = true; Cairo.Rectangle(32, 32, old_mouse_Y, old_mouse_X, MainContext); Cairo.Rectangle(32, 32, old_mouse_Y, old_mouse_X, VideoContext); Cairo.Rectangle(32, 32, tmp_mouse_Y, tmp_mouse_X, VideoContext); } old_mouse_X = tmp_mouse_X; old_mouse_Y = tmp_mouse_Y; var queue = RedrawRects; Monitor.AcquireLock(ref RedrawRectsLock); while (queue.Count > 0) { var rect = (Rect *)queue.Dequeue(); Cairo.Rectangle(rect->Height, rect->Width, rect->Y, rect->X, MainContext); Cairo.Rectangle(rect->Height, rect->Width, rect->Y, rect->X, VideoContext); Libc.free((uint)rect); update = true; } Monitor.ReleaseLock(ref RedrawRectsLock); if (update) { Cairo.Clip(MainContext); var list = Stacking; Monitor.AcquireLock(ref StackingLock); int count = list.Count; for (int index = 0; index < count; index++) { var win = list[index]; Cairo.Save(MainContext); Cairo.Translate(win.Y, win.X, MainContext); Cairo.SetSourceSurface(0, 0, win.Surface, MainContext); Cairo.Paint(MainContext); Cairo.Restore(MainContext); } Monitor.ReleaseLock(ref StackingLock); } if (update) { Cairo.Clip(VideoContext); Cairo.Translate(0, 0, VideoContext); Cairo.SetOperator(Operator.Source, VideoContext); Cairo.SetSourceSurface(0, 0, MainSurface, VideoContext); Cairo.Paint(VideoContext); Cairo.Translate(old_mouse_Y, old_mouse_X, VideoContext); Cairo.SetOperator(Operator.Over, VideoContext); Cairo.SetSourceSurface(0, 0, MouseSurface, VideoContext); Cairo.Paint(VideoContext); } Cairo.Restore(MainContext); Cairo.Restore(VideoContext); Task.Switch(); } }
public void SaveToPng(string png) { Cairo.cairo_surface_write_to_png(Surface, png); Cairo.cairo_destroy(Cr); Cairo.cairo_surface_destroy(Surface); }
private static unsafe void DrawWindow(GuiRequest *request, byte[] xData) { request->Type = RequestType.NewWindow; request->Error = ErrorType.None; var window = (NewWindow *)request; window->X = 340; window->Y = 159; window->Width = 600; window->Height = 450; Compositor.Server.Write(xData); SystemClient.Read(xData); if (request->Error != ErrorType.None) { Debug.Write("Error5: %d\n", (int)request->Error); return; } string HashCode = new string(window->Buffer); var aBuffer = SHM.Obtain(HashCode, 0, false); int winID = window->WindowID; Debug.Write("winID: %d\n", winID); uint surface = Cairo.ImageSurfaceCreateForData(600 * 4, 450, 600, ColorFormat.ARGB32, aBuffer); uint cr = Cairo.Create(surface); Cairo.SetOperator(Operator.Over, cr); Cairo.Rectangle(450, 600, 0, 0, cr); Cairo.SetSourceRGBA(1, 0.41, 0.41, 0.41, cr); Cairo.Fill(cr); Cairo.Rectangle(446, 596, 2, 2, cr); Cairo.SetSourceRGBA(1, 0.87, 0.87, 0.87, cr); Cairo.Fill(cr); Cairo.Rectangle(410, 580, 30, 10, cr); Cairo.SetSourceRGBA(1, 1, 1, 1, cr); Cairo.Fill(cr); Cairo.SetSourceRGBA(1, 0.41, 0.41, 0.41, cr); Cairo.SelectFontFace(FontWeight.Normal, FontSlant.Normal, Marshal.C_String(""), cr); Cairo.SetFontSize(15, cr); Cairo.MoveTo(18, 215, cr); Cairo.ShowText(Marshal.C_String("Atom OS : Installation Guide"), cr); Cairo.SelectFontFace(FontWeight.Bold, FontSlant.Normal, Marshal.C_String(""), cr); Cairo.MoveTo(18, 580, cr); Cairo.ShowText(Marshal.C_String("X"), cr); Cairo.SurfaceFlush(surface); Cairo.Destroy(cr); Cairo.SurfaceDestroy(surface); request->Type = RequestType.Redraw; var req = (Redraw *)request; req->WindowID = winID; req->X = 0; req->Y = 0; req->Width = 600; req->Height = 450; Compositor.Server.Write(xData); Debug.Write("Time: %d\n", Timer.TicksFromStart); while (true) { SystemClient.Read(xData); if (request->Error != ErrorType.None) { continue; } if (request->Type != RequestType.MouseEvent) { continue; } var mreq = (MouseEvent *)request; if (mreq->WindowID != winID) { continue; } if ((mreq->Function & MouseFunction.Click) != 0) { int x = mreq->Xpos; int y = mreq->Ypos; if (y < 40) { request->Type = RequestType.DragRequest; var mv = (DragRequest *)request; mv->WindowID = winID; Compositor.Server.Write(xData); } } } }