Browse Source

Fix up widget bounds within the window

gh-pages
falkTX 11 years ago
parent
commit
b4146e6121
5 changed files with 36 additions and 3 deletions
  1. +7
    -1
      dgl/NanoVG.hpp
  2. +6
    -0
      dgl/Widget.hpp
  3. +5
    -0
      dgl/src/NanoVG.cpp
  4. +2
    -1
      dgl/src/Widget.cpp
  5. +16
    -1
      dgl/src/Window.cpp

+ 7
- 1
dgl/NanoVG.hpp View File

@@ -279,7 +279,6 @@ public:
return fContext; return fContext;
} }


protected:
/** /**
Begin drawing a new frame. Begin drawing a new frame.
@param withAlha Controls if drawing the shapes to the render target should be done using straight or pre-multiplied alpha. @param withAlha Controls if drawing the shapes to the render target should be done using straight or pre-multiplied alpha.
@@ -695,6 +694,13 @@ protected:
*/ */
void textAlign(Align align); void textAlign(Align align);


/**
Sets the text align of current text style.
Overloaded function for convenience.
@see Align
*/
void textAlign(int align);

/** /**
Sets the font face based on specified id of current text style. Sets the font face based on specified id of current text style.
*/ */


+ 6
- 0
dgl/Widget.hpp View File

@@ -296,6 +296,12 @@ protected:
*/ */
virtual void onResize(const ResizeEvent&); virtual void onResize(const ResizeEvent&);


/**
Wherever the Y position is inverted.
(starts at the bottom)
*/
bool fInvertedY;

private: private:
Window& fParent; Window& fParent;
bool fVisible; bool fVisible;


+ 5
- 0
dgl/src/NanoVG.cpp View File

@@ -529,6 +529,11 @@ void NanoVG::textAlign(NanoVG::Align align)
nvgTextAlign(fContext, align); nvgTextAlign(fContext, align);
} }


void NanoVG::textAlign(int align)
{
nvgTextAlign(fContext, align);
}

void NanoVG::fontFaceId(FontId font) void NanoVG::fontFaceId(FontId font)
{ {
nvgFontFaceId(fContext, font); nvgFontFaceId(fContext, font);


+ 2
- 1
dgl/src/Widget.cpp View File

@@ -23,7 +23,8 @@ START_NAMESPACE_DGL
// Widget // Widget


Widget::Widget(Window& parent) Widget::Widget(Window& parent)
: fParent(parent),
: fInvertedY(false),
fParent(parent),
fVisible(true) fVisible(true)
{ {
fParent._addWidget(this); fParent._addWidget(this);


+ 16
- 1
dgl/src/Window.cpp View File

@@ -575,8 +575,23 @@ struct Window::PrivateData {


if (widget->isVisible()) if (widget->isVisible())
{ {
glViewport(widget->getAbsoluteX(), -widget->getAbsoluteY(), fView->width, fView->height);
const int ypos = widget->fInvertedY ? fView->height - widget->getHeight() - widget->getAbsoluteY() : widget->getAbsoluteY();

// reset color
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

// limit viewport to widget bounds
glViewport(widget->getAbsoluteX(), ypos, widget->getWidth(), widget->getHeight());

// need scale contents to match viewport
glPushMatrix();
glScalef(float(fView->width)/float(widget->getWidth()), float(fView->height)/float(widget->getHeight()), 1.0f);

// display widget
widget->onDisplay(); widget->onDisplay();

// pop
glPopMatrix();
} }
} }




Loading…
Cancel
Save