ahk binding library for cimgui

Post your working scripts, libraries and tools.
kazhafeizhale
Posts: 77
Joined: 25 Dec 2018, 10:58

ahk binding library for cimgui

16 Sep 2023, 05:51

cimgui-ahk
Auto generated ahk wrapper for Dear ImGui via cimgui

It comes with a default backend with win32 dx11

It works on , windows(x64)

Current solution is:
Use cimgui's json generate function and struct definition
The type system supports the ctypes library by thqby
540617b1176fa053a11679d1b10e135dfbc112c226f8114bc1a90b8137ae64c2.png
540617b1176fa053a11679d1b10e135dfbc112c226f8114bc1a90b8137ae64c2.png (90.89 KiB) Viewed 3372 times
https://github.com/sxzxs/cimgui-ahk
kazhafeizhale
Posts: 77
Joined: 25 Dec 2018, 10:58

Re: ahk binding library for cimgui

24 Sep 2023, 03:35

add Log in to demo
image.png
image.png (292.44 KiB) Viewed 3136 times
crocodile
Posts: 98
Joined: 28 Dec 2020, 13:41

Re: ahk binding library for cimgui

24 Sep 2023, 12:00

Thank you for your work.
What are its advantages over imgui4ahk? Which one should I use?
kazhafeizhale
Posts: 77
Joined: 25 Dec 2018, 10:58

Re: ahk binding library for cimgui

24 Sep 2023, 21:02

crocodile wrote:
24 Sep 2023, 12:00
Thank you for your work.
What are its advantages over imgui4ahk? Which one should I use?
cimgui is recommended because it is automatically generated by the tool and the function is more complete
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: ahk binding library for cimgui

25 Sep 2023, 00:44

Trying to run the examples from the freshly cloned repository (Authotkey V2.0.9):
AutoHotkey64_KAQIp0oN2Z.png
AutoHotkey64_KAQIp0oN2Z.png (14.52 KiB) Viewed 2855 times
kazhafeizhale
Posts: 77
Joined: 25 Dec 2018, 10:58

Re: ahk binding library for cimgui

25 Sep 2023, 01:04

hoppfrosch wrote:
25 Sep 2023, 00:44
Trying to run the examples from the freshly cloned repository (Authotkey V2.0.9):

AutoHotkey64_KAQIp0oN2Z.png
Sorry,sizeof is built in to version H.
I checked it just now, and there may be a few changes that need to be made
You can run it with version H first
https://github.com/thqby/AutoHotkey_H/releases
kazhafeizhale
Posts: 77
Joined: 25 Dec 2018, 10:58

Re: ahk binding library for cimgui

25 Sep 2023, 02:34

hoppfrosch wrote:
25 Sep 2023, 00:44
Trying to run the examples from the freshly cloned repository (Authotkey V2.0.9):

AutoHotkey64_KAQIp0oN2Z.png
I have made compatibility changes to version L, version 2.0.10 test
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: ahk binding library for cimgui

26 Sep 2023, 00:31

I have made compatibility changes to version L, version 2.0.10 test
Works now - thx for your fast response!
kazhafeizhale
Posts: 77
Joined: 25 Dec 2018, 10:58

Re: ahk binding library for cimgui

26 Sep 2023, 10:38

Add demo
image.png
image.png (373.89 KiB) Viewed 2724 times
crocodile
Posts: 98
Joined: 28 Dec 2020, 13:41

Re: ahk binding library for cimgui

26 Sep 2023, 11:18

What image formats does imgui support? I found that it can't open .avif images.
kazhafeizhale
Posts: 77
Joined: 25 Dec 2018, 10:58

Re: ahk binding library for cimgui

26 Sep 2023, 23:25

crocodile wrote:
26 Sep 2023, 11:18
What image formats does imgui support? I found that it can't open .avif images.
There are two interfaces available here:
1、 ImageFromFile use D3DX11CreateShaderResourceViewFromFileW

