🟡cl_block
cl_block serves as an interactive draggable block object for GUI-based applications in Garry's Mod. Derived from GMod's VGUI, it is specifically tailored for block-based logic layout resembling platfo
BLOCK Class Definition:
Properties:
isDragging
- Determines whether the block is currently being dragged by the user.dragOffsetX
,dragOffsetY
- Record the offset position of the cursor when dragging starts.color
- Represents the color of the block.connectorLength
- The length of the connector displayed when blocks are connected.connectedBlock
- Holds information about any block it's connected to.
Functions & Methods:
Init() - Initializes the block, setting its default size, color, and other properties.
SetBlockColor(col) - Sets the color of the block.
col
: Color type.
CheckCollision(other) - Checks if the block is colliding with another block.
other
: Other block object.
SetBarSide(side) - Sets the side (left/right) for the connection bar on the block.
side
: String ("left" or "right").
Disconnect() - Disconnects the current block from any other block it's connected to.
OnMousePressed() - Called when the block is clicked on; enables dragging and disconnects from any connected block.
OnMouseReleased() - Called when the mouse button is released; stops the dragging action.
Think() - Constantly running logic when block is dragged; handles connections and collisions with other blocks.
SetBlockWidth(width) - Sets the width of the block.
width
: Numeric width value.
SetBlockHeight(height) - Sets the height of the block.
height
: Numeric height value.
Paint(w, h) - Called to paint the block on the screen; handles its appearance and any connectors if connected.
w
: Width of the block.h
: Height of the block.
Example Usage:
-- Create a Dlib Frame
local frame = vgui.Create("Dlib.Frame")
frame:SetSize(500, 500)
frame:Center()
-- Add first Dlib Block to the frame
local block1 = vgui.Create("Dlib.Block", frame)
block1:SetPos(50, 50)
block1:SetBlockWidth(50)
block1:SetBlockHeight(100)
block1:SetBlockColor(Color(255, 0, 0))
block1:SetBarSide("left") -- Set bar on the left side
-- Add second Dlib Block to the frame
local block2 = vgui.Create("Dlib.Block", frame)
block2:SetPos(200, 200)
block2:SetBlockWidth(150)
block2:SetBlockHeight(100)
block2:SetBlockColor(Color(0, 255, 0))
block2:SetBarSide("right") -- Set bar on the right side
Preview:

Note:
Ensure that any application using cl_block
has appropriate error handling and collision detection to ensure smooth user experience and performance.
Last updated