Skip to content

Commit

Permalink
KOTOR: Add methods to convert between coordinate systems and use them
Browse files Browse the repository at this point in the history
  • Loading branch information
farmboy0 committed Dec 13, 2017
1 parent 570b95d commit 72f4b23
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/engines/kotor/gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ void GUI::hide() {
::Engines::GUI::hide();
}

void GUI::convertToXoreos(float &x, float &y, const float widgetHeight) const {
x = x - (_guiWidth / 2.0f);
y = (_guiHeight / 2.0f) - y - widgetHeight;
}

void GUI::convertToGUI(float &x, float &y, const float widgetHeight) const {
x = x + (_guiWidth / 2.0f);
y = widgetHeight + (-1.0f * (y - (_guiHeight / 2.0f)));
}

void GUI::mouseDown() {
CursorMan.setState("down");
}
Expand Down Expand Up @@ -113,8 +123,7 @@ void GUI::loadWidget(const Aurora::GFF3Struct &strct, Widget *parent) {
float wX, wY, wZ;
ctx.widget->getPosition(wX, wY, wZ);

wX = wX - (_guiWidth / 2.0f);
wY = ((_guiHeight - wY) - ctx.widget->getHeight()) - (_guiHeight / 2.0f);
convertToXoreos(wX, wY, ctx.widget->getHeight());
wZ = _widgetZ + wZ;

ctx.widget->setPosition(wX, wY, wZ);
Expand Down
13 changes: 13 additions & 0 deletions src/engines/kotor/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ class GUI : public Engines::GUI {
virtual void show(); ///< Show the GUI.
virtual void hide(); ///< Hide the GUI.

/**
* Converts Kotor' GUI coordinates with a coordinate origin
* in the upper left corner to the Xoreos coordinate system
* with the coordinate origin in the center.
*/
void convertToXoreos(float &x, float &y, const float widgetHeight) const;
/**
* Converts Xoreos' coordinates with a coordinate origin
* in the center to Kotor's GUI coordinates
* with the coordinate origin in the the upper left corner.
*/
void convertToGUI(float &x, float &y, const float widgetHeight) const;

protected:
enum WidgetType {
kWidgetTypeInvalid = - 1,
Expand Down

0 comments on commit 72f4b23

Please sign in to comment.