2、LoadTextureFromFile use stb_image
crocodile
Posts: 98
Joined: 28 Dec 2020, 13:41

Re: ahk binding library for cimgui

27 Sep 2023, 00:10

Thanks. Can you add an example of displaying BGRA pixels?
GDIP() can display webp/avif which are emerging formats, but it can't display .jxl images because the current version of the jxl library only supports the RGB format and GdipCreateBitmapFromScan0() only supports the BGRA format and I haven't found any other GDIP function that supports RGB.

This is how gdip loads the webp:

Code: Select all

data := FileRead(pic, "RAW")
pBits := DllCall("libwebp.dll\WebPDecodeBGRA", "uptr", data.ptr, "Int", data.size, "IntP", &pw := 0, "intP", &ph := 0, "Cdecl ptr")
DllCall("Gdiplus.dll\GdipCreateBitmapFromScan0", "Int", pw, "Int", ph, "Int", ((pw * 32 + 31) & ~31) >> 3, "UInt", 0x26200A, "Ptr", pBits, "PtrP", &pBitmap := 0)
This is the jxl library I packaged:

Code: Select all

;pixel := jxl_pix(pic), pw := pixel.w, ph := pixel.h
;DllCall("Gdiplus.dll\GdipCreateBitmapFromScan0", "Int", pw, "Int", ph, "Int", ((pw * 32 + 31) & ~31) >> 3, "UInt", 0x26200A, "Ptr", pixel.ptr, "PtrP", &pBitmap := 0)

jxl_pix(buf, opt := "") { ; https://github.com/libjxl/libjxl/releases
	static dll_dir := xxx "\jxl",
		jth_hd := DllCall("GetModuleHandle", "str", "jxl_threads.dll")
		|| (DllCall("SetDllDirectory", "Str", dll_dir), DllCall("LoadLibrary", "str", dll_dir "\jxl.dll", "Cdecl UPtr"),
			DllCall("LoadLibrary", "str", dll_dir "\jxl_threads.dll", "Cdecl UPtr")),
		JxlResizableParallelRunner := DllCall("GetProcAddress", "Ptr", jth_hd, "AStr", "JxlResizableParallelRunner", "ptr"),
		JXL_DEC_FRAME := 0x400,
		JXL_DEC_FULL_IMAGE := 0x1000,
		JXL_DEC_NEED_IMAGE_OUT_BUFFER := 5,
		JXL_DEC_NEED_MORE_INPUT := 2,
		JXL_DEC_ERROR := 1,
		JXL_DEC_BASIC_INFO := 0x40,
		JXL_DEC_COLOR_ENCODING := 0x100,
		JXL_DEC_FRAME_PROGRESSION := 0x8000,
		JXL_DEC_SUCCESS := 0


	if buf is String
		buf := FileRead(buf, "RAW")

	runn := DllCall("jxl_threads.dll\JxlResizableParallelRunnerCreate", "ptr", 0, "int", 8, "Ptr")
	dec := DllCall("jxl.dll\JxlDecoderCreate", "ptr", 0, "Ptr")

	DllCall("jxl.dll\JxlDecoderSubscribeEvents", "ptr", dec, "uint", JXL_DEC_BASIC_INFO | JXL_DEC_FULL_IMAGE, "int")

	DllCall("jxl.dll\JxlDecoderSetParallelRunner", "ptr", dec, "ptr", JxlResizableParallelRunner, "ptr", runn, "int")
	DllCall("jxl.dll\JxlDecoderSetInput", "ptr", dec, "ptr", buf, "uint", buf.size, "int")
	DllCall("jxl.dll\JxlDecoderCloseInput", "ptr", dec, "Ptr")

	fo := Buffer(24, 0)
	NumPut "int", 4, "int", 2, "int64", 0, fo

	loop 4
	{
		switch status := DllCall("jxl.dll\JxlDecoderProcessInput", "ptr", dec, "Ptr")
		{
			case JXL_DEC_BASIC_INFO:	;64
				info := Buffer(2048, 0)
				DllCall("jxl.dll\JxlDecoderGetBasicInfo", "ptr", dec, "ptr", info, "int")
				pw := NumGet(info, 4, "uint")
				ph := NumGet(info, 8, "uint")
				th := DllCall("jxl_threads.dll\JxlResizableParallelRunnerSuggestThreads", "uint64", pw, "uint64", ph, "int")
				DllCall("jxl_threads.dll\JxlResizableParallelRunnerSetThreads", "ptr", runn, "uint64", th, "Ptr")

			case JXL_DEC_NEED_IMAGE_OUT_BUFFER: ;5
				DllCall("jxl.dll\JxlDecoderImageOutBufferSize", "ptr", dec, "ptr", fo, "uintp", &sz := 0, "int")
				out := Buffer(sz, 0), out.w := pw, out.h := ph
				DllCall("jxl.dll\JxlDecoderSetImageOutBuffer", "ptr", dec, "ptr", fo, "ptr", out, "uint64", sz, "int")

			case JXL_DEC_FULL_IMAGE: ;4096- One frame
				break
			default:
				break
		}
	}

	DllCall("jxl.dll\JxlDecoderDestroy", "ptr", dec, "Ptr")
	DllCall("jxl_threads.dll\JxlResizableParallelRunnerDestroy", "ptr", runn, "Ptr")
	return out
}
kazhafeizhale
Posts: 77
Joined: 25 Dec 2018, 10:58

