2
0

guiBubbleTextCtrl.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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/utility/guiBubbleTextCtrl.h"
  23. #include "gui/core/guiCanvas.h"
  24. IMPLEMENT_CONOBJECT(GuiBubbleTextCtrl);
  25. ConsoleDocClass( GuiBubbleTextCtrl,
  26. "@brief A single-line text control that displays its text in a multi-line popup when clicked.\n\n"
  27. "This control acts like a GuiTextCtrl (and inherits from it), when clicked it creates a GuiMLTextCtrl "
  28. "roughly where you clicked with the same text in it. This allows you to have a single line text control "
  29. "which upon clicking will display the entire text contained in a multi-line format.\n\n"
  30. "@tsexample\n"
  31. "new GuiBubbleTextCtrl(BubbleTextGUI)\n"
  32. "{\n"
  33. " text = \"This is the first sentence. This second sentence can be sized outside of the default single "
  34. "line view, upon clicking this will be displayed in a multi-line format.\";\n"
  35. "};\n"
  36. "@endtsexample\n\n"
  37. "@see GuiTextCtrl\n"
  38. "@see GuiMLTextCtrl\n\n"
  39. "@ingroup GuiControls\n"
  40. );
  41. //------------------------------------------------------------------------------
  42. void GuiBubbleTextCtrl::popBubble()
  43. {
  44. // Release the mouse:
  45. mInAction = false;
  46. mouseUnlock();
  47. // Pop the dialog
  48. getRoot()->popDialogControl(mDlg);
  49. // Kill the popup
  50. mDlg->removeObject(mPopup);
  51. mPopup->removeObject(mMLText);
  52. mMLText->deleteObject();
  53. mPopup->deleteObject();
  54. mDlg->deleteObject();
  55. }
  56. //------------------------------------------------------------------------------
  57. void GuiBubbleTextCtrl::onMouseDown(const GuiEvent &event)
  58. {
  59. if (mInAction)
  60. {
  61. popBubble();
  62. return;
  63. }
  64. mDlg = new GuiControl();
  65. AssertFatal(mDlg, "Failed to create the GuiControl for the BubbleTextCtrl");
  66. mDlg->setDataField( StringTable->insert("profile"), NULL, "GuiModelessDialogProfile");
  67. mDlg->setField("horizSizing", "width");
  68. mDlg->setField("vertSizing", "height");
  69. mDlg->setField("extent", "640 480");
  70. mPopup = new GuiControl();
  71. AssertFatal(mPopup, "Failed to create the GuiControl for the BubbleTextCtrl");
  72. mPopup->setDataField( StringTable->insert("profile"), NULL, "GuiBubblePopupProfile");
  73. mMLText = new GuiMLTextCtrl();
  74. AssertFatal(mMLText, "Failed to create the GuiMLTextCtrl for the BubbleTextCtrl");
  75. mMLText->setDataField( StringTable->insert("profile"), NULL, "GuiBubbleTextProfile");
  76. mMLText->setField("position", "2 2");
  77. mMLText->setField("extent", "296 51");
  78. mMLText->setText((char*)mText,dStrlen(mText));
  79. mMLText->registerObject();
  80. mPopup->registerObject();
  81. mDlg->registerObject();
  82. mPopup->addObject(mMLText);
  83. mDlg->addObject(mPopup);
  84. mPopup->resize(event.mousePoint,Point2I(300,55));
  85. getRoot()->pushDialogControl(mDlg,0);
  86. mouseLock();
  87. mInAction = true;
  88. }