guiBubbleTextCtrl.cc 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "gui/guiBubbleTextCtrl.h"
  23. #include "gui/guiCanvas.h"
  24. IMPLEMENT_CONOBJECT(GuiBubbleTextCtrl);
  25. //------------------------------------------------------------------------------
  26. void GuiBubbleTextCtrl::popBubble()
  27. {
  28. // Release the mouse:
  29. mInAction = false;
  30. mouseUnlock();
  31. // Pop the dialog
  32. getRoot()->popDialogControl(mDlg);
  33. // Kill the popup
  34. mDlg->removeObject(mPopup);
  35. mPopup->removeObject(mMLText);
  36. mMLText->deleteObject();
  37. mPopup->deleteObject();
  38. mDlg->deleteObject();
  39. }
  40. //------------------------------------------------------------------------------
  41. void GuiBubbleTextCtrl::onMouseDown(const GuiEvent &event)
  42. {
  43. if (mInAction)
  44. {
  45. popBubble();
  46. return;
  47. }
  48. mDlg = new GuiControl();
  49. AssertFatal(mDlg, "Failed to create the GuiControl for the BubbleTextCtrl");
  50. mDlg->setField("profile","GuiModelessDialogProfile");
  51. mDlg->setField("horizSizing", "width");
  52. mDlg->setField("vertSizing", "height");
  53. //MIN_RESOLUTION defined in platformWin32/platformGL.h
  54. mDlg->setField("extent", MIN_RESOLUTION_XY_STRING);
  55. mPopup = new GuiControl();
  56. AssertFatal(mPopup, "Failed to create the GuiControl for the BubbleTextCtrl");
  57. mPopup->setField("profile","GuiBubblePopupProfile");
  58. mMLText = new GuiMLTextCtrl();
  59. AssertFatal(mMLText, "Failed to create the GuiMLTextCtrl for the BubbleTextCtrl");
  60. mMLText->setField("profile","GuiBubbleTextProfile");
  61. mMLText->setField("position", "2 2");
  62. mMLText->setField("extent", "296 51");
  63. mMLText->setText((char*)mText,dStrlen(mText));
  64. mMLText->registerObject();
  65. mPopup->registerObject();
  66. mDlg->registerObject();
  67. mPopup->addObject(mMLText);
  68. mDlg->addObject(mPopup);
  69. mPopup->resize(event.mousePoint,Point2I(300,55));
  70. getRoot()->pushDialogControl(mDlg,0);
  71. mouseLock();
  72. mInAction = true;
  73. }