GTK+ IOStream  Beta
<< GTK+ >> add C++ IOStream operators to GTK+. Now with extra abilities ... like network serialisation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PangoTest.C
Go to the documentation of this file.
1 /* Copyright 2000-2013 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 /* Compile with ...
18 g++ -ggdb `gtk-config --cflags` PangoTest.C -o PangoTest `gtk-config --libs`
19 */
20 #include "gtkInterface.H"
21 #include "Buttons.H"
22 #include "Labels.H"
23 #include "Pango.H"
24 #include "ColourLineSpec.H"
25 
26 static void quit(void *wid, gpointer data) {
27  gtk_main_quit();
28 }
29 
30 int main(int argc, char *argv[]) {
31 
32  gtk_init( &argc, &argv ); // init GTK
33 
34  GtkInterface topWindow; // Create the top box
35 
36  Buttons buttons; // create a quit button
37  Labels labs; // create a labels list
38  Pango pango; // Create a Pango class for marking up the labels
39  HBox hBox; // create an HBox
40  VBox vBox; // create a VBox
41  vBox.start=true; // ensure packing is from the start
42 
43 
44 // // create a quit buttons and add some example pango labels
45 // labs<<"label without markup"; // add an unformatted label
46 
47  pango<<ColourLineSpec("r15000")<<"Different colours, "<<ColourLineSpec("o11000")<<"same label!"; // same label with different colours/sizes
48 
49  labs<<pango; // load a formatted label
50  // format a the strings "text red 15" and "text orango 11" to their desired size and colours
51  // PangoIOS::reset removes and previous strings and markup
52  pango<<PangoIOS::Reset<<ColourLineSpec("r15000")<<"text red 15000"<<ColourLineSpec("o11000")<<" text orange 11"; // same label with different colours/sizes
53 
54  labs<<pango; // load a formatted label
55 
56 
57  // this will make a big italic label which removes formatting at the end of the label.
58  pango<<PangoIOS::Reset<<Font("Sans italic 20")<<"big italic font"<<PangoIOS::Next<<" removed formatting.";
59 
60  labs<<pango;
61 
62  vBox << labs; // load the labels into a vertical box
63  hBox << vBox // load the vertically stacked labels into the horizontal box
64  << (buttons<<BUTTONLABELSTRUCT("Quit", quit, NULL)); // create and add the button to the HBox
65 
66  vBox.show(); // show the VBox
67  hBox.show(); // show the HBox
68  topWindow << hBox; // Load the HBox into the top window
69 
70  gtk_main(); // run GTK+
71 }
72 
73 // setup the possible plot colours ...
74 int ColourLineSpec::colourCnt=9; // this number matches with the number of colours below
75 const char *ColourLineSpec::shortColours[]= {(char *)"y",(char *)"m",(char *)"c",(char *)"r",(char *)"g",(char *)"b",(char *)"w",(char *)"k",(char *)"o"}; // standard colours
76 const char *ColourLineSpec::X11Colours[]= {(char *)"yellow", (char *)"magenta", (char *)"cyan", (char *)"red", (char *)"green", (char *)"blue", (char *)"white", (char *)"black", (char *)"orange"};