Tutorial on the Lotion <strong>User</strong> <strong>Interface</strong> Classes5.5 The Theme class and blue.cppThe Theme class:• displays the controls and applet icons• manages user input• runs an applet if it is selected• is the parent class for the Blue, Minimal, and Robot classes.There are several themes available for use in the application. This section uses example codefrom lotion\themes\blue.cpp:• Theme namespace and includes• Theme onCreate() method• Theme update methods on page 5-34• Handling user interface events in the Theme class on page 5-36• Theme addApplet() method on page 5-36• Theme createWidgetGroup() method on page 5-37• Theme runApplet() and closeApplet() methods on page 5-37• Theme draw() method on page 5-38.5.5.1 Theme namespace and includesThe Theme methods use the Themes, Lotion, and MDE namespaces. See Example 5-27:Example 5-26 Theme namespace and includes#include "blue.h"#include "../../application.h"#include "blue_widget_group.h"#include "../../transitions/puzzle.h"#include "../../transitions/slime.h"#include "../../transitions/cube.h"using namespace MDE;namespace Lotion{namespace Themes{...}}5.5.2 Theme onCreate() methodExample 5-27 shows the start of the blue.cpp file and the onCreate() method:Example 5-27 Theme onCreate() method...void Blue::onCreate(Widget* w){printf("Blue: Loading shader\n");state = StateBrowsing;ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 5-32ID070710Non-Confidential - Draft - Beta
Tutorial on the Lotion <strong>User</strong> <strong>Interface</strong> ClassessetPosition(MDE::vec2i(0, 0));setSize(MDE::vec2i(8000, 4800));font = getFont("fonts/orbitron-light.ttf", 24);prog = getProgram("themes/blue/shader.vert;themes/blue/shader.frag");// Backgroundprintf("Blue: Loading background\n");backgroundLayer = createLayer(prog, 1, 0, 0,Lotion::LayerModeRGBA, "blue_bg");backgroundLayer->createInstances(1, backgroundInstances);backgroundInstances[0]->createQuads(1, false, backgroundQuads);backgroundQuads[0]->set2DRectangle(vec2(0,0), getResolution(), 0);backgroundQuads[0]->setTexture(0, getBitmap("themes/blue/backdrop.png"),BitmapComponentsRGBA_PremultiplyAlpha);backgroundLayer->setFilter(GL_NEAREST, GL_NEAREST);// Logoprintf("Blue: Loading logo\n");backgroundInstances[0]->createQuads(1, true, backgroundQuads);backgroundQuads[1]->set2DRectangle(vec2(2,2), vec2(126, 46), 0);backgroundQuads[1]->setTexture(0, getBitmap("themes/blue/mali_logo.png"),BitmapComponentsRGBA_PremultiplyAlpha);// Iconsprintf("Blue: Loading icons: shader\n");Program menuProg =getProgram("themes/blue/menu.vert;themes/blue/menu.frag");iconLayer = createLayer(menuProg, 4, 0, 0, LayerModeRGBCompressed,"blue_icons");iconLayer->setFilter(GL_NEAREST, GL_NEAREST);iconLayer->createInstances(iconCount, iconInstances);printf("Blue: Loading icons: text shader\n");Program textProg =getProgram("themes/blue/text.vert;themes/blue/text.frag");printf("Blue: Loading icons: creating layer\n");textLayer = createLayer(textProg, 1, 0, 0, LayerModeRGBA, "blue_text");printf("Blue: Loading icons: creating layer instances\n");textLayer->createInstances(iconCount, iconTextInstances);textLayer->setFilter(GL_NEAREST, GL_NEAREST);for (int i = 0; i < iconCount; i++){printf("Blue: Loading icons: Icon %d\n", i);iconInstances[i]->createQuads(4, true, iconQuads);float add_refl = 0.f;float refl_dist = 30.f;// IconiconQuads[i*4+0]->set2DRectangle(vec2(i * 265.f+16, 105.f + add_refl),vec2(240.f, 136.f), 0);iconQuads[i*4+0]->setTexture(0, getBitmap("themes/blue/empty.png"),BitmapComponentsRGB);iconQuads[i*4+0]->setTexture(1, getBitmap("themes/blue/empty.png"),BitmapComponentsRGB);// Icon ReflectioniconQuads[i*4+1]->set2DRectangle(vec2(i * 265+16, 87+162*2+refl_dist+ add_refl),vec2(240, -136), 0);iconQuads[i*4+1]->setTexture(0, getBitmap("themes/blue/empty.png"),BitmapComponentsRGB);iconQuads[i*4+1]->setTexture(1, getBitmap("themes/blue/empty.png"),BitmapComponentsRGB);ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 5-33ID070710Non-Confidential - Draft - Beta