Skip to content

Commit

Permalink
Fix fitted rounded boxes + Style tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoam committed May 1, 2015
1 parent b6609d6 commit fbe9850
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 58 deletions.
10 changes: 8 additions & 2 deletions data/interface/styles/blendish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,16 @@ Expandbox :
topdown_gradient : 5,0

ExpandboxHeader :
copy_skin : Label
inherit_skin : Label
background_colour : 0.0,0.0,0.0,0.0
hovered :
background_colour : 0.0,0.0,0.0,0.0
border_colour : 1.0,1.0,1.0,0.3
border_width : 1.0,1.0,1.0,1.0

TreeNodeHeader :
inherit_skin : ExpandboxHeader
activated :
background_colour : 1.0,1.0,1.0,0.3

ColumnHeader :
copy_skin : Label
Expand Down
10 changes: 9 additions & 1 deletion data/interface/styles/blendish_dark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,15 @@ Expandbox :
ExpandboxHeader :
inherit_skin : Label
background_colour : 0.0,0.0,0.0,0.0

hovered :
border_colour : 1.0,1.0,1.0,0.3
border_width : 2.0,2.0,2.0,2.0

TreeNodeHeader :
inherit_skin : ExpandboxHeader
activated :
background_colour : 1.0,1.0,1.0,0.3

ColumnHeader :
inherit_skin : Label
border_colour : 0.275,0.275,0.275,1.0
Expand Down
2 changes: 1 addition & 1 deletion src/Ui/Frame/mkInk.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace mk
class MK_UI_EXPORT Inkbox : public NonCopy
{
public:
Inkbox(Frame& frame) : mFrame(frame), mVisible(frame.visible()), mSelectFirst(0), mSelectSecond(0) {}
Inkbox(Frame& frame) : mFrame(frame), mVisible(false), mSelectFirst(0), mSelectSecond(0) {}
virtual ~Inkbox() {}

Frame& frame() { return mFrame; }
Expand Down
6 changes: 3 additions & 3 deletions src/Ui/Nano/mkGlWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <iostream>

#ifndef KIUI_EMSCRIPTEN
//#define CAP_FRAMERATE
#define CAP_FRAMERATE
#endif

#ifdef CAP_FRAMERATE
Expand Down Expand Up @@ -265,9 +265,9 @@ namespace mk
mNanoWindow->nextFrame(time, delta);

#ifdef CAP_FRAMERATE
double delta = 16.66666667 - ((glfwGetTime() - time) * 1000.f);
double deltaf = 16.66666667 - ((glfwGetTime() - time) * 1000.f);

if(delta > 0.f)
if(deltaf > 0.f)
std::this_thread::sleep_for(std::chrono::milliseconds(int(delta)));
#endif

Expand Down
50 changes: 26 additions & 24 deletions src/Ui/Nano/mkNanoInk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include <cmath>

#include <iostream>

#define NANO_ATLAS

namespace mk
Expand Down Expand Up @@ -45,22 +47,14 @@ namespace mk
return isnan(a) ? b : (isnan(b) ? a : ((a > b) ? a : b));
}

void nvgRoundedBox(NVGcontext *ctx, float x, float y, float w, float h, float cr0, float cr1, float cr2, float cr3)
void nvgRoundedBox(NVGcontext *ctx, float x, float y, float w, float h, float cr0, float cr1, float cr2, float cr3, Dimension fitDim = DIM_0)
{
nvgRoundedRect4(ctx, x, y, w, h, cr0, cr1, cr2, cr3);

/*float d;
w = fmaxf(0, w);
h = fmaxf(0, h);
d = fminf(w, h);
nvgMoveTo(ctx, x, y + h*0.5f);
nvgArcTo(ctx, x, y, x + w, y, cr0);
nvgArcTo(ctx, x + w, y, x + w, y + h, cr1);
nvgArcTo(ctx, x + w, y + h, x, y + h, cr2);
nvgArcTo(ctx, x, y + h, x, y, cr3);
nvgClosePath(ctx);*/
if(fitDim == DIM_0)
nvgRoundedRect4(ctx, x, y, w, h, cr0, cr1, cr2, cr3);
else if(fitDim == DIM_X)
nvgRoundedRect4FitY(ctx, x, y, w, h, cr0, cr1, cr2, cr3);
else if(fitDim == DIM_Y)
nvgRoundedRect4FitX(ctx, x, y, w, h, cr0, cr1, cr2, cr3);
}

