Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flags to skip window rendering for subsequent access to drawLists. #1660

Closed
wants to merge 2 commits into from

Conversation

biojppm
Copy link

@biojppm biojppm commented Mar 4, 2018

The flags are ImGuiWindowFlags_NoBackground/NoWindow. They make it easier to create an invisible window for drawing texts outside of imgui via raw access to the draw lists as suggested in #628. The window drawing is skipped when ImGuiWindowFlags_NoWindow is set, so this saves us from setting alpha on the window for this purpose.

The flags are ImGuiWindowFlags_NoBackground/NoWindow. They make it easier to create an invisible window for drawing texts outside of imgui via raw access to the draw lists as suggested in ocornut#628.
@ocornut
Copy link
Owner

ocornut commented Mar 4, 2018

Hello,

Thanks for your suggestion.

I don’t feel NoBackground is necessary as you can already use SetNextWindowBgAlpha(0.0f) that’s one line of code and it’s a fairly uncommon use case. We are also running out of window flag so it’s best to not allocate them too easily.

Note that you can easily allocate ImDrawList or use GetOverlayDrawList(). For a window with the flag you proposed you won’t have much control over the display order either way.

Perhaps instead we could add a call to register a ImDrawList for inclusion in the draw data, with option for whether it is in the front or in the back. And/or maybe add a GetBackgroundDrawList() helper like overlay drawlist.

I understand the use of something like _NoWindow but the name is a little vague and misleading here, and the choice of flags (NoInputs, NoSavedSettings) too arbitrary. Perhaps one flag to disable all the decorations would be of use.

(Also the line of code you added doesn’t match the local coding style)

@biojppm
Copy link
Author

biojppm commented Mar 4, 2018

Hi,

Thanks for your suggestions. And most importantly thanks for imgui, I've really found it useful!

I first tried drawing my screen texts with the technique you suggested in #628 ; basically setting all those flags and calling ImGui::SetNextWindowBgAlpha(0.f);. But this approach still draws the window decorations, so it's not what I wanted (which is just plain text drawn on arbitrary screen positions). And also from what I surmise (I may be wrong here), I still get the draw call for the background over the full screen, even though alpha is zero everywhere. You're right that _NoBackground is not strictly needed, but then we could avoid drawing the background when the incoming alpha is 0 (something which is not being done).

The GetOverlayDrawList() approach almost solves my problem without the use of window, except that as expected the texts render over the GUI windows, which is undesirable. So you're right that something like GetBackgroundDrawList() would come in just handy here.

By the way, the flags I added to _NoWindow also come from your suggestion in #628, and I do think _NoInputs does make sense in this case (you don't want to accidentally click something you're not seeing); as for _NoSavedSettings, well, I'm fine either way; I was taking your word here.

So, given the conditions that I...

  1. remove _NoBackground and disable drawing the background when alpha is zero
  2. rename _NoWindow to a name of your choice, and adjust these flag set to something you can agree with
  3. and of course, fix the style issues you pointed out

... would you be able to accept this PR?

Or maybe, alternatively, add GetBackgroundDrawList() and submit it in a different PR?

Let me know if you're fine with either (or both, or none) of these choices.

All the best,
João

ocornut added a commit that referenced this pull request Oct 15, 2018
@ocornut
Copy link
Owner

ocornut commented Oct 15, 2018

Hello @biojppm

I looked at this today, and I don't understand those statements:

but then we could avoid drawing the background when the incoming alpha is 0 (something which is not being done).
remove _NoBackground and disable drawing the background when alpha is zero

The background is already not drawn when alpha is zero.
Begin() does:

ImU32 bg_col = GetColorU32(GetWindowBgColorIdxFromFlags(flags));
if (g.NextWindowData.BgAlphaCond != 0)
{
    bg_col = (bg_col & ~IM_COL32_A_MASK) | (IM_F32_TO_INT8_SAT(g.NextWindowData.BgAlphaVal) << IM_COL32_A_SHIFT);
    g.NextWindowData.BgAlphaCond = 0;
}
window->DrawList->AddRectFilled(
  window->Pos + ImVec2(0, window->TitleBarHeight()), 
  window->Pos + window->Size, 
  bg_col, 
  window_rounding, 
  (flags & ImGuiWindowFlags_NoTitleBar) ? ImDrawCornerFlags_All : ImDrawCornerFlags_Bot);

And AddRectFilled as with every other ImDrawList function does:

void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners_flags)
{
    if ((col & IM_COL32_A_MASK) == 0)
        return;

That already skips rendering.

I am however adding a _NoBackground as suggested by this PR, but not exactly the same as yours. The _NoBackground flag I am adding doesn't hide scrolling, resize grips like yours.

The main reason for adding this is that it allows us to create combination flags to solve what we are discussing this. Without it it we can't have a flag to denote an "invisible" window, etc.

rename _NoWindow to a name of your choice, and adjust these flag set to something you can agree with

Designing this is the difficult part as many different combinations are genuinely useful. I have now added:

ImGuiWindowFlags_NoDecoration = NoTitleBar + NoResize + NoScrollbar + NoCollapse.

And reworked NoInputs (essentially the old behavior of NoInputs is now NoMouseInputs, and NoInputs is NoMouseInput+NoNav).

Given that, to achieve what you describe you can use:

NoDecoration+NoBackground+NoInputs+NoSavedSettings

And depending if you use only the drawlist with a custom clipping rectangle or not, you may set to set the window pos/size to cover the viewport you need.

I would not mind adding a new flag combination to combine all 4 above but I can't find of a proper name for it now that would convey both the visual aspect (NoDecoration+NoBackground) and the inputs aspect.

I also have a problem with GetOverlayDrawList() as it cannot work the same in with multi-viewports enabled. Internally we have a new function GetOverlayDrawList() given a viewport as parameter, and the no-parameter version returns the overdraw for the current windows which will certainly break some code calling this before Begin. Until this is sorted out it doesn't feel wise to add an additional GetBackgroundDrawList(), and given the whole discussion it looks like some form of z-order control would be wholly preferable.

ocornut added a commit that referenced this pull request Oct 15, 2018
…to ease creating new flag combinations. Added ImGuiWindowFlags_NoDecoration helper flag which is essentially NoTitleBar+NoResize+NoScrollbar+NoCollapse. (#1660)
ocornut added a commit that referenced this pull request Oct 15, 2018
…WindowFlags_NoInputs (essentially we have renamed ImGuiWindowFlags_NoInputs to ImGuiWindowFlags_NoMouseInputs). Made the new ImGuiWindowFlags_NoInputs encompass both NoMouseInputs+NoNav, which is consistent with its description. (#1660, #787)
@ocornut
Copy link
Owner

ocornut commented Jan 17, 2019

Closing this now, I think the original PR is well covered enough with the flags added mid october,

@ocornut ocornut closed this Jan 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants