Skip to content

Commit 592641c

Browse files
committed
+ Added example for new graphics helpers
1 parent 7992620 commit 592641c

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

EmptyFlow.SciterAPI/Client/HostGraphicsAPI.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ public void GraphicsFillGradientRadial ( nint hgfx, float x1, float y1, float x2
125125
/// <param name="y2">Y2 coordinate.</param>
126126
public void GraphicsDrawLine ( nint hgfx, float x1, float y1, float x2, float y2 ) => TryToExecuteGraphics ( ( api ) => api.gLine ( hgfx, x1, y1, x2, y2 ) );
127127

128+
/// <summary>
129+
/// Draws line from x1,y1 to x2,y2 with width and color.
130+
/// </summary>
131+
/// <param name="hgfx">Pointer on graphics surface.</param>
132+
/// <param name="x1">X1 coordinate.</param>
133+
/// <param name="y1">Y1 coordinate.</param>
134+
/// <param name="x2">X2 coordinate.</param>
135+
/// <param name="y2">Y2 coordinate.</param>
136+
public void GraphicsDrawLine ( nint hgfx, float x1, float y1, float x2, float y2, uint color, float width ) {
137+
TryToExecuteGraphics (
138+
( api ) => {
139+
api.gLineColor ( hgfx, color );
140+
api.gLineWidth ( hgfx, width );
141+
api.gLine ( hgfx, x1, y1, x2, y2 );
142+
}
143+
);
144+
}
145+
128146
/// <summary>
129147
/// Draw ellipse.
130148
/// </summary>
@@ -171,7 +189,7 @@ public void GraphicsDrawText ( nint hgfx, string text, float x, float y, uint po
171189
}
172190

173191
public void GraphicsDrawImage ( nint hgfx, nint image, float x, float y, float w, float h, uint ix, uint iy, uint iw, uint ih, float opacity ) {
174-
TryToExecuteGraphics ( ( api ) => api.gDrawImage ( hgfx, image, x, y, w, h, ix, iy,iw, ih, opacity) );
192+
TryToExecuteGraphics ( ( api ) => api.gDrawImage ( hgfx, image, x, y, w, h, ix, iy, iw, ih, opacity ) );
175193
}
176194

177195
/// <summary>

src/Program.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ public TestGraphicsEventHandler ( nint element, SciterAPIHost host ) : base ( el
4444

4545
public override void DrawEvent ( DrawEvents command, nint gfx, SciterRectangle area, uint reserved ) {
4646
var color = Host.Graphics.RGBA ( 0, 204, 0, 255 );
47-
if ( command == DrawEvents.DRAW_BACKGROUND ) {
48-
Host.Graphics.gFillColor ( gfx, color );
49-
Host.Graphics.gRectangle ( gfx, area.Left, area.Top, area.Width, area.Height );
50-
/*
51-
ctx.fillStyle = "blue";
52-
ctx.fillRect(10, 10, 100, 100);
53-
*/
47+
var blue = Host.Graphics.RGBA ( 0, 0, 255, 255 );
48+
if ( command == DrawEvents.DRAW_CONTENT ) {
49+
Host.GraphicsSaveState ( gfx );
50+
Host.GraphicsFillColor ( gfx, color );
51+
Host.GraphicsDrawRectangle ( gfx, area.Left, area.Top, area.Width, area.Height );
52+
Host.GraphicsDrawLine ( gfx, 10, 10, 100, 100, blue, 10 );
53+
Host.GraphicsRestoreState ( gfx );
5454
}
5555
}
5656

0 commit comments

Comments
 (0)