Debian Codegraph @

Tests/ListBoxTest/listboxtest.cpp

raw
1 #include <ClanLib/core.h>
2 #include <ClanLib/gui.h>
3 #include <ClanLib/guistylesilver.h>
4 #include <ClanLib/application.h>
5 #include <ClanLib/display.h>
6 #include <ClanLib/gl.h>
7
8 class TestItem : public CL_ListItem
9 {
10 private:
11 std::string key;
12
13 public:
14 TestItem(std::string k, std::string v)
15 {
16 key = k;
17 str = v;
18 }
19
20 std::string getKey()
21 {
22 return key;
23 }
24 };
25
26 // The main application
27 class App : public CL_ClanApplication
28 {
29 public:
30 int main(int argc, char** argv)
31 {
32 // Create a console window for text-output if not available
33 CL_ConsoleWindow console("Console");
34 console.redirect_stdio();
35
36 try
37 {
38 CL_SetupCore::init();
39 CL_SetupDisplay::init();
40 CL_SetupGL::init();
41 CL_SetupGUI::init();
42
43 CL_DisplayWindow window("GUITest example", 640, 480);
44
45 // Create the GUI using the default style
46 CL_ResourceManager gui_resources("../../Resources/GUIStyleSilver/gui.xml", false);
47 CL_StyleManager_Silver style(&gui_resources);
48 CL_GUIManager gui(&style);
49
50 TestItem item1("key01", "value01");
51 TestItem item2("key02", "value02");
52 TestItem item3("key03", "value03");
53
54 CL_ListBox list(&gui);
55 list.insert_item(&item1);
56 list.insert_item(&item2);
57 list.insert_item(&item3);
58
59 // this one prints "item1k key01"
60 std::cout << "item1k " << item1.getKey() << std::endl;
61 // this one prints "item1v value01"
62 std::cout << "item1v " << item1.str << std::endl;
63
64 // then I get the first item
65 TestItem *item = (TestItem *)list.get_item(0);
66
67 // this one should print "itemk key01", but instead, it prints "itemk value02"
68 std::cout << "itemk " << item->getKey() << std::endl;
69 // however, the value is alright, this line prints "itemv value01"
70 std::cout << "itemv " << item->str << std::endl;
71
72 // Main loop
73 while (!CL_Keyboard::get_keycode(CL_KEY_ESCAPE))
74 {
75 CL_Display::clear();
76 gui.show();
77
78 CL_System::keep_alive(10);
79 CL_Display::flip();
80 }
81
82 CL_SetupGL::deinit();
83 CL_SetupGUI::deinit();
84 CL_SetupDisplay::deinit();
85 CL_SetupCore::deinit();
86 }
87 catch (CL_Error e)
88 {
89 std::cout << e.message.c_str() << std::endl;
90
91 // Display console close message and wait for a key
92 console.display_close_message();
93 }
94
95 return 0;
96 }
97 } app;