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