VEditorScrollControl.cpp 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //-----------------------------------------------------------------------------
  2. // Verve
  3. // Copyright (C) 2014 - Violent Tulip
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. #include "Verve/GUI/VEditorScrollControl.h"
  24. #include "gfx/gfxDrawUtil.h"
  25. //-----------------------------------------------------------------------------
  26. IMPLEMENT_CONOBJECT( VEditorScrollControl );
  27. //-----------------------------------------------------------------------------
  28. //-----------------------------------------------------------------------------
  29. //
  30. // Mouse Methods.
  31. //
  32. //-----------------------------------------------------------------------------
  33. void VEditorScrollControl::onMouseUp( const GuiEvent &pEvent )
  34. {
  35. Parent::onMouseUp( pEvent );
  36. // Event.
  37. onMouseEvent( "onMouseUp", pEvent );
  38. }
  39. void VEditorScrollControl::onRightMouseUp( const GuiEvent &pEvent )
  40. {
  41. Parent::onMouseUp( pEvent );
  42. // Event.
  43. onMouseEvent( "onRightMouseUp", pEvent );
  44. }
  45. void VEditorScrollControl::onMouseEvent( const char *pEventName, const GuiEvent &pEvent )
  46. {
  47. const S32 offsetX = ( mHasVScrollBar ) ? mScrollBarThickness : 0;
  48. const S32 offsetY = ( mHasHScrollBar ) ? mScrollBarThickness : 0;
  49. const RectI contentRect( 2, 2, getWidth() - offsetX - 4 - 1, getHeight() - offsetY - 4 - ( mHasHScrollBar ) );
  50. if ( !contentRect.pointInRect( pEvent.mousePoint ) )
  51. {
  52. // Return!
  53. return;
  54. }
  55. // Argument Buffers.
  56. char argBuffer[3][32];
  57. // Format Event-Position Buffer.
  58. dSprintf( argBuffer[0], 32, "%d %d", pEvent.mousePoint.x, pEvent.mousePoint.y );
  59. // Format Event-Modifier Buffer.
  60. dSprintf( argBuffer[1], 32, "%d", pEvent.modifier );
  61. // Format Mouse-Click Count Buffer.
  62. dSprintf( argBuffer[2], 32, "%d", pEvent.mouseClickCount );
  63. // Call Scripts.
  64. Con::executef( this, pEventName, argBuffer[0], argBuffer[1], argBuffer[2] );
  65. }
  66. //-----------------------------------------------------------------------------
  67. //
  68. // Render Methods.
  69. //
  70. //-----------------------------------------------------------------------------
  71. void VEditorScrollControl::onRender( Point2I pOffset, const RectI &pUpdateRect )
  72. {
  73. Parent::onRender( pOffset, pUpdateRect );
  74. const S32 offsetX = ( mHasVScrollBar ) ? mScrollBarThickness : 1;
  75. const S32 offsetY = ( mHasHScrollBar ) ? mScrollBarThickness : 1;
  76. RectI contentRect( pOffset.x + 1, pOffset.y + 1, getWidth() - offsetX - 1, getHeight() - offsetY - 1 );
  77. contentRect.intersect( pUpdateRect );
  78. GFX->getDrawUtil()->drawRect( contentRect, mProfile->mBorderColor );
  79. }