Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoherbelin committed Jun 6, 2024
2 parents 19b8412 + 7092de8 commit 90962d0
Show file tree
Hide file tree
Showing 18 changed files with 197 additions and 91 deletions.
Binary file modified rsc/images/icons.dds
Binary file not shown.
12 changes: 10 additions & 2 deletions src/CloneSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
CloneSource::CloneSource(Source *origin, uint64_t id) : Source(id), origin_(origin), paused_(false), filter_(nullptr)
{
// initial name copies the origin name: diplucates are namanged in session
name_ = origin->name();
name_ = origin_name_ = origin->name();

// set symbol
symbol_ = new Symbol(Symbol::CLONE, glm::vec3(0.75f, 0.75f, 0.01f));
Expand All @@ -64,6 +64,7 @@ CloneSource::~CloneSource()
void CloneSource::detach()
{
Log::Info("Source '%s' detached from '%s'.", name().c_str(), origin_->name().c_str() );
origin_name_ = origin_->name();
origin_ = nullptr;
}

Expand Down Expand Up @@ -233,7 +234,7 @@ uint CloneSource::texture() const

Source::Failure CloneSource::failed() const
{
return (origin_ == nullptr || origin_->failed()) ? FAIL_FATAL : FAIL_NONE;
return (origin_ == nullptr || origin_->failed()) ? FAIL_RETRY : FAIL_NONE;
}

void CloneSource::accept(Visitor& v)
Expand All @@ -251,3 +252,10 @@ std::string CloneSource::info() const
{
return "Clone";
}

std::string CloneSource::origin_name() const
{
if (origin_)
return origin_->name();
return origin_name_;
}
2 changes: 2 additions & 0 deletions src/CloneSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class CloneSource : public Source
// implementation of cloning mechanism
void detach();
inline Source *origin() const { return origin_; }
std::string origin_name() const;

// Filtering
void setFilter(FrameBufferFilter::Type T);
Expand All @@ -44,6 +45,7 @@ class CloneSource : public Source

void init() override;
Source *origin_;
std::string origin_name_;

// control
bool paused_;
Expand Down
57 changes: 29 additions & 28 deletions src/ImGuiToolkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ bool ImGuiToolkit::ButtonSwitch(const char* label, bool* toggle, const char* too



void _drawIcon(ImVec2 screenpos, int i, int j, bool enabled = true)
void _drawIcon(ImVec2 screenpos, int i, int j, bool enabled = true, ImGuiWindow* window = ImGui::GetCurrentWindow() )
{
// icons.dds is a 20 x 20 grid of icons
if (textureicons == 0)
Expand All @@ -184,7 +184,6 @@ void _drawIcon(ImVec2 screenpos, int i, int j, bool enabled = true)
if (!enabled)
tint_color = ImGui::GetStyle().Colors[ImGuiCol_TextDisabled];

ImGuiWindow* window = ImGui::GetCurrentWindow();
ImRect bb(screenpos, screenpos + ImVec2(ImGui::GetTextLineHeightWithSpacing(), ImGui::GetTextLineHeightWithSpacing()));
window->DrawList->AddImage((void*)(intptr_t)textureicons, bb.Min, bb.Max, uv0, uv1, ImGui::GetColorU32(tint_color) );
}
Expand Down Expand Up @@ -565,14 +564,8 @@ bool ImGuiToolkit::ComboIcon (const char* label, int* current_item,

*current_item = CLAMP( *current_item, 0, (int) items.size() - 1);

// make some space
char space_buf[] = " ";
const ImVec2 space_size = ImGui::CalcTextSize(" ", NULL);
const int space_num = static_cast<int>( ceil(g.FontSize / space_size.x) );
space_buf[space_num]='\0';

char text_buf[256];
ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%s %s", space_buf, std::get<2>( items.at(*current_item) ).c_str());
ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), " %s", std::get<2>( items.at(*current_item) ).c_str());
if ( ImGui::BeginCombo( label, text_buf, ImGuiComboFlags_None) ) {
for (int p = 0; p < (int) items.size(); ++p){
ImGui::PushID((void*)(intptr_t)p);
Expand Down Expand Up @@ -600,17 +593,12 @@ bool ImGuiToolkit::SelectableIcon(int i, int j, const char* label, bool selected
{
ImGuiContext& g = *GImGui;
ImVec2 draw_pos = ImGui::GetCursorScreenPos() - g.Style.FramePadding * 0.5;

// make some space
char space_buf[] = " ";
const ImVec2 space_size = ImGui::CalcTextSize(" ", NULL);
const int space_num = static_cast<int>( ceil(g.FontSize / space_size.x) );
space_buf[space_num+1]='\0';

char text_buf[256];
ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%s%s", space_buf, label);
ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), " %s", label);

ImGui::PushID( i * 20 + j + ImGui::GetID("##SelectableIcon") );
ImGui::PushID( i * 20 + j + ImGui::GetID(text_buf) );

// draw menu item
bool ret = ImGui::Selectable(text_buf, selected, ImGuiSelectableFlags_None, size_arg);
Expand All @@ -627,26 +615,39 @@ bool ImGuiToolkit::SelectableIcon(int i, int j, const char* label, bool selected
return ret;
}


bool ImGuiToolkit::MenuItemIcon (int i, int j, const char* label, const char* shortcut, bool selected, bool enabled)
{
ImVec2 draw_pos = ImGui::GetCursorScreenPos();

// make some space
char space_buf[] = " ";
const ImVec2 space_size = ImGui::CalcTextSize(" ", NULL);
const int space_num = static_cast<int>( ceil(ImGui::GetTextLineHeightWithSpacing() / space_size.x) );
space_buf[space_num]='\0';
ImGuiContext& g = *GImGui;
draw_pos.y -= g.Style.ItemSpacing.y * 0.5f;

char text_buf[256];
ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%s %s", space_buf, label);
ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), " %s", label);

// draw menu item
bool ret = ImGui::MenuItem(text_buf, shortcut, selected, enabled);

// draw icon
ImGui::SetCursorScreenPos(draw_pos);
Icon(i, j, enabled);
// overlay of icon on top of first item
_drawIcon(draw_pos, i, j, enabled);

return ret;
}

bool ImGuiToolkit::BeginMenuIcon(int i, int j, const char *label, bool enabled)
{
ImGuiWindow *win = ImGui::GetCurrentWindow();
ImVec2 draw_pos = ImGui::GetCursorScreenPos();
ImGuiContext &g = *GImGui;
draw_pos.y += g.Style.ItemSpacing.y * 0.5f;

char text_buf[256];
ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), " %s", label);

