> For the complete documentation index, see [llms.txt](https://docs.perfectcs2.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.perfectcs2.com/exemplos/mira.md).

# Mira personalizada

Desenha uma mira no centro da tela, com estilo, tamanho, espaço, cor e contorno. Mostra:

* uma opção com cor (`ui.toggle` com `color`);
* opções bloqueadas conforme outra (`:enabled` dentro de `:callback`);
* desenho com `render.rect_filled` e `render.circle_filled`.

Salve como `crosshair.lua` na pasta de scripts e ligue na aba **Scripts**.

```lua
-- @name Custom Crosshair
-- @author perfect
-- @version 1.0
-- @description Draws a crosshair with size, gap, color and outline.

ui.group("Crosshair", "Lines at the center of the screen")
local enabled = ui.toggle("Enabled", "Draw the crosshair", true, color(255, 255, 255))
local style   = ui.combo("Style", "Shape of the crosshair", { "Cross", "Dot", "T-Shape" })
local size    = ui.slider("Size", "Length of each line", 2, 20, 6, "%.0f px")
local gap     = ui.slider_int("Gap", "Space in the middle", 0, 10, 3, "%d px")
local outline = ui.toggle("Outline", "Dark border around the lines", true)

-- Size and gap don't apply to the dot.
local function refresh()
    local dot = style:get() == "Dot"
    size:enabled(not dot, "Not used by the Dot style")
    gap:enabled(not dot, "Not used by the Dot style")
end
style:callback(refresh)
refresh()

local function bar(x, y, w, h, clr)
    if outline:get() then
        render.rect_filled(x - 1, y - 1, w + 2, h + 2, color(0, 0, 0, 200))
    end
    render.rect_filled(x, y, w, h, clr)
end

callbacks.add("draw", function()
    local on, clr = enabled:get()
    if not on then return end

    local w, h = render.screen_size()
    local cx, cy = math.floor(w / 2), math.floor(h / 2)
    local length, space = size:get(), gap:get()

    if style:get() == "Dot" then
        if outline:get() then render.circle_filled(cx, cy, 3.5, color(0, 0, 0, 200)) end
        render.circle_filled(cx, cy, 2.5, clr)
        return
    end

    if style:get() == "Cross" then
        bar(cx - 1, cy - space - length, 2, length, clr) -- top
    end
    bar(cx - 1, cy + space, 2, length, clr)              -- bottom
    bar(cx - space - length, cy - 1, length, 2, clr)     -- left
    bar(cx + space, cy - 1, length, 2, clr)              -- right
end)
```

Com o estilo **Dot**, o tamanho e o espaço ficam apagados no menu, com a explicação ao passar o mouse.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.perfectcs2.com/exemplos/mira.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
