A quick & dirty guide on how to manage interactive display windows in G'MIC

Yes. But more on the direction of Grafx2 with a more modern interface.

@David_Tschumperle How to hide windows at a code level? After fixing bugs, I realized I wanted to create two different mode of operations. One mode should only have one window.

w[] 0
(or w0[] 0, etc…).

1 Like

If you went in the direction of Mario Gmicky Paint, that would be something. Would elevate G’MIC to another level.

It definitely would. Now to come to think of it, it’s actually easier to make than the interactive RPG tiling tool I’m working on. That one is exhausting.

1 Like

I think I want to leave a tip. For interactive window project. It’s great to use command or m to create functions. It makes work a lot easier to understand.

For example from snippets (This code doesn’t work, but they’re part of a working code I’m working on now):

if narg($7)||narg($8)||narg($9)
    if narg($7) __r_col={min(abs($7),255)} else __r_col=0 fi
    if narg($8) __g_col={min(abs($8),255)} else __g_col=0 fi
    if narg($9) __b_col={min(abs($9),255)} else __b_col=0 fi

    m "xalp : drgba $__r_col,$__g_col,$__b_col"
else
    m "xalp : drgba"
fi

m "out2display : skip ${""2=},${""3=},${""4=1},${""5=1},${""6=},${""7=} if $""1 $__bg rv blend alpha fi xalp if narg($""6)||narg($""7) if narg($""2)&&narg($""3)&&narg($""4)&&narg($""5) f. begin(xc=$""2;yc=$""3;tw=$""4;th=$""5;psx=floor(xc/tw)*$2;psy=floor(yc/$2)*$2;border=2;border_left=psx+border;border_right=psx+$2-border;border_up=psy+border;border_down=psy+$2-border;boundx=psx+$2;boundy=psy+$2;);if(narg($""6),tracker=(x>psx&&x<boundx)&&(y>psy&&y<boundy)?((x<=border_left||x>=border_right)||(y<=border_up||y>=border_down)?$""6:i):i;,tracker=i;);grid=!(((x%$2)==0||(y%$2)==0)||(x==(w-1)||y==(h-1)))?tracker:(narg($""7)?$""7:i); fi fi"

m "pass2tile : pass$""1 f[0] i(#-1,$""2+x,$""3+y) rm."

    if $b1" && "$x1>=0" && "$y1>=0" && "$x1<w#1" && "$y1<h#1
        select_from_tileset=1
        tsx={floor($x1/$min_tile)*$min_tile} tsy={floor($y1/$min_tile)*$min_tile}
        pass2tile[-1] [1],$tsx,$tsy
        +out2display. 0
        w2[-1] 
        rm.
        
        if $tileset_gridmode
            +out2display[$ni] $tileset_background,$tsx,$tsy,$tile_width,$tile_height,$trackpadcol,$gridcol
        else
            +out2display[$ni] $tileset_background,$tsx,$tsy,$tile_width,$tile_height,$trackpadcol
        fi
        w1[-1]
        rm.
        
        wait 400

    fi

Note how the out2display is quite long. Now, imagine what I had to do without using command and debugging it. Quite painful, right?

This windowing business requires many lines of code (just look at David’s code in stdlib – wow), so breaking it down into manageable chunks is wise.

command used in this way is equivalent to a macro function in the math interpreter. I haven’t done this because I tend to make standalone commands that can be accessed everywhere.

@David_Tschumperle is there a simple way to check for an event such as “the mouse has moved over the display”?

Must we compare window coordinates to do that?

This code demonstrates that a move event is indeed generated:
gmic run "400,400 w0 do v + e {u(1)} v - wait while {*}&&\!{*,ESC}"

Not directly, you have to store old mouse coordinates and compare with the current to check the mouse has moved.

Thanks, it’s what I suspected. The context was that I wanted to skip/ignore those events, but I can work around it with a different approach.