Skip to content

Commit

Permalink
Added background type drawing.
Browse files Browse the repository at this point in the history
Fixed network error.
  • Loading branch information
ggarra13 committed Oct 13, 2023
1 parent 01129bd commit 1df09ce
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 51 deletions.
2 changes: 2 additions & 0 deletions mrv2/docs/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ v0.8.0
- Fixed missing frames (Repeat Last and Repeat Scratched) when the user was
reading a different layer and he was playing backwards or stepping through
the frames.
- Added drawing background transparent, solid or checkers.
- Fixed a network error (harmless) about edit mode.
- Some UI fixes:
* The Zoom factor in the Pixel Toolbar keeps its value when selecting
it from the pulldown.
Expand Down
6 changes: 4 additions & 2 deletions mrv2/lib/mrvEdit/mrvEditCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2082,8 +2082,10 @@ namespace mrv

if (mode != EditMode::kNone)
{
Message msg = {
{"command", "setEditMode"}, {"value", mode}, {"height", H}};
Message msg;
msg["command"] = "setEditMode";
msg["value"] = mode;
msg["height"] = H;
tcp->pushMessage(msg);
}

Expand Down
1 change: 1 addition & 0 deletions mrv2/lib/mrvEdit/mrvEditMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ namespace mrv

TLRENDER_ENUM_IMPL(EditMode, "None", "Timeline", "Saved", "Full");
TLRENDER_ENUM_SERIALIZE_IMPL(EditMode);

} // namespace mrv
30 changes: 26 additions & 4 deletions mrv2/lib/mrvFl/mrvCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1547,13 +1547,35 @@ namespace mrv
fl_open_uri(docs.c_str());
}

void toggle_black_background_cb(Fl_Menu_* m, ViewerUI* ui)
void transparent_background_cb(Fl_Menu_* m, ViewerUI* ui)
{
timeline::BackgroundOptions options =
ui->uiView->getBackgroundOptions();
const Fl_Menu_Item* item = m->mvalue();
if (item->checked())
options.type = timeline::Background::Transparent;
ui->uiView->setBackgroundOptions(options);
}

void solid_background_cb(Fl_Menu_* m, ViewerUI* ui)
{
timeline::BackgroundOptions options =
ui->uiView->getBackgroundOptions();
const Fl_Menu_Item* item = m->mvalue();
if (item->checked())
options.type = timeline::Background::Solid;
ui->uiView->setBackgroundOptions(options);
}

void checkers_background_cb(Fl_Menu_* m, ViewerUI* ui)
{
timeline::BackgroundOptions options =
ui->uiView->getBackgroundOptions();
bool value = true;
const Fl_Menu_Item* item = m->mvalue();
if (!item->checked())
value = false;
ui->uiView->setBlackBackground(value);
if (item->checked())
options.type = timeline::Background::Checkers;
ui->uiView->setBackgroundOptions(options);
}

void toggle_annotation_cb(Fl_Menu_* m, ViewerUI* ui)
Expand Down
6 changes: 4 additions & 2 deletions mrv2/lib/mrvFl/mrvCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ namespace mrv
//! Call the browser with documentation.
void help_documentation_cb(Fl_Menu_*, ViewerUI* ui);

//! Make background black or default gray.
void toggle_black_background_cb(Fl_Menu_* m, ViewerUI* ui);
//! Make background transparent (gray), black or checkers.
void transparent_background_cb(Fl_Menu_* m, ViewerUI* ui);
void solid_background_cb(Fl_Menu_* m, ViewerUI* ui);
void checkers_background_cb(Fl_Menu_* m, ViewerUI* ui);

// Netowrk toggles
void toggle_sync_send_cb(Fl_Menu_* m, ViewerUI* ui);
Expand Down
11 changes: 10 additions & 1 deletion mrv2/lib/mrvFl/mrvSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
namespace
{
const char* kModule = "mrv2s";
const int kSessionVersion = 7;
const int kSessionVersion = 8;
} // namespace

namespace
Expand Down Expand Up @@ -281,6 +281,7 @@ namespace mrv
Message compare = model->observeCompareOptions()->get();
Message stereo = model->observeStereo3DOptions()->get();
Message environmentMap = ui->uiView->getEnvironmentMapOptions();
Message background = ui->uiView->getBackgroundOptions();
int stereoIndex = model->observeStereoIndex()->get();

session["ui"] = bars;
Expand All @@ -293,6 +294,7 @@ namespace mrv
session["stereo3DOptions"] = stereo;
session["stereoIndex"] = stereoIndex;
session["environmentMapOptions"] = environmentMap;
session["backgroundOptions"] = background;
session["displayOptions"] = display;
session["editMode"] = editMode;
session["metadata"] = sessionMetadata;
Expand Down Expand Up @@ -597,6 +599,13 @@ namespace mrv
session["metadata"].get_to(sessionMetadata);
}

if (version >= 8)
{
timeline::BackgroundOptions background =
session["backgroundOptions"];
view->setBackgroundOptions(background);
}

enable_cypher(true);
ui->uiMain->fill_menu(ui->uiMenuBar);

Expand Down
34 changes: 24 additions & 10 deletions mrv2/lib/mrvGL/mrvGLViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ namespace mrv
CHECK_GL;

StoreLocale;

gl.render->begin(
renderSize, p.colorConfigOptions, p.lutOptions);
CHECK_GL;
Expand Down Expand Up @@ -318,20 +319,31 @@ namespace mrv
CHECK_GL;

float r = 0.F, g = 0.F, b = 0.F, a = 1.F;
if (!p.presentation && !p.blackBackground)
if (!p.presentation)
{
uint8_t ur, ug, ub;
Fl::get_color(p.ui->uiPrefs->uiPrefsViewBG->color(), ur, ug, ub);
r = ur / 255.0f;
g = ug / 255.0f;
b = ub / 255.0f;
switch (p.backgroundOptions.type)
{
case timeline::Background::Solid:
p.backgroundOptions.solidColor =
image::Color4f(0.F, 0.F, 0.F, 1.F);
break;
case timeline::Background::Transparent:
{
uint8_t ur, ug, ub;
Fl::get_color(
p.ui->uiPrefs->uiPrefsViewBG->color(), ur, ug, ub);
r = ur / 255.0f;
g = ug / 255.0f;
b = ub / 255.0f;
p.backgroundOptions.solidColor = image::Color4f(r, g, b, a);
break;
}
default:
break;
}
}

#ifdef USE_GL_DOUBLE
glDrawBuffer(GL_BACK_LEFT);
#else
glDrawBuffer(GL_FRONT_LEFT);
#endif
CHECK_GL;
glClearColor(r, g, b, a);
CHECK_GL;
Expand All @@ -340,6 +352,8 @@ namespace mrv

if (gl.buffer && gl.shader)
{
_drawBackground();

math::Matrix4x4f mvp;

if (p.environmentMapOptions.type != EnvironmentMapOptions::kNone)
Expand Down
2 changes: 2 additions & 0 deletions mrv2/lib/mrvGL/mrvGLViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ namespace mrv

void _drawHelpText() const noexcept;

void _drawBackground() const noexcept;

void _drawRectangleOutline(
const math::Box2i& box, const image::Color4f& color,
const math::Matrix4x4f& mvp) const noexcept;
Expand Down
37 changes: 37 additions & 0 deletions mrv2/lib/mrvGL/mrvGLViewportDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// mrv2
// Copyright Contributors to the mrv2 Project. All rights reserved.

#include <tlUI/DrawUtil.h>
#include <tlGL/Util.h>

#include "mrvCore/mrvLocale.h"
Expand Down Expand Up @@ -1164,4 +1165,40 @@ namespace mrv
gl.render->end();
}

void Viewport::_drawBackground() const noexcept
{
MRV2_GL();
TLRENDER_P();
if (p.timelinePlayers.empty())
return;
const auto& viewportSize = getViewportSize();

timeline::RenderOptions renderOptions;
renderOptions.clear = false;

gl.render->begin(
viewportSize, timeline::ColorConfigOptions(),
timeline::LUTOptions(), renderOptions);

switch (p.backgroundOptions.type)
{
case timeline::Background::Solid:
gl.render->clearViewport(p.backgroundOptions.solidColor);
break;
case timeline::Background::Checkers:
gl.render->clearViewport(image::Color4f(0.F, 0.F, 0.F));
gl.render->drawColorMesh(
ui::checkers(
math::Box2i(0, 0, viewportSize.w, viewportSize.h),
p.backgroundOptions.checkersColor0,
p.backgroundOptions.checkersColor1,
p.backgroundOptions.checkersSize),
math::Vector2i(), image::Color4f(1.F, 1.F, 1.F));
break;
default:
break;
}

gl.render->end();
}
} // namespace mrv
33 changes: 21 additions & 12 deletions mrv2/lib/mrvGL/mrvTimelineViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace mrv
{
using namespace tl;

timeline::BackgroundOptions TimelineViewport::Private::backgroundOptions;
EnvironmentMapOptions TimelineViewport::Private::environmentMapOptions;
math::Box2i TimelineViewport::Private::selection =
math::Box2i(0, 0, -1, -1);
Expand All @@ -58,7 +59,6 @@ namespace mrv
bool TimelineViewport::Private::safeAreas = false;
bool TimelineViewport::Private::dataWindow = false;
bool TimelineViewport::Private::displayWindow = false;
bool TimelineViewport::Private::blackBackground = false;
std::string TimelineViewport::Private::helpText;
float TimelineViewport::Private::helpTextFade;
bool TimelineViewport::Private::hudActive = true;
Expand Down Expand Up @@ -430,6 +430,26 @@ namespace mrv
return _p->colorConfigOptions;
}

const timeline::BackgroundOptions&
TimelineViewport::getBackgroundOptions() const noexcept
{
return _p->backgroundOptions;
}

void TimelineViewport::setBackgroundOptions(
const timeline::BackgroundOptions& value)
{
TLRENDER_P();
if (value == p.backgroundOptions)
return;
Message msg;
msg["command"] = "setBackgroundOptions";
msg["value"] = value;
tcp->pushMessage(msg);
p.backgroundOptions = value;
redrawWindows();
}

void TimelineViewport::setColorConfigOptions(
const timeline::ColorConfigOptions& value) noexcept
{
Expand Down Expand Up @@ -1704,17 +1724,6 @@ namespace mrv
Fl::flush(); // force the redraw
}

bool TimelineViewport::getBlackBackground() const noexcept
{
return _p->blackBackground;
}

void TimelineViewport::setBlackBackground(bool active) noexcept
{
_p->blackBackground = active;
redrawWindows();
}

bool TimelineViewport::getPresentationMode() const noexcept
{
return _p->presentation;
Expand Down
14 changes: 8 additions & 6 deletions mrv2/lib/mrvGL/mrvTimelineViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include <tlTimeline/BackgroundOptions.h>
#include <tlTimeline/IRender.h>

#include "mrvCore/mrvStereo3DOptions.h"
Expand Down Expand Up @@ -85,6 +86,13 @@ namespace mrv
//! Return the current video image in BGRA order after drawing it.
const image::Color4f* image() const;

//! Get the compositing status.
const timeline::BackgroundOptions&
getBackgroundOptions() const noexcept;

//! Set the background options.
void setBackgroundOptions(const timeline::BackgroundOptions& value);

//! Set the color configuration.
void
setColorConfigOptions(const timeline::ColorConfigOptions&) noexcept;
Expand Down Expand Up @@ -273,12 +281,6 @@ namespace mrv
//! Get the window to full screen and hide/show all bars.
bool getPresentationMode() const noexcept;

//! Get the compositing status.
bool getBlackBackground() const noexcept;

//! Set the compositing status.
void setBlackBackground(bool active) noexcept;

//! Retrieve the full sceen mode.
bool getFullScreenMode() const noexcept;

Expand Down
6 changes: 3 additions & 3 deletions mrv2/lib/mrvGL/mrvTimelineViewportPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#pragma once

#include <tlTimeline/BackgroundOptions.h>

#include "mrvDraw/Annotation.h"

class ViewerUI;
Expand All @@ -14,6 +16,7 @@ namespace mrv

struct TimelineViewport::Private
{
static timeline::BackgroundOptions backgroundOptions;
timeline::ColorConfigOptions colorConfigOptions;
timeline::LUTOptions lutOptions;
std::vector<tl::timeline::ImageOptions> imageOptions;
Expand Down Expand Up @@ -62,9 +65,6 @@ namespace mrv
//! Right mouse menu
Fl_Menu_Button* popupMenu = nullptr;

//! Compositing switch (render on black or on background color)
static bool blackBackground;

//! Temporary help text displayed in HUD
static std::string helpText;
static float helpTextFade;
Expand Down
12 changes: 8 additions & 4 deletions mrv2/lib/mrvNetwork/mrvCommandInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,12 @@ namespace mrv
app->setDisplayOptions(o);
ui->uiMain->fill_menu(ui->uiMenuBar);
}
else if (c == "setBackgroundOptions")
{
const tl::timeline::BackgroundOptions& o = message["value"];
view->setBackgroundOptions(o);
ui->uiMain->fill_menu(ui->uiMenuBar);
}
else if (c == "setCompareOptions")
{
const tl::timeline::CompareOptions& o = message["value"];
Expand Down Expand Up @@ -1136,17 +1142,15 @@ namespace mrv
tcp->unlock();
return;
}
editModeH = message["height"];
EditMode value = message["value"];
editMode = value;
std::cerr << "message " << message << std::endl;
editModeH = message["height"];
bool presentation = ui->uiView->getPresentationMode();
if (!presentation)
ui->uiView->resizeWindow();

set_edit_mode_cb(value, ui);
// if (value == EditMode::kTimeline)
// ui->uiEdit->value(1);
// ui->uiEdit->do_callback();
}
else if (c == "Network Panel")
{
Expand Down
Loading

0 comments on commit 1df09ce

Please sign in to comment.