x86UNIXMessageBox.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #ifndef _X86UNIXMESSAGEBOX_H_
  23. #define _X86UNIXMESSAGEBOX_H_
  24. #include <X11/Xlib.h>
  25. #include "core/util/tVector.h"
  26. class XMessageBoxButton
  27. {
  28. public:
  29. XMessageBoxButton();
  30. XMessageBoxButton(const char* label, int clickVal);
  31. const char *getLabel() { return static_cast<const char*>(mLabel); }
  32. int getClickVal() { return mClickVal; }
  33. int getLabelWidth() { return mLabelWidth; }
  34. void setLabelWidth(int width) { mLabelWidth = width; }
  35. void setButtonRect(int x, int y, int width, int height)
  36. {
  37. mX = x;
  38. mY = y;
  39. mWidth = width;
  40. mHeight = height;
  41. }
  42. void setMouseCoordinates(int x, int y)
  43. {
  44. mMouseX = x;
  45. mMouseY = y;
  46. }
  47. bool drawReverse()
  48. {
  49. return mMouseDown && pointInRect(mMouseX, mMouseY);
  50. }
  51. bool pointInRect(int x, int y)
  52. {
  53. if (x >= mX && x <= (mX+mWidth) &&
  54. y >= mY && y <= (mY+mHeight))
  55. return true;
  56. return false;
  57. }
  58. void setMouseDown(bool mouseDown) { mMouseDown = mouseDown; }
  59. bool isMouseDown() { return mMouseDown; }
  60. private:
  61. static const int LabelSize = 100;
  62. char mLabel[LabelSize];
  63. int mClickVal;
  64. int mLabelWidth;
  65. int mX, mY, mWidth, mHeight;
  66. int mMouseX, mMouseY;
  67. bool mMouseDown;
  68. };
  69. class XMessageBox
  70. {
  71. public:
  72. static const int OK = 1;
  73. static const int Cancel = 2;
  74. static const int Retry = 3;
  75. static const int IgnoreAll = 4;
  76. XMessageBox(Display* display);
  77. ~XMessageBox();
  78. int alertOK(const char *windowTitle, const char *message);
  79. int alertOKCancel(const char *windowTitle, const char *message);
  80. int alertRetryCancel(const char *windowTitle, const char *message);
  81. int alertAssert(const char *windowTitle, const char *message);
  82. private:
  83. int show();
  84. void repaint();
  85. void splitMessage();
  86. void clearMessageLines();
  87. int loadFont();
  88. void setDimensions();
  89. int getButtonLineWidth();
  90. const char* mMessage;
  91. const char* mTitle;
  92. Vector<XMessageBoxButton> mButtons;
  93. Vector<char*> mMessageLines;
  94. Display* mDisplay;
  95. GC mGC;
  96. Window mWin;
  97. XFontStruct* mFS;
  98. int mFontHeight;
  99. int mFontAscent;
  100. int mFontDescent;
  101. int mFontDirection;
  102. int mScreenWidth, mScreenHeight, mMaxWindowWidth, mMaxWindowHeight;
  103. int mMBWidth, mMBHeight;
  104. };
  105. #endif // #define _X86UNIXMESSAGEBOX_H_