From 700b7e00f69f861d14fb381c84f2e2aa8bac0f55 Mon Sep 17 00:00:00 2001 From: dinau Date: Mon, 30 Dec 2024 16:56:09 +0900 Subject: [PATCH] examples: small changes --- README.md | 52 +++++++++++-------- .../glfw_opengl3_base/glfw_opengl3_base.ini | 4 +- .../glfw_opengl3_base/glfw_opengl3_base.nim | 3 +- examples/glfw_opengl3_base/imgui.ini | 2 +- .../glfw_opengl3_image_load.nim | 3 +- .../glfw_opengl3_image_save.ini | 14 ++--- .../glfw_opengl3_image_save.nim | 15 +++--- examples/glfw_opengl3_jp/glfw_opengl3_jp.nim | 10 ++-- examples/makefile.common.mk | 3 +- examples/sdl2_opengl3/sdl2_opengl3.nim | 3 +- examples/sdl3_opengl3/sdl3_opengl3.nim | 10 ++-- examples/utils/appImGui.nim | 26 +++++++++- examples/utils/setupFonts.nim | 2 +- 13 files changed, 86 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 7ec02ae..6ee5baa 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ - [Install](#install) - [Build examples](#build-examples) - [Available libraries](#available-libraries) + - [Frontends and Backends](#frontends-and-backends) - [Screen shot (examples)](#screen-shot-examples) - [glfw_opengl3](#glfw_opengl3) - [glfw_opengl3_imknobs](#glfw_opengl3_imknobs) @@ -31,13 +32,13 @@ - [Similar project ImGui / CImGui](#similar-project-imgui--cimgui) - [SDL Game tutorial Platfromer](#sdl-game-tutorial-platfromer) - [Other link2](#other-link2) + - [Memo](#memo) # ImGuin -![alt](https://github.com/dinau/imguin/actions/workflows/run.yml/badge.svg) -![alt](https://github.com/dinau/imguin/actions/workflows/linux.yml/badge.svg) +![alt](https://github.com/dinau/imguin/actions/workflows/run.yml/badge.svg) ![alt](https://github.com/dinau/imguin/actions/workflows/linux.yml/badge.svg) Updated to latest ImGui/CImGui version: : **v1.91.6dock** (2024/12) @@ -60,17 +61,15 @@ It may be better to use the **mainstream** project [nimgl/imgui](https://github. - [Nim-2.0.14](https://nim-lang.org) or later - Windows10 or later [MSys2/MinGW](https://www.msys2.org/) command line tools (Unix tools), make, cp, rm, git, ...etc -- Linux Mint 22 (or Ubuntu / Debian families ?) +- Linux Mint 22 (or Ubuntu / Debian families ) ```sh - $ sudo apt install xorg-dev libopengl-dev libgl1-mesa-dev + $ sudo apt install gcc g++ make git ``` - and for glfw3 and sdl2, - ```sh - $ sudo apt install libglfw3 libglfw3-dev - $ sudo apt install libsdl2-dev + $ sudo apt install xorg-dev libopengl-dev libgl1-mesa-dev + $ sudo apt install libglfw3 libglfw3-dev libsdl2-dev ``` ### Install @@ -93,14 +92,14 @@ nimble install https://github.com/dinau/imguin ``` 1. Sample program is here, [examples](examples). -For instance [glfw_opengl3.nim](examples/glfw_opengl3/glfw_opengl3.nim), +For instance [glfw_opengl3_base.nim](examples/glfw_opengl3_base/glfw_opengl3_base.nim), ```sh - cd imguin/examples/glfw_opengl3 + cd imguin/examples/glfw_opengl3_base make # or make run ``` - After build, run `./glfw_opengl3(.exe)` + After build, run `./glfw_opengl3_base(.exe)` Compiation options depend on `./config.nims` and `./Makefile`. @@ -110,16 +109,27 @@ For instance [glfw_opengl3.nim](examples/glfw_opengl3/glfw_opengl3.nim), --- -| | Library name | | -|-----|---------------------------------------------------------------------------------------------------------------------|--------------| -| v | ImGui / CImGui | Base library | -| v | ImPlot / CImPlot | -| v | ImNodes/ CImNodes | -| v | ImGuizmo/ CImGuizmo | -| v | ImGui-Knobs/ CImGui-Knobs | -| v | ImGuiFileDialog / [CImGuiFileDialog](https://github.com/dinau/CImGuiFileDialog) | Windows | -| ... | ... | ... | -| x | [ImGuiColorTextEdit](https://github.com/BalazsJako/ImGuiColorTextEdit) / [cimCTE](https://github.com/cimgui/cimCTE) | 2025 ? | +| | Library name | | +|-----|-------------------------------------------------------------------------------------------------------------------------------|--------------| +| v | [ImGui](https://github.com/ocornut/imgui) / [CImGui](https://github.com/cimgui/cimgui) | Base library | +| v | [ImPlot](https://github.com/epezent/implot) / [CImPlot](https://github.com/cimgui/cimplot) | | +| v | [ImNodes](https://github.com/Nelarius/imnodes) / [CImNodes](https://github.com/cimgui/cimnodes) | | +| v | [ImGuizmo](https://github.com/CedricGuillemet/ImGuizmo) / [CImGuizmo](https://github.com/cimgui/cimguizmo) | | +| v | [ImGui-Knobs]([https://github.com/altschuler/imgui-knobs)/ [CImGui-Knobs](src/imguin/private/cimgui-knobs) | | +| v | [ImGuiFileDialog](https://github.com/aiekick/ImGuiFileDialog) / [CImGuiFileDialog](https://github.com/dinau/CImGuiFileDialog) | | +| ... | ... | ... | +| x | [ImGuiColorTextEdit](https://github.com/BalazsJako/ImGuiColorTextEdit) / [cimCTE](https://github.com/cimgui/cimCTE) | 2025 ? | + +#### Frontends and Backends + +--- + + | | GLFW | SDL2 | SDL3 | | + | --- | :----: | :---- | :----: | --- | + | OpenGL3
backend | v | v | v | | + | SDL2
backend | - | ? | - | 2025? | + | SDL3
backend | - | - | ? | 2025? | + ### Screen shot (examples) diff --git a/examples/glfw_opengl3_base/glfw_opengl3_base.ini b/examples/glfw_opengl3_base/glfw_opengl3_base.ini index 30e15fa..9362fcd 100644 --- a/examples/glfw_opengl3_base/glfw_opengl3_base.ini +++ b/examples/glfw_opengl3_base/glfw_opengl3_base.ini @@ -1,6 +1,6 @@ [Window] -startupPosX=383 -startupPosY=67 +startupPosX=399 +startupPosY=63 viewportWidth=1024 viewportHeigth=800 colBGx=0.4246913492679596 diff --git a/examples/glfw_opengl3_base/glfw_opengl3_base.nim b/examples/glfw_opengl3_base/glfw_opengl3_base.nim index a12f453..8b2bd18 100644 --- a/examples/glfw_opengl3_base/glfw_opengl3_base.nim +++ b/examples/glfw_opengl3_base/glfw_opengl3_base.nim @@ -50,8 +50,7 @@ proc main() = igText("%s%s", ICON_FA_COMMENT_MEDICAL & " Nim-", NimVersion) igInputTextWithHint("InputText" ,"Input text here" ,sBuf) - var s = "Input result:" & sBuf - igText(s.cstring) + igText(("Input result:" & sBuf).cstring) igCheckbox("Demo window", addr showDemoWindow) igCheckbox("Another window", addr showAnotherWindow) igSliderFloat("Float", addr fval, 0.0f, 1.0f, "%.3f", 0) diff --git a/examples/glfw_opengl3_base/imgui.ini b/examples/glfw_opengl3_base/imgui.ini index 8651008..2b7af00 100644 --- a/examples/glfw_opengl3_base/imgui.ini +++ b/examples/glfw_opengl3_base/imgui.ini @@ -14,7 +14,7 @@ Size=417,456 Collapsed=0 [Window][imgui Another Window] -Pos=47,338 +Pos=24,478 Size=321,80 Collapsed=0 diff --git a/examples/glfw_opengl3_image_load/glfw_opengl3_image_load.nim b/examples/glfw_opengl3_image_load/glfw_opengl3_image_load.nim index 768ebbe..1def69a 100644 --- a/examples/glfw_opengl3_image_load/glfw_opengl3_image_load.nim +++ b/examples/glfw_opengl3_image_load/glfw_opengl3_image_load.nim @@ -61,8 +61,7 @@ proc main() = igText("%s%s", ICON_FA_COMMENT_MEDICAL & " Nim-", NimVersion) igInputTextWithHint("InputText" ,"Input text here" ,sBuf) - var s = "Input result:" & sBuf - igText(s.cstring) + igText(("Input result:" & sBuf).cstring) igCheckbox("Demo window", addr showDemoWindow) igCheckbox("Another window", addr showAnotherWindow) igSliderFloat("Float", addr fval, 0.0f, 1.0f, "%.3f", 0) diff --git a/examples/glfw_opengl3_image_save/glfw_opengl3_image_save.ini b/examples/glfw_opengl3_image_save/glfw_opengl3_image_save.ini index a670160..5681e51 100644 --- a/examples/glfw_opengl3_image_save/glfw_opengl3_image_save.ini +++ b/examples/glfw_opengl3_image_save/glfw_opengl3_image_save.ini @@ -1,9 +1,11 @@ [Window] -startupPosX=431 -startupPosY=91 -viewportWidth=1001 +startupPosX=363 +startupPosY=71 +viewportWidth=1024 viewportHeigth=900 -colBGx=0.06189299374818802 -colBGy=0.355555534362793 -colBGz=0.2250388562679291 +colBGx=0.25 +colBGy=0.6499999761581421 +colBGz=0.8500000238418579 colBGw=1.0 +[Image] +imageSaveFormatIndex=0 diff --git a/examples/glfw_opengl3_image_save/glfw_opengl3_image_save.nim b/examples/glfw_opengl3_image_save/glfw_opengl3_image_save.nim index f13be69..ea9d282 100644 --- a/examples/glfw_opengl3_image_save/glfw_opengl3_image_save.nim +++ b/examples/glfw_opengl3_image_save/glfw_opengl3_image_save.nim @@ -18,7 +18,6 @@ const SaveImageName = "ImageSaved" var imageExt:string imageFormatTbl = [(kind:"JPEG 90%",ext:".jpg"), ("PNG",".png"), ("BMP",".bmp"), ("TGA",".tga")] - cbItemIndex = 0 #------ # main @@ -72,8 +71,7 @@ proc main() = igText("%s%s", ICON_FA_COMMENT_MEDICAL & " Nim-", NimVersion) igInputTextWithHint("InputText" ,"Input text here" ,sBuf) - var s = "Input result:" & sBuf - igText(s.cstring) + igText(("Input result:" & sBuf).cstring) igCheckbox("Demo window", addr showDemoWindow) igCheckbox("Another window", addr showAnotherWindow) igSliderFloat("Float", addr fval, 0.0f, 1.0f, "%.3f", 0) @@ -87,11 +85,11 @@ proc main() = igPushStyleColorVec4(ImGuiCol_Text.ImGuiCol, ImVec4(x: 0.0, y: 0.0, z:0.0, w: 1.0)) # Image save button - imageExt = imageFormatTbl[cbItemIndex].ext + imageExt = imageFormatTbl[win.ini.imageSaveFormatIndex].ext svName = fmt"{SaveImageName}_{counter:05}{imageExt}" if igButton("Save Image", ImVec2(x: 0.0f, y: 0.0f)): let wkSize = igGetMainViewport().Worksize - saveImage(svName,0, 0, wkSize.x.int, wkSize.y.int, 3) # --- Save Image ! + saveImage(svName,0, 0, wkSize.x.int, wkSize.y.int) # --- Save Image ! igPopStyleColor(4) igPopID() @@ -103,14 +101,13 @@ proc main() = #-- ComboBox: Select save image format igSetNextItemWidth(100) - if igBeginCombo("##".cstring, imageFormatTbl[cbItemIndex].kind.cstring, 0): + if igBeginCombo("##".cstring, imageFormatTbl[win.ini.imageSaveFormatIndex].kind.cstring, 0): for n,val in imageFormatTbl: - var is_selected = (cbItemIndex == n) + var is_selected = (win.ini.imageSaveFormatIndex == n) if igSelectableBoolPtr(val.kind.cstring, is_selected.addr, 0, ImVec2(x: 0.0,y: 0.0)): if is_selected: igSetItemDefaultFocus() - cbItemIndex = n - #app.image.imageSaveFormatIndex = cbItemIndex + win.ini.imageSaveFormatIndex = n igEndCombo() setTooltip("Select image format") diff --git a/examples/glfw_opengl3_jp/glfw_opengl3_jp.nim b/examples/glfw_opengl3_jp/glfw_opengl3_jp.nim index 146e175..dcc85d7 100644 --- a/examples/glfw_opengl3_jp/glfw_opengl3_jp.nim +++ b/examples/glfw_opengl3_jp/glfw_opengl3_jp.nim @@ -64,14 +64,12 @@ proc firstWindow(win:Window) = igBegin("Window".cstring, showFirstWindow.addr, 0) defer: igEnd() - var s = "GLFW v" & $glfwGetVersionString() - igText(s.cstring) - s = "OpenGL v" & ($cast[cstring](glGetString(GL_VERSION))).split[0] - igText(s.cstring) + igText((ICON_FA_COMMENT & " " & getFrontendVersionString()).cstring) + igText((ICON_FA_COMMENT_SMS & " " & getBackendVersionString()).cstring) + igText("これは日本語表示テスト") igInputTextWithHint("テキスト入力", "ここに日本語を入力", sBuf) - s = "入力結果:" & sBuf - igText(s.cstring) + igText(("入力結果:" & sBuf).cstring) igCheckbox("デモ・ウインドウ表示", showDemoWindow.addr) igSliderFloat("浮動小数", somefloat.addr, 0.0f, 1.0f, "%3f", 0) igColorEdit3("背景色変更", win.ini.clearColor.array3, ImGuiColorEditFlags_None.ImGuiColorEditFlags) diff --git a/examples/makefile.common.mk b/examples/makefile.common.mk index 5dadb37..14927f3 100644 --- a/examples/makefile.common.mk +++ b/examples/makefile.common.mk @@ -4,6 +4,8 @@ TARGET = $(notdir $(CURDIR)) ifeq ($(OS),Windows_NT) EXE = .exe +else + OPT += --passL:-lstdc++ endif TARGET_EXE = $(TARGET)$(EXE) @@ -13,7 +15,6 @@ OPT += -d:strip OPT += -o:$(TARGET_EXE) #OPT += --listCmd #OPT += --verbosity:2 -OPT += --passL:-lstdc++ all: build dll diff --git a/examples/sdl2_opengl3/sdl2_opengl3.nim b/examples/sdl2_opengl3/sdl2_opengl3.nim index 8ed09ab..6c745e3 100644 --- a/examples/sdl2_opengl3/sdl2_opengl3.nim +++ b/examples/sdl2_opengl3/sdl2_opengl3.nim @@ -71,8 +71,7 @@ proc main() = igText((ICON_FA_COMMENT_SMS & " " & getBackendVersionString()).cstring) igInputTextWithHint("InputText" ,"Input text here" ,sBuf) - var s = "Input result:" & sBuf - igText(s.cstring) + igText(("Input result:" & sBuf).cstring) igCheckbox("Demo window", addr showDemoWindow) igSliderFloat("Float", addr fval, 0.0f, 1.5f, "%.3f", 0) igColorEdit3("Bcakground color", win.ini.clearColor.array3, ImGuiColorEditFlags_None.ImGuiColorEditFlags) diff --git a/examples/sdl3_opengl3/sdl3_opengl3.nim b/examples/sdl3_opengl3/sdl3_opengl3.nim index b73fa48..3020d17 100644 --- a/examples/sdl3_opengl3/sdl3_opengl3.nim +++ b/examples/sdl3_opengl3/sdl3_opengl3.nim @@ -70,8 +70,7 @@ proc main() = igText((ICON_FA_COMMENT_SMS & " " & getBackendVersionString()).cstring) igInputTextWithHint("InputText" ,"Input text here" ,sBuf) - var s = "Input result:" & sBuf - igText(s.cstring) + igText(("Input result:" & sBuf).cstring) igCheckbox("Demo window", addr showDemoWindow) igSliderFloat("Float", addr fval, 0.0f, 1.5f, "%.3f", 0) igColorEdit3("Background color", win.ini.clearColor.array3, ImGuiColorEditFlags_None.ImGuiColorEditFlags) @@ -110,10 +109,9 @@ proc main() = igGetCursorScreenPos(addr imageBoxPosTop) # Get absolute pos. igImage(cast[ImTextureID](textureId), size, uv0, uv1, tint_col, border_col); igGetCursorScreenPos(addr imageBoxPosEnd) # Get absolute pos. - when false: # TODO WIP - # Magnifiying glass - if igIsItemHovered(ImGui_HoveredFlags_DelayNone.ImGuiHoveredFlags): - zoomGlass(zoomTextureID, textureWidth, imageBoxPosTop, imageBoxPosEnd) + # Magnifiying glass + if igIsItemHovered(ImGui_HoveredFlags_DelayNone.ImGuiHoveredFlags): + zoomGlass(zoomTextureID, textureWidth, imageBoxPosTop, imageBoxPosEnd) #-------- # render diff --git a/examples/utils/appImGui.nim b/examples/utils/appImGui.nim index 05cf825..5ad9063 100644 --- a/examples/utils/appImGui.nim +++ b/examples/utils/appImGui.nim @@ -25,6 +25,7 @@ type IniData = object clearColor*: ccolor startupPosX*, startupPosY*:cint viewportWidth*, viewportHeight*:cint + imageSaveFormatIndex*:int type Window* = object handle*: glfw.GLFWwindow @@ -214,7 +215,7 @@ proc setClearColor*(win: var Window, col: ccolor) = #------ proc free*(mem: pointer) {.importc,header:"".} -# Sections (Cat.) +# Sections const scWindow = "Window" # [Window] const startupPosX = "startupPosX" @@ -225,6 +226,9 @@ const colBGx = "colBGx" const colBGy = "colBGy" const colBGz = "colBGz" const colBGw = "colBGw" +# [Image] +const scImage = "Image" +const imageSaveFormatIndex = "imageSaveFormatIndex" #--------- # loadIni --- Load ini @@ -236,15 +240,19 @@ proc loadIni*(this: var Window) = #---------- if fileExists(iniName): let cfg = loadConfig(iniName) - # Windows + # Window pos this.ini.startupPosX = cfg.getSectionValue(scWindow,startupPosX).parseInt.cint if 10 > this.ini.startupPosX: this.ini.startupPosX = 10 this.ini.startupPosY = cfg.getSectionValue(scWindow,startupPosY).parseInt.cint if 10 > this.ini.startupPosY: this.ini.startupPosY = 10 + + # Window size this.ini.viewportWidth = cfg.getSectionValue(scWindow,viewportWidth).parseInt.cint if this.ini.viewportWidth < 100: this.ini.viewportWidth = 900 this.ini.viewportHeight = cfg.getSectionValue(scWindow,viewportHeight).parseInt.cint if this.ini.viewportHeight < 100: this.ini.viewportHeight = 900 + + # Background color var fval:float discard parsefloat(cfg.getSectionValue(scWindow, colBGx, "0.25"), fval) this.ini.clearColor.elm.x = fval.cfloat @@ -254,6 +262,10 @@ proc loadIni*(this: var Window) = this.ini.clearColor.elm.z = fval.cfloat discard parsefloat(cfg.getSectionValue(scWindow, colBGw, "1.00"), fval) this.ini.clearColor.elm.w = fval.cfloat + + # Image format index + this.ini.imageSaveFormatIndex = cfg.getSectionValue(scImage,imageSaveFormatIndex).parseInt.cint + #---------------- # Set first defaults #---------------- @@ -261,6 +273,7 @@ proc loadIni*(this: var Window) = this.ini.startupPosX = 100 this.ini.startupPosY = 200 this.ini.clearColor = ccolor(elm:(x:0.25f, y:0.65f, z:0.85f, w:1.0f)) + this.ini.imageSaveFormatIndex = 0 #--------- # saveIni --- save iniFile @@ -268,15 +281,24 @@ proc loadIni*(this: var Window) = proc saveIni*(this: var Window) = let iniName = getAppFilename().changeFileExt("ini") var ini = newConfig() + # Window pos getWindowPos(this.handle, addr this.ini.startupPosX,addr this.ini.startupPosY) ini.setSectionKey(scWindow,startupPosX,$this.ini.startupPosX) ini.setSectionKey(scWindow,startupPosY,$this.ini.startupPosY) + + # Window size let ws = igGetMainViewPort().WorkSize ini.setSectionKey(scWindow, viewportWidth,$ws.x.cint) ini.setSectionKey(scWindow, viewportHeight,$ws.y.cint) + + # Background color ini.setSectionKey(scWindow, colBGx, $this.ini.clearColor.elm.x) ini.setSectionKey(scWindow, colBGy, $this.ini.clearColor.elm.y) ini.setSectionKey(scWindow, colBGz, $this.ini.clearColor.elm.z) ini.setSectionKey(scWindow, colBGw, $this.ini.clearColor.elm.w) + + # Image format index + ini.setSectionKey(scImage, imageSaveFormatIndex, $this.ini.imageSaveFormatIndex) + # save ini file writeFile(iniName,$ini) diff --git a/examples/utils/setupFonts.nim b/examples/utils/setupFonts.nim index e8a3966..d114f1f 100644 --- a/examples/utils/setupFonts.nim +++ b/examples/utils/setupFonts.nim @@ -4,7 +4,7 @@ import imguin/lang/imgui_ja_gryph_ranges import ../utils/fonticon/IconsFontAwesome6 export IconsFontAwesome6 -let IconfontFullPath = "../utils/fonticon/fa6/fa-solid-900.ttf" +let IconfontFullPath = os.joinPath(os.getAppDir(),"../utils/fonticon/fa6/fa-solid-900.ttf") #-------------- # point2px