From 02661843deee4b8457e0246a693f9c689218009b Mon Sep 17 00:00:00 2001 From: jp9000 Date: Wed, 30 Mar 2016 18:44:49 -0700 Subject: [PATCH] UI: Draw cropped scene item edges as green in preview --- obs/window-basic-main.cpp | 24 ++++++++++++++++++++++++ obs/window-basic-main.hpp | 4 ++++ obs/window-basic-preview.cpp | 30 +++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index eaba4c3ea..87476592f 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -862,6 +862,26 @@ void OBSBasic::InitPrimitives() gs_vertex2f(0.0f, 0.0f); box = gs_render_save(); + gs_render_start(true); + gs_vertex2f(0.0f, 0.0f); + gs_vertex2f(0.0f, 1.0f); + boxLeft = gs_render_save(); + + gs_render_start(true); + gs_vertex2f(0.0f, 0.0f); + gs_vertex2f(1.0f, 0.0f); + boxTop = gs_render_save(); + + gs_render_start(true); + gs_vertex2f(1.0f, 0.0f); + gs_vertex2f(1.0f, 1.0f); + boxRight = gs_render_save(); + + gs_render_start(true); + gs_vertex2f(0.0f, 1.0f); + gs_vertex2f(1.0f, 1.0f); + boxBottom = gs_render_save(); + gs_render_start(true); for (int i = 0; i <= 360; i += (360/20)) { float pos = RAD(float(i)); @@ -1279,6 +1299,10 @@ OBSBasic::~OBSBasic() obs_enter_graphics(); gs_vertexbuffer_destroy(box); + gs_vertexbuffer_destroy(boxLeft); + gs_vertexbuffer_destroy(boxTop); + gs_vertexbuffer_destroy(boxRight); + gs_vertexbuffer_destroy(boxBottom); gs_vertexbuffer_destroy(circle); obs_leave_graphics(); diff --git a/obs/window-basic-main.hpp b/obs/window-basic-main.hpp index 177d145ac..7d3dc6773 100644 --- a/obs/window-basic-main.hpp +++ b/obs/window-basic-main.hpp @@ -113,6 +113,10 @@ private: std::unique_ptr outputHandler; gs_vertbuffer_t *box = nullptr; + gs_vertbuffer_t *boxLeft = nullptr; + gs_vertbuffer_t *boxTop = nullptr; + gs_vertbuffer_t *boxRight = nullptr; + gs_vertbuffer_t *boxBottom = nullptr; gs_vertbuffer_t *circle = nullptr; bool sceneChanging = false; diff --git a/obs/window-basic-preview.cpp b/obs/window-basic-preview.cpp index 3f92a3169..5a6ea6f8a 100644 --- a/obs/window-basic-preview.cpp +++ b/obs/window-basic-preview.cpp @@ -747,12 +747,36 @@ bool OBSBasicPreview::DrawSelectedItem(obs_scene_t *scene, DrawCircleAtPos(0.5f, 1.0f, boxTransform, main->previewScale); DrawCircleAtPos(1.0f, 0.5f, boxTransform, main->previewScale); - gs_load_vertexbuffer(main->box); - gs_matrix_push(); gs_matrix_scale3f(main->previewScale, main->previewScale, 1.0f); gs_matrix_mul(&boxTransform); - gs_draw(GS_LINESTRIP, 0, 0); + + obs_sceneitem_crop crop; + obs_sceneitem_get_crop(item, &crop); + + if (info.bounds_type == OBS_BOUNDS_NONE && crop_enabled(&crop)) { + vec4 color; + gs_effect_t *eff = gs_get_effect(); + gs_eparam_t *param = gs_effect_get_param_by_name(eff, "color"); + +#define DRAW_SIDE(side, vb) \ + if (crop.side > 0) \ + vec4_set(&color, 0.0f, 1.0f, 0.0f, 1.0f); \ + else \ + vec4_set(&color, 1.0f, 0.0f, 0.0f, 1.0f); \ + gs_effect_set_vec4(param, &color); \ + gs_load_vertexbuffer(main->vb); \ + gs_draw(GS_LINESTRIP, 0, 0); + + DRAW_SIDE(left, boxLeft); + DRAW_SIDE(top, boxTop); + DRAW_SIDE(right, boxRight); + DRAW_SIDE(bottom, boxBottom); +#undef DRAW_SIDE + } else { + gs_load_vertexbuffer(main->box); + gs_draw(GS_LINESTRIP, 0, 0); + } gs_matrix_pop();