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

Use w1 instead of w to activate window#1. w only acts on window#0.

Thanks. Also, I would like to enable scrolling. The test image I’m using is way too big to fit on screen. That limits its usability.

There are no easy ways to get scrolling bars on the display windows. You’ll have to program it by yourself (and I can already tell you, that will be probably harder than what you think).

As I just said above : there are a lot of limitations with the G’MIC display windows, just don’t expect you can re-create an entire graphical user interface with the G’MIC display capabilities. In theory, you can do it, but it would be cumbersome. I must confess I wouldn’t risk it myself.

If you need a real customized graphical interface for a GIMP plug-in, don’t use G’MIC, really. Do your plug-in with Qt/GTK/Whatever GUI Lib, and use C++ code, but don’t try doing this in G’MIC.
It is definitely not the right tool to do that.

I think I found my workaround that’ll work. Now, I don’t know where’s the limitation, but can G’MIC detect scroll event? What about keyboard arrow key?

There is not something like ‘scroll event’.
Events you can detect is key press, mouse button press, mouse button motion.
Even if you need a drag&drop, you have to code it by yourself, by :

  • Detecting mouse button press event.
  • Storing the location of the pointer as $x0,$y0
  • Detecting mouse button release event.
  • Get the new location as $x1,$y1
  • Then, do something with your $x0,$y0,$x1,$y1.

That’s really ‘low-level’ programming. It’s still possible to manage user interactions, but things are usually easier to code with a real GUI library.

@David_Tschumperle

A sneak peak of what I’m doing.

foo:
rm
tile_size=32

gw=512
gh=512

nw={floor($gw/$tile_size)*$tile_size}
nh={floor($gh/$tile_size)*$tile_size}

$gw,$gh,1,4,((x%$tile_size==0)||(y%$tile_size==0))||(x==(w-1)||y==(h-1))?1

n 0,255

i $1

l.
    xr={ceil(w#-1/(16*$tile_size))}
    yr={ceil(h#-1/(16*$tile_size))}
    split_tiles. {-16*$tile_size}
    mw=${-max_w}
    mh=${-max_h}
    ti=$!
endl

$tile_size,$tile_size,1,4,0

w[0] {w#0},{h#0},0,"Grid"
w1[1] {w#1},{h#1},0,"Tileset"
w2[-1] {w#-1*2},{h#-1*2},0,"Tile"

ci=0
lr=0
tb=0
tbc=0
ni=1

do
    x,y,b,ww,wh={*,x,y,b,w,h}
    x1,y1,b1,ww1,wh1={*1,x,y,b,w,h}
    
    if {*1,ARROWRIGHT}
        lr+=1
        lr={$lr%$xr}
        ci={($lr+$tb)%$ti}
        ni={$ci+1}
        w1[$ni]
    elif {*1,ARROWLEFT}
        lr-=1
        lr={$lr%$xr}
        ci={($lr+$tb)%$ti}
        ni={$ci+1}
        w1[$ni]
    elif {*1,ARROWDOWN}
        tbc+=1
        tbc={$tbc%$yr}
        tb={$tbc*$xr}
        ci={($lr+$tb)%$ti}
        ni={$ci+1}
        w1[$ni]
    elif {*1,ARROWUP}
        tbc-=1
        tbc={$tbc%$yr}
        tb={$tbc*$xr}
        ci={($lr+$tb)%$ti}
        ni={$ci+1}
        w1[$ni]
    fi
    if $b1" && "$x1>=0" && "$y1>=0
        f. i(#$ni,floor($x1/$tile_size)*$tile_size+x,floor($y1/$tile_size)*$tile_size+y,z,c)
        w2[-1]
    fi
    if $b" &&"$x>=0" && "$y>=0
        sh. 3
        j[0] [-2],{floor($x/$tile_size)*$tile_size},{floor($y/$tile_size)*$tile_size},0,0,1,[-1],255
        rm.
        w[0]
    fi
    wait
while {*}" && "!{*,ESC}
4 Likes

Makings of an RPG or rogue-like. :slight_smile::+1:
repeat
You wake up; slime attacks you for 10 points; you die.
done

1 Like

@David_Tschumperle Question, can window command be modified to have the option to inherently display alpha background as a option? The reason I’m asking is that it would be a lot of work just to enable alpha background.

Not sure what you are requesting here.
window can only display images with 1,2 or 3 channels. If you need some sort of ‘alpha’ support, then probably drgba could help to convert your RGBA image into a RGB representation to be displayed.

Well, dbrga command alone should make this a lot easier. Thanks though ideally, I would like for something like that to be built-in as a option within window so that less lines would be needed.

Not a good idea IMHO. There are probably thousands ways one wants to manage alpha-channel for a display window, so having an option for that (and for a built-in command as window) could not be “complete”.
Of course, you can always define your own custom_window command that manages the alpha-channel just as you want.

Okay, the more I work on the tile mini-program. I did found out that {,e} makes the command switch mode. So, I have to ask you what keys are not available in use for {,?}? I used {*,s} and the mode flickering is gone.

So you mean {*,S} ?
Testing a key is always done with a syntax involving a capital letter.

There’s another thing I might make with more knowledge on interactive filter scripting. I think I can actually theoretically make a MS Paint clone or something like amiga painting softwares. In fact, it would be exciting to make such a entire program with gmic scripting.

A bit like command x_paint ? :stuck_out_tongue:

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