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