2005-10-22 11:22:05 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2004-05-12 15:36:07 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2004-11-18 19:53:00 +00:00
|
|
|
#include <simgear/compiler.h>
|
2008-07-27 16:25:13 +00:00
|
|
|
#include <osg/GL>
|
2004-05-12 15:36:07 +00:00
|
|
|
#include <plib/pw.h>
|
|
|
|
#include <plib/pu.h>
|
|
|
|
#include <simgear/props/props.hxx>
|
|
|
|
#include <simgear/props/props_io.hxx>
|
|
|
|
|
|
|
|
#include "layout.hxx"
|
|
|
|
|
|
|
|
// Takes a property file on the command line, lays it out, and writes
|
|
|
|
// the resulting tree back to stdout. Requires that the
|
|
|
|
// "Helvetica.txf" font file from the base package be in the current
|
|
|
|
// directory.
|
|
|
|
|
|
|
|
// g++ -Wall -g -o layout layout.cxx layout-props.cxx layout-test.cxx
|
|
|
|
// -I/fg/include -L/fg/lib -I.. -lsgprops -lsgdebug -lsgstructure
|
|
|
|
// -lsgmisc -lsgxml -lplibpw -lplibpu -lplibfnt -lplibul -lGL
|
|
|
|
|
|
|
|
// We can't load a plib fntTexFont without a GL context, so we use the
|
|
|
|
// PW library to initialize things. The callbacks are required, but
|
|
|
|
// just stubs.
|
|
|
|
void exitCB(){ pwCleanup(); exit(0); }
|
|
|
|
void resizeCB(int w, int h){ }
|
|
|
|
void mouseMotionCB(int x, int y){ puMouse(x, y); }
|
|
|
|
void mouseButtonCB(int button, int updn, int x, int y){ puMouse(button, updn, x, y); }
|
|
|
|
void keyboardCB(int key, int updn, int x, int y){ puKeyboard(key, updn, x, y); }
|
|
|
|
|
|
|
|
const char* FONT_FILE = "Helvetica.txf";
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
FILE* tmp;
|
|
|
|
if(!(tmp = fopen(FONT_FILE, "r"))) {
|
|
|
|
fprintf(stderr, "Could not open %s for reading.\n", FONT_FILE);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fclose(tmp);
|
|
|
|
|
2009-08-24 16:00:10 +00:00
|
|
|
pwInit(0, 0, 600, 400, 0, const_cast<char*>("Layout Test"), true, 0);
|
2004-05-12 15:36:07 +00:00
|
|
|
pwSetCallbacks(keyboardCB, mouseButtonCB, mouseMotionCB,
|
|
|
|
resizeCB, exitCB);
|
|
|
|
|
|
|
|
fntTexFont helv;
|
|
|
|
helv.load(FONT_FILE);
|
|
|
|
puFont puhelv(&helv);
|
|
|
|
|
|
|
|
LayoutWidget::setDefaultFont(&puhelv, 15);
|
|
|
|
SGPropertyNode props;
|
|
|
|
readProperties(argv[1], &props);
|
|
|
|
LayoutWidget w(&props);
|
|
|
|
int pw=0, ph=0;
|
|
|
|
w.calcPrefSize(&pw, &ph);
|
|
|
|
w.layout(0, 0, pw, ph);
|
2008-06-02 21:07:35 +00:00
|
|
|
writeProperties(std::cout, &props, true);
|
2004-05-12 15:36:07 +00:00
|
|
|
}
|