Skip to content

Commit

Permalink
added a way to get the scalling factor from any widget
Browse files Browse the repository at this point in the history
fixed typos
added GL_GLEXT_PROTOTYPES define for linux users
  • Loading branch information
meeloo committed Aug 13, 2014
1 parent 2fb6fc7 commit fec53e2
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/ngl.h
Expand Up @@ -496,6 +496,7 @@ typedef wchar_t nglUChar;

# elif !defined _MINUI3_

#define GL_GLEXT_PROTOTYPES
# include <GL/gl.h>
//# include <GL/glu.h>
# include "nui_GL/glext.h"
Expand Down
3 changes: 3 additions & 0 deletions include/nuiMainWindow.h
Expand Up @@ -188,6 +188,9 @@ class nuiMainWindow : public nuiTopLevel
virtual bool OnMouseMove (nglMouseInfo& rInfo);
virtual bool OnMouseCanceled(nglMouseInfo& rInfo);
virtual bool OnRotation (uint Angle);
virtual float GetScale() const;
virtual float GetScaleInv() const;

//@}

nuiEventSink<nuiMainWindow> mMainWinSink;
Expand Down
3 changes: 3 additions & 0 deletions include/nuiTopLevel.h
Expand Up @@ -167,6 +167,9 @@ class nuiTopLevel : public nuiSimpleContainer
virtual const std::map<nglTouchId, nglMouseInfo>& GetMouseStates() const;
virtual nuiSize GetStatusBarSize() const;

virtual float GetScale() const;
virtual float GetScaleInv() const;

protected:
void Exit();
void SetDrawContext(nuiDrawContext* pDrawContext);
Expand Down
2 changes: 2 additions & 0 deletions include/nuiWidget.h
Expand Up @@ -510,6 +510,8 @@ class nuiWidget : public nuiObject
bool GetNeedSelfRedraw() const { return mNeedSelfRedraw; }
bool GetNeedIdealRect() const { return mNeedIdealRect; }

virtual float GetScale() const; ///< Return current HDPI scaling
virtual float GetScaleInv() const; ///< Return 1.0/GetScale()
//@}

NUI_GETSET(bool, AutoUpdateLayout);
Expand Down
5 changes: 5 additions & 0 deletions nui3.xcodeproj/project.pbxproj
Expand Up @@ -12246,6 +12246,7 @@
XP_UNIX,
HAVE_FT_FACE_GETCHARVARIANTINDEX,
AVMPLUS_IA32,
NDEBUG,
);
"GCC_PREPROCESSOR_DEFINITIONS[arch=ppc]" = (
NGL_STATIC_BUILD,
Expand All @@ -12258,6 +12259,7 @@
XP_UNIX,
HAVE_FT_FACE_GETCHARVARIANTINDEX,
AVMPLUS_PPC,
NDEBUG,
);
"GCC_PREPROCESSOR_DEFINITIONS[arch=x86_64]" = (
NGL_STATIC_BUILD,
Expand All @@ -12270,6 +12272,7 @@
XP_UNIX,
HAVE_FT_FACE_GETCHARVARIANTINDEX,
AVMPLUS_AMD64,
NDEBUG,
);
"GCC_PREPROCESSOR_DEFINITIONS[sdk=iphoneos*][arch=*]" = (
NGL_STATIC_BUILD,
Expand All @@ -12282,6 +12285,7 @@
XP_UNIX,
HAVE_FT_FACE_GETCHARVARIANTINDEX,
AVMPLUS_ARM,
NDEBUG,
);
"GCC_PREPROCESSOR_DEFINITIONS[sdk=iphonesimulator*]" = (
NGL_STATIC_BUILD,
Expand All @@ -12295,6 +12299,7 @@
XP_UNIX,
HAVE_FT_FACE_GETCHARVARIANTINDEX,
AVMPLUS_IA32,
NDEBUG,
);
GCC_THREADSAFE_STATICS = NO;
GCC_UNROLL_LOOPS = YES;
Expand Down
6 changes: 4 additions & 2 deletions src/Layout/nuiScrollView.cpp
Expand Up @@ -290,9 +290,11 @@ bool nuiScrollView::SetRect(const nuiRect& rRect)
mXOffset = XOffset;
mYOffset = YOffset;
}
const float pixel_size = GetScale();
const float inv_pixel_size = GetScaleInv();

