Skip to content

Commit

Permalink
Widgets|libappfw: Converting from logical to window (pixel) coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Oct 12, 2016
1 parent 2a25c5d commit 15257e5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
11 changes: 6 additions & 5 deletions doomsday/sdk/libappfw/include/de/framework/vrwindowtransform.h
Expand Up @@ -37,13 +37,14 @@ class LIBAPPFW_PUBLIC VRWindowTransform : public WindowTransform
public:
VRWindowTransform(BaseWindow &window);

void glInit();
void glDeinit();
void glInit() override;
void glDeinit() override;

Vector2ui logicalRootSize(Vector2ui const &physicalWindowSize) const;
Vector2f windowToLogicalCoords(Vector2i const &pos) const;
Vector2ui logicalRootSize(Vector2ui const &physicalWindowSize) const override;
Vector2f windowToLogicalCoords(Vector2i const &pos) const override;
Vector2f logicalToWindowCoords(Vector2i const &pos) const override;

void drawTransformed();
void drawTransformed() override;

GLTextureFramebuffer &unwarpedFramebuffer();

Expand Down
14 changes: 10 additions & 4 deletions doomsday/sdk/libappfw/include/de/framework/windowtransform.h
Expand Up @@ -19,6 +19,7 @@
#ifndef LIBAPPFW_WINDOWTRANSFORM_H
#define LIBAPPFW_WINDOWTRANSFORM_H

#include <de/Rectangle>
#include <de/Vector>

namespace de {
Expand Down Expand Up @@ -46,22 +47,27 @@ class WindowTransform

/**
* Determines how large the root widget should be for a particular canvas size.
*
* @param physicalCanvasSize Canvas size (pixels).
*
* @return Logical size (UI units).
*/
virtual Vector2ui logicalRootSize(Vector2ui const &physicalCanvasSize) const;

/**
* Translate a point in physical window coordinates to logical coordinates.
*
* @param pos Window coordinates (pixels).
*
* @return Logical coordinates inside the root widget's area.
*/
virtual Vector2f windowToLogicalCoords(Vector2i const &pos) const;

/**
* Translate a point in logical coordinates to window coordinates.
* @param rect Logical coordinates.
* @return Window coordinates (pixels).
*/
virtual Vector2f logicalToWindowCoords(Vector2i const &pos) const;

Rectanglef logicalToWindowCoords(Rectanglei const &rect) const;

/**
* Applies the appropriate transformation state and tells the window to draw its
* contents.
Expand Down
13 changes: 13 additions & 0 deletions doomsday/sdk/libappfw/src/vrwindowtransform.cpp
Expand Up @@ -434,6 +434,19 @@ Vector2f VRWindowTransform::windowToLogicalCoords(Vector2i const &winPos) const
return pos;
}

Vector2f VRWindowTransform::logicalToWindowCoords(Vector2i const &logicalPos) const
{
Vector2f pos = logicalPos;

Vector2f const size = window().pixelSize();
Vector2f viewSize = window().windowContentSize();

// Scale to pixel size.
pos = pos / viewSize * size;

return pos;
}

void VRWindowTransform::drawTransformed()
{
d->draw();
Expand Down
13 changes: 12 additions & 1 deletion doomsday/sdk/libappfw/src/windowtransform.cpp
Expand Up @@ -13,7 +13,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/WindowTransform"
Expand Down Expand Up @@ -58,6 +58,17 @@ Vector2f WindowTransform::windowToLogicalCoords(Vector2i const &pos) const
return pos;
}

Vector2f WindowTransform::logicalToWindowCoords(Vector2i const &pos) const
{
return pos;
}

Rectanglef WindowTransform::logicalToWindowCoords(Rectanglei const &rect) const
{
return Rectanglef(logicalToWindowCoords(rect.topLeft),
logicalToWindowCoords(rect.bottomRight));
}

void WindowTransform::drawTransformed()
{
return d->win->drawWindowContent();
Expand Down

0 comments on commit 15257e5

Please sign in to comment.