/ghost/ui/common.h

http://ghostcb.googlecode.com/ · C Header · 108 lines · 72 code · 21 blank · 15 comment · 2 complexity · 6070f78c6b971b44890ba2b5d385c9ec MD5 · raw file

  1. #ifndef COMMON_H
  2. #define COMMON_H
  3. #ifdef WIN32
  4. # include <panel.h>
  5. #else
  6. # ifdef USE_XCURSES
  7. # include <xpanel.h>
  8. # else
  9. # include <panel.h>
  10. # endif
  11. #endif
  12. #include <string>
  13. #include <vector>
  14. using namespace std;
  15. // Safe Delete
  16. #define SafeDelete(x) if((x)) { delete x; x = 0; }
  17. #define SafeDeleteArray(x) if((x)) { delete[] x; x = 0; }
  18. typedef unsigned int uint;
  19. #ifdef __PDCURSES__
  20. enum Color
  21. {
  22. Null = 99,
  23. Black = 0,
  24. Blue,
  25. Green,
  26. Cyan,
  27. Red,
  28. Magenta,
  29. Yellow,
  30. White
  31. };
  32. #else
  33. enum Color
  34. {
  35. Null = 99,
  36. Black = 0,
  37. Red,
  38. Green,
  39. Yellow,
  40. Blue,
  41. Magenta,
  42. Cyan,
  43. White
  44. };
  45. #endif
  46. // Get attribute from bgcolor and fgcolor
  47. attr_t attribute(Color bgcolor, Color fgcolor, bool bold = false);
  48. // Get color pair from bgcolor and fgcolor
  49. uint colorpair(Color bgcolor, Color fgcolor);
  50. // Point (x, y)
  51. class CPoint
  52. {
  53. public:
  54. CPoint(uint x = 0, uint y = 0);
  55. // Set point
  56. void set(uint x, uint y);
  57. // Get x
  58. uint x();
  59. // Get y
  60. uint y();
  61. private:
  62. uint _x;
  63. uint _y;
  64. };
  65. // Size (width, height)
  66. class CSize
  67. {
  68. public:
  69. CSize(uint width = 0, uint height = 0);
  70. // Set size
  71. void set(uint width, uint height);
  72. // Get width
  73. uint width();
  74. // Get height
  75. uint height();
  76. // Set fixed size. If enabled, vertical layout will not
  77. // resize height and horizontal layout will not resize width.
  78. // Note: layout will correct the size, if it's invalid.
  79. void setFixed(bool enabled);
  80. // Get fixed.
  81. bool fixed();
  82. private:
  83. uint _width;
  84. uint _height;
  85. bool _fixed;
  86. };
  87. #endif