Page 1 of 1

ahk binding library for cimgui

Posted: 16 Sep 2023, 05:51
by kazhafeizhale
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 3704 times
https://github.com/sxzxs/cimgui-ahk

Re: ahk binding library for cimgui

Posted: 24 Sep 2023, 03:35
by kazhafeizhale
add Log in to demo
image.png
image.png (292.44 KiB) Viewed 3468 times

Re: ahk binding library for cimgui

Posted: 24 Sep 2023, 12:00
by crocodile
Thank you for your work.
What are its advantages over imgui4ahk? Which one should I use?

Re: ahk binding library for cimgui

Posted: 24 Sep 2023, 21:02
by kazhafeizhale
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

Re: ahk binding library for cimgui

Posted: 25 Sep 2023, 00:44
by hoppfrosch
Trying to run the examples from the freshly cloned repository (Authotkey V2.0.9):
AutoHotkey64_KAQIp0oN2Z.png
AutoHotkey64_KAQIp0oN2Z.png (14.52 KiB) Viewed 3187 times

Re: ahk binding library for cimgui

Posted: 25 Sep 2023, 01:04
by kazhafeizhale
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

Re: ahk binding library for cimgui

Posted: 25 Sep 2023, 02:34
by kazhafeizhale
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

Re: ahk binding library for cimgui

Posted: 26 Sep 2023, 00:31
by hoppfrosch
I have made compatibility changes to version L, version 2.0.10 test
Works now - thx for your fast response!

Re: ahk binding library for cimgui

Posted: 26 Sep 2023, 10:38
by kazhafeizhale
Add demo
image.png
image.png (373.89 KiB) Viewed 3056 times

Re: ahk binding library for cimgui

Posted: 26 Sep 2023, 11:18
by crocodile
What image formats does imgui support? I found that it can't open .avif images.

Re: ahk binding library for cimgui

Posted: 26 Sep 2023, 23:25
by kazhafeizhale
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

Re: ahk binding library for cimgui

Posted: 27 Sep 2023, 00:10
by crocodile
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
}

Re: ahk binding library for cimgui

Posted: 27 Sep 2023, 04:01
by kazhafeizhale
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
}

Re: ahk binding library for cimgui

Posted: 27 Sep 2023, 06:50
by crocodile
Thanks, but I'm terribly sorry, I originally meant to express a desire to add examples that support the RGB format, not BGRA.

Re: ahk binding library for cimgui

Posted: 28 Sep 2023, 05:21
by kazhafeizhale
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

Re: ahk binding library for cimgui

Posted: 07 Oct 2023, 11:01
by Feather
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.

Re: ahk binding library for cimgui

Posted: 08 Oct 2023, 04:07
by kazhafeizhale
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

Re: ahk binding library for cimgui

Posted: 08 Oct 2023, 06:38
by Feather
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!

Re: ahk binding library for cimgui

Posted: 16 Jan 2024, 03:26
by kazhafeizhale
1、Add external drawing function
image.png
image.png (51.94 KiB) Viewed 1339 times

Re: ahk binding library for cimgui

Posted: 16 Jan 2024, 16:07
by sashaatx
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!!