-
Notifications
You must be signed in to change notification settings - Fork 2
tutorial.basic.12
Hi, welcome back to this tutorial in which weβll talk about how to use the mouse and how to implement scrolling!
To check how your mouse is interacting with a certain object, use the uiz_mouse_isOver_object_leftCheck function. You can find more info on this function by extending the "Mouse" section in the wiki sidebar and clicking uiz_mouse_isOver.
uiz_mouse_isOver_object_leftCheck will give you the following values:
- uiz_nomouse: The mouse is not clicking the frame nor hovering over it.
- uiz_mouseover: The mouse is hovering over the frame but not clicking it.
- uiz_mousepressed: The mouse is hovering over the frame and has justbeen clicked. (only counts for one single step)
- uiz_mouseclick: The mouse is hovering over the frame and holding themouse button.
- uiz_mousereleased: The mouse is hovering over the frame and has just been released. (only counts for one single step)
So, when your mouse clicks an object, you can expect uiz_mouse_isOver_object_leftCheck for that object to return a value of uiz_mouseclick, while if the mouse wouldnβt be over the object at all, it would be uiz_nomouse. The pressed and released values (uiz_mousepressed and uiz_mousereleased) work just like you expect them to in Game Maker.
There are a multiple ways to implement scroll wheels. In this tutorial, I will show you a method using a obj_uiZ_frame object. A obj_uiZ_frame is a lot like a obj_uiZ_canvas. However, the frame has some more advanced features, like scrollbar support.
To showcase this variables properly, create a new object in a new room, and in itβs create event, init uiz, and create a frame somewhere in the middle of the screen, just an empty frame object.
You code should look somewhat like this:
EXAMPLE 44:
//init uiz
uiz_init()
//create a frame
frame = uiz_c(obj_uiZ_frame);
//set values
uiz_position_t(frame, uiz_center, uiz_center);
uiz_size(frame, 1,dp, 0.5, dp);
//fix our frame
uiz_fix(frame)
Which looks like:
IMAGE 57Now, we canβt see anything because the frame is invisible, but letβs add an object. In these cases I prefer using a gradient square, because itβs edges are easy to see and thus makes for a great debugging object. The default values for it might not be that pretty, but they are fine to showcase it to you now. Weβll make our gradientsquare higher than our frame though. You can make it twice or even trice as high.
EXAMPLE 45:
//init uiz
uiz_init()
//create a frame
frame=uiz_c(obj_uiZ_frame);
//set values
uiz_position_t(frame, uiz_center, uiz_center);
uiz_size(frame, 1,dp, 0.5, dp);
//fix our frame
uiz_fix(frame)
//create gradientsquare
grad=uiz_c(obj_uiZ_gradientsquare)
//put it in our frame
uiz_setParent(grad,frame)
//make it fill our frame
uiz_position_t(grad, uiz_fill, uiz_top);
uiz_size_h(grad, 2,dp);
//fix our grad
uiz_fix(grad)
Now, this should look like:
IMAGE 58Now you can clearly see that the gradientsquare is not being fully drawn. This is because of the containment system uiz has. The left-bottom of the gradientsquare is c_aqua and that of the right-bottom is c_purple, which isnβt what we are seeing here.
There is functionality build into frames that allow them to easily have scroll bars. To get started with using scrollbars you simply need the uiz_frame_setscrollable function. This line will say βThis frame is now able to have a scrollbar.β It doesnβt have to mean that there is a scrollbar. If the content inside the frame is smaller than the frame itself, a scrollbar doesnβt have to be drawn at all, so uiZ disables it.
However, there are a few problems with this. First, the frame must know all the positions of all the objects inside the frame. But that requires the objects inside the frame to know the position of the parent. And having or not having a scrollbar can influence the usable space of the frame. It almost looks like some sort of stupid loop. However, it is not if you use the function
Making a more custom scrollbar using objects. Another way of making our frame completely scrollable, weβll add the object βobj_uiZ_framescrollbarβ However we need to position the object ourselves and when weβve done that we just need to set the variable βframeβ to the frame we want to scroll, and weβre automatically done.
EXAMPLE 46:
//init uiz
uiz_init()
//create a frame
frame=uiz_c(obj_uiZ_frame);
//set values
uiz_position_t(frame, uiz_center, uiz_center);
uiz_size(frame, 1,dp, 3, dp);
uiz_frame_setscrollable(frame, false, true);
//fix our frame
uiz_fix(frame)
//create gradientsquare
grad=uiz_c(obj_uiZ_gradientsquare)
//put it in our frame
uiz_setParent(grad,frame)
//make it fill our frame
uiz_position_t(grad, uiz_fill, uiz_top);
uiz_size_h(grad, 8,dp);
//fix our grad
uiz_fix(grad)
//fix our frame
uiz_fix(frame)
Which looks like:
IMAGE 60Congrats, you now know how to make a scrollable frame.
That was actually the last part in the basic tutorial. In the future other tutorials will be added. Anyways, I hope you are now able to create your own ui. This tutorial didnβt go too far into all the settings of objects, and you will have to look at the manual for that. But at least you know how to position them anywhere in a structured ui. From here I would recommend following the βmake your own objectβ tutorials. Good luck!
And remember, if you have any questions, hit me up on the game maker forum: https://forum.yoyogames.com/index.php?members/tthecreator.233/
Or make an issue on GitHub:
https://github.com/Tthecreator/uiZ/issues
πTutorials
Basics 1: Basic positioning
Basics 2: Parenting system
Basics 3: Advanced positioning
Basics 4: Advanced sizing and set point
Basics 5: Canvas and containment
Basics 6: Alpha and depth
Basics 7: Using the manual and Animations
Basics 8: Object backgrounds
Basics 9: Grids
Basics 10: Framesets
Basics 11: Windows
Basics 12: Scroll bars
βοΈ Positioning
π Depth
π Structures
π Objects
obj_uiZ_3waybutton
obj_uiZ_button
obj_uiZ_checkbox
obj_uiZ_clock
obj_uiZ_colorbox
obj_uiZ_cover
obj_uiZ_drawdslist
obj_uiZ_dropdown
obj_uiZ_easybutton
obj_uiZ_frame
obj_uiZ_framescrollbar
obj_uiZ_functionbar
obj_uiZ_gradientsquare
obj_uiZ_gradientroundrect
obj_uiZ_gridlist
obj_uiZ_huesquare
obj_uiZ_loadingbar
obj_uiZ_loadingcircle
obj_uiZ_menubutton
obj_uiZ_mousemenu
obj_uiZ_radiobox
obj_uiZ_rotator
obj_uiZ_slider
obj_uiZ_scrollbar
obj_uiZ_slider_2col
obj_uiZ_slickslider
obj_uiZ_slideframe
obj_uiZ_sprbutton
obj_uiZ_spriteanimationbutton
obj_uiZ_spritecounter
obj_uiZ_stringbox
obj_uiZ_sliderstruct
obj_uiZ_surfacecanvas
obj_uiZ_sprite
obj_uiZ_square
obj_uiZ_squarebutton
obj_uiZ_swipicon
obj_uiZ_switch
obj_uiZ_tabslider
obj_uiZ_tabs
obj_uiZ_treelist
obj_uiZ_text
obj_uiZ_text_background
obj_uiZ_textarea
obj_uiZ_valuebox
π Strings
uiz_addChar
uiz_changechar
uiz_charCanHaveAddon
uiz_returnCharAddon
uiz_charIsNumber
uiz_charIsNumberOrText
uiz_getlines
uiz_gettext_contained
uiz_gettextlines_contained
uiz_getValidVariableName
uiz_isSpaceChar
uiz_lastStringChars
uiz_removeChar
uiz_replaceChars_
uiz_string_copy
uiz_string_digits
uiz_string_format
uiz_string_fromReal
uiz_string_real_getFracLength
uiz_string_real_getIntLength
uiz_string_repeat
uiz_string_replace
uiz_string_pos_at
uiz_stringUntilNewline