All Projects → wyozi → 3d2d-imgui

wyozi / 3d2d-imgui

Licence: MIT License
Immediate mode 3D2D UI for Garry's Mod

Programming Languages

lua
6591 projects

Labels

Projects that are alternatives of or similar to 3d2d-imgui

VJ-Base
An addon for Garry's mod that contains bunch of bases to make many different types of addons.
Stars: ✭ 57 (+39.02%)
Mutual labels:  gmod, glua
Half-Life-Resurgence
Recreation & expansion of NPCs, entities, and weapons from the Half-Life series into Garry's Mod!
Stars: ✭ 52 (+26.83%)
Mutual labels:  gmod, glua
3D2D-Textscreens
3D2D Textscreens Garry's Mod Workshop Addon
Stars: ✭ 26 (-36.59%)
Mutual labels:  gmod, glua
Autorun-rs
Undetectable scripthook with lua execution and filesteal. Modern replacement for gluasteal and most lua executors
Stars: ✭ 63 (+53.66%)
Mutual labels:  gmod, glua
Fun
Small fun scripts
Stars: ✭ 22 (-46.34%)
Mutual labels:  gmod, glua
helix-plugins
github.com/Bilwin/helix-plugins
Stars: ✭ 24 (-41.46%)
Mutual labels:  gmod, glua
gmod-medialib
Media playback library for Garry's Mod.
Stars: ✭ 28 (-31.71%)
Mutual labels:  gmod, glua
EasyChat
A modular Garry's Mod chat addon for both users and developers.
Stars: ✭ 74 (+80.49%)
Mutual labels:  gmod
zombie-escape
🏃 Gamemode for Garry's Mod based on the popular Counter-Strike: Source server mod
Stars: ✭ 17 (-58.54%)
Mutual labels:  gmod
glua-docs
🔍 Quick documentation lookup for Garry's Mod Lua
Stars: ✭ 14 (-65.85%)
Mutual labels:  gmod
helix
A Garry's Mod roleplaying framework developed by nebulous for the people. Helix IS open-source - the code can be used as you wish.
Stars: ✭ 123 (+200%)
Mutual labels:  gmod
machado
This repository provides users with a framework to store, search and visualize biological data.
Stars: ✭ 18 (-56.1%)
Mutual labels:  gmod
map-compiling-toolkit
Tools for map compiling in Source Engine, tailored for Garry's Mod (and metastruct, sorry)
Stars: ✭ 17 (-58.54%)
Mutual labels:  gmod
gSynch
gSynch allows you to synchronise your Git repository with your Steam Workshop publication in few clicks.
Stars: ✭ 28 (-31.71%)
Mutual labels:  gmod
GModCEFCodecFix
Automatic Patching/Updating of GMod CEF
Stars: ✭ 68 (+65.85%)
Mutual labels:  gmod
ui3d2d
A clean and simple 3D2D UI library for Garry's Mod. Built to be easy to use and optimised.
Stars: ✭ 18 (-56.1%)
Mutual labels:  gmod
sourcesdk-minimal
A compact and Garry's Mod compatible SourceSDK (don't use in other Source engine games).
Stars: ✭ 34 (-17.07%)
Mutual labels:  gmod
BadCoderz
Find unoptimized gmod addons and KILL the devs who made them
Stars: ✭ 66 (+60.98%)
Mutual labels:  gmod
gm luaerror
A module for Garry's Mod that adds hooks for obtaining errors that happen on the client and server (if activated on server, it also pushes errors from clients).
Stars: ✭ 35 (-14.63%)
Mutual labels:  gmod
Pointshop2
Next-Gen Garrysmod shop system https://discord.gg/N9DmwwX
Stars: ✭ 37 (-9.76%)
Mutual labels:  gmod

3D2D Immediate Mode GUI for Garry's Mod

3D2D panels made simple.

USE IMGUI INSTEAD

Development of this library has been stopped and you should use IMGUI library. It has a more flexible API and fixes many of the fundamental design issues this library has had from the beginning, especially related to heap memory usage. Here's a small comparison of equivalent code rendering 30 clickable buttons in each library:

tdui used 	24.4609375	 kbytes of heap memory
imgui used 	0.21484375	 kbytes of heap memory

Example

example

local tdui = include("tdui.lua") -- tdui.lua should be in same folder and AddCSLuaFile'd

