Created
November 2, 2013 03:02
-
-
Save rikkimax/7274981 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 330 | |
uniform int win_Height; | |
uniform int win_Width; | |
uniform int com_Height; | |
uniform int com_Width; | |
uniform int com_X; | |
uniform int com_Y; | |
uniform int com_Count; | |
uniform vec4 borderColor; | |
uniform vec4 backgroundColor; | |
out vec4 outColor; | |
void main(){ | |
outColor = gl_FragCoord; | |
float x = gl_FragCoord.x; | |
float y = gl_FragCoord.y; | |
bool component = x > com_X && x < com_X + com_Width && | |
y > win_Height - com_Y && y < (win_Height - com_Y) + com_Height; | |
if (component) { | |
float rlx = x - com_X; // left x base coord | |
float rrx = com_Width - rlx; | |
float rty = ((win_Height - com_Y) + com_Height) - y; // top y base coord | |
float rby = com_Height - rty; // bottom y base coord | |
float borderWidth = ((com_Height + com_Width) * 2f) / 100f; | |
float borderWidth2 = borderWidth * 2; | |
//draws a border | |
if (rlx < borderWidth && rty < borderWidth) { // outer top left | |
float d = distance(vec2(rlx, rty), vec2(borderWidth, borderWidth)); | |
if (d <= borderWidth) { | |
outColor = borderColor; | |
} | |
} else if (rlx < borderWidth2 && rty < borderWidth2) { // inner top left | |
float d = distance(vec2(rlx, rty), vec2(borderWidth2, borderWidth2)); | |
if (d >= borderWidth) { | |
outColor = borderColor; | |
} else { | |
outColor = backgroundColor; | |
} | |
} else if (rrx < borderWidth && rty < borderWidth) { // outer top right | |
float d = distance(vec2(rrx, rty), vec2(borderWidth, borderWidth)); | |
if (d <= borderWidth) { | |
outColor = borderColor; | |
} | |
} else if (rrx < borderWidth2 && rty < borderWidth2) { // inner top right | |
float d = distance(vec2(rrx, rty), vec2(borderWidth2, borderWidth2)); | |
if (d >= borderWidth) { | |
outColor = borderColor; | |
} else { | |
outColor = backgroundColor; | |
} | |
} else if (rlx < borderWidth && rby < borderWidth) { // outer bottom left | |
float d = distance(vec2(rlx, rby), vec2(borderWidth, borderWidth)); | |
if (d <= borderWidth) { | |
outColor = borderColor; | |
} | |
} else if (rlx < borderWidth2 && rby < borderWidth2) { // inner bottom left | |
float d = distance(vec2(rlx, rby), vec2(borderWidth2, borderWidth2)); | |
if (d >= borderWidth) { | |
outColor = borderColor; | |
} else { | |
outColor = backgroundColor; | |
} | |
} else if (rrx < borderWidth && rby < borderWidth) { // outer bottom right | |
float d = distance(vec2(rrx, rby), vec2(borderWidth, borderWidth)); | |
if (d <= borderWidth) { | |
outColor = borderColor; | |
} | |
} else if (rrx < borderWidth2 && rby < borderWidth2) { // inner bottom right | |
float d = distance(vec2(rrx, rby), vec2(borderWidth2, borderWidth2)); | |
if (d >= borderWidth) { | |
outColor = borderColor; | |
} else { | |
outColor = backgroundColor; | |
} | |
} else if (rlx > borderWidth / 1.3 && rty > borderWidth / 1.3 && rrx > borderWidth / 1.3 && rby > borderWidth / 1.3) { | |
// now with the content area | |
outColor = backgroundColor; | |
} else { | |
outColor = borderColor; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment