PolyScreenEntity.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * PolyScreenEntity.h
  3. * TAU
  4. *
  5. * Created by Ivan Safrin on 3/13/08.
  6. * Copyright 2008 __MyCompanyName__. All rights reserved.
  7. *
  8. */
  9. // @package Screen
  10. #pragma once
  11. #include "PolyGlobals.h"
  12. #include "PolyVector2.h"
  13. #include "PolyInputEvent.h"
  14. #include "PolyEventDispatcher.h"
  15. #include "PolyRectangle.h"
  16. #include "PolyEntity.h"
  17. namespace Polycode {
  18. class _PolyExport ScreenEntity : public Entity, public EventDispatcher {
  19. public:
  20. using Entity::setPosition;
  21. using Entity::setScale;
  22. ScreenEntity();
  23. ~ScreenEntity();
  24. void setPosition(float x, float y);
  25. void setScale(float x, float y);
  26. void setRotation(float roatation);
  27. float getRotation();
  28. bool _onMouseDown(float x, float y, int timestamp);
  29. bool _onMouseUp(float x, float y, int timestamp);
  30. void _onMouseMove(float x, float y, int timestamp);
  31. void _onMouseWheelUp(float x, float y, int timestamp);
  32. void _onMouseWheelDown(float x, float y, int timestamp);
  33. virtual void onMouseDown(float x, float y){}
  34. virtual void onMouseUp(float x, float y){}
  35. virtual void onMouseMove(float x, float y){}
  36. virtual void onMouseWheelUp(float x, float y) {}
  37. virtual void onMouseWheelDown(float x, float y) {}
  38. void _onKeyDown(TAUKey key, wchar_t charCode);
  39. void _onKeyUp(TAUKey key, wchar_t charCode);
  40. virtual void onKeyDown(TAUKey key, wchar_t charCode){}
  41. virtual void onKeyUp(TAUKey key, wchar_t charCode){}
  42. bool hitTest(float x, float y);
  43. Matrix4 buildPositionMatrix();
  44. void adjustMatrixForChildren();
  45. float getWidth();
  46. float getHeight();
  47. void setWidth(float w) { width = w; hitwidth = w; }
  48. void setHeight(float h) { height = h; hitheight = h; }
  49. virtual void onGainFocus(){}
  50. virtual void onLoseFocus(){}
  51. void startDrag(float xOffset, float yOffset);
  52. void stopDrag();
  53. void setBlendingMode(int newBlendingMode);
  54. void setPositionMode(int newPositionMode);
  55. void setDragLimits(Rectangle rect);
  56. void clearDragLimits();
  57. void focusChild(ScreenEntity *child);
  58. void focusNextChild();
  59. Vector2 getPosition2D();
  60. static const int POSITION_TOPLEFT = 0;
  61. static const int POSITION_CENTER = 1;
  62. bool isFocusable();
  63. bool hasFocus;
  64. bool blockMouseInput;
  65. int zindex;
  66. bool snapToPixels;
  67. protected:
  68. bool focusable;
  69. bool focusChildren;
  70. bool isDragged;
  71. float dragOffsetX;
  72. float dragOffsetY;
  73. bool mouseOver;
  74. float width;
  75. float height;
  76. float hitwidth;
  77. float hitheight;
  78. float xmouse;
  79. float ymouse;
  80. int positionMode;
  81. Rectangle *dragLimits;
  82. int lastClickTicks;
  83. ScreenEntity *focusedChild;
  84. };
  85. }