Custom Draw Scripts

Custom Draw Scripts

This is an advanced section, that you should be comfortable with GML/scripts to accomplish. It is a powerful feature that allows you draw within a cell/line, and have the widget handle scrolling and GUI events.

For listbox widgets, both the horizontal and vertical listboxes you can have a custom draw method of controlling how to draw the contents of each line. You just simply set uiCustomDrawScript=scr_yourscript; When the custom script is set, the listbox will call your script EACH TIME a line needs to be drawn. So if your listbox has 10 items, your custom script will be called 10 times (it is optimized that it only calls your script for visible lines, but you don’t need to worry about that in your script). See the sample project’s custom draw scripts to understand what it does. Here’s a breakdown of the parameter that are sent to your custom script:

curListB = argument0; // self.id of calling listbox_ext;
curIndex = argument1; // index (0 based) of items of listbox
curX = argument2; //X to draw
curY = argument3; //Y to draw
curHeight = argument4; // default height of lineitem (usually textheight, return must be the actual height for variable heights)
curWidth = argument5; // width of drawing area;
curLineSt = argument6; // cur string to display.
curSelected = argument7; //if line is hilited true/false

The important thing to remember is to draw within the rectangle (curX,curY,curX+curWidth,curY+curHeight). The listbox only contains items[] array so if you need more info to store by line then you would need to store that info into your own arrays. You ONLY DRAW the one line item, you do not draw more than one line in your custom drawscript, curIndex is the current item being drawn (0 = first item in list).

Make sure you set the curHeight as the return variable of your script. The listbox control allows for variable height lines so it needs to know how high the drawscript took. For listbox_horizontal you need to make sure you set curWidth instead of curHeight.

Also, you need to ensure that the items[] array has correct number of elements you expect. Meaning, if you have an external array/ds_list that you want to display, you must first ensure that the items[] array has the same # of elements (they could be dummy values). But the list needs to know how many items it needs to call/draw to your custom script.

You may also like...