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

how to disable gui auto draw to draw manually in draw() to set order #70

Open
moebiussurfing opened this issue Apr 1, 2019 · 7 comments

Comments

@moebiussurfing
Copy link

I am using an ofxGuiGraphics into a container to draw the background of my app.
I tried to send back the panel with groupBackground->moveToBack();
but when I draw other things into ofApp::draw(), all goes into background, gui is in front.

theres some way to disable auto draw to be able to draw in front all gui?
something like:

setup
gui_background.disaleAutoDraw();

draw
gui_background.draw();
myCubes.draw();

@frauzufall
Copy link
Owner

Hi, yes, the idea was to have the GUI on top of everything and the ability to hide it with gui.getVisible().set(false). But you can do what you asked for - add this to the end of your setup method:

ofRemoveListener(ofEvents().draw, gui.getDocument(), &DOM::Document::draw, OF_EVENT_ORDER_AFTER_APP);

.. and then draw it like this:

void ofApp::draw(ofEventArgs &e) {
    gui.getDocument()->draw(e);
}

Hope it helps :) Maybe I should wrap this somehow because it is a bit ugly... I like your suggested methods.

@brunovianna
Copy link

I have a similar need but this fix didn't work. I use the gui so that the user chooses from a list of videos. After pressing the button, the gui should disappear and the video should start. However, even if I use the tip above there is still a black background being drawn on top of the video. The only way I can draw is by not creating the gui object. Should I somehow delete the gui object altogether to make it go away?

@moebiussurfing
Copy link
Author

I generally use gui.getVisible().set(false). To hide all gui. Maybe you can move the panel outside the window..

@brunovianna
Copy link

Thanks for the suggestion, but I had already tried gui.getVisible().set(false) without success.
Also setting the panel position away from the screen didn't help.

It seems like the gui draws some kid of black blackground with a bit of transparency. I can almost see the video playing behind it...

@moebiussurfing
Copy link
Author

moebiussurfing commented Jul 23, 2019

hey @brunovianna, look around this code to see if it helps in some way:
I am using ofxGuiExtende also over a video player and it's hiding fine when I want.
You need to hide/show not in draw() loop, just with a trigger like key trigger below.
Also you can play clearing or setting the background in draw(), and maybe to play too with depth/alpha/translates too...

//--
//main.cpp

#include "ofMain.h"
#include "ofApp.h"
//========================================================================
int main( ){
    ofSetupOpenGL(1280, 720,OF_WINDOW);
	ofRunApp(new ofApp());
}
//--


//---
//ofApp.h
#pragma once
#include "ofMain.h"
#include "ofxGuiExtended.h"
#include "ofxHapPlayer.h"

class ofApp : public ofBaseApp{
public:
//...
    ofxGui gui;
    ofxGuiPanel *panel;
    ofParameter<int> timePeriod_ms;
    ofParameter<int> bpm;
    ofParameter<float> start;
    ofParameter<float> finish;
    ofParameter<bool> MARK_IN;
    ofParameterGroup params;
//--


//--
//ofApp.cpp

//--------------------------------------------------------------
void ofApp::setup(){
//define params (forget names)
    ENABLE_glitch1.set("GLITCH 1", false);
    ENABLE_skiper.set("ENABLE AUTO SKIPER", false);
    TRIG_skiper.set("TRIG SKIP", false);
    ENABLE_LOOP.set("ENABLE_LOOP", false);
    bpm.set("BPM", 120, 10, 300);
    beatNum.set("beatNum", 0, 0, 4);
//...
//add params to group params
    params.add(ENABLE_skiper);
    params.add(timePeriod_ms);
    params.add(TRIG_skiper);
//...
// create gui panel
    panel = gui.addPanel(params);
//...

//--------------------------------------------------------------
void ofApp::draw(){
	/// you can test with this
	/// to force if video player make some of
	/// this enablers inside
    //ofEnableAlphaBlenging();
    //ofDisableAlphaBlenging();

	/// you can test with this
	/// to force if video player make some of
	/// this enablers inside
    ofPushMatrix();
	ofPushStyle();	
    
    //-

    // all 3D
    /// you can test with this
	/// to force if video player make some of
	/// this enablers inside
	ofEnableDepthTest();

    //..all drawing

	ofPopStyle();	
    ofPopMatrix();

	//-

	drawVideo();
	
	//-

    // all 2D
    /// you can test with this
	/// to force if video player make some of
	/// this enablers inside

    ofDisableDepthTest();

    //-

    // HELP INFO:

    if (SHOW_gui)
    {
        string info = "ofxPostGlitch\n";
        info += "1 - 0 : Apply glitch effects.\n";
        info += "q - u : Apply color remap effects.\n";
        
        ofPushMatrix();
		ofPushStyle();
        ofTranslate(pos_x, pos_y);
        if (bShowHelp){
            ofSetColor(0, 200);
            ofDrawRectangle(25, 17, 320, 60);
            ofSetColor(255);
            ofDrawBitmapString(info, 30,30);
        }
        ofPopStyle();
        ofPopMatrix();
    }
}

//--------------------------------------------------------------
void ofApp::drawVideo()
{
    ofClear(0, 0, 0, 255);
    //clear screen, same that ofBackground(128);
    
    if (player.isLoaded())
    {
        // Draw the video frame
        ofSetColor(255, 255, 255);
        ofRectangle videoRect(0, 0, player.getWidth(), player.getHeight());
        videoRect.scaleTo(ofGetWindowRect());

        player.draw(videoRect.x, videoRect.y, videoRect.width, videoRect.height);
    }

}

//--------------------------------------------------------------
void ofApp::keyPressed(int key)
{
   //..
    // show gui

    if (key == 'g')
    {
        SHOW_gui = !SHOW_gui;

        gui.getVisible().set(SHOW_gui);
    }
    //...

@moebiussurfing
Copy link
Author

Also you can change the background color of the panel to maximum alpha ..

@brunovianna
Copy link

Thanks @moebiussurfing . I have found the bug - I was setting ofSetColor to draw some text when the gui was visible. For some reason, even after I stopped using the gui, this was messing up with the drawing of the video. I tested using ofSetColor(255,20,20) and got a red tainted video. I don't if it is worth looking into the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants