| 1 |
#include "ReadableGuiView.h" |
| 2 |
|
| 3 |
#include "math/Vector4.h" |
| 4 |
#include "gui/GuiWindowDef.h" |
| 5 |
|
| 6 |
namespace gui |
| 7 |
{ |
| 8 |
|
| 9 |
ReadableGuiView::ReadableGuiView(wxWindow* parent) : |
| 10 |
GuiView(parent) |
| 11 |
{} |
| 12 |
|
| 13 |
void ReadableGuiView::setGLViewPort() |
| 14 |
{ |
| 15 |
double width = _windowDims[0]; |
| 16 |
double height = _windowDims[1]; |
| 17 |
|
| 18 |
double aspectRatio = _bgDims[0] / _bgDims[1]; |
| 19 |
|
| 20 |
if (width / height > aspectRatio) |
| 21 |
{ |
| 22 |
width = height * aspectRatio; |
| 23 |
} |
| 24 |
else |
| 25 |
{ |
| 26 |
height = width / aspectRatio; |
| 27 |
} |
| 28 |
|
| 29 |
SetSize(static_cast<int>(width), -1); |
| 30 |
|
| 31 |
glViewport(0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height)); |
| 32 |
} |
| 33 |
|
| 34 |
void ReadableGuiView::setGui(const IGuiPtr& gui) |
| 35 |
{ |
| 36 |
// Call the base class first |
| 37 |
GuiView::setGui(gui); |
| 38 |
|
| 39 |
Vector2 topLeft(0, 0); |
| 40 |
Vector2 bottomRight(640, 480); |
| 41 |
|
| 42 |
if (_gui != NULL) |
| 43 |
{ |
| 44 |
IGuiWindowDefPtr bgWindowDef = _gui->findWindowDef("backgroundImage"); |
| 45 |
if (!bgWindowDef) |
| 46 |
{ |
| 47 |
bgWindowDef = _gui->findWindowDef("backgroundmulti"); |
| 48 |
if (!bgWindowDef) |
| 49 |
{ |
| 50 |
bgWindowDef = _gui->findWindowDef("backgroundsingle"); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
if (bgWindowDef != NULL) |
| 55 |
{ |
| 56 |
const Vector4& rect = bgWindowDef->rect; |
| 57 |
topLeft = Vector2(rect[0], rect[1]); |
| 58 |
bottomRight = Vector2(rect[0] + rect[2], rect[1] + rect[3]); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
_bgDims = bottomRight - topLeft; |
| 63 |
|
| 64 |
_renderer.setVisibleArea(topLeft, bottomRight); |
| 65 |
} |
| 66 |
|
| 67 |
} // namespace |