Re: ahk binding library for cimgui

27 Sep 2023, 04:01

crocodile wrote:
27 Sep 2023, 00:10
Thanks. Can you add an example of displaying BGRA pixels?
GDIP() can display webp/avif which are emerging formats, but it can't display .jxl images because the current version of the jxl library only supports the RGB format and GdipCreateBitmapFromScan0() only supports the BGRA format and I haven't found any other GDIP function that supports RGB.

This is how gdip loads the webp:

Code: Select all

data := FileRead(pic, "RAW")
pBits := DllCall("libwebp.dll\WebPDecodeBGRA", "uptr", data.ptr, "Int", data.size, "IntP", &pw := 0, "intP", &ph := 0, "Cdecl ptr")
DllCall("Gdiplus.dll\GdipCreateBitmapFromScan0", "Int", pw, "Int", ph, "Int", ((pw * 32 + 31) & ~31) >> 3, "UInt", 0x26200A, "Ptr", pBits, "PtrP", &pBitmap := 0)
This is the jxl library I packaged:

Code: Select all

;pixel := jxl_pix(pic), pw := pixel.w, ph := pixel.h
;DllCall("Gdiplus.dll\GdipCreateBitmapFromScan0", "Int", pw, "Int", ph, "Int", ((pw * 32 + 31) & ~31) >> 3, "UInt", 0x26200A, "Ptr", pixel.ptr, "PtrP", &pBitmap := 0)

