]> git.mxchange.org Git - flightgear.git/blob - src/GUI/layout-test.cxx
Migrate FlightGear code to use "#include SG_GL*" defined in
[flightgear.git] / src / GUI / layout-test.cxx
1 #include <iostream>
2
3 #include <simgear/compiler.h>
4 #include SG_GL_H
5 #include <plib/pw.h>
6 #include <plib/pu.h>
7 #include <simgear/props/props.hxx>
8 #include <simgear/props/props_io.hxx>
9
10 #include "layout.hxx"
11
12 // Takes a property file on the command line, lays it out, and writes
13 // the resulting tree back to stdout.  Requires that the
14 // "Helvetica.txf" font file from the base package be in the current
15 // directory.
16
17 // g++ -Wall -g -o layout layout.cxx layout-props.cxx layout-test.cxx
18 // -I/fg/include -L/fg/lib -I.. -lsgprops -lsgdebug -lsgstructure
19 // -lsgmisc -lsgxml -lplibpw -lplibpu -lplibfnt -lplibul -lGL
20
21 // We can't load a plib fntTexFont without a GL context, so we use the
22 // PW library to initialize things.  The callbacks are required, but
23 // just stubs.
24 void exitCB(){ pwCleanup(); exit(0); }
25 void resizeCB(int w, int h){ }
26 void mouseMotionCB(int x, int y){ puMouse(x, y); }
27 void mouseButtonCB(int button, int updn, int x, int y){ puMouse(button, updn, x, y); }
28 void keyboardCB(int key, int updn, int x, int y){ puKeyboard(key, updn, x, y); }
29
30 const char* FONT_FILE = "Helvetica.txf";
31
32 int main(int argc, char** argv)
33 {
34     FILE* tmp;
35     if(!(tmp = fopen(FONT_FILE, "r"))) {
36         fprintf(stderr, "Could not open %s for reading.\n", FONT_FILE);
37         exit(1);
38     }
39     fclose(tmp);
40
41     pwInit(0, 0, 600, 400, 0, "Layout Test", true, 0);
42     pwSetCallbacks(keyboardCB, mouseButtonCB, mouseMotionCB,
43                    resizeCB, exitCB);
44
45     fntTexFont helv;
46     helv.load(FONT_FILE);
47     puFont puhelv(&helv);
48
49     LayoutWidget::setDefaultFont(&puhelv, 15);
50     SGPropertyNode props;
51     readProperties(argv[1], &props);
52     LayoutWidget w(&props);
53     int pw=0, ph=0;
54     w.calcPrefSize(&pw, &ph);
55     w.layout(0, 0, pw, ph);
56     writeProperties(cout, &props, true);
57 }