Posted by & filed under KSP Scripting (NI Kontakt) - Tutorials, KSP: Custom UI (design).

this tutorial is based on the Wallpaper and the Dynamic Wallpaper (via label element) tutorial. Actually once the initial wallpaper is set we can’t change it anymore but we can move the wallpaper image vertically via set_skin_offset(). So if we use an image which is as double as high as our ui_size (in this case 2 x 608px) we can put 2 wallpapers into this one image file like shown on the left. The visible area is only from 0 pixel to 608 pixel.

We can now set a button for example which moves the background skin 608 pixel vertically to put the second wallpaper into the visible area. This short demo video shows how it works:

For this demonstration we did a slow animation but of course usually you may wanna switch the wallpaper instantly. So simply set wait() to zero or remove the whole while loop (but don’t forget to add the set_skin_offset(608) again)

Example

on init
  make_perfview
  set_ui_height_px(540)
  set_control_par_str($INST_WALLPAPER_ID,$CONTROL_PAR_PICTURE,"wallpaper")
  declare $count
  declare ui_button $switch_wp
  set_control_par_str(get_ui_id($switch_wp),$CONTROL_PAR_PICTURE,"btn_1")
  set_control_par_str(get_ui_id($switch_wp),$CONTROL_PAR_TEXT,"")
  set_control_par(get_ui_id($switch_wp),$CONTROL_PAR_WIDTH,40)
  set_control_par(get_ui_id($switch_wp),$CONTROL_PAR_HEIGHT,40)
  set_control_par(get_ui_id($switch_wp),$CONTROL_PAR_POS_X,296)
  set_control_par(get_ui_id($switch_wp),$CONTROL_PAR_POS_Y,430)
end on

on ui_control($switch_wp)
  if ($switch_wp=1)
    $count := 0
    {set_skin_offset(608)}
    while ($count<609)
      set_skin_offset($count)
      wait(1000) {set to zero to switch instantly or remove the whole while loop}
      inc($count)
    end while
  else
    set_skin_offset(0)
  end if
end on

You can also set a background wallpaper via label element. It’s up to you which method you like the most. Both have advantages. With the label element it is much easier to design your backgrounds instead of making a long image “tube” especially when altering your background graphic a lot. The set_skin_offset method however is somewhat easier to handle when it comes to coding and also less error prone. Also you can only “change” the first 68px (where the Kontakt panel resides) with set_skin_offset()

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *