Added icon under zoom/speed indicator bar

This commit is contained in:
Marc Gilleron 2017-10-15 21:20:51 +02:00
parent 0c9d201044
commit 59e6a27da1
3 changed files with 234 additions and 24 deletions

View file

@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="24"
height="24"
version="1.1"
viewBox="0 0 24 24"
id="svg2"
inkscape:version="0.91 r13725"
sodipodi:docname="icon_viewport_speed.svg">
<metadata
id="metadata12">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs10" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1017"
id="namedview8"
showgrid="true"
inkscape:zoom="55.837564"
inkscape:cx="12.355509"
inkscape:cy="13.455858"
inkscape:window-x="-8"
inkscape:window-y="32"
inkscape:window-maximized="1"
inkscape:current-layer="g4">
<inkscape:grid
type="xygrid"
id="grid4196" />
</sodipodi:namedview>
<g
transform="translate(0,-1028.4)"
id="g4">
<circle
style="fill:#e0e0e0;fill-opacity:0.99607843;stroke:#000000;stroke-width:1.02133572;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path4150"
cy="1033.9"
cx="16.5"
r="2.9893322" />
<rect
y="1031.4"
x="5"
height="0.99997556"
width="7"
id="rect4188"
style="fill:#000000;fill-opacity:0.99607843;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<rect
style="fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.99607843"
id="rect4178"
width="7"
height="1.0000244"
x="5"
y="1030.4" />
<rect
y="1035.4"
x="1"
height="0.99997556"
width="6"
id="rect4190"
style="fill:#000000;fill-opacity:0.99607843;stroke:none;stroke-width:0.98120075;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<rect
style="fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:0.98308611;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.99607843"
id="rect4180"
width="6"
height="0.99997556"
x="1"
y="1034.4" />
<rect
y="1042.4"
x="2"
height="1.0000244"
width="7"
id="rect4192"
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:1;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<rect
style="fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:1;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.99607843"
id="rect4182"
width="7"
height="0.99997556"
x="2"
y="1041.4" />
<path
style="fill:#e0e0e0;fill-opacity:0.99607843;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 4.121611,1045.8307 -0.1638725,2.0132 6.1803345,0.6321 2.865785,-3.8285 3.825066,1.2671 -1.634214,3.6617 1.802597,0.9365 2.751611,-5.7254 -5.323873,-2.3187 1.381211,-2.6534 2.589918,2.1082 4.477133,-2.2965 -0.976935,-1.5052 -3.180386,1.3802 -3.253887,-2.6678 -4.922628,-2.5117 -3.6554378,3.6189 1.4307035,1.5154 2.4736963,-2.3877 2.012407,0.9882 -1.262113,3.517 -2.5945824,4.631 z"
id="path4186"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccccccccccccccccccccc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="24"
height="24"
version="1.1"
viewBox="0 0 24 24"
id="svg2"
inkscape:version="0.91 r13725"
sodipodi:docname="icon_viewport_zoom.svg">
<metadata
id="metadata12">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs10" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1017"
id="namedview8"
showgrid="true"
inkscape:zoom="32"
inkscape:cx="12.62433"
inkscape:cy="11.793762"
inkscape:window-x="-8"
inkscape:window-y="32"
inkscape:window-maximized="1"
inkscape:current-layer="g4">
<inkscape:grid
type="xygrid"
id="grid4798" />
</sodipodi:namedview>
<g
transform="translate(0,-1028.4)"
id="g4">
<path
d="m 8.9917563,1029.9083 a 7.4877313,7.4846399 0 0 0 -7.4877312,7.4847 7.4877313,7.4846399 0 0 0 7.4877312,7.4847 7.4877313,7.4846399 0 0 0 4.1240927,-1.2455 l 6.464009,6.4613 2.11768,-2.1168 -6.464008,-6.4613 a 7.4877313,7.4846399 0 0 0 1.246002,-4.1224 7.4877313,7.4846399 0 0 0 -7.4877307,-7.4847 z m 0,2.9939 a 4.4926389,4.4907841 0 0 1 4.4926387,4.4908 4.4926389,4.4907841 0 0 1 -4.4926387,4.4909 4.4926389,4.4907841 0 0 1 -4.4926386,-4.4909 4.4926389,4.4907841 0 0 1 4.4926386,-4.4908 z"
id="path6"
style="fill:#e0e0e0;fill-opacity:0.99607999;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
inkscape:connector-curvature="0" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -2095,7 +2095,7 @@ void SpatialEditorViewport::_notification(int p_what) {
}
// TODO That should be part of the drawing API...
static void stroke_rect(CanvasItem *ci, Rect2 rect, Color color, real_t width = 1.0) {
static void stroke_rect(CanvasItem &ci, Rect2 rect, Color color, real_t width = 1.0) {
// a---b
// | |
@ -2105,10 +2105,31 @@ static void stroke_rect(CanvasItem *ci, Rect2 rect, Color color, real_t width =
Vector2 c(rect.position.x, rect.position.y + rect.size.y);
Vector2 d(rect.position + rect.size);
ci->draw_line(a, b, color, width);
ci->draw_line(b, d, color, width);
ci->draw_line(d, c, color, width);
ci->draw_line(c, a, color, width);
ci.draw_line(a, b, color, width);
ci.draw_line(b, d, color, width);
ci.draw_line(d, c, color, width);
ci.draw_line(c, a, color, width);
}
static void draw_indicator_bar(Control &surface, real_t fill, Ref<Texture> icon) {
// Adjust bar size from control height
Vector2 surface_size = surface.get_size();
real_t h = surface_size.y / 2.0;
real_t y = (surface_size.y - h) / 2.0;
Rect2 r(10, y, 6, h);
real_t sy = r.size.y * fill;
// Note: because this bar appears over the viewport, it has to stay readable for any background color
// Draw both neutral dark and bright colors to account this
surface.draw_rect(r, Color(1, 1, 1, 0.2));
surface.draw_rect(Rect2(r.position.x, r.position.y + r.size.y - sy, r.size.x, sy), Color(1, 1, 1, 0.6));
stroke_rect(surface, r.grow(1), Color(0, 0, 0, 0.7));
Vector2 icon_size = icon->get_size();
Vector2 icon_pos = Vector2(r.position.x - (icon_size.x - r.size.x) / 2, r.position.y + r.size.y + 2);
surface.draw_texture(icon, icon_pos);
}
void SpatialEditorViewport::_draw() {
@ -2167,35 +2188,47 @@ void SpatialEditorViewport::_draw() {
draw_rect = Rect2(Vector2(), s).clip(draw_rect);
stroke_rect(surface, draw_rect, Color(0.6, 0.6, 0.1, 0.5), 2.0);
stroke_rect(*surface, draw_rect, Color(0.6, 0.6, 0.1, 0.5), 2.0);
} else {
if (zoom_indicator_delay > 0.0) {
// Show indicative zoom factor
real_t min_distance = ZOOM_MIN_DISTANCE; // TODO Why not pick znear to limit zoom?
real_t max_distance = camera->get_zfar();
real_t scale_length = (max_distance - min_distance);
if (is_freelook_active()) {
// Show speed
if (Math::abs(scale_length) > CMP_EPSILON) {
real_t logscale_t = 1.0 - Math::log(1 + cursor.distance - min_distance) / Math::log(1 + scale_length);
real_t min_speed = FREELOOK_MIN_SPEED;
real_t max_speed = camera->get_zfar();
real_t scale_length = (max_speed - min_speed);
// There is no real maximum distance so that factor can become negative,
// Let's make it look asymptotic instead (will decrease slower and slower).
if (logscale_t < 0.25)
logscale_t = 0.25 * Math::exp(4.0 * logscale_t - 1.0);
if (Math::abs(scale_length) > CMP_EPSILON) {
real_t logscale_t = 1.0 - Math::log(1 + freelook_speed - min_speed) / Math::log(1 + scale_length);
Vector2 surface_size = surface->get_size();
real_t h = surface_size.y / 2.0;
real_t y = (surface_size.y - h) / 2.0;
// There is no real maximum speed so that factor can become negative,
// Let's make it look asymptotic instead (will decrease slower and slower).
if (logscale_t < 0.25)
logscale_t = 0.25 * Math::exp(4.0 * logscale_t - 1.0);
Rect2 r(10, y, 6, h);
real_t sy = r.size.y * logscale_t;
draw_indicator_bar(*surface, 1.0 - logscale_t, get_icon("ViewportSpeed", "EditorIcons"));
}
surface->draw_rect(r, Color(1, 1, 1, 0.2));
surface->draw_rect(Rect2(r.position.x, r.position.y + r.size.y - sy, r.size.x, sy), Color(1, 1, 1, 0.6));
stroke_rect(surface, r.grow(1), Color(0, 0, 0, 0.7));
} else {
// Show zoom
real_t min_distance = ZOOM_MIN_DISTANCE; // TODO Why not pick znear to limit zoom?
real_t max_distance = camera->get_zfar();
real_t scale_length = (max_distance - min_distance);
if (Math::abs(scale_length) > CMP_EPSILON) {
real_t logscale_t = 1.0 - Math::log(1 + cursor.distance - min_distance) / Math::log(1 + scale_length);
// There is no real maximum distance so that factor can become negative,
// Let's make it look asymptotic instead (will decrease slower and slower).
if (logscale_t < 0.25)
logscale_t = 0.25 * Math::exp(4.0 * logscale_t - 1.0);
draw_indicator_bar(*surface, logscale_t, get_icon("ViewportZoom", "EditorIcons"));
}
}
}
}