# PGS and custom GUI [K4 Bug?]



## Luca Capozzi (Jun 16, 2012)

Hi guys,

i'm running into a weird issue: i have an ui_button that sets a PGS value, but when I try to add a custom picture to it, something strange happens and the animation screws up and I can only see few pixels when the button is pressed. I tried the same picture with the PGS command commented and all works fine.

edit:
the problem seems related to on pgs_changed callback. I use it on every slot since i need that if a user push a button from (for example) Slot 2, the same button must be pressed on Slot 1 and viceversa. If I remove this callback, everything works fine.

Anybody experienced the same issue?

Thanks a lot,
Luca


----------



## Big Bob (Jun 16, 2012)

Hi Luca,



> something strange happens and the animation screws up and I can only see few pixels when the button is pressed.



The word 'animation' implies that either your ui callback and/or the pgs callback have 'wait' statements involved in them. Could you post a brief example of how you are coding both handlers (minus all the superfluous stuff)? There are some restrictions on pgs events (such as pgs callbacks cannot be multi-threaded) and some of these may apply to your situation. However, I can't tell without seeing a little more detail of what you are doing.

Rejoice,

Bob


----------



## Luca Capozzi (Jun 16, 2012)

hi bob and thanks for your reply. I mean the button frames for a custom png. I don't think i'm doing something trivial.. this is a script to show the "bug". I also attached a screenshot of this issue: on the left, there's a working condition.. on the right, the bugged one.


```
on init
 pgs_create_key(TMP_PGS, 16)
 declare ui_button $test
 
 $test := pgs_get_key_val(TMP_PGS, 1)
 set_control_par_str(get_ui_id($test), $CONTROL_PAR_TEXT, "") 
 set_control_par_str(get_ui_id($test), $CONTROL_PAR_PICTURE, "tmp_switch")

 make_perfview
end on

on ui_control($test)
 pgs_set_key_val(TMP_PGS, 1, $test)
end on

on pgs_changed
 $test := pgs_get_key_val(TMP_PGS, 1)
end on
```

If I use this same png file without PGS commands, it works perfectly.

Thanks again,
Luca


----------



## Big Bob (Jun 16, 2012)

How strange!

And this doesn't happen with the standard graphic image for the button?

Is the simple code you posted sufficient to demonstrate the problem or do you need to be using multiple script slots, etc? I tried the code you posted with no ill effects for several button images that I've created.

If the posted code is sufficient to demonstrate the problem, could you zip up the png and its corresponding txt file and attach it to a post so I can try it here?

To be continued ? ...

Rejoice,

Bob

BTW Does the problem vanish if you put a short wait in ui callback?


----------



## Luca Capozzi (Jun 16, 2012)

Hi Bob,

I've already tried using a wait command and the issue appears just after it ends. 
I've tried forcing width and height or loading the image out of a resource container but unsuccessfully. I've also tried with several png files, with same results.

Here's a zip with a test nki, a png and related text file.

Thanks again,
Luca


----------



## Luca Capozzi (Jun 17, 2012)

the only workaround, so far, is to set this button as ui_slider with a mouse behaviour of -500, but I find this solution annoying from a user point of view when I use the GUI.

Cheers,
Luca


----------



## mk282 (Jun 17, 2012)

First script:


```
on init
 make_perfview
 set_ui_height(2)

 pgs_create_key(TMP_PGS, 16)
 
 declare ui_button $test
 
 set_control_par_str(get_ui_id($test), $CONTROL_PAR_PICTURE, "tmp_switch")
 set_control_par_str(get_ui_id($test), $CONTROL_PAR_TEXT, "")
 set_control_par(get_ui_id($test), $CONTROL_PAR_WIDTH, 58)
 set_control_par(get_ui_id($test), $CONTROL_PAR_HEIGHT, 58)

 move_control_px($test,66,2)

 make_persistent($test)

 message("")
end on

on ui_control($test)
 pgs_set_key_val(TMP_PGS, 0, $test)
end on

on pgs_changed
 $test := pgs_get_key_val(TMP_PGS, 0)
end on
```

Second script (for example):


```
on init

 declare ui_button $btn

 make_persistent($btn)

end on

on ui_control ($btn)
 pgs_set_key_val(TMP_PGS, 0, $btn)
end on

on pgs_changed
 $btn := pgs_get_key_val(TMP_PGS, 0)
end on
```


And it works!


----------



## Luca Capozzi (Jun 17, 2012)

