Skip to content

Commit bd291d4

Browse files
committed
+ Added methods for creating text for drawing
1 parent 549de96 commit bd291d4

File tree

5 files changed

+46
-18
lines changed

5 files changed

+46
-18
lines changed

EmptyFlow.SciterAPI/Client/HostGraphicsAPI.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,27 @@ public void GraphicsDrawRoundedRectangle ( nint hgfx, float x1, float y1, float
232232
public GraphicsTextModel GraphicsCreateTextForElement ( nint hgfx, nint he, string text, string className ) {
233233
if ( !CheckGraphics () ) return new GraphicsTextModel { Element = nint.Zero, Id = nint.Zero };
234234

235-
var pointer = Marshal.StringToHGlobalUni ( text );
236235
nint textPointer;
237-
var graphResult = m_graphicsApi.textCreateForElement ( out textPointer, pointer, (uint) text.Length, he, className );
236+
var graphResult = m_graphicsApi.textCreateForElement ( out textPointer, text, (uint) text.Length, he, className );
238237
if ( graphResult != GraphInResult.Ok ) {
239238
Console.WriteLine ( "GraphicsCreateTextForElement resulted with error, actual result - " + graphResult );
240239
return new GraphicsTextModel { Id = nint.Zero, Element = nint.Zero };
241240
}
242241
return new GraphicsTextModel { Id = textPointer, Element = he };
243242
}
244243

244+
public GraphicsTextModel GraphicsCreateTextForElementWithStyle ( nint hgfx, nint he, string text, string style ) {
245+
if ( !CheckGraphics () ) return new GraphicsTextModel { Element = nint.Zero, Id = nint.Zero };
246+
247+
nint textPointer;
248+
var graphResult = m_graphicsApi.textCreateForElementAndStyle ( out textPointer, text, (uint) text.Length, he, style, (uint) style.Length );
249+
if ( graphResult != GraphInResult.Ok ) {
250+
Console.WriteLine ( "GraphicsCreateTextForElementWithStyle resulted with error, actual result - " + graphResult );
251+
return new GraphicsTextModel { Id = nint.Zero, Element = nint.Zero };
252+
}
253+
return new GraphicsTextModel { Id = textPointer, Element = he };
254+
}
255+
245256
public void GraphicsReleaseText ( GraphicsTextModel text ) {
246257
if ( !CheckGraphics () ) return;
247258

@@ -257,10 +268,10 @@ public void GraphicsReleaseText ( GraphicsTextModel text ) {
257268
/// <param name="x">X coordinate.</param>
258269
/// <param name="y">Y coordinate.</param>
259270
/// <param name="coordinates">Position (1..9).</param>
260-
public void GraphicsDrawText ( nint hgfx, GraphicsTextModel text, Vector2 coordinates, uint position ) {
271+
public void GraphicsDrawText ( nint hgfx, GraphicsTextModel text, Vector2 coordinates, SciterTextPosition position ) {
261272
if ( !CheckGraphics () ) return;
262273

263-
m_graphicsApi.gDrawText ( hgfx, text.Id, coordinates.X, coordinates.Y, position );
274+
m_graphicsApi.gDrawText ( hgfx, text.Id, coordinates.X, coordinates.Y, (uint) position );
264275
}
265276

266277
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 ) {

EmptyFlow.SciterAPI/EmptyFlow.SciterAPI.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
SciterAPIHost.CreateMainWindow parameters width and height now is not mandatory, if you not specify window it will be centered and half from screen size
2525
SciterAPIHost.GraphicsDrawImage added override with Vector2 parameters
2626
SciterAPIHost.GraphicsCreateTextForElement new method for creating text related to element
27-
SciterAPIHost.GraphicsDrawText full refactored and fixed
27+
SciterAPIHost.GraphicsCreateTextForElementWithStyle new method for creating text related to element
28+
SciterAPIHost.GraphicsDrawText full refactored
2829
</PackageReleaseNotes>
2930
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3031
</PropertyGroup>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace EmptyFlow.SciterAPI.Enums {
2+
3+
public enum SciterTextPosition : uint {
4+
BottomLeft = 1, // The x, y coordinates define the bottom-left corner of the text.
5+
BottomCenter = 2, // The x, y coordinates define the bottom-center of the text.
6+
BottomRight = 3, // The x, y coordinates define the bottom-right corner of the text.
7+
MiddleLeft = 4, // The x, y coordinates define the middle-left edge of the text.
8+
CenterCenter = 5, // The x, y coordinates define the exact center of the text.
9+
MiddleRight = 6, // The x, y coordinates define the middle-right edge of the text.
10+
TopLeft = 7, // The x, y coordinates define the top-left corner of the text ( this is the default if pointOf is omitted).
11+
TopCenter = 8, // The x, y coordinates define the top-center of the text.
12+
TopRight = 9 // The x, y coordinates define the top-right corner of the text.
13+
};
14+
15+
}

EmptyFlow.SciterAPI/Structs/GraphicsApiStruct.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ namespace EmptyFlow.SciterAPI.Structs {
5353
public delegate GraphInResult GraphicsGLineGradientRadial ( IntPtr hgfx, float x, float y, float rx, float ry, ColorStop[] stops, uint nstops );
5454
public delegate GraphInResult GraphicsGFillGradientRadial ( IntPtr hgfx, float x, float y, float rx, float ry, ColorStop[] stops, uint nstops );
5555
public delegate GraphInResult GraphicsGFillMode ( IntPtr hgfx, bool evenOdd );
56-
public delegate GraphInResult GraphicsTextCreateForElement ( out nint ptext, nint text, uint textLength, IntPtr he, [MarshalAs ( UnmanagedType.LPWStr )] string classNameOrNull );
57-
public delegate GraphInResult GraphicsTextCreateForElementAndStyle ( IntPtr ptext, [MarshalAs ( UnmanagedType.LPWStr )] string text, uint textLength, IntPtr he, [MarshalAs ( UnmanagedType.LPWStr )] string style, uint styleLength );
56+
public delegate GraphInResult GraphicsTextCreateForElement ( out nint ptext, [MarshalAs ( UnmanagedType.LPWStr )] string text, uint textLength, IntPtr he, [MarshalAs ( UnmanagedType.LPWStr )] string classNameOrNull );
57+
public delegate GraphInResult GraphicsTextCreateForElementAndStyle ( out nint ptext, [MarshalAs ( UnmanagedType.LPWStr )] string text, uint textLength, IntPtr he, [MarshalAs ( UnmanagedType.LPWStr )] string style, uint styleLength );
5858
public delegate GraphInResult GraphicsTextAddRef ( IntPtr path );
5959
public delegate GraphInResult GraphicsTextRelease ( IntPtr path );
6060
public delegate GraphInResult GraphicsTextGetMetrics ( IntPtr text, out float minWidth, out float maxWidth, out float height, out float ascent, out float descent, out float nLines );

src/Program.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
using EmptyFlow.SciterAPI;
33
using EmptyFlow.SciterAPI.Client;
44
using EmptyFlow.SciterAPI.Client.Models;
5-
using EmptyFlow.SciterAPI.Structs;
5+
using EmptyFlow.SciterAPI.Enums;
66
using System.Numerics;
7-
using static System.Net.Mime.MediaTypeNames;
87

9-
var host = new SciterAPIHost ( "C:/IDEs/sciter/sciter-js-sdk-6.0.2.30/bin/windows/x64", true, true );
10-
var path = "file://C:/IDEs/sciter/sciter-js-sdk-6.0.2.30/samples/html/details-summary.htm";
8+
var pathToSciter = "C:/IDEs/sciter/sciter-js-sdk-6.0.2.30";
9+
10+
var host = new SciterAPIHost ( Path.Combine ( pathToSciter, "bin/windows/x64" ), true, true );
11+
var path = "file://" + Path.Combine ( pathToSciter, "samples/html/details-summary.htm" );
1112
host.Callbacks.AddAttachBehaviourFactory ( "testbehaviour", ( element ) => new TestGraphicsEventHandler ( element, host ) );
1213
host.CreateMainWindow ( 0, 0, enableDebug: true, enableFeature: true );
1314
host.AddWindowEventHandler ( new MyWindowEventHandler ( host.MainWindow, host ) );
@@ -31,10 +32,6 @@ public override void BehaviourEvent ( BehaviourEvents cmd, nint heTarget, nint h
3132
}
3233
}
3334

34-
/*public override nint SOMEventPassport () {
35-
return Host.CreateSomPassport ( "testpass" );
36-
}*/
37-
3835
}
3936

4037
public class TestGraphicsEventHandler : ElementEventHandler {
@@ -44,16 +41,20 @@ public TestGraphicsEventHandler ( nint element, SciterAPIHost host ) : base ( el
4441

4542
public GraphicsTextModel? Text { get; set; }
4643

44+
public GraphicsTextModel? Text2 { get; set; }
45+
4746
public override void DrawEvent ( DrawEvents command, nint gfx, SciterRectangle area, uint reserved ) {
4847
var color = Host.Graphics.RGBA ( 0, 204, 0, 255 );
4948
var blue = Host.Graphics.RGBA ( 0, 0, 255, 255 );
50-
if (Text == null) Text = Host.GraphicsCreateTextForElement ( gfx, ProcessedElement, "test text!!!111", "solid" );
49+
if ( Text == null ) Text = Host.GraphicsCreateTextForElement ( gfx, ProcessedElement, "test text!!!111", "test-class" );
50+
if ( Text2 == null ) Text2 = Host.GraphicsCreateTextForElementWithStyle ( gfx, ProcessedElement, "test text!!!111", "font-size: 18px;color: green;" );
5151
if ( command == DrawEvents.DRAW_CONTENT ) {
5252
Host.GraphicsSaveState ( gfx );
5353
Host.GraphicsFillColor ( gfx, color );
54-
Host.GraphicsDrawRectangle ( gfx, area.Left, area.Top, area.Width, area.Height );
54+
Host.GraphicsDrawRectangle ( gfx, area.Left, area.Top, area.Left + area.Width, area.Top + area.Height );
5555
Host.GraphicsDrawLine ( gfx, area.LeftTopCorner, area.RightBottomCorner, blue, 10 );
56-
Host.GraphicsDrawText ( gfx, Text, new Vector2 ( area.Left, area.Top ), 1 );
56+
Host.GraphicsDrawText ( gfx, Text, new Vector2 ( area.Left, area.Top ), SciterTextPosition.TopLeft );
57+
Host.GraphicsDrawText ( gfx, Text2, new Vector2 ( area.Left, area.Top + 30 ), SciterTextPosition.TopLeft );
5758
Host.GraphicsRestoreState ( gfx );
5859
}
5960
}

0 commit comments

Comments
 (0)