XOffset = (nuiSize)ToNearest(XOffset);
YOffset = (nuiSize)ToNearest(YOffset);
XOffset = (nuiSize)ToNearest(XOffset * pixel_size) * inv_pixel_size;
YOffset = (nuiSize)ToNearest(YOffset * pixel_size) * inv_pixel_size;

GetIdealRect();
nuiRect rIdealRect(mChildrenUnionRect); ///< needed because GetIdealRect may return a UserRect
Expand Down
2 changes: 1 addition & 1 deletion src/Renderers/nuiGL2Painter.cpp
Expand Up @@ -967,7 +967,7 @@ void nuiGL2Painter::SetVertexBuffersPointers(const nuiRenderArray& rArray, Rende

if (bound % 10000 == 0)
{
NGL_OUT("VAO/VBO %lld created %lld bound (%f cache hit)\n", created, bound, (float)bound / (float)created);
NGL_DEBUG(NGL_OUT("VAO/VBO %lld created %lld bound (%f cache hit)\n", created, bound, (float)bound / (float)created););
}

NGL_ASSERT(it != rInfo.mVAOs.end());
Expand Down
10 changes: 10 additions & 0 deletions src/WidgetTree/nuiMainWindow.cpp
Expand Up @@ -1351,4 +1351,14 @@ void nuiMainWindow::DestroyAllWindows()
NGL_ASSERT(mpWindows.empty());
}

float nuiMainWindow::GetScale() const
{
return mpNGLWindow->GetScale();
}

float nuiMainWindow::GetScaleInv() const
{
return mpNGLWindow->GetScaleInv();
}


10 changes: 9 additions & 1 deletion src/WidgetTree/nuiTopLevel.cpp
Expand Up @@ -2593,7 +2593,7 @@ void nuiTopLevel::SetTabBackward(nuiWidget* pSource, nuiWidget* pDestination, bo
// Add the relation to the reverse table (for quick removal when the pointed widget will die)
mTabBackwardRev[pDestination].insert(pSource);

// If needed, added the bacward relation too (so that Tab and then shift-Tab goes back to the original source)
// If needed, added the backward relation too (so that Tab and then shift-Tab goes back to the original source)
if (AutoReverse)
{
SetTabForward(pDestination, pSource, false);
Expand Down Expand Up @@ -2705,5 +2705,13 @@ void nuiTopLevel::DumpGrabMap(int line) const
#endif
}

float nuiTopLevel::GetScale() const
{
return nuiGetScaleFactor();
}

float nuiTopLevel::GetScaleInv() const
{
return nuiGetInvScaleFactor();
}

19 changes: 18 additions & 1 deletion src/WidgetTree/nuiWidget.cpp
Expand Up @@ -2058,7 +2058,7 @@ bool nuiWidget::HasGrab(nglTouchId TouchId)

bool nuiWidget::StealMouseEvent(const nglMouseInfo& rInfo)
{
NGL_OUT("%s/%s (%p) Preempting mouse from existing grabber!\n", GetObjectClass().GetChars(), GetObjectName().GetChars(), this);
NGL_DEBUG(if (GetDebug()) NGL_LOG("widget", NGL_LOG_INFO, "%s/%s (%p) Preempting mouse from existing grabber!\n", GetObjectClass().GetChars(), GetObjectName().GetChars(), this););
nuiTopLevel* pTop = GetTopLevel();
NGL_ASSERT(pTop);
return pTop->StealMouseEvent(this, rInfo);
Expand Down Expand Up @@ -5169,3 +5169,20 @@ void nuiWidget::ClearDefaultDecorations()
{
mDefaultDecorations.clear();
}

float nuiWidget::GetScale() const
{
nuiTopLevel* pTop = GetTopLevel();
if (pTop)
return pTop->GetScale();
return nuiGetScaleFactor();
}

float nuiWidget::GetScaleInv() const
{
nuiTopLevel* pTop = GetTopLevel();
if (pTop)
return pTop->GetScaleInv();
return nuiGetInvScaleFactor();
}

0 comments on commit fec53e2

Please sign in to comment.