2010-12-10 08:27:20 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// How to use Fl_Text_Display with colors. -erco 11/09/2010
|
|
|
|
// Originally from erco's cheat sheet, permission by author.
|
2010-12-10 08:27:20 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Shows how to use the two Fl_Text_Buffer's needed to manage
|
|
|
|
// the text and style info separately.
|
2010-12-10 10:49:22 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// For an example of a color text *editor*, see the 'editor'
|
|
|
|
// example in the test directory.
|
2010-12-10 08:27:20 +03:00
|
|
|
//
|
|
|
|
// Copyright 2010 Greg Ercolano.
|
|
|
|
// Copyright 1998-2010 by Bill Spitzak and others.
|
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
2010-12-10 08:27:20 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2010-12-10 08:27:20 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
2010-12-10 08:27:20 +03:00
|
|
|
//
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Window.H>
|
|
|
|
#include <FL/Fl_Text_Display.H>
|
|
|
|
int main() {
|
|
|
|
// Style table
|
|
|
|
Fl_Text_Display::Style_Table_Entry stable[] = {
|
|
|
|
// FONT COLOR FONT FACE FONT SIZE
|
|
|
|
// --------------- ----------- --------------
|
|
|
|
{ FL_RED, FL_COURIER, 18 }, // A - Red
|
|
|
|
{ FL_DARK_YELLOW, FL_COURIER, 18 }, // B - Yellow
|
|
|
|
{ FL_DARK_GREEN, FL_COURIER, 18 }, // C - Green
|
|
|
|
{ FL_BLUE, FL_COURIER, 18 }, // D - Blue
|
|
|
|
};
|
|
|
|
Fl_Window *win = new Fl_Window(640, 480, "Simple Text Display With Colors");
|
|
|
|
Fl_Text_Display *disp = new Fl_Text_Display(20, 20, 640-40, 480-40);
|
2020-07-01 19:03:10 +03:00
|
|
|
Fl_Text_Buffer *tbuff = new Fl_Text_Buffer(); // text buffer
|
|
|
|
Fl_Text_Buffer *sbuff = new Fl_Text_Buffer(); // style buffer
|
2010-12-10 08:27:20 +03:00
|
|
|
disp->buffer(tbuff);
|
2020-07-01 19:03:10 +03:00
|
|
|
int stable_size = sizeof(stable)/sizeof(stable[0]); // # entries in style table (4)
|
2010-12-10 08:27:20 +03:00
|
|
|
disp->highlight_data(sbuff, stable, stable_size, 'A', 0, 0);
|
|
|
|
// Text
|
|
|
|
tbuff->text("Red Line 1\nYel Line 2\nGrn Line 3\nBlu Line 4\n"
|
2020-07-01 19:03:10 +03:00
|
|
|
"Red Line 5\nYel Line 6\nGrn Line 7\nBlu Line 8\n");
|
2010-12-10 08:27:20 +03:00
|
|
|
// Style for text
|
|
|
|
sbuff->text("AAAAAAAAAA\nBBBBBBBBBB\nCCCCCCCCCC\nDDDDDDDDDD\n"
|
2020-07-01 19:03:10 +03:00
|
|
|
"AAAAAAAAAA\nBBBBBBBBBB\nCCCCCCCCCC\nDDDDDDDDDD\n");
|
2010-12-10 08:27:20 +03:00
|
|
|
win->resizable(*disp);
|
|
|
|
win->show();
|
|
|
|
return(Fl::run());
|
|
|
|
}
|