jxl_pix(buf, opt := "") { ; https://github.com/libjxl/libjxl/releases
	static dll_dir := xxx "\jxl",
		jth_hd := DllCall("GetModuleHandle", "str", "jxl_threads.dll")
		|| (DllCall("SetDllDirectory", "Str", dll_dir), DllCall("LoadLibrary", "str", dll_dir "\jxl.dll", "Cdecl UPtr"),
			DllCall("LoadLibrary", "str", dll_dir "\jxl_threads.dll", "Cdecl UPtr")),
		JxlResizableParallelRunner := DllCall("GetProcAddress", "Ptr", jth_hd, "AStr", "JxlResizableParallelRunner", "ptr"),
		JXL_DEC_FRAME := 0x400,
		JXL_DEC_FULL_IMAGE := 0x1000,
		JXL_DEC_NEED_IMAGE_OUT_BUFFER := 5,
		JXL_DEC_NEED_MORE_INPUT := 2,
		JXL_DEC_ERROR := 1,
		JXL_DEC_BASIC_INFO := 0x40,
		JXL_DEC_COLOR_ENCODING := 0x100,
		JXL_DEC_FRAME_PROGRESSION := 0x8000,
		JXL_DEC_SUCCESS := 0


	if buf is String
		buf := FileRead(buf, "RAW")

	runn := DllCall("jxl_threads.dll\JxlResizableParallelRunnerCreate", "ptr", 0, "int", 8, "Ptr")
	dec := DllCall("jxl.dll\JxlDecoderCreate", "ptr", 0, "Ptr")

	DllCall("jxl.dll\JxlDecoderSubscribeEvents", "ptr", dec, "uint", JXL_DEC_BASIC_INFO | JXL_DEC_FULL_IMAGE, "int")

	DllCall("jxl.dll\JxlDecoderSetParallelRunner", "ptr", dec, "ptr", JxlResizableParallelRunner, "ptr", runn, "int")
	DllCall("jxl.dll\JxlDecoderSetInput", "ptr", dec, "ptr", buf, "uint", buf.size, "int")
	DllCall("jxl.dll\JxlDecoderCloseInput", "ptr", dec, "Ptr")

	fo := Buffer(24, 0)
	NumPut "int", 4, "int", 2, "int64", 0, fo

	loop 4
	{
		switch status := DllCall("jxl.dll\JxlDecoderProcessInput", "ptr", dec, "Ptr")
		{
			case JXL_DEC_BASIC_INFO:	;64
				info := Buffer(2048, 0)
				DllCall("jxl.dll\JxlDecoderGetBasicInfo", "ptr", dec, "ptr", info, "int")
				pw := NumGet(info, 4, "uint")
				ph := NumGet(info, 8, "uint")
				th := DllCall("jxl_threads.dll\JxlResizableParallelRunnerSuggestThreads", "uint64", pw, "uint64", ph, "int")
				DllCall("jxl_threads.dll\JxlResizableParallelRunnerSetThreads", "ptr", runn, "uint64", th, "Ptr")

			case JXL_DEC_NEED_IMAGE_OUT_BUFFER: ;5
				DllCall("jxl.dll\JxlDecoderImageOutBufferSize", "ptr", dec, "ptr", fo, "uintp", &sz := 0, "int")
				out := Buffer(sz, 0), out.w := pw, out.h := ph
				DllCall("jxl.dll\JxlDecoderSetImageOutBuffer", "ptr", dec, "ptr", fo, "ptr", out, "uint64", sz, "int")

			case JXL_DEC_FULL_IMAGE: ;4096- One frame
				break
			default:
				break
		}
	}

	DllCall("jxl.dll\JxlDecoderDestroy", "ptr", dec, "Ptr")
	DllCall("jxl_threads.dll\JxlResizableParallelRunnerDestroy", "ptr", runn, "Ptr")
	return out
}
I have add demo7 to show webp image from memory

Code: Select all

#Requires AutoHotkey v2.0
#include <wincapture>
#include <cimgui>
#DllLoad %A_ScriptDir%\libwebp.dll

wincapture.init()

pic := A_ScriptDir '\images\test.webp'
data := FileRead(pic, "RAW")
pBits := DllCall("libwebp\WebPDecodeBGRA", "uptr", data.ptr, "Int", data.size, "IntP", &pw := 0, "intP", &ph := 0, "Cdecl ptr")
bf := BitmapBuffer(pBits, ((pw * 32 + 31) & ~31) >> 3, pw, ph)
bf.show()
BMP := bf.BMP()