thanks to EvilDragon, I solved this issue. I must set both width and height with 2px over the real size.. so if mine was 56x56 i must set as 58x58.

Thanks again!
Luca


----------



## Big Bob (Jun 17, 2012)

Hi Luca,

It was nice to wake up this morning and see that you have already solved your problem with MK's help. o-[][]-o 

I am a little puzzled though by the apparent fix being centered on sizing the image. Maybe MK can comment a bit more on this. I never noticed before that specifying a size (WxH) overtly was required if one wanted to accept the 'native' size of the image. Although, I guess whenever I use a custom image, I generally do overtly specify its size (but I didn't know that was required). 

And what precisely do you think this has to do with using the pgs callback? :? 

Rejoice,

Bob

EDIT: I guess I should have read the NI forum post first :lol: After reading that, I think I'll withdraw my request for a better explanation, I now get the connection 8)


----------



## Luca Capozzi (Jun 17, 2012)

it was related to pgs since if I comment out pgs commands, the image works perfectly :\ weird.


----------



## Big Bob (Jun 17, 2012)

Yes indeed! I also don't think that one should have to specify the size of a graphic unless you want to stretch it. But, apparently, MK has discovered some sort of bug in K4 that requires such an overt sizing. Now you have discovered that it is also exacerbated in some way by the presence or absence of the pgs callback mechanism.

Maybe if NI ever fixes the first problem, the second one will also vanish? :lol: 

In any case, I'm glad you got things working even if we don't quite understand exactly why. :roll: 

Rejoice,

Bob


----------



## mk282 (Jun 18, 2012)

I always set the w/h of any image, just for good practice. It is NOT required if you have "no" for h/v stretching in the .txt file (unless you have a horizontal animation, read on). But it's still good practice.


Also, I don't think PGS is the root of the problem here - I think it has more to do with the switch image Luca used is a horizontal animation, and if you don't define the dimensions in KSP then it misbehaves (my guess - Kontakt doesn't pull all info from the .txt file if you don't define the dimensions, because it sees the image as vertical animation until you define them).


There seems to be some quite whimsical bugs w.r.t. graphics and .txt file connection in Kontakt...


----------



## Big Bob (Jun 18, 2012)

HI Mario,

Yes, it could well be that the tie-in with pgs is a timing issue in the internal task scheduling within K4. Especially, if there seems to be an anomoly with horizontal image animation.

In any case, your suggestion about always sizing custom images is probably well founded. I think I always have done this in the past but, I didn't know that it was more or less essential to avoid problems.

BTW what does the w.r.t. stand for in w.r.t. graphics? :oops: 

Rejoice,

Bob


----------



## Mike Greene (Jun 18, 2012)

Big Bob @ Mon Jun 18 said:


> BTW what does the w.r.t. stand for in w.r.t. graphics? :oops:


w.r.t. = "with respect to"

So it would be:
_"There seems to be some quite whimsical bugs with respect to graphics and .txt file connection in Kontakt..."_


----------



## Big Bob (Jun 18, 2012)

Thanks Mike,

One more TLA to try to cram into my old brain :lol: 

But, now that I think about it, I thought all these internet acronyms were written without any periods. e.g. AFAIK, IIRC, etc. Why does this one have periods? :roll: 

Rejoice,

Bob


----------



## mk282 (Jun 19, 2012)

Big Bob @ 18.6.2012 said:


> But, now that I think about it, I thought all these internet acronyms were written without any periods. e.g. AFAIK, IIRC, etc. Why does this one have periods? :roll:



Because it was used before Internet even existed 


I think in math literature, especially.


----------



## Big Bob (Jun 19, 2012)

> Because it was used before Internet even existed
> 
> I think in math literature, especially.


Not in my circles  But then my circles are pretty old relative to yours :lol:


----------



## mk282 (Jun 19, 2012)

Just going by what was written on Wikipedia 

http://en.wikipedia.org/wiki/Wrt#WR

WRT â€“ "With respect to", especially in fields such as Mathematics.

Alternative forms

w.r.t. (sense 1 and 2)
w/r/t (sense 1 and 2)

1. with respect to
2. with regard to


----------



## Big Bob (Jun 19, 2012)

I'm am in total shock :shock: to discover that there is something on Wikipedia that I didn't already know and have memorized :lol: 

I guess I shall have to 'retire to Sussex and keep bees' along with Sherlock Holmes ~o)


----------

