88
99#endregion
1010
11+ using System ;
1112using Exomia . Framework . Components ;
1213using Exomia . Framework . Game ;
1314using Exomia . Framework . Graphics ;
15+ using Exomia . Framework . Input ;
1416using Exomia . Framework . Mathematics ;
1517using Exomia . Framework . Resources ;
18+ using Exomia . Framework . UI ;
19+ using Exomia . Framework . UI . Brushes ;
20+ using Exomia . Framework . UI . Controls ;
1621using SharpDX ;
1722
1823namespace Exomia . Framework . Example . Canvas
@@ -81,9 +86,9 @@ public MyGame()
8186 protected override void OnInitializeGameGraphicsParameters ( ref GameGraphicsParameters parameters )
8287 {
8388 parameters . IsMouseVisible = true ;
84- parameters . Width = 1600 ;
85- parameters . Height = 1024 ;
86- parameters . EnableMultiSampling = true ;
89+ parameters . Width = 1920 ;
90+ parameters . Height = 1080 ;
91+ parameters . EnableMultiSampling = false ;
8792 parameters . MultiSampleCount = MultiSampleCount . MsaaX8 ;
8893 }
8994
@@ -95,33 +100,157 @@ protected override void OnInitialize()
95100 _spriteBatch = ToDispose ( new SpriteBatch ( GraphicsDevice ) ) ;
96101 _canvas = ToDispose ( new Graphics . Canvas ( GraphicsDevice ) ) ;
97102
98- /*
99- * TODO: Add your initialization logic here
100- */
103+ var uiManager = Add ( new UiManager ( "uiManager" ) { Visible = true , DrawOrder = 1 } ) ;
104+
105+ var container = new Container
106+ {
107+ Enabled = true ,
108+ Visible = true ,
109+ BackgroundBrush = new SolidColorBrush ( Color . Orange ) ,
110+ ClientRectangle = new RectangleF ( 50 , 700 , 400 , 400 )
111+ } ;
112+ container . MouseEntered += ( Control sender , in MouseEventArgs args ) =>
113+ {
114+ Console . WriteLine ( "entered..." ) ;
115+ } ;
116+ container . MouseLeaved += ( Control sender , in MouseEventArgs args ) =>
117+ {
118+ Console . WriteLine ( "leaved..." ) ;
119+ } ;
120+
121+ _texture = Content . Load < Texture > ( "logo1.jpg" ) ;
122+
123+ var container2 = new Container
124+ {
125+ Enabled = true ,
126+ Visible = true ,
127+ BackgroundBrush = new TextureBrush ( _texture ) ,
128+ ClientRectangle = new RectangleF ( 50 , 50 , 500 , 75 )
129+ } ;
130+ container2 . MouseEntered += ( Control sender , in MouseEventArgs args ) =>
131+ {
132+ Console . WriteLine ( "2 entered..." ) ;
133+ } ;
134+ container2 . MouseLeaved += ( Control sender , in MouseEventArgs args ) =>
135+ {
136+ Console . WriteLine ( "2 leaved..." ) ;
137+ } ;
138+ container . Add ( container2 ) ;
139+ uiManager . Add ( container ) ;
140+
141+ _spriteFont1_12Px = Content . Load < SpriteFont > ( Fonts . ARIAL_12_PX , true ) ;
142+ _spriteFont1_24Px = Content . Load < SpriteFont > ( Fonts . ARIAL_24_PX , true ) ;
143+
144+ var label1 = new Label ( _spriteFont1_24Px , "Hello there!" )
145+ {
146+ Enabled = true ,
147+ Visible = true ,
148+ BackgroundBrush = new BorderBrush ( Color . BlueViolet ) ,
149+ ClientRectangle = new RectangleF ( 320 , 300 , 200 , 50 ) ,
150+ TextAlignment = TextAlignment . MiddleCenter
151+ } ;
152+ label1 . MouseEntered += ( Control sender , in MouseEventArgs args ) =>
153+ {
154+ label1 . Text = "entered..." ;
155+ } ;
156+ label1 . MouseLeaved += ( Control sender , in MouseEventArgs args ) =>
157+ {
158+ label1 . Text = "leaved..." ;
159+ } ;
160+ container . Add ( label1 ) ;
161+
162+ var button1 = new Button ( _spriteFont1_24Px , "click me!" )
163+ {
164+ Enabled = true ,
165+ Visible = true ,
166+ BackgroundBrush = new SolidColorBrush ( Color . Yellow ) ,
167+ ClientRectangle = new RectangleF ( 900 , 900 , 400 , 80 ) ,
168+ TextAlignment = TextAlignment . MiddleCenter
169+ } ;
170+ button1 . MouseEntered += ( Control sender , in MouseEventArgs args ) =>
171+ {
172+ button1 . Text = "entered..." ;
173+ } ;
174+ button1 . MouseLeaved += ( Control sender , in MouseEventArgs args ) =>
175+ {
176+ button1 . Text = "leaved..." ;
177+ } ;
178+ button1 . MouseClick += ( Control sender , in MouseEventArgs args , ref EventAction action ) =>
179+ {
180+ button1 . Text = "clicked..." ;
181+ } ;
182+ button1 . GotFocus += ( Control sender ) =>
183+ {
184+ button1 . Text = "got focus..." ;
185+ } ;
186+ button1 . LostFocus += ( Control sender ) =>
187+ {
188+ button1 . Text = "lost focus..." ;
189+ } ;
190+ uiManager . Add ( button1 ) ;
191+
192+ var checkbox1 = new Checkbox
193+ {
194+ Enabled = true ,
195+ Visible = true ,
196+ BackgroundBrush = new SolidColorBrush ( Color . Yellow ) ,
197+ CheckedBrush = new SolidColorBrush ( Color . Blue ) ,
198+ ClientRectangle = new RectangleF ( 380 , 0 , 40 , 40 ) ,
199+ Padding = new Padding ( 5 )
200+ } ;
201+ container . Add ( checkbox1 ) ;
202+
203+ var progressbar1 = new Progressbar
204+ {
205+ Enabled = true ,
206+ Visible = true ,
207+ BackgroundBrush = new BorderBrush ( Color . Yellow ) ,
208+ BarBrush = new SolidColorBrush ( Color . Blue ) ,
209+ ClientRectangle = new RectangleF ( 300 , 180 , 200 , 50 ) ,
210+ Padding = new Padding ( 10 , 5 ) ,
211+ Value = 0.13f
212+ } ;
213+ progressbar1 . MouseEntered += ( Control sender , in MouseEventArgs args ) =>
214+ {
215+ progressbar1 . Value += 0.05f ;
216+ } ;
217+ container . Add ( progressbar1 ) ;
218+
219+ var slider1 = new Slider
220+ {
221+ Enabled = true ,
222+ Visible = true ,
223+ SliderTrackBrush = new SolidColorBrush ( Color . Gray ) ,
224+ SliderCaretBrush = new SolidColorBrush ( Color . DarkGray ) ,
225+ ClientRectangle = new RectangleF ( 300 , 250 , 200 , 50 ) ,
226+ Padding = new Padding ( 20 , 5 ) ,
227+ Value = 0
228+ } ;
229+ container . Add ( slider1 ) ;
230+
231+ var label2 = new Label ( _spriteFont1_24Px , "0" )
232+ {
233+ Enabled = true ,
234+ Visible = true ,
235+ ClientRectangle = new RectangleF ( 555 , 950 , 200 , 50 ) ,
236+ TextAlignment = TextAlignment . MiddleLeft
237+ } ;
238+ slider1 . ValueChanged += slider => { label2 . Text = slider . Value . ToString ( ) ; } ;
239+ uiManager . Add ( label2 ) ;
101240 }
102241
103242 /// <inheritdoc />
104243 /// OnLoadContent will be called once per game and is the place to load all of your content.
105244 protected override void OnLoadContent ( )
106245 {
107- /*
108- * TODO: use base.Content to load your game content here
109- */
110-
111- _texture = Content . Load < Texture > ( "logo1.jpg" ) ;
112246 _texture2 = Content . Load < Texture > ( "logo2.png" ) ;
113-
114- _spriteFont1_12Px = Content . Load < SpriteFont > ( Fonts . ARIAL_12_PX , true ) ;
115- _spriteFont1_24Px = Content . Load < SpriteFont > ( Fonts . ARIAL_24_PX , true ) ;
116247 }
117248
118249 /// <inheritdoc />
119250 /// OnUnloadContent will be called once per game and is the place to unload all content
120251 protected override void OnUnloadContent ( )
121252 {
122- /*
123- * TODO: Unload any non ContentManager content here
124- */
253+ Content . Unload < Texture > ( "logo2.png" ) ;
125254 }
126255
127256 /// <inheritdoc />
@@ -140,7 +269,6 @@ protected override void Update(GameTime gameTime)
140269 protected override void Draw ( GameTime gameTime )
141270 {
142271 GraphicsDevice . Clear ( Color . CornflowerBlue ) ;
143-
144272 _canvas . Begin ( rasterizerState : GraphicsDevice . RasterizerStates . CullBackDepthClipOffMultiSampleOn ) ;
145273
146274 k += gameTime . DeltaTimeS / 2 ;
@@ -159,11 +287,11 @@ protected override void Draw(GameTime gameTime)
159287 _canvas . DrawFillRectangle ( new RectangleF ( 200 , 200 , 100 , 50 ) , Color . Yellow , k , new Vector2 ( 200 , 200 ) , 1.0f ) ;
160288 _canvas . DrawRectangle ( new RectangleF ( 200 , 200 , 100 , 50 ) , Color . Green , 5.0f , k , new Vector2 ( 200 , 200 ) , 1.0f ) ;
161289
162- _canvas . DrawLine ( new Line2 ( 300 , 400 , 345 , 400 ) , Color . Red , 5.0f , 1.0f , 0 , Vector2 . Zero ) ;
163- _canvas . DrawLine ( new Line2 ( 400 , 400 , 450 , 450 ) , Color . Red , 5.0f , 1.0f , k , new Vector2 ( 425 , 425 ) ) ;
290+ _canvas . DrawLine ( new Line2 ( 300 , 400 , 345 , 400 ) , Color . Red , 5.0f , 0 , Vector2 . Zero , 1.0f ) ;
291+ _canvas . DrawLine ( new Line2 ( 400 , 400 , 450 , 450 ) , Color . Red , 5.0f , k , new Vector2 ( 425 , 425 ) , 1.0f ) ;
164292
165- _canvas . DrawLine ( new Line2 ( 300 , 450 , 345 , 450 ) , Color . Yellow , 5.0f , 1.0f , 0 , Vector2 . Zero ) ;
166- _canvas . DrawLine ( new Line2 ( 400 , 450 , 450 , 400 ) , Color . Yellow , 5.0f , 1.0f , k , new Vector2 ( 425 , 425 ) ) ;
293+ _canvas . DrawLine ( new Line2 ( 300 , 450 , 345 , 450 ) , Color . Yellow , 5.0f , 0 , Vector2 . Zero , 1.0f ) ;
294+ _canvas . DrawLine ( new Line2 ( 400 , 450 , 450 , 400 ) , Color . Yellow , 5.0f , k , new Vector2 ( 425 , 425 ) , 1.0f ) ;
167295
168296 _canvas . DrawFillPolygon ( polyA , Color . Red , 0.0f , Vector2 . Zero , 1.0f ) ;
169297 _canvas . DrawPolygon ( polyA , Color . Green , 5.0f , 0.0f , Vector2 . Zero , 1.0f ) ;
@@ -271,7 +399,9 @@ protected override void Draw(GameTime gameTime)
271399 _canvas . Draw ( _texture2 , new RectangleF ( 1350 , 50 , 200 , 200 ) , Color . White ) ;
272400
273401 _canvas . DrawText ( _spriteFont1_12Px , "This is the canvas example." , new Vector2 ( 450 , 50 ) , Color . Black , 0 ) ;
274- _canvas . DrawText ( _spriteFont1_24Px , "This is the canvas example." , new Vector2 ( 450 , 65 ) , Color . Black , k , new Vector2 ( 450 , 65 ) , 1.0f , TextureEffects . None ) ;
402+ _canvas . DrawText (
403+ _spriteFont1_24Px , "This is the canvas example." , new Vector2 ( 450 , 65 ) , Color . Black , k ,
404+ new Vector2 ( 450 , 65 ) , 1.0f , TextureEffects . None ) ;
275405
276406 _canvas . End ( ) ;
277407
0 commit comments