// draw menu item
bool ret = ImGui::BeginMenu(text_buf, enabled);

// overlay of icon on top of first item
_drawIcon(draw_pos, i, j, enabled, win);

return ret;
}
Expand Down Expand Up @@ -1763,7 +1764,7 @@ void ImGuiToolkit::SetAccentColor(accent_color color)
colors[ImGuiCol_TextDisabled] = ImVec4(0.55f, 0.55f, 0.55f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.13f, 0.13f, 0.13f, 0.94f);
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_PopupBg] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f);
colors[ImGuiCol_PopupBg] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
colors[ImGuiCol_Border] = ImVec4(0.69f, 0.69f, 0.69f, 0.25f);
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_FrameBg] = ImVec4(0.39f, 0.39f, 0.39f, 0.55f);
Expand Down
1 change: 1 addition & 0 deletions src/ImGuiToolkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace ImGuiToolkit
bool ButtonIcon (int i, int j, const char* tooltip = nullptr, bool expanded = false);
bool ButtonIconToggle (int i, int j, bool* toggle, const char *tooltip = nullptr);
bool ButtonIconMultistate (std::vector<std::pair<int, int> > icons, int* state, std::vector<std::string> tooltips);
bool BeginMenuIcon(int i, int j, const char *label, bool enabled = true);
bool MenuItemIcon (int i, int j, const char* label, const char* shortcut = nullptr, bool selected = false, bool enabled = true);
bool SelectableIcon(int i, int j, const char* label, bool selected, const ImVec2& size_arg = ImVec2(0,0));
bool ComboIcon (const char* label, int* current_item, std::vector<std::tuple<int, int, std::string> > items, std::vector<std::string> tooltips = {});
Expand Down
26 changes: 18 additions & 8 deletions src/ImageFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ void ImageFilteringShader::setCode(const std::string &code, std::promise<std::st
custom_shading_.setShaders("shaders/image.vs", shader_code_, (int)n, ret);
}
else if (ret != nullptr) {
ret->set_value("No change.");
ret->set_value("No change");
}
}