NVGcolor nvgColour(const Colour& colour)
Expand All @@ -86,6 +80,7 @@ namespace mk
, mImage(0)
, mOverlay(0)
, mTile(0)
, mFitCorners(DIM_0)
, mImageUpdate(true)
, mTextUpdate(true)
{}
Expand Down Expand Up @@ -135,9 +130,6 @@ namespace mk
{
InkStyle& skin = this->skin();

nvgResetDisplayList(mImageCache);
nvgBindDisplayList(mCtx, mImageCache);

float left = mFrame.cleft();
float top = mFrame.ctop();
float width = mFrame.cwidth();
Expand All @@ -148,6 +140,15 @@ namespace mk
float pwidth = mFrame.pwidth();
float pheight = mFrame.pheight();

float halfb = skin.borderWidth().x0() * 0.5;
float b = skin.borderWidth().x0();

if(width - b <= 0.f || height - b <= 0.f)
return;

nvgResetDisplayList(mImageCache);
nvgBindDisplayList(mCtx, mImageCache);

#if 0 // DEBUG
nvgBeginPath(mCtx);
nvgRect(mCtx, left + 0.5f, top + 0.5f, width - 1.f, height - 1.f);
Expand Down Expand Up @@ -202,15 +203,12 @@ namespace mk
// Rect

nvgBeginPath(mCtx);

float halfb = skin.borderWidth().x0() * 0.5;
float b = skin.borderWidth().x0();
if(mCorners.null())
nvgRect(mCtx, left + halfb, top + halfb, width - b, height - b);
else
nvgRoundedBox(mCtx, left + halfb, top + halfb, width - b, height- b, c0, c1, c2, c3);
nvgRoundedBox(mCtx, left + halfb, top + halfb, width - b, height - b, c0, c1, c2, c3, mFitCorners);

if(skin.backgroundColour().a() != 0.f)
if(skin.backgroundColour().a() > 0.f)
{
if(skin.topdownGradient().null())
{
Expand Down Expand Up @@ -271,7 +269,7 @@ namespace mk
return;

if(!mTextCache)
mTextCache = nvgCreateDisplayList(2);
mTextCache = nvgCreateDisplayList(3);

if(mTextUpdate)
this->redrawText();
Expand Down Expand Up @@ -610,6 +608,8 @@ namespace mk

mCorners.setY0(fmaxf(0.f, parent.mCorners.y0() - (mFrame.parent()->dsize(DIM_X) - (mFrame.dposition(DIM_X) + mFrame.dsize(DIM_X)))));
mCorners.setX1(fmaxf(0.f, parent.mCorners.x1() - (mFrame.parent()->dsize(DIM_X) - (mFrame.dposition(DIM_X) + mFrame.dsize(DIM_X)))));

mFitCorners = DIM_X;
}
else if(mFrame.parent()->layoutDim() == DIM_Y)
{
Expand All @@ -618,6 +618,8 @@ namespace mk

mCorners.setX1(fmaxf(0.f, parent.mCorners.x1() - (mFrame.parent()->dsize(DIM_Y) - (mFrame.dposition(DIM_Y) + mFrame.dsize(DIM_Y)))));
mCorners.setY1(fmaxf(0.f, parent.mCorners.y1() - (mFrame.parent()->dsize(DIM_Y) - (mFrame.dposition(DIM_Y) + mFrame.dsize(DIM_Y)))));

mFitCorners = DIM_Y;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Ui/Nano/mkNanoInk.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace mk
Image* mOverlay;
Image* mTile;
Image* mSkin;
Dimension mFitCorners;
bool mTextUpdate;
bool mImageUpdate;
bool mMoved;
Expand Down
50 changes: 24 additions & 26 deletions src/Ui/Nano/nanovg/nanovg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2555,26 +2555,24 @@ void nvgRoundedRect(NVGcontext* ctx, float x, float y, float w, float h, float r
}

// @kiui
void nvgRoundedFittedRect4(NVGcontext* ctx, float x, float y, float w, float h, float r0, float r1, float r2, float r3)
void nvgRoundedRect4FitX(NVGcontext* ctx, float x, float y, float w, float h, float r0, float r1, float r2, float r3)
{
float wmax = nvg__maxf(r0, r3) + nvg__maxf(r1, r2);
float hmax = nvg__maxf(r0, r1) + nvg__maxf(r2, r3);
float wcrop = wmax - w;
float hcrop = hmax - h;
float hcrop = nvg__maxf(0.f, hmax - h);

if(hcrop > 0.f)
{
w -= hcrop * 2.f;
x += hcrop;
wcrop = wmax - w;
}
w -= hcrop;
x += hcrop / 2.f;

if(wcrop > 0.f)
{
h -= wcrop * 2.f;
y += wcrop;
hcrop = hmax - h;
}
nvgRoundedRect4(ctx, x, y, w, h, r0, r1, r2, r3);
}

void nvgRoundedRect4FitY(NVGcontext* ctx, float x, float y, float w, float h, float r0, float r1, float r2, float r3)
{
float wmax = nvg__maxf(r0, r3) + nvg__maxf(r1, r2);
float wcrop = nvg__maxf(0.f, wmax - w);

h -= wcrop;
y += wcrop / 2.f;

nvgRoundedRect4(ctx, x, y, w, h, r0, r1, r2, r3);
}
Expand All @@ -2583,20 +2581,20 @@ void nvgRoundedRect4(NVGcontext* ctx, float x, float y, float w, float h, float
{
float wmax = nvg__maxf(r0, r3) + nvg__maxf(r1, r2);
float hmax = nvg__maxf(r0, r1) + nvg__maxf(r2, r3);
float wcrop = wmax - w;
float hcrop = hmax - h;
float wcrop = nvg__maxf(0.f, wmax - w);
float hcrop = nvg__maxf(0.f, hmax - h);

float r0h = r0 - ((hcrop > 0.f) ? hcrop * r0 / hmax : 0.f);
float r0w = r0 - ((wcrop > 0.f) ? wcrop * r0 / wmax : 0.f);
float r0h = r0 - (hcrop * r0 / hmax);
float r0w = r0 - (wcrop * r0 / wmax);

float r1h = r1 - ((hcrop > 0.f) ? hcrop * r1 / hmax : 0.f);
float r1w = r1 - ((wcrop > 0.f) ? wcrop * r1 / wmax : 0.f);
float r1h = r1 - (hcrop * r1 / hmax);
float r1w = r1 - (wcrop * r1 / wmax);

float r2h = r2 - ((hcrop > 0.f) ? hcrop * r2 / hmax : 0.f);
float r2w = r2 - ((wcrop > 0.f) ? wcrop * r2 / wmax : 0.f);
float r2h = r2 - (hcrop * r2 / hmax);
float r2w = r2 - (wcrop * r2 / wmax);

float r3h = r3 - ((hcrop > 0.f) ? hcrop * r3 / hmax : 0.f);
float r3w = r3 - ((wcrop > 0.f) ? wcrop * r3 / wmax : 0.f);
float r3h = r3 - (hcrop * r3 / hmax);
float r3w = r3 - (wcrop * r3 / wmax);

float vals[] = {
NVG_MOVETO, x, y + r0h,
Expand Down
3 changes: 2 additions & 1 deletion src/Ui/Nano/nanovg/nanovg.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ void nvgRoundedRect(NVGcontext* ctx, float x, float y, float w, float h, float r

// @kiui
void nvgRoundedRect4(NVGcontext* ctx, float x, float y, float w, float h, float r0, float r1, float r2, float r3);
void nvgRoundedFittedRect4(NVGcontext* ctx, float x, float y, float w, float h, float r0, float r1, float r2, float r3);
void nvgRoundedRect4FitX(NVGcontext* ctx, float x, float y, float w, float h, float r0, float r1, float r2, float r3);
void nvgRoundedRect4FitY(NVGcontext* ctx, float x, float y, float w, float h, float r0, float r1, float r2, float r3);

// Creates new ellipse shaped sub-path.
void nvgEllipse(NVGcontext* ctx, float cx, float cy, float rx, float ry);
Expand Down

0 comments on commit fbe9850

Please sign in to comment.