axiosengine 

axiosengine Commit Details


Date:2012-04-17 22:07:51 (12 years 5 months ago)
Author:nathan@daedalus
Branch:master
Commit:494a128094f068952509e951b176f457b470fc6a
Parents: 2277056e6b17f95740935ad1fe96653651d5c167
Message:Adding code for mouse handling

--HG--
branch : axios-newgsm
Changes:

File differences

axios/Engine/AxiosEvents.cs
11
22
3
34
45
56
......
1920
2021
2122
22
23
2324
2425
2526
2627
2728
28
29
2930
3031
3132
3233
3334
34
35
3536
3637
3738
3839
3940
40
41
4142
4243
4344
4445
45
46
4647
4748
4849
4950
50
51
5152
5253
5354
5455
55
56
5657
5758
5859
5960
60
61
6162
6263
6364
using System;
using FarseerPhysics.SamplesFramework;
using GameStateManagement;
namespace Axios.Engine
{
}
}
public delegate void AxiosHandler(object sender, AxiosGameScreen gameScreen, InputHelper input);
public delegate void AxiosHandler(object sender, AxiosGameScreen gameScreen, InputState input);
public delegate void AxiosGameObjectHandler(AxiosGameObject sender);
#region GameObjectEventMethods
public virtual void OnFocusEnter(AxiosGameScreen gameScreen, InputHelper input)
public virtual void OnFocusEnter(AxiosGameScreen gameScreen, InputState input)
{
this.HasFocus = true;
this.OnEvent(FocusEnter, gameScreen, input);
}
public virtual void OnFocusLeave(AxiosGameScreen gameScreen, InputHelper input)
public virtual void OnFocusLeave(AxiosGameScreen gameScreen, InputState input)
{
this.HasFocus = false;
this.OnEvent(FocusLeave, gameScreen, input);
}
public virtual void OnMouseHover(AxiosGameScreen gameScreen, InputHelper input)
public virtual void OnMouseHover(AxiosGameScreen gameScreen, InputState input)
{
this.OnEvent(MouseHover, gameScreen, input);
}
public virtual void OnMouseLeave(AxiosGameScreen gameScreen, InputHelper input)
public virtual void OnMouseLeave(AxiosGameScreen gameScreen, InputState input)
{
this.OnEvent(MouseLeave, gameScreen, input);
}
public virtual void OnValueChange(AxiosGameScreen gameScreen, InputHelper input)
public virtual void OnValueChange(AxiosGameScreen gameScreen, InputState input)
{
this.OnEvent(ValueChange, gameScreen, input);
}
public virtual void OnMouseDown(AxiosGameScreen gameScreen, InputHelper input)
public virtual void OnMouseDown(AxiosGameScreen gameScreen, InputState input)
{
this.OnEvent(MouseDown, gameScreen, input);
}
public virtual void OnMouseUp(AxiosGameScreen gameScreen, InputHelper input)
public virtual void OnMouseUp(AxiosGameScreen gameScreen, InputState input)
{
this.OnEvent(MouseUp, gameScreen, input);
}
axios/Engine/AxiosGameScreen.cs
334334
335335
336336
337
337
338338
339339
340340
}
}
public override void HandleInput(InputHelper input, GameTime gameTime)
public override void HandleInput(InputState input, GameTime gameTime)
{
base.HandleInput(input, gameTime);
axios/Engine/AxiosTimer.cs
22
33
44
5
56
67
78
......
6566
6667
6768
68
69
6970
7071
7172
7273
73
74
7475
7576
7677
using Axios.Engine.Interfaces;
using Microsoft.Xna.Framework;
using GameStateManagement;
namespace Axios.Engine
{
}
public override void HandleInput(AxiosGameScreen gameScreen, FarseerPhysics.SamplesFramework.InputHelper input, Microsoft.Xna.Framework.GameTime gameTime)
public override void HandleInput(AxiosGameScreen gameScreen, InputState input, Microsoft.Xna.Framework.GameTime gameTime)
{
}
public override void HandleCursor(AxiosGameScreen gameScreen, FarseerPhysics.SamplesFramework.InputHelper input)
public override void HandleCursor(AxiosGameScreen gameScreen, InputState input)
{
}
axios/Engine/Interfaces/IAxiosGameObject.cs
11
22
3
34
45
56
......
89
910
1011
11
12
12
13
1314
1415
1516
using FarseerPhysics.SamplesFramework;
using Microsoft.Xna.Framework;
using GameStateManagement;
namespace Axios.Engine.Interfaces
{
void Update(AxiosGameScreen gameScreen, GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen);
void LoadContent(AxiosGameScreen gameScreen);
void HandleInput(AxiosGameScreen gameScreen, InputHelper input, GameTime gameTime);
void HandleCursor(AxiosGameScreen gameScreen, InputHelper input);
void HandleInput(AxiosGameScreen gameScreen, InputState input, GameTime gameTime);
void HandleCursor(AxiosGameScreen gameScreen, InputState input);
void UnloadContent(AxiosGameScreen gameScreen);
}
}
axios/Engine/UI/AxiosButton.cs
11
22
33
4
45
56
67
......
4849
4950
5051
51
52
5253
5354
5455
......
5657
5758
5859
59
60
6061
6162
6263
6364
6465
6566
66
67
6768
6869
6970
7071
7172
7273
73
74
7475
7576
7677
......
7980
8081
8182
82
8383
84
84
85
8586
8687
8788

