22using EmptyFlow . SciterAPI ;
33using EmptyFlow . SciterAPI . Client ;
44using EmptyFlow . SciterAPI . Client . Models ;
5+ using EmptyFlow . SciterAPI . Client . PseudoSom ;
56using EmptyFlow . SciterAPI . Enums ;
67using System . Numerics ;
78
89// These example developer used for experiment with some new features
910// please use another examples in folder Examples. Thanks!
1011
11- var pathToSciter = "C:/IDEs/sciter/sciter-js-sdk-6.0.3.2 " ;
12+ var pathToSciter = "C:/IDEs/sciter/sciter-js-sdk-6.0.3.9 " ;
1213
1314var host = new SciterAPIHost ( Path . Combine ( pathToSciter , "bin/windows/x64" ) , true , true ) ;
1415var path = "file://" + Path . Combine ( pathToSciter , "samples/html/details-summary.htm" ) ;
15- host . Callbacks . AddAttachBehaviourFactory ( "testbehaviour" , ( element ) => new TestGraphicsEventHandler ( element , host ) ) ;
16- host . CreateMainWindow ( 300 , 300 , enableDebug : true , enableFeature : true ) ;
16+ //host.Callbacks.AddAttachBehaviourFactory ( "testbehaviour", ( element ) => new TestGraphicsEventHandler ( element, host ) );
17+ host . Callbacks . AddAttachBehaviourFactory ( "psom" , ( element ) => new PseudoSomHandler ( element , host ) ) ;
18+ host . EnableDebugMode ( ) ;
19+ host . EnableFeatures ( SciterRuntimeFeatures . ALLOW_SOCKET_IO ) ;
20+ host . CreateWindow ( asMain : true , debugOutput : true ) ;
1721host . AddWindowEventHandler ( new MyWindowEventHandler ( host . MainWindow , host ) ) ;
1822host . LoadFile ( path ) ;
1923host . Process ( ) ;
2024
2125
2226public class MyWindowEventHandler : WindowEventHandler {
2327
24- public MyWindowEventHandler ( nint window , SciterAPIHost host ) : base ( window , host ) {
25- }
26-
27- public override void BehaviourEvent ( BehaviourEvents cmd , nint heTarget , nint he , nint reason , SciterValue data , string name ) {
28- if ( cmd == BehaviourEvents . DOCUMENT_READY ) {
29- Host . MoveWindow ( Host . MainWindow , new SciterWindowPosition ( 800 , 300 ) ) ;
30- var files = Host . ShowWindowSelectFileDialog (
31- Host . MainWindow ,
32- SciterSelectFileDialogMode . Open ,
33- new Dictionary < string , string > {
34- [ "Pdf Files (*.pdf)" ] = "*.pdf" ,
35- [ "All Files (*.*)" ] = "*.*" ,
36- } ,
37- "pdf" ,
38- "Lalala" ,
39- "" ) ;
40- if ( files ? . Any ( ) == true ) {
41-
42- }
43- }
44- }
28+ public MyWindowEventHandler ( nint window , SciterAPIHost host ) : base ( window , host ) {
29+ }
30+
31+ public override void BehaviourEvent ( BehaviourEvents cmd , nint heTarget , nint he , nint reason , SciterValue data , string name ) {
32+ if ( cmd == BehaviourEvents . DOCUMENT_READY ) {
33+ var value = Host . GetWindowParent ( Host . MainWindow ) ;
34+ if ( value == 0 ) {
35+
36+ }
37+ }
38+ }
39+
40+ }
41+
42+ public class TestModel : IPseudoSomModel {
43+
44+ private readonly SciterAPIHost m_host ;
45+
46+ public TestModel ( SciterAPIHost host ) {
47+ m_host = host ;
48+ }
49+
50+ public SciterValue CallMethod ( string name , IEnumerable < SciterValue > parameters ) {
51+ return m_host . CreateNullValue ( ) ;
52+ }
53+
54+ public HashSet < string > GetMethods ( ) {
55+ return [ ] ;
56+ }
57+
58+ public string GetModelName ( ) => "mymodel" ;
59+
60+ public HashSet < string > GetProperties ( ) => [ "counter" ] ;
61+
62+ public int Counter { get ; set ; } = 5 ;
63+
64+ public SciterValue GetPropetyValue ( string name ) {
65+ return name switch {
66+ "counter" => m_host . CreateValue ( Counter ) ,
67+ _ => m_host . CreateNullValue ( )
68+ } ;
69+ }
70+
71+ public bool SetPropetyValue ( SciterValue value , string name ) {
72+ if ( name == "counter" ) {
73+ Counter = m_host . GetValueInt32 ( ref value ) ;
74+ return true ;
75+ }
76+
77+ return false ;
78+ }
79+ }
80+
81+ public class PseudoSomHandler : ElementEventHandler {
82+
83+ readonly TestModel _model ;
84+
85+ public PseudoSomHandler ( nint element , SciterAPIHost host ) : base ( element , host ) {
86+ _model = new TestModel ( host ) ;
87+ }
88+
89+ public override void AfterRegisterEvent ( ) {
90+ PseudoSom . RegisterModel ( _model , Host , Host . MainWindow , m_subscribedElement ) ;
91+ }
92+
93+ public override ( SciterValue ? value , bool handled ) ScriptMethodCall ( string name , IEnumerable < SciterValue > arguments ) {
94+ return PseudoSom . Handle ( _model , Host , name , arguments ) ;
95+ }
4596
4697}
4798
4899public class TestGraphicsEventHandler : ElementEventHandler {
49100
50- public TestGraphicsEventHandler ( nint element , SciterAPIHost host ) : base ( element , host ) {
51- Text = Host . GraphicsCreateTextForElement ( element , "test text!!!111" , "test-class" ) ;
52- Text2 = Host . GraphicsCreateTextForElementWithStyle ( element , "test text!!!111" , "font-size: 18px;color: green;" ) ;
53- Color1 = Host . GraphicsGetColor ( 0 , 204 , 0 ) ;
54- Color2 = Host . GraphicsGetColor ( 0 , 0 , 255 ) ;
55- }
101+ public TestGraphicsEventHandler ( nint element , SciterAPIHost host ) : base ( element , host ) {
102+ Text = Host . GraphicsCreateTextForElement ( element , "test text!!!111" , "test-class" ) ;
103+ Text2 = Host . GraphicsCreateTextForElementWithStyle ( element , "test text!!!111" , "font-size: 18px;color: green;" ) ;
104+ Color1 = Host . GraphicsGetColor ( 0 , 204 , 0 ) ;
105+ Color2 = Host . GraphicsGetColor ( 0 , 0 , 255 ) ;
106+ }
56107
57- public uint Color1 { get ; set ; }
108+ public uint Color1 { get ; set ; }
58109
59- public uint Color2 { get ; set ; }
110+ public uint Color2 { get ; set ; }
60111
61- public GraphicsTextModel Text { get ; set ; }
112+ public GraphicsTextModel Text { get ; set ; }
62113
63- public GraphicsTextModel Text2 { get ; set ; }
114+ public GraphicsTextModel Text2 { get ; set ; }
64115
65- public override void DrawEvent ( DrawEvents command , nint gfx , SciterRectangle area , uint reserved ) {
66- if ( command == DrawEvents . DRAW_CONTENT ) {
67- Host . GraphicsSaveState ( gfx ) ;
68- Host . GraphicsFillColor ( gfx , Color1 ) ;
69- Host . GraphicsDrawRectangle ( gfx , area . Left , area . Top , area . Left + area . Width , area . Top + area . Height ) ;
70- Host . GraphicsDrawLine ( gfx , area . LeftTopCorner , area . RightBottomCorner , Color2 , 10 ) ;
71- Host . GraphicsDrawText ( gfx , Text , new Vector2 ( area . Left , area . Top ) , SciterTextPosition . TopLeft ) ;
72- Host . GraphicsDrawText ( gfx , Text2 , new Vector2 ( area . Left , area . Top + 30 ) , SciterTextPosition . TopLeft ) ;
73- Host . GraphicsRestoreState ( gfx ) ;
74- }
75- }
116+ public override void DrawEvent ( DrawEvents command , nint gfx , SciterRectangle area , uint reserved ) {
117+ if ( command == DrawEvents . DRAW_CONTENT ) {
118+ Host . GraphicsSaveState ( gfx ) ;
119+ Host . GraphicsFillColor ( gfx , Color1 ) ;
120+ Host . GraphicsDrawRectangle ( gfx , area . Left , area . Top , area . Left + area . Width , area . Top + area . Height ) ;
121+ Host . GraphicsDrawLine ( gfx , area . LeftTopCorner , area . RightBottomCorner , Color2 , 10 ) ;
122+ Host . GraphicsDrawText ( gfx , Text , new Vector2 ( area . Left , area . Top ) , SciterTextPosition . TopLeft ) ;
123+ Host . GraphicsDrawText ( gfx , Text2 , new Vector2 ( area . Left , area . Top + 30 ) , SciterTextPosition . TopLeft ) ;
124+ Host . GraphicsRestoreState ( gfx ) ;
125+ }
126+ }
76127
77128}
0 commit comments