Skip to content

Commit

Permalink
Fix sticking out border in curved resize mode (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Mar 1, 2019
1 parent c5fb399 commit aa1bb8c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/src/main/cpp/Cylinder.cpp
Expand Up @@ -281,6 +281,15 @@ Cylinder::GetCylinderTheta() const {
return m.theta;
}

vrb::RenderStatePtr
Cylinder::GetRenderState() const {
if (m.geometry) {
return m.geometry->GetRenderState();
}

return nullptr;
}

void
Cylinder::SetCylinderTheta(const float aAngleLength) {
m.theta = aAngleLength;
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/Cylinder.h
Expand Up @@ -38,6 +38,7 @@ class Cylinder {
float GetCylinderRadius() const;
float GetCylinderHeight() const;
float GetCylinderTheta() const;
vrb::RenderStatePtr GetRenderState() const;
void SetCylinderTheta(const float aAngleLength);
void SetTintColor(const vrb::Color& aColor);
vrb::NodePtr GetRoot() const;
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/cpp/WidgetResizer.cpp
Expand Up @@ -15,6 +15,7 @@
#include "vrb/Geometry.h"
#include "vrb/RenderState.h"
#include "vrb/SurfaceTextureFactory.h"
#include "vrb/TextureGL.h"
#include "vrb/TextureSurface.h"
#include "vrb/Toggle.h"
#include "vrb/Transform.h"
Expand All @@ -23,6 +24,23 @@

namespace crow {

static const char* sCylinderFragmentShader = R"SHADER(
precision highp float;
uniform sampler2D u_texture0;
varying vec4 v_color;
varying vec2 v_uv;
void main() {
vec4 color = vec4(1.0f, 1.0f, 1.0f, 1.0f);
if ((v_uv.x < 0.0f) || (v_uv.x > 1.0f)) {
color.a = 0.0f;
}
gl_FragColor = color * v_color;
}
)SHADER";

struct ResizeBar;

typedef std::shared_ptr<ResizeBar> ResizeBarPtr;
Expand Down Expand Up @@ -74,6 +92,12 @@ struct ResizeBar {
if (aMode == ResizeBar::Mode::Cylinder) {
result->cylinder = Cylinder::Create(aContext, 1.0f, kBarSize, vrb::Color(1.0f, 1.0f, 1.0f, 1.0f), kBorder, vrb::Color(1.0f, 1.0f, 1.0f, 0.0f));
result->cylinder->SetLightsEnabled(false);
if (aScale.x() == 1.0f) {
// Fix sticking out border at the bottom of the resize bar (No handles to hide it...)
vrb::TextureGLPtr defaultTexture = aContext->GetDefaultTexture();
result->cylinder->SetTexture(defaultTexture, defaultTexture->GetWidth(), defaultTexture->GetHeight());
result->cylinder->GetRenderState()->SetCustomFragmentShader(sCylinderFragmentShader);
}
result->transform->AddNode(result->cylinder->GetRoot());
} else {
result->geometry = CreateGeometry(aContext, -max, max, aBorder);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/vrb

0 comments on commit aa1bb8c

Please sign in to comment.