main()
main()
{
    ui := imgui()
    ui.enableviewports(true)
    hwnd := ui.guicreate_unbackground('test',,, 'GetGlyphRangesDefault')
    WinSetAlwaysOnTop(1, hwnd)

    ;使用这个方法,需要手动释放
    ui.LoadTextureFromMemory(BMP, BMP.size, &out_srv := 0, &out_width := 0, &out_height := 0)
    size := ui.ImageGetSize(out_srv)

    is_open := true
    is_open_demo := true
    text := 'hi imgui'
    while(ui.peekmsg())
    {
        ui.beginframe()
        if(is_open_demo)
            ui.igShowDemoWindow(&is_open_demo)
        if(is_open)
        {
            ui.igBegin(ui.str('main'), &is_open, 0)
            if(ui.igButton(ui.str('Button'), ImVec2([100, 100])))
            {
                MsgBox('ok')
            }
            ui.igImageButton(ui.str('imageButton2'), out_srv, ImVec2(size))
            ui.igEnd()
        }
        else
        {
            ExitApp
        }
        ui.endframe()
    }
    ExitApp
}
crocodile
Posts: 98
Joined: 28 Dec 2020, 13:41

Re: ahk binding library for cimgui

27 Sep 2023, 06:50

Thanks, but I'm terribly sorry, I originally meant to express a desire to add examples that support the RGB format, not BGRA.
kazhafeizhale
Posts: 77
Joined: 25 Dec 2018, 10:58

Re: ahk binding library for cimgui

28 Sep 2023, 05:21

crocodile wrote:
27 Sep 2023, 06:50
Thanks, but I'm terribly sorry, I originally meant to express a desire to add examples that support the RGB format, not BGRA.
I know opencv There are existing functions ,https://github.com/thqby/opencv_ahk
Or write your own conversion function in machine code
Feather
Posts: 24
Joined: 14 Nov 2022, 02:14

Re: ahk binding library for cimgui

07 Oct 2023, 11:01

Hi, does imgui have a control similar to ListView? I'm writing a BT search script where the search results will be inserted into a specified location based on file size, which happens to utilize the ListView's automatic sorting feature. But the thing that bothers me is that ListView can only display one line of text.
Can imgui display multiple lines if it has a ListView control? Or can imgui's text control auto-sort like ListView? Very much looking forward to have an example of this.
kazhafeizhale
Posts: 77
Joined: 25 Dec 2018, 10:58

Re: ahk binding library for cimgui

08 Oct 2023, 04:07

Feather wrote:
07 Oct 2023, 11:01
Hi, does imgui have a control similar to ListView? I'm writing a BT search script where the search results will be inserted into a specified location based on file size, which happens to utilize the ListView's automatic sorting feature. But the thing that bothers me is that ListView can only display one line of text.
Can imgui display multiple lines if it has a ListView control? Or can imgui's text control auto-sort like ListView? Very much looking forward to have an example of this.
The data sorting of imgui is manually sorted by the user
Multiple lines can be displayed
I added a related example, demo11
Feather
Posts: 24
Joined: 14 Nov 2022, 02:14

Re: ahk binding library for cimgui

08 Oct 2023, 06:38

Thanks, this last example impressed me and I will try to refactor my scripts using cimgui.
Is it possible for imgui to display Markdown documents? This is the feature I would most like to implement in AutoHotkey as I would like to write a note-taking software with AutoHotkey, but the current AutoHotkey is very difficult to implement. I'm really very imgui to be able to implement it!
kazhafeizhale
Posts: 77
Joined: 25 Dec 2018, 10:58

Re: ahk binding library for cimgui

16 Jan 2024, 03:26

1、Add external drawing function
image.png
image.png (51.94 KiB) Viewed 1007 times
sashaatx
Posts: 342
Joined: 27 May 2021, 08:27
Contact:

Re: ahk binding library for cimgui

16 Jan 2024, 16:07

wow this library is great! I wish I found this a long time ago. If you have a preferred reference documentation/tutorial, Ive never heard of this lib. cimgui. And I spend a lot of time in the gui application cross-language space.



At very first glance, before reading any documentation, it looks a lot like
nicegui https://github.com/zauberzeug/nicegui or
tkinter while() frame loops in python.

do you have a quick or go-to way of setting scaling

Thanks!!
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: DuyMinh, Xeilous and 24 guests