| |||
| Home > Tutorial on the Lotion User Interface Classes > Modifications to lightshow.cpp > Widget initialization and event handling | |||
New methods are added to respond to widget creation or change. See Example 5.24:
Example 5.24. Widget initialization and event handling
void LightShow::onCreate(Widget* w) {
static const int NORMAL_FONT_SIZE=21;
if (w != this)
return;
styggShader = false;
useWireframe = false;
Context* context = getApplication()->getContext();
Proxy* proxy = getApplication()->getProxy();
scene = proxy->getSceneAsset(
"applets/lightshow/lightshow_remake.MBA{applets/lightshow/}");
flarePrg = proxy->getProgram(
"applets/lightshow/flare.vert;applets/lightshow/flare.frag");
prg_gl2 = proxy->getProgram(
"applets/lightshow/lightshow.vert;applets/lightshow/lightshow.frag");
prg_gl1 = proxy->getProgram(
"applets/lightshow/lightshow_gl1.vert;applets/lightshow/lightshow_gl1.frag");
prepareFlares(context, flarePrg);
camNode = (NodeAsset*) scene->getAsset(Asset::TYPE_NODE, "Camera01-node");
targetNode = (NodeAsset*) scene->getAsset(Asset::TYPE_NODE,
"Camera01.Target-node");
light0Node = (NodeAsset*) scene->getAsset(Asset::TYPE_NODE, "Omni01-node");
light1Node = (NodeAsset*) scene->getAsset(Asset::TYPE_NODE, "Omni02-node");
flareTex = proxy->getTexture2D("applets/lightshow/flare.png");
time = 0;
wg = createWidgetGroup("lightshow_wg");
// add the user controls to switch between shading effects
panel = wg->createPanel(this);
panel->setSize(MDE::vec2i(180, 200));
panel->setPosition(MDE::vec2i(0, 0));
settingsGlLbl = wg->createCustomLabel(this);
settingsGlLbl->build(NORMAL_FONT_SIZE, 16);
settingsGlLbl->setPosition(vec2i(10, 0));
settingsGlLbl->setColor(vec4(1.f, 1.f, 1.f, 1.f));
settingsGlLbl->setTextAlign(TEXT_ALIGN_LEFT | TEXT_ALIGN_TOP);
settingsGlLbl->setText("GL Version");
gl11Chk = wg->createRadioButton(this);
gl11Chk->setText("GLES 1.1");
gl11Chk->setPosition(vec2i(10, 25));
gl20Chk = wg->createRadioButton(this);
gl20Chk->setText("GLES 2.0");
gl20Chk->setPosition(vec2i(10, 50));
glVersion = new RadioButtonGroup();
glVersion->add(gl11Chk);
glVersion->add(gl20Chk);
renderLbl = wg->createCustomLabel(this);
renderLbl->build(NORMAL_FONT_SIZE, 16);
renderLbl->setPosition(vec2i(10, 90));
renderLbl->setColor(vec4(1.f, 1.f, 1.f, 1.f));
renderLbl->setTextAlign(TEXT_ALIGN_LEFT | TEXT_ALIGN_TOP);
renderLbl->setText("Rendermode");
solidChk = wg->createRadioButton(this);
solidChk->setText("Solid");
solidChk->setPosition(vec2i(10, 115));
wireframeChk = wg->createRadioButton(this);
wireframeChk->setText("Wireframe");
wireframeChk->setPosition(vec2i(10, 140));
renderMode = new RadioButtonGroup();
renderMode->add(solidChk);
renderMode->add(wireframeChk);
exitButton = wg->createExitButton(this);
exitButton->setPosition(MDE::vec2i(130, 150));
solidChk->check();
gl20Chk->check();
setPosition(MDE::vec2i(0, 0));
setSize(MDE::vec2i(800, 480));
}
void LightShow::onValueChanged(Widget* w) {
useWireframe = wireframeChk->isChecked();
styggShader = gl11Chk->isChecked();
}