|
14 | 14 | #include "imgui_utils.as"
|
15 | 15 | imgui_utils::CloseWindowPrompt closeBtnHandler;
|
16 | 16 |
|
| 17 | +// overlay |
| 18 | +string ovName = "ov"+thisScript; |
17 | 19 | bool ov_fail = false;
|
18 |
| - |
| 20 | +// panel |
| 21 | +string paName = "pa"+thisScript; |
19 | 22 | bool pa_fail = false;
|
| 23 | +int paNumCreates = 0; |
| 24 | +// misc |
20 | 25 | int framecounter = 0;
|
21 | 26 | float pos_step = 50; // pixels
|
22 | 27 |
|
23 | 28 | void frameStep(float dt)
|
24 | 29 | {
|
25 |
| - Ogre::Overlay@ ov; |
26 |
| - if (!ov_fail) { |
27 |
| - // NOTE: getByName() will calmly return NULL if overlay doesn't exist. |
28 |
| - @ov = Ogre::OverlayManager::getSingleton().getByName("ov"); |
29 |
| - // CAUTION: attempt to create the same overlay again will throw an exception, interrupting the script in between! |
30 |
| - if (@ov == null) { @ov = Ogre::OverlayManager::getSingleton().create("ov"); } |
31 |
| - if (@ov == null) { ov_fail = true; } |
32 |
| - else { ov.show(); } |
33 |
| - } |
34 |
| - |
35 |
| - Ogre::OverlayElement@ pa; |
36 |
| - |
37 |
| - if (!pa_fail ){ |
38 |
| - if ( Ogre::OverlayManager::getSingleton().hasOverlayElement("pa")) { |
39 |
| - |
40 |
| - // CAUTION: getOverlayElement() will throw exception if not found, always do `hasOverlayElement()` first! |
41 |
| - @pa = Ogre::OverlayManager::getSingleton().getOverlayElement("pa"); |
42 |
| - } |
43 |
| - // CAUTION: using the same name twice will throw an exception, interrupting the script in between! |
44 |
| - if (@pa == null ) { @pa = Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "pa"); |
45 |
| - if (@pa == null ) { pa_fail=true; } |
46 |
| - else { |
47 |
| -// game.log("adding pa to ov"); |
48 |
| - ov.add2D(pa); |
49 |
| - pa.setMetricsMode(Ogre::GMM_PIXELS); |
50 |
| - pa.setPosition(100,100); |
51 |
| - pa.setDimensions(100,100); |
52 |
| - pa.show(); |
53 |
| - } |
54 |
| - } |
55 |
| - pa.setMaterialName("tracks/wheelface", 'OgreAutodetect'); |
56 |
| - } |
57 |
| - |
| 30 | + Ogre::Overlay@ ov; |
| 31 | + if (!ov_fail) |
| 32 | + { |
| 33 | + // NOTE: getByName() will calmly return NULL if overlay doesn't exist. |
| 34 | + @ov = Ogre::OverlayManager::getSingleton().getByName(ovName); |
| 35 | + // CAUTION: attempt to create the same overlay again will throw an exception, interrupting the script in between! |
| 36 | + if (@ov == null) |
| 37 | + { |
| 38 | + @ov = Ogre::OverlayManager::getSingleton().create(ovName); |
| 39 | + } |
| 40 | + if (@ov == null) |
| 41 | + { |
| 42 | + ov_fail = true; |
| 43 | + } |
| 44 | + else |
| 45 | + { |
| 46 | + ov.show(); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + Ogre::OverlayElement@ pa; |
| 51 | + |
| 52 | + if (!pa_fail ) |
| 53 | + { |
| 54 | + if ( Ogre::OverlayManager::getSingleton().hasOverlayElement(paName)) |
| 55 | + { |
| 56 | + game.log('Looking for pa'); |
| 57 | + // CAUTION: getOverlayElement() will throw exception if not found, always do `hasOverlayElement()` first! |
| 58 | + @pa = Ogre::OverlayManager::getSingleton().getOverlayElement(paName); |
| 59 | + |
| 60 | + } |
| 61 | + // CAUTION: using the same name twice will throw an exception, interrupting the script in between! |
| 62 | + if (@pa == null ) |
| 63 | + { |
| 64 | + @pa = Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", paName); |
| 65 | + paNumCreates++; |
| 66 | + game.log('paNumCreates:'+paNumCreates); |
| 67 | + if (@pa == null ) |
| 68 | + { |
| 69 | + pa_fail=true; |
| 70 | + } |
| 71 | + else |
| 72 | + { |
| 73 | + // game.log("adding pa to ov"); |
| 74 | + ov.add2D(pa); |
| 75 | + pa.setMetricsMode(Ogre::GMM_PIXELS); |
| 76 | + pa.setPosition(100,100); |
| 77 | + pa.setDimensions(100,100); |
| 78 | + pa.setMaterialName("tracks/wheelface", 'OgreAutodetect'); |
| 79 | + pa.show(); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + } |
| 84 | + |
58 | 85 | if (ImGui::Begin("Example", closeBtnHandler.windowOpen, 0))
|
59 | 86 | {
|
60 | 87 | closeBtnHandler.draw();
|
61 |
| - ImGui::Text("overlays should work; ov_fail:"+ov_fail+", pa_fail:"+pa_fail |
62 |
| - +", frames:"+framecounter); |
| 88 | + ImGui::Text("overlays should work; ov_fail:"+ov_fail+", pa_fail:"+pa_fail +", frames:"+framecounter); |
63 | 89 | framecounter++;
|
64 | 90 | if (!pa_fail && @pa != null)
|
65 | 91 | {
|
66 |
| - |
| 92 | + |
67 | 93 | ImGui::TextDisabled("The wheel overlay:");
|
68 |
| - if (ImGui::Button("Hide")) { pa.hide(); } |
69 |
| - ImGui::SameLine(); if (ImGui::Button("Show")) { pa.show(); } |
70 |
| - |
71 |
| - if (ImGui::Button("Position: Left+")) { pa.setLeft(pa.getLeft()+pos_step); } |
72 |
| - ImGui::SameLine(); if (ImGui::Button("Position:left-")) { pa.setLeft(pa.getLeft()-pos_step); } |
73 |
| - |
74 |
| - if (ImGui::Button("Position: Top+")) { pa.setTop(pa.getTop()+pos_step); } |
75 |
| - ImGui::SameLine(); if (ImGui::Button("Position:Top-")) { pa.setTop(pa.getTop()-pos_step); } |
76 |
| - |
77 |
| - if (ImGui::Button("Width+")) { pa.setWidth(pa.getWidth()+pos_step); } |
78 |
| - ImGui::SameLine(); if (ImGui::Button("Width-")) { pa.setWidth(pa.getWidth()-pos_step); } |
79 |
| - |
80 |
| - if (ImGui::Button("height+")) { pa.setHeight(pa.getHeight()+pos_step); } |
81 |
| - ImGui::SameLine(); if (ImGui::Button("height-")) { pa.setHeight(pa.getHeight()-pos_step); } |
82 |
| - |
| 94 | + if (ImGui::Button("Hide")) { pa.hide(); } |
| 95 | + ImGui::SameLine(); if (ImGui::Button("Show")) { pa.show(); } |
| 96 | + |
| 97 | + if (ImGui::Button("Position: Left+")) { pa.setLeft(pa.getLeft()+pos_step); } |
| 98 | + ImGui::SameLine(); if (ImGui::Button("Position:left-")) { pa.setLeft(pa.getLeft()-pos_step); } |
| 99 | + |
| 100 | + if (ImGui::Button("Position: Top+")) { pa.setTop(pa.getTop()+pos_step); } |
| 101 | + ImGui::SameLine(); if (ImGui::Button("Position:Top-")) { pa.setTop(pa.getTop()-pos_step); } |
| 102 | + |
| 103 | + if (ImGui::Button("Width+")) { pa.setWidth(pa.getWidth()+pos_step); } |
| 104 | + ImGui::SameLine(); if (ImGui::Button("Width-")) { pa.setWidth(pa.getWidth()-pos_step); } |
| 105 | + |
| 106 | + if (ImGui::Button("height+")) { pa.setHeight(pa.getHeight()+pos_step); } |
| 107 | + ImGui::SameLine(); if (ImGui::Button("height-")) { pa.setHeight(pa.getHeight()-pos_step); } |
| 108 | + |
83 | 109 | }
|
84 | 110 | ImGui::End();
|
85 | 111 | }
|
|
0 commit comments