You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.7KB

  1. //
  2. // "$Id: textdisplay-with-colors.cxx 8183 2011-01-04 17:31:56Z AlbrechtS $"
  3. //
  4. // How to use Fl_Text_Display with colors. -erco 11/09/2010
  5. // Originally from erco's cheat sheet, permission by author.
  6. //
  7. // Shows how to use the two Fl_Text_Buffer's needed to manage
  8. // the text and style info separately.
  9. //
  10. // For an example of a color text *editor*, see the 'editor'
  11. // example in the test directory.
  12. //
  13. // Copyright 2010 Greg Ercolano.
  14. // Copyright 1998-2010 by Bill Spitzak and others.
  15. //
  16. // This library is free software; you can redistribute it and/or
  17. // modify it under the terms of the GNU Library General Public
  18. // License as published by the Free Software Foundation; either
  19. // version 2 of the License, or (at your option) any later version.
  20. //
  21. // This library is distributed in the hope that it will be useful,
  22. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. // Library General Public License for more details.
  25. //
  26. // You should have received a copy of the GNU Library General Public
  27. // License along with this library; if not, write to the Free Software
  28. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  29. // USA.
  30. //
  31. // Please report all bugs and problems on the following page:
  32. //
  33. // http://www.fltk.org/str.php
  34. //
  35. #include <FL/Fl.H>
  36. #include <FL/Fl_Window.H>
  37. #include <FL/Fl_Text_Display.H>
  38. int main() {
  39. // Style table
  40. Fl_Text_Display::Style_Table_Entry stable[] = {
  41. // FONT COLOR FONT FACE FONT SIZE
  42. // --------------- ----------- --------------
  43. { FL_RED, FL_COURIER, 18 }, // A - Red
  44. { FL_DARK_YELLOW, FL_COURIER, 18 }, // B - Yellow
  45. { FL_DARK_GREEN, FL_COURIER, 18 }, // C - Green
  46. { FL_BLUE, FL_COURIER, 18 }, // D - Blue
  47. };
  48. Fl_Window *win = new Fl_Window(640, 480, "Simple Text Display With Colors");
  49. Fl_Text_Display *disp = new Fl_Text_Display(20, 20, 640-40, 480-40);
  50. Fl_Text_Buffer *tbuff = new Fl_Text_Buffer(); // text buffer
  51. Fl_Text_Buffer *sbuff = new Fl_Text_Buffer(); // style buffer
  52. disp->buffer(tbuff);
  53. int stable_size = sizeof(stable)/sizeof(stable[0]); // # entries in style table (4)
  54. disp->highlight_data(sbuff, stable, stable_size, 'A', 0, 0);
  55. // Text
  56. tbuff->text("Red Line 1\nYel Line 2\nGrn Line 3\nBlu Line 4\n"
  57. "Red Line 5\nYel Line 6\nGrn Line 7\nBlu Line 8\n");
  58. // Style for text
  59. sbuff->text("AAAAAAAAAA\nBBBBBBBBBB\nCCCCCCCCCC\nDDDDDDDDDD\n"
  60. "AAAAAAAAAA\nBBBBBBBBBB\nCCCCCCCCCC\nDDDDDDDDDD\n");
  61. win->resizable(*disp);
  62. win->show();
  63. return(Fl::run());
  64. }
  65. //
  66. // End of "$Id: textdisplay-with-colors.cxx 8183 2011-01-04 17:31:56Z AlbrechtS $".
  67. //