using FarseerPhysics.SamplesFramework;
using Microsoft.Xna.Framework.Graphics;
using GameStateManagement;
namespace Axios.Engine.UI
{
}
public override void OnMouseHover(AxiosGameScreen gameScreen, InputHelper input)
public override void OnMouseHover(AxiosGameScreen gameScreen, InputState input)
{
base.OnMouseHover(gameScreen, input);
}
public override void OnMouseLeave(AxiosGameScreen gameScreen, InputHelper input)
public override void OnMouseLeave(AxiosGameScreen gameScreen, InputState input)
{
base.OnMouseLeave(gameScreen, input);
this.Texture = _normaltexture;
}
public override void OnMouseDown(AxiosGameScreen gameScreen, InputHelper input)
public override void OnMouseDown(AxiosGameScreen gameScreen, InputState input)
{
base.OnMouseDown(gameScreen, input);
this.Texture = _clicktexture;
}
public override void OnMouseUp(AxiosGameScreen gameScreen, InputHelper input)
public override void OnMouseUp(AxiosGameScreen gameScreen, InputState input)
{
base.OnMouseUp(gameScreen, input);
}
public override void HandleCursor(AxiosGameScreen gameScreen, InputHelper input)
public override void HandleCursor(AxiosGameScreen gameScreen, InputState input)
{
base.HandleCursor(gameScreen, input);
axios/ScreenSystem/InputState.cs
247247
248248
249249
250
250
251251
252252
253253
......
299299
300300
301301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
302348
303349
304350
......
426472
427473
428474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
429530
430531
/// <summary>
/// Reads the latest state user input.
/// </summary>
public void Update()
public void Update(GameTime gameTime)
{
_lastMouseState = _currentMouseState;
if (_handleVirtualStick)
{
Gestures.Add(TouchPanel.ReadGesture());
}
// Update cursor
Vector2 oldCursor = _cursor;
if (CurrentGamePadStates[0].IsConnected && CurrentGamePadStates[0].ThumbSticks.Left != Vector2.Zero)
{
Vector2 temp = CurrentGamePadStates[0].ThumbSticks.Left;
_cursor += temp * new Vector2(300f, -300f) * (float)gameTime.ElapsedGameTime.TotalSeconds;
Mouse.SetPosition((int)_cursor.X, (int)_cursor.Y);
}
else
{
_cursor.X = _currentMouseState.X;
_cursor.Y = _currentMouseState.Y;
}
_cursor.X = MathHelper.Clamp(_cursor.X, 0f, _viewport.Width);
_cursor.Y = MathHelper.Clamp(_cursor.Y, 0f, _viewport.Height);
if (_cursorIsValid && oldCursor != _cursor)
{
_cursorMoved = true;
}
else
{
_cursorMoved = false;
}
#if WINDOWS
if (_viewport.Bounds.Contains(_currentMouseState.X, _currentMouseState.Y))
{
_cursorIsValid = true;
}
else
{
_cursorIsValid = false;
}
#elif WINDOWS_PHONE
if (_currentMouseState.LeftButton == ButtonState.Pressed)
{
_cursorIsValid = true;
}
else
{
_cursorIsValid = false;
}
#endif
}
return (_lastVirtualState.IsButtonDown(button) &&
_currentVirtualState.IsButtonUp(button));
}
/// <summary>
/// Helper for checking if a mouse button was newly pressed during this update.
/// </summary>
public bool IsNewMouseButtonPress(MouseButtons button)
{
switch (button)
{
case MouseButtons.LeftButton:
return (_currentMouseState.LeftButton == ButtonState.Pressed &&
_lastMouseState.LeftButton == ButtonState.Released);
case MouseButtons.RightButton:
return (_currentMouseState.RightButton == ButtonState.Pressed &&
_lastMouseState.RightButton == ButtonState.Released);
case MouseButtons.MiddleButton:
return (_currentMouseState.MiddleButton == ButtonState.Pressed &&
_lastMouseState.MiddleButton == ButtonState.Released);
case MouseButtons.ExtraButton1:
return (_currentMouseState.XButton1 == ButtonState.Pressed &&
_lastMouseState.XButton1 == ButtonState.Released);
case MouseButtons.ExtraButton2:
return (_currentMouseState.XButton2 == ButtonState.Pressed &&
_lastMouseState.XButton2 == ButtonState.Released);
default:
return false;
}
}
/// <summary>
/// Checks if the requested mouse button is released.
/// </summary>
/// <param name="button">The button.</param>
public bool IsNewMouseButtonRelease(MouseButtons button)
{
switch (button)
{
case MouseButtons.LeftButton:
return (_lastMouseState.LeftButton == ButtonState.Pressed &&
_currentMouseState.LeftButton == ButtonState.Released);
case MouseButtons.RightButton:
return (_lastMouseState.RightButton == ButtonState.Pressed &&
_currentMouseState.RightButton == ButtonState.Released);
case MouseButtons.MiddleButton:
return (_lastMouseState.MiddleButton == ButtonState.Pressed &&
_currentMouseState.MiddleButton == ButtonState.Released);
case MouseButtons.ExtraButton1:
return (_lastMouseState.XButton1 == ButtonState.Pressed &&
_currentMouseState.XButton1 == ButtonState.Released);
case MouseButtons.ExtraButton2:
return (_lastMouseState.XButton2 == ButtonState.Pressed &&
_currentMouseState.XButton2 == ButtonState.Released);
default:
return false;
}
}
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.08700s using 13 queries.