local p
hook.Add("PostDrawTranslucentRenderables", "Paint3D2DUI", function(bDrawingSkybox, bDrawingDepth)
    -- This is required so that TDUI isn't drawn twice (which would break input)
    if bDrawingDepth then return end

    -- Create a 3D2D-IMGUI instance and cache it
    -- Note: if drawing TDUI inside a ENT:Draw(), you should cache the
    --       panel to the entity instance (self) instead of a local variable.
    --       That way there will be one panel per entity.
    p = p or tdui.Create()

    -- Draw a rectangle (x, y, w, h, [fill_color], [outline_color])
    p:Rect(-320, 0, 640, 600, _, Color(255, 255, 255))

    -- Draw a line of text (text, font, x, y, [color], [halign], [valign])
    -- Note: text is implicitly horizontally centered
    p:Text("Hello there!", "!Roboto@100", 0, 20)

    -- Draw a button (text, font, x, y, w, h, [color])
    -- Return value is boolean indicating whether left mouse or +use was pressed during this frame
    if p:Button("Say hi", "DermaLarge", -200, 160, 400, 100) then
        RunConsoleCommand("say", "hi!")
    end

    -- Draws a simple crosshair cursor at current mouse position
    p:Cursor()

    -- Renders all the queued draw commands at given 3D location (this one's near gm_construct wall)
    p:Render(Vector(980, -83, -79), Angle(0, 0, 0), 0.1)
end)

Installation

Copy tdui.lua into a folder in your addon and make sure it is AddCSLuaFiled.

Usage

Panel creation (should be called only once):

local p = tdui.Create()

Drawing components (should be called in a drawing hook, eg. ENT:Draw() or PostDrawTranslucentRenderables):

p:Rect(x, y, w, h, [fill_color], [outline_color])

p:Mat(material, x, y, w, h)

-- Same vertices layout as surface.DrawPoly
p:Polygon(vertices, color, material)

-- Note: horizontally aligned to center by default
p:Text(text, font, x, y, [color], [halign], [valign], [scissor_rect])

local isMouseOrUseDown = p:Button(text, font, x, y, w, h, [color])
if isMouseOrUseDown then
 	-- this is only called once per press
	print "Hello!"
end

-- Note: because TDUI attempts to be as stateless as possible, you need to pass
-- the current slider value to the slider function. The fraction returned by the
-- function is the new slider value.
-- Fraction is a numeric value between 0 and 1. TDUI Slider has no concept of "min" and "max"
-- values. You'll need to calculate those yourself.
local frac = p:Slider(gFrac, x, y, w, h)
if frac ~= gFrac then
	print "Slider value changed!"
	gFrac = frac
end

-- You can pass normal GMod fonts to the font parameter of p:Text and p:Button
-- but it also accepts some special formats that you can use:

p:Text("Hello world", "!Roboto@18", 0, 0)
-- This kind of syntax automatically creates and caches a font based on "Roboto"
-- typeface at size 18. The caching is pretty efficient so this can be used even
-- in finished projects, not just during development.

p:Cursor()

Configuration:

-- Draws and accepts input through walls
p:SetIgnoreZ(true)

-- Scales (multiplies) all UI elements by this value. This can be used during development
-- to test different UI scales or if you're lazy and don't want to scale values by hand.
-- This method also scales fonts that use the special !Typeface@Size format
p:SetUIScale(10)

-- Adds this tdui to list of tduis that are checked when the player presses +use bind
-- If said bind is pressed and user is hovering a TDUI on the list, the bind is blocked.
-- This is useful for eg. TDUIs inside cars, so that player doesn't leave car upon pressing +use
-- on tdui.
p:BlockUseBind()

Rendering (should be called in same drawing hook as drawing components):

p:Render(pos, angles, scale)

Tips

Code is mostly self-documenting. If there's a part you don't understand, feel free to post an issue.

Cache the panel. Use a local variable for hooks and self.Panel = self.Panel or tdui.CreatePanel() for ENT:Draw().

Make the scale parameter to p:Render as small as possible (eg. 0.1) and compensate by either scaling UI elements manually or by using p:SetUIScale. This makes the elements look sharper.

Don't be afraid to use the y-axis as the horizontal center point. 3D2D-IMGUI supports negative coordinates and the example uses them.

If you need to make eg. scrolling text, p:Text() accepts scissor_rect as the last parameter. It should be a table containing x, y, x2, y2.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].