Xlib_textfader.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. *
  3. * Copyright (c) 2002, Marc Bruenink
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * 3. Neither the name of the author nor the names of his contributors may be
  16. * used to endorse or promote products derived from this software without
  17. * specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #ifndef _XLIB_TEXTFADER_H_
  32. #define _XLIB_TEXTFADER_H_
  33. #include <X11/Xlib.h>
  34. #include <X11/Xcms.h> // color
  35. #include <X11/Xutil.h> // XGetPixel
  36. #include <climits> // MAX_INT
  37. #include <ostream.h>
  38. #include <unistd.h>
  39. #include <stdlib.h> //rand()
  40. // class define
  41. //text will be faded in the center of the screen.
  42. #define TF_WINDOW_CENTER (1<<1)
  43. // Coordinates marks the middlex and middley of the text
  44. // default: upper left corner of text
  45. //#define TF_COORDINATES_CENTER (1<<2)
  46. // some defines for the arrangement method
  47. // first 2 bytes marks the row and last 2 bytes the column
  48. // use XOR !!!!
  49. #define TF_COORDINATES_UPPER_LEFT ((1<<2) |(1<<4))
  50. #define TF_COORDINATES_UPPER_CENTER ((1<<2) |(1<<5))
  51. #define TF_COORDINATES_UPPER_RIGHT ((1<<2) |(1<<4)|(1<<5))
  52. #define TF_COORDINATES_CENTER_LEFT ((1<<3) |(1<<4))
  53. #define TF_COORDINATES_CENTER_CENTER ((1<<3) |(1<<5))
  54. #define TF_COORDINATES_CENTER_RIGHT ((1<<3) |(1<<4)|(1<<5))
  55. #define TF_COORDINATES_LOWER_LEFT ((1<<2)|(1<<3) |(1<<4))
  56. #define TF_COORDINATES_LOWER_CENTER ((1<<2)|(1<<3) |(1<<5))
  57. #define TF_COORDINATES_LOWER_RIGHT ((1<<2)|(1<<3) |(1<<4)|(1<<5))
  58. #define TF_COORDINATES_SET(old, new) ((old & (~((unsigned long) (1<<2)|(1<<3)|(1<<4)|(1<<5)))) | new)
  59. #define TF_COORDINATES_GET(old) (old & ((unsigned long)(1<<2)|(1<<3)|(1<<4)|(1<<5)))
  60. class Xlib_textfader {
  61. Display *dpy;
  62. int screen;
  63. int screenHeight, screenWidth;
  64. int screenDepth;
  65. Visual *screenVisual;
  66. XFontStruct *font;
  67. XGCValues gc_val;
  68. unsigned long gc_valValueMask;
  69. XSetWindowAttributes attr;
  70. unsigned long attrValueMask;
  71. XColor textColor;
  72. // fade positions
  73. int pos_x, pos_y;
  74. public:
  75. Xlib_textfader();
  76. ~Xlib_textfader();
  77. // fade section
  78. int fade(char* text, int length, unsigned int fadeTime, unsigned long optionmask);
  79. inline int get_fade_position_x() {
  80. return pos_x;
  81. }
  82. inline int get_fade_position_y() {
  83. return pos_y;
  84. }
  85. inline void set_fade_position_x(int _x){
  86. pos_x = _x;
  87. }
  88. inline void set_fade_position_y(int _y) {
  89. pos_y = _y;
  90. }
  91. inline void set_fade_position(int _x, int _y){
  92. pos_y = _y;
  93. pos_x = _x;
  94. }
  95. // font section
  96. int get_font_height();
  97. int get_font_width();
  98. inline XFontStruct* get_font(){
  99. return font;
  100. }
  101. int set_font(char* name);
  102. char** get_list_fonts(int* count, char *pattern);
  103. // screen section
  104. inline int get_screen_height(){
  105. return screenHeight;
  106. }
  107. inline int get_screen_width() {
  108. return screenWidth;
  109. }
  110. // gc values section
  111. int set_text_color(char* name);
  112. int set_text_color(double red, double green, double blue);
  113. inline unsigned long get_text_color(){
  114. return gc_val.foreground;
  115. }
  116. };// end class
  117. #endif