### Integrate with VGUI Panels using Paint Helpers (Lua) Source: https://context7.com/jaffies/paint/llms.txt Demonstrates how to use `paint.startPanel`/`paint.endPanel` and `paint.startVGUI`/`paint.endVGUI` for drawing within VGUI panels. Includes examples for handling coordinate translation and scissor rect clipping for nested elements like DScrollPanel. ```lua function PANEL:Paint(w, h) paint.startPanel(self, true, true) -- pos=true, boundaries=true paint.roundedBoxes.roundedBox(16, 0, 0, w, h, color_white) paint.circles.drawCircle(w/2, h/2, 30, 30, Color(255, 0, 0)) paint.endPanel(true, true) end ``` ```lua function PANEL:Paint(w, h) paint.startVGUI() paint.roundedBoxes.roundedBox(32, 0, 0, w, h, { Color(255, 0, 0), Color(0, 255, 0), Color(0, 0, 255), Color(255, 255, 0) }) paint.endVGUI() end ``` ```lua function PANEL:Paint(w, h) local x, y = self:LocalToScreen(0, 0) paint.pushScissorRect(x, y, x + w, y + h) -- Content here is clipped to panel bounds paint.startPanel(self) paint.roundedBoxes.roundedBox(8, -10, -10, w + 20, h + 20, color_white) paint.endPanel() paint.popScissorRect() end ``` -------------------------------- ### Optimize Drawing with paint.batch Source: https://context7.com/jaffies/paint/llms.txt The paint.batch module consolidates multiple draw calls into single meshes for significant performance gains, especially for complex UIs or data visualizations. It provides functions to start and stop batching, draw batched meshes, automatically rebuild panel meshes, and apply relative positioning to batched elements. ```lua -- Batch multiple rectangles paint.batch.startBatching() for i = 1, 100 do paint.rects.drawRect(i * 15, 100, 12, 50, { color_white, Color(100, 100, 100), Color(100, 100, 100), color_white }) end local batchedMesh = paint.batch.stopBatching() -- Draw the batched mesh render.SetMaterial(paint.defaultMaterial) batchedMesh:Draw() -- Batch rounded boxes paint.batch.startBatching() for i = 1, 50 do paint.roundedBoxes.roundedBox(8, i * 20, 200, 16, 40, HSVToColor(i * 7, 1, 1)) end local roundedMesh = paint.batch.stopBatching() -- Panel with automatic mesh rebuilding local panel = vgui.Create("DPanel") paint.batch.wrapPanel(panel) function panel:PaintMesh(w, h) -- This is called automatically when panel size changes paint.roundedBoxes.roundedBox(16, 0, 0, w, h, color_white) paint.circles.drawCircle(w/2, h/2, 20, 20, Color(255, 0, 0)) end -- Batch with relative positioning paint.batch.setRelativePosition(100, 50) paint.batch.startBatching() -- All coordinates are now offset by (100, 50) paint.rects.drawRect(0, 0, 50, 50, color_white) paint.batch.stopBatching() ``` -------------------------------- ### Parse and Render SVGs with paint.svg (Lua) Source: https://context7.com/jaffies/paint/llms.txt Demonstrates the functionality of the `paint.svg` module for parsing SVG content and generating meshes. Currently supports `rect` and `circle` elements with basic attributes like `fill`, `stroke`, and positioning. Includes examples for parsing SVG strings, generating meshes, drawing them, and handling color definitions. ```lua -- Parse SVG string local svgContent = [[ ]] local parsedSVG = paint.svg.parseSVG(svgContent) ``` ```lua -- Generate mesh from parsed SVG local svgMesh = paint.svg.generateIMesh(parsedSVG, { w = 200, h = 200, x = 100, y = 100 }) ``` ```lua -- Draw the SVG mesh render.SetMaterial(paint.defaultMaterial) svgMesh:Draw() ``` ```lua -- Using CSS colors local blueColor = paint.svg.colors['blue'] local customColor = paint.svg.colors.fromHex('#FF5733') ``` -------------------------------- ### Apply SSAA Anti-Aliasing with Downsampling (Lua) Source: https://context7.com/jaffies/paint/llms.txt Utilizes the `paint.downsampling` module to implement Super-Sampling Anti-Aliasing (SSAA) by rendering graphics at double resolution and then downscaling. This results in significantly smoother edges for rendered shapes. Examples show basic usage and an option to disable automatic coordinate multiplication. ```lua -- Basic SSAA usage function PANEL:Paint(w, h) paint.downsampling.start() -- Everything drawn here is at 2x resolution paint.roundedBoxes.roundedBox(16, 0, 0, w * 2, h * 2, color_white) paint.circles.drawCircle(w, h, 60, 60, Color(255, 0, 0)) paint.downsampling.stop() end ``` ```lua -- Without coordinate multiplication (stopMultiply = true) function PANEL:Paint(w, h) paint.downsampling.start(true) -- Coordinates are not auto-scaled paint.roundedBoxes.roundedBox(16, 0, 0, w, h, color_white) paint.downsampling.stop() end ``` -------------------------------- ### Create Tintable Materials with getColoredMaterial (Lua) Source: https://context7.com/jaffies/paint/llms.txt Showcases the `paint.getColoredMaterial` function, which generates a reusable material adaptable to any color. This is particularly useful for creating dynamic visual effects like animated halos or pulsing elements without the overhead of mesh regeneration. Examples include an animated halo and a pulsing circle. ```lua -- Animated halo/shadow effect function PANEL:Paint(w, h) local animatedColor = HSVToColor(RealTime() * 100, 1, 1) local coloredMat = paint.getColoredMaterial(animatedColor) paint.outlines.drawOutline(32, 0, 0, w, h, { color_white, color_transparent }, coloredMat, 16) end ``` ```lua -- Pulsing circle with color animation function PANEL:Paint(w, h) local pulse = math.sin(RealTime() * 3) * 0.5 + 0.5 local color = Color(255 * pulse, 100, 255 * (1 - pulse)) local mat = paint.getColoredMaterial(color) paint.circles.drawCircle(w/2, h/2, 40, 40, color_white, 32, nil, nil, mat) end ``` -------------------------------- ### Draw Rectangles with Paint Library Source: https://context7.com/jaffies/paint/llms.txt Illustrates drawing rectangles using the `paint.rects` module. Features include solid colors, per-corner gradients, material texturing, UV mapping, and optional skew transformations. Rectangles can be batched for performance. ```lua paint.rects.drawRect(100, 100, 200, 100, color_white) paint.rects.drawRect(100, 100, 128, 64, { Color(255, 0, 0), -- Top Left Color(0, 255, 0), -- Top Right Color(0, 0, 255), -- Bottom Right Color(255, 255, 0) -- Bottom Left }) local mat = Material("icon16/application_xp.png") paint.rects.drawRect(100, 100, 64, 64, color_white, mat, 0.5, 0, 1, 0.75) paint.rects.drawRect(64, 0, 64, 64, { Color(255, 0, 0), Color(0, 255, 0), Color(0, 0, 255), color_white }, mat) paint.rects.drawRect(100, 100, 100, 50, color_white, nil, 0, 0, 1, 1, 20) ``` -------------------------------- ### Draw Rounded Boxes with Paint Library Source: https://context7.com/jaffies/paint/llms.txt Demonstrates drawing rounded boxes using the `paint.roundedBoxes` module. Supports solid colors, per-corner gradients, custom materials, UV coordinates, and squircle shapes. The `roundedBoxEx` function allows for asymmetrical rounding. ```lua paint.roundedBoxes.roundedBox(32, 100, 100, 200, 100, color_white) paint.roundedBoxes.roundedBox(20, 50, 50, 128, 64, { Color(255, 0, 0), -- Top Left (red) Color(0, 255, 0), -- Top Right (green) Color(0, 0, 255), -- Bottom Right (blue) Color(255, 255, 0), -- Bottom Left (yellow) Color(0, 0, 0) -- Center (black) }) local iconMaterial = Material("icon16/application_xp.png") paint.roundedBoxes.roundedBox(16, 100, 100, 64, 64, color_white, iconMaterial) paint.roundedBoxes.roundedBox(32, 100, 100, 128, 128, color_white, iconMaterial, 0.25, 0.25, 0.75, 0.75) paint.roundedBoxes.roundedBoxEx(16, 100, 100, 100, 50, color_white, false, true, false, true) paint.roundedBoxes.roundedBox(32, 100, 100, 100, 100, color_white, nil, nil, nil, nil, nil, 4) ``` -------------------------------- ### Create Hollow Outlines with paint.outlines Source: https://context7.com/jaffies/paint/llms.txt The paint.outlines module generates hollow outlines for rounded boxes. It supports gradient coloring, per-side thickness control, and custom parameters for advanced effects like glows and shadows. An extended function `drawOutlineEx` allows for asymmetrical outlines. ```lua -- Basic outline with gradient (inner to outer color) paint.outlines.drawOutline(32, 100, 100, 128, 64, { Color(255, 255, 255), -- Inner edge Color(0, 0, 0) -- Outer edge }, nil, 8) -- Transparent fade-out outline (shadow/glow effect) paint.outlines.drawOutline(32, 100, 100, 128, 64, { Color(255, 255, 255), Color(255, 255, 255, 0) -- Transparent outer edge }, nil, 16) -- Outline with different thickness per side (left, top, right, bottom) paint.outlines.drawOutline(16, 100, 100, 100, 100, color_white, nil, 8, 4, 8, 4) -- Animated rainbow outline local color1 = HSVToColor(RealTime() * 120, 1, 1) local color2 = HSVToColor(RealTime() * 120 + 30, 1, 1) paint.outlines.drawOutline(32, 100, 100, 128, 64, {color1, color2}, nil, 16) -- Asymmetrical outline (specific corners only) -- drawOutlineEx(radius, x, y, w, h, leftTop, rightTop, rightBottom, leftBottom, colors, material, l, t, r, b) paint.outlines.drawOutlineEx(16, 100, 100, 100, 100, true, false, true, false, color_white, nil, 8) ``` -------------------------------- ### Draw Circles and Ellipses with Paint Library Source: https://context7.com/jaffies/paint/llms.txt Showcases drawing circles and ellipses using the `paint.circles` module. Supports gradients, angle slicing for pie charts, squircle shapes, and material texturing. Uses center coordinates for positioning and includes an `drawOutline` function. ```lua paint.circles.drawCircle(200, 200, 50, 50, color_white) paint.circles.drawCircle(200, 200, 80, 40, color_white) paint.circles.drawCircle(200, 200, 60, 60, { Color(255, 255, 255), -- Center color Color(0, 0, 255) -- Edge color }) paint.circles.drawCircle(200, 200, 50, 50, Color(255, 0, 0), 24, 0, 90) paint.circles.drawCircle(200, 200, 50, 50, Color(255, 0, 0), 24, 0, 120) paint.circles.drawCircle(200, 200, 50, 50, Color(0, 255, 0), 24, 120, 240) paint.circles.drawCircle(200, 200, 50, 50, Color(0, 0, 255), 24, 240, 360) paint.circles.drawCircle(200, 200, 50, 50, color_white, 32, 0, 360, nil, 0, 4) paint.circles.drawOutline(200, 200, 50, 50, { Color(255, 255, 255), -- Inner edge Color(0, 0, 255) -- Outer edge }, 10, 32) ``` -------------------------------- ### Apply Screen Blur Effects with paint.blur Source: https://context7.com/jaffies/paint/llms.txt The paint.blur module enables applying screen blur effects to any paint shape, simulating frosted glass or depth-of-field. It captures and processes screen content, returning a blur material or texture. Custom blur parameters can be specified. ```lua -- Basic blur usage in a panel function PANEL:Paint(w, h) local x, y = self:LocalToScreen(0, 0) local scrW, scrH = ScrW(), ScrH() -- Get the blur material local blurMat = paint.blur.getBlurMaterial() -- Draw blurred rectangle with UV mapping to screen position paint.rects.drawRect(0, 0, w, h, color_white, blurMat, x / scrW, y / scrH, (x + w) / scrW, (y + h) / scrH) end -- Blurred rounded box function PANEL:Paint(w, h) local x, y = self:LocalToScreen(0, 0) local scrW, scrH = ScrW(), ScrH() local blurMat = paint.blur.getBlurMaterial() paint.roundedBoxes.roundedBox(32, 0, 0, w, h, color_white, blurMat, x / scrW, y / scrH, (x + w) / scrW, (y + h) / scrH) end -- Custom blur with specific parameters -- getBlurMaterial(id, time, blurStrength, passes, expensive) local customBlur = paint.blur.getBlurMaterial('myBlur', 1/60, 15, 2, true) -- Get blur as texture instead of material local blurTexture = paint.blur.getBlurTexture() ``` -------------------------------- ### Stencil Masking for Advanced UI Effects in Lua Source: https://context7.com/jaffies/paint/llms.txt Demonstrates how to use Source Engine stencils with the Paint library in Lua for advanced masking effects like ripple animations and custom clipping. It configures stencil buffer operations to control drawing areas. Requires the Paint library and Source Engine's rendering capabilities. ```lua local function mask(drawMask, drawContent) render.ClearStencil() render.SetStencilEnable(true) render.SetStencilWriteMask(1) render.SetStencilTestMask(1) render.SetStencilFailOperation(STENCIL_REPLACE) render.SetStencilPassOperation(STENCIL_REPLACE) render.SetStencilZFailOperation(STENCIL_KEEP) render.SetStencilCompareFunction(STENCIL_ALWAYS) render.SetStencilReferenceValue(1) drawMask() render.SetStencilFailOperation(STENCIL_KEEP) render.SetStencilPassOperation(STENCIL_REPLACE) render.SetStencilCompareFunction(STENCIL_EQUAL) drawContent() render.SetStencilEnable(false) end -- Material Design ripple effect button function BUTTON:Paint(w, h) paint.startPanel(self) mask(function() paint.roundedBoxes.roundedBox(16, 0, 0, w, h, Color(33, 150, 243)) end, function() if self.ripple then local progress = (RealTime() - self.ripple.time) / 0.5 if progress < 1 then local radius = math.max(w, h) * progress * 1.5 local alpha = 80 * (1 - progress) paint.circles.drawCircle(self.ripple.x, self.ripple.y, radius, radius, ColorAlpha(color_white, alpha)) end end end) paint.endPanel() end ``` -------------------------------- ### Draw Gradient Lines with paint.lines Source: https://context7.com/jaffies/paint/llms.txt The paint.lines module draws lines between two points, supporting single colors or per-vertex gradients for smooth color transitions. Multiple lines can be drawn in sequence. ```lua -- Simple line with single color paint.lines.drawLine(10, 10, 200, 150, Color(255, 255, 255)) -- Gradient line (different start and end colors) paint.lines.drawLine(10, 20, 200, 100, Color(0, 255, 0), Color(255, 0, 255)) -- Multiple gradient lines paint.lines.drawLine(40, 10, 70, 40, Color(255, 255, 0)) paint.lines.drawLine(100, 50, 300, 200, Color(255, 0, 0), Color(0, 0, 255)) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.