33 using Microsoft.Xna.Framework;
60 private Image imageReleased;
61 private Image imagePressed;
62 private Image imageHover;
64 private State state = State.Released;
66 private bool isPressed {
get {
return state == State.LeftPressed || state == State.RightPressed; } }
68 private Color releasedColor;
69 private Color hoverColor;
70 private Color pressedColor;
75 public Image ImageReleased
77 get {
return imageReleased; }
80 imageReleased = value;
89 public Image ImagePressed
91 get {
return imagePressed; }
103 public Image ImageHover
105 get {
return imageHover; }
114 public override Vector Size
135 releasedColor = value;
169 State firstState = State.Released;
171 void TouchPress(
Touch touch )
173 if ( Pressed != null && (state == State.Hover || state == State.Released) )
176 firstState = State.LeftPressed;
177 SetState( State.LeftPressed );
180 void TouchHover(
Touch touch )
185 if ( touchX >=
Left && touchX <= Right && touchY >=
Bottom && touchY <=
Top )
187 if ( firstState == State.Released )
188 firstState = State.Hover;
190 if ( state != firstState )
191 SetState( firstState );
195 SetState( State.Released );
199 void TouchRelease(
Touch touch )
204 firstState = State.Released;
205 SetState( State.Released );
207 if ( Released != null )
211 void TouchClick(
Touch touch )
236 : base( width, height )
241 private void Initialize()
246 TextColor =
new Color( 250, 250, 250, 240 );
247 AddedToGame += InitializeControls;
250 private void InitializeMargins()
263 : this( width, height )
274 public PushButton(
double width,
double height,
string text )
275 : base( width, height, text )
280 private void InitializeControls()
302 private void InitializeShape()
306 double relativeHorizontalSize = edgeSize / Width;
307 double relativeVerticalSize = edgeSize / Height;
310 Vector topLeftInner =
new Vector( -0.5 + relativeHorizontalSize, 0.5 - relativeVerticalSize );
312 Vector bottomLeftInner =
new Vector( -0.5 + relativeHorizontalSize, -0.5 + relativeVerticalSize );
314 Vector topRightInner =
new Vector( 0.5 - relativeHorizontalSize, 0.5 - relativeVerticalSize );
316 Vector bottomRightInner =
new Vector( 0.5 - relativeHorizontalSize, -0.5 + relativeVerticalSize );
320 Vector[] leftSideVertices = { topLeftOuter, topLeftInner, bottomLeftOuter, bottomLeftInner, };
321 Vector[] topSideVertices = { topLeftOuter, topRightOuter, topLeftInner, topRightInner, };
322 Vector[] rightSideVertices = { topRightOuter, bottomRightOuter, topRightInner, bottomRightInner, };
323 Vector[] bottomSideVertices = { bottomRightOuter, bottomLeftOuter, bottomRightInner, bottomLeftInner, };
325 leftSideShape =
new ShapeCache( leftSideVertices, triangles );
326 topSideShape =
new ShapeCache( topSideVertices, triangles );
327 RightSideShape =
new ShapeCache( rightSideVertices, triangles );
328 BottomSideShape =
new ShapeCache( bottomSideVertices, triangles );
330 const double scale = 1.4;
332 topLeftOuter =
new Vector( -0.5, 0.5 );
333 topLeftInner =
new Vector( -0.5 + relativeHorizontalSize / scale, 0.5 - relativeVerticalSize / scale );
334 bottomLeftOuter =
new Vector( -0.5, -0.5 );
335 bottomLeftInner =
new Vector( -0.5 + relativeHorizontalSize / scale, -0.5 + relativeVerticalSize * scale );
336 topRightOuter =
new Vector( 0.5, 0.5 );
337 topRightInner =
new Vector( 0.5 - relativeHorizontalSize * scale, 0.5 - relativeVerticalSize / scale );
338 bottomRightOuter =
new Vector( 0.5, -0.5 );
339 bottomRightInner =
new Vector( 0.5 - relativeHorizontalSize * scale, -0.5 + relativeVerticalSize * scale );
341 Vector[] leftSidePressedVertices = { topLeftOuter, topLeftInner, bottomLeftOuter, bottomLeftInner, };
342 Vector[] topSidePressedVertices = { topLeftOuter, topRightOuter, topLeftInner, topRightInner, };
343 Vector[] rightSidePressedVertices = { topRightOuter, bottomRightOuter, topRightInner, bottomRightInner, };
344 Vector[] bottomSidePressedVertices = { bottomRightOuter, bottomLeftOuter, bottomRightInner, bottomLeftInner, };
346 leftSidePressedShape =
new ShapeCache( leftSidePressedVertices, triangles );
347 topSidePressedShape =
new ShapeCache( topSidePressedVertices, triangles );
348 RightSidePressedShape =
new ShapeCache( rightSidePressedVertices, triangles );
349 BottomSidePressedShape =
new ShapeCache( bottomSidePressedVertices, triangles );
352 private void SetState( State state )
359 base.Color = hoverColor;
360 if ( ImageHover != null )
363 case State.RightPressed:
364 case State.LeftPressed:
365 base.
Color = pressedColor;
366 if ( ImagePressed != null )
367 ImagePressed = ImagePressed;
370 base.Color = releasedColor;
371 if ( ImageReleased != null )
372 Image = ImageReleased;
379 if ( Clicked != null )
385 if ( RightClicked != null )
405 AddShortcut( i, button );
420 if ( state != State.Hover && state != State.Released )
424 SetState( State.LeftPressed );
426 SetState( State.RightPressed );
428 if ( Pressed != null )
432 private void Release()
434 if ( state != State.LeftPressed && state != State.RightPressed )
437 bool wasLeft = state == State.LeftPressed;
438 bool wasRight = state == State.RightPressed;
443 SetState(State.Hover);
445 if ( wasLeft ) Click();
446 else if ( wasRight ) RightClick();
450 SetState( State.Released );
453 if ( Released != null )
465 protected override void Draw( Matrix parentTransformation, Matrix transformation )
467 base.Draw( parentTransformation, transformation );
483 left = leftSidePressedShape;
484 top = topSidePressedShape;
485 right = RightSidePressedShape;
486 bottom = BottomSidePressedShape;
489 Renderer.DrawFilledShape( left, ref transformation, color1 );
490 Renderer.DrawFilledShape( top, ref transformation, color1 );
491 Renderer.DrawFilledShape( right, ref transformation, color2 );
492 Renderer.DrawFilledShape( bottom, ref transformation, color2 );
498 if ( Down != null && ( state == State.LeftPressed || state == State.RightPressed ) )
Vector PositionOnScreen
Kosketuksen paikka ruudulla.
bool IsCursorOn(IGameObject obj)
Onko hiiren kursori annetun olion päällä.
Listener ListenMovement(double trigger, AnalogHandler handler, string helpText)
Kuuntelee hiiren liikettä.
static Color Darker(Color c, int howMuch)
Antaa tummemman värin. Vähentaa jokaista kolmea osaväriä arvon howMuch verran.
Listener ListenOn(IGameObject o, ButtonState state, TouchHandler handler, String helpText)
Listener Listen(Button button, ButtonState state, Handler handler, string helpText)
Kosketuspaneelin kosketus.
static Jypeli.Controls.Controls Controls
Pelin kontrollit.
ButtonState
Napin (minkä tahansa) asento.
int NumTouches
Kuinka monta kosketusta näytöllä on aktiivisena.
Sisältää tiedon ajasta, joka on kulunut pelin alusta ja viime päivityksestä.
Sisältää valmiiksi lasketut kolmiot, joiden avulla piirtäminen on suoraviivaista. ...
Peliluokka reaaliaikaisille peleille.
static Image Color(Image image, Color color)
Värittää kuvan.
Listener InContext(ListenContext context)
Kuuntelee tapahtumaa vain tietyssä kontekstissa.
GamePad [] GameControllers
Peliohjaimet 1-4.
Parametrit analogisen ohjauksen (hiiren tai ohjaustikun) tapahtumalle.
Listener Listen(ButtonState state, TouchHandler handler, string helpText)
Keyboard Keyboard
Näppäimistö.
TouchPanel TouchPanel
Kosketusnäyttö. Vain kännykässä.
Listener Listen(Key k, ButtonState state, Handler handler, String helpText)
Luokka, joka sisältää metodeita kuvioiden ja tekstuurien piirtämiseen 2D-tasossa. ...
Listener Listen(MouseButton b, ButtonState state, Handler handler, string helpText)
Kuuntelee hiiren nappulan painalluksia.
Muotojen määrityksessä käytettävä kolmio.
static Color Lighter(Color c, int howMuch)
Antaa kirkkaamman värin. Kasvattaa jokaista kolmea osaväriä arvon howMuch verran. ...
Listener ListenOn(IGameObject obj, MouseButton b, ButtonState state, Handler handler, String helpText)
Kuuntelee hiirenpainalluksia annetun peliolion päällä.