Expand All @@ -292,7 +292,7 @@ void ImageFilteringShader::copy(ImageFilteringShader const& S)
/// ////
////////////////////////////////////////

ImageFilter::ImageFilter (): FrameBufferFilter(), buffers_({nullptr, nullptr})
ImageFilter::ImageFilter (): FrameBufferFilter(), buffers_({nullptr, nullptr}), channel1_output_session(true)
{
// surface and shader for first pass
shaders_.first = new ImageFilteringShader;
Expand Down Expand Up @@ -381,6 +381,7 @@ void ImageFilter::draw (FrameBuffer *input)
input_ = input;
// create first-pass surface and shader, taking as texture the input framebuffer
surfaces_.first->setTextureIndex( input_->texture() );
shaders_.first->secondary_texture = input_->texture();
// (re)create framebuffer for result of first-pass
if (buffers_.first != nullptr)
delete buffers_.first;
Expand All @@ -390,6 +391,7 @@ void ImageFilter::draw (FrameBuffer *input)
input_->blit( buffers_.first );
// create second-pass surface and shader, taking as texture the first-pass framebuffer
surfaces_.second->setTextureIndex( buffers_.first->texture() );
shaders_.second->secondary_texture = input_->texture();
// (re)create framebuffer for result of second-pass
if (buffers_.second != nullptr)
delete buffers_.second;
Expand All @@ -401,16 +403,18 @@ void ImageFilter::draw (FrameBuffer *input)
if ( enabled() || forced )
{
// FIRST PASS
if (channel1_output_session)
shaders_.first->secondary_texture = Mixer::manager().session()->frame()->texture();
// render input surface into frame buffer
shaders_.first->mask_texture = Mixer::manager().session()->frame()->texture();
buffers_.first->begin();
surfaces_.first->draw(glm::identity<glm::mat4>(), buffers_.first->projection());
buffers_.first->end();

// SECOND PASS
if ( program_.isTwoPass() ) {
if (channel1_output_session)
shaders_.second->secondary_texture = Mixer::manager().session()->frame()->texture();
// render filtered surface from first pass into frame buffer
shaders_.second->mask_texture = Mixer::manager().session()->frame()->texture();
buffers_.second->begin();
surfaces_.second->draw(glm::identity<glm::mat4>(), buffers_.second->projection());
buffers_.second->end();
Expand Down Expand Up @@ -525,6 +529,7 @@ std::vector< FilteringProgram > ResampleFilter::programs_ = {

ResampleFilter::ResampleFilter (): ImageFilter(), factor_(RESAMPLE_INVALID)
{
channel1_output_session = false;
}

void ResampleFilter::setFactor(int factor)
Expand Down Expand Up @@ -579,7 +584,7 @@ void ResampleFilter::draw (FrameBuffer *input)

// create first-pass surface and shader, taking as texture the input framebuffer
surfaces_.first->setTextureIndex( input_->texture() );
shaders_.first->mask_texture = input_->texture();
shaders_.first->secondary_texture = input_->texture();
// (re)create framebuffer for result of first-pass
if (buffers_.first != nullptr)
delete buffers_.first;
Expand All @@ -604,7 +609,7 @@ void ResampleFilter::draw (FrameBuffer *input)
// SECOND PASS for QUARTER resolution (divide by 2 after first pass divide by 2)
// create second-pass surface and shader, taking as texture the first-pass framebuffer
surfaces_.second->setTextureIndex( buffers_.first->texture() );
shaders_.second->mask_texture = input_->texture();
shaders_.second->secondary_texture = input_->texture();
// (re)create framebuffer for result of second-pass
if (buffers_.second != nullptr)
delete buffers_.second;
Expand Down Expand Up @@ -662,6 +667,7 @@ std::vector< FilteringProgram > BlurFilter::programs_ = {
BlurFilter::BlurFilter (): ImageFilter(), method_(BLUR_INVALID), mipmap_buffer_(nullptr)
{
mipmap_surface_ = new Surface;
channel1_output_session = false;
}

BlurFilter::~BlurFilter ()
Expand Down Expand Up @@ -733,7 +739,7 @@ void BlurFilter::draw (FrameBuffer *input)

// create first-pass surface and shader, taking as texture the input framebuffer
surfaces_.first->setTextureIndex( mipmap_buffer_->texture() );
shaders_.first->mask_texture = input_->texture();
shaders_.first->secondary_texture = input_->texture();
// (re)create framebuffer for result of first-pass
if (buffers_.first != nullptr)
delete buffers_.first;
Expand All @@ -743,7 +749,7 @@ void BlurFilter::draw (FrameBuffer *input)

// create second-pass surface and shader, taking as texture the first-pass framebuffer
surfaces_.second->setTextureIndex( buffers_.first->texture() );
shaders_.second->mask_texture = input_->texture();
shaders_.second->secondary_texture = input_->texture();
// (re)create framebuffer for result of second-pass
if (buffers_.second != nullptr)
delete buffers_.second;
Expand Down Expand Up @@ -803,6 +809,7 @@ std::vector< FilteringProgram > SharpenFilter::programs_ = {

SharpenFilter::SharpenFilter (): ImageFilter(), method_(SHARPEN_INVALID)
{
channel1_output_session = false;
}

void SharpenFilter::setMethod(int method)
Expand Down Expand Up @@ -880,6 +887,7 @@ std::vector< FilteringProgram > SmoothFilter::programs_ = {

SmoothFilter::SmoothFilter (): ImageFilter(), method_(SMOOTH_INVALID)
{
channel1_output_session = false;
}

void SmoothFilter::setMethod(int method)
Expand Down Expand Up @@ -950,6 +958,7 @@ std::vector< FilteringProgram > EdgeFilter::programs_ = {

EdgeFilter::EdgeFilter (): ImageFilter(), method_(EDGE_INVALID)
{
channel1_output_session = false;
}

void EdgeFilter::setMethod(int method)
Expand Down Expand Up @@ -1020,6 +1029,7 @@ std::vector< FilteringProgram > AlphaFilter::programs_ = {

AlphaFilter::AlphaFilter (): ImageFilter(), operation_(ALPHA_INVALID)
{
channel1_output_session = false;
}

void AlphaFilter::setOperation(int op)
Expand Down
1 change: 1 addition & 0 deletions src/ImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class ImageFilter : public FrameBufferFilter
std::pair< FrameBuffer *, FrameBuffer * > buffers_;
std::pair< ImageFilteringShader *, ImageFilteringShader *> shaders_;
void updateParameters();
bool channel1_output_session;
};


Expand Down
12 changes: 6 additions & 6 deletions src/ImageShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const char* MaskShader::mask_icons[4] = { ICON_FA_WINDOW_CLOSE, ICON_FA_EDIT, I
const char* MaskShader::mask_names[4] = { "No mask", "Paint mask", "Shape mask", "Source mask" };
const char* MaskShader::mask_shapes[5] = { "Ellipse", "Oblong", "Rectangle", "Horizontal", "Vertical" };

ImageShader::ImageShader(): Shader(), mask_texture(0), stipple(0.f)
ImageShader::ImageShader(): Shader(), secondary_texture(0), stipple(0.f)
{
// static program shader
program_ = &imageShadingProgram;
Expand All @@ -60,21 +60,21 @@ void ImageShader::use()
program_->setUniform("iNodes", iNodes);

// default mask
if (mask_texture == 0)
mask_texture = Resource::getTextureWhite();
if (secondary_texture == 0)
secondary_texture = Resource::getTextureWhite();

// setup mask texture
glActiveTexture(GL_TEXTURE1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture (GL_TEXTURE_2D, mask_texture);
glBindTexture (GL_TEXTURE_2D, secondary_texture);
glActiveTexture(GL_TEXTURE0);
}

void ImageShader::reset()
{
Shader::reset();
mask_texture = 0;
secondary_texture = 0;

// no stippling
stipple = 0.f;
Expand All @@ -84,7 +84,7 @@ void ImageShader::reset()

void ImageShader::copy(ImageShader const& S)
{
mask_texture = S.mask_texture;
secondary_texture = S.secondary_texture;
stipple = S.stipple;
iNodes = S.iNodes;
}
Expand Down
4 changes: 1 addition & 3 deletions src/ImageShader.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef IMAGESHADER_H
#define IMAGESHADER_H

#include <string>
#include <map>
#include <sys/types.h>

#include "Shader.h"
Expand All @@ -18,7 +16,7 @@ class ImageShader : public Shader
void accept(Visitor& v) override;
void copy(ImageShader const& S);

uint mask_texture;
uint secondary_texture;

// uniforms
float stipple;
Expand Down
Loading

0 comments on commit 90962d0

Please sign in to comment.