Skip to content

Commit

Permalink
added: Magnifying glass functionality
Browse files Browse the repository at this point in the history
added: iconFontViewer sources
  • Loading branch information
dinau committed Oct 26, 2024
1 parent b13d3b2 commit 0a4635d
Show file tree
Hide file tree
Showing 29 changed files with 3,689 additions and 123 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# All examples will be built at a time.
#
EXAMPLE_DIRS := \
examples/iconFontViewer \
examples/imPlotDemo \
examples/glfw_opengl3 \
examples/glfw_opengl3_implot \
Expand All @@ -13,6 +14,7 @@ ifeq ($(OS),Windows_NT)
endif

all:
zig version
$(foreach exdir,$(EXAMPLE_DIRS), $(call def_make,$(exdir),$@ ))

.PHONY: test clean gen cleanexe
Expand Down
84 changes: 47 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [Examples screen shots](#examples-screen-shots)
- [glfw_opengl3 / sdl2_opengl3 / sdl3_opengl3](#glfw_opengl3--sdl2_opengl3--sdl3_opengl3)
- [glfw_opengl3_jp](#glfw_opengl3_jp)
- [iconFontViewer](#iconfontviewer)
- [glfw_opengl3_image_load](#glfw_opengl3_image_load)
- [glfw_opengl3_implot](#glfw_opengl3_implot)
- [ImPlot Demo written in Zig lang.](#implot-demo-written-in-zig-lang)
Expand All @@ -30,11 +31,10 @@
- [SDL libraries](#sdl-libraries)
- [My tools version](#my-tools-version)
- [Similar project](#similar-project)
- [Star History](#star-history)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# ImGuinZ
## ImGuinZ

This project aims to simply and easily build [Dear ImGui](https://github.com/ocornut/imgui)
[(CImGui)](https://github.com/cimgui/cimgui) / [ImPlot](https://github.com/epezent/implot) [(CImPlot)](https://github.com/cimgui/cimplot)
Expand All @@ -47,23 +47,25 @@ ImGui / CImGui version **1.91.4dock** (2024/10)
![alt](img/icon_font.png)
- Included GLFW 3.3.9 static library (for Windows)
- Included SDL2/SDL3 libraries (for Windows)
- Included STB libraries (only stb_image)
- Included STB libraries (only stb_image) for Load / Save images
- Available [ImPlot](https://github.com/epezent/implot) [(CImPlot)](https://github.com/cimgui/cimplot) with `ImDrawIdx="unsigned int"`
- Enabled Input method \(IME\) flag with `IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS`


## Prerequisites
### Prerequisites

---

- Zig version, now using
Zig: 0.14.0-dev.1954+2d888a8e6
Probably [zig-windows-x86_64-0.14.0-dev.xxxx+yyyy...](https://ziglang.org/download/) might be ok. (-:)
- Zig version
1. Zig: 0.14.0-dev.2047+985b13934 OK
Probably [zig-windows-x86_64-0.14.0-dev.xxxx+yyyy...](https://ziglang.org/download/) might be OK
1. zig-0.12.1: or later OK

- WindowsOS
- Windows10 or later
- MSys2/MinGW basic commands (make, rm, cp, strip ...)
- Linux OS
Linux Mint 22 (or Ubuntu/Debian families ?)
Linux Mint 22 is OK. (or Ubuntu / Debian families ?)

```sh
$ sudo apt install xorg-dev libopengl-dev libgl1-mesa-dev
Expand All @@ -76,7 +78,7 @@ Linux Mint 22 (or Ubuntu/Debian families ?)
$ sudo apt install libsdl2-dev
```

## Build and run
### Build and run

---

Expand All @@ -97,9 +99,9 @@ Linux Mint 22 (or Ubuntu/Debian families ?)
make run # or zig build --release=fast run
```

## Examples screen shots
### Examples screen shots

### glfw_opengl3 / sdl2_opengl3 / sdl3_opengl3
#### glfw_opengl3 / sdl2_opengl3 / sdl3_opengl3

---

Expand All @@ -109,118 +111,126 @@ Linux Mint 22 (or Ubuntu/Debian families ?)

![alt](img/glfw_opengl3.png)

### glfw_opengl3_jp
#### glfw_opengl3_jp

---

Load / Show CJK fonts
[glfw_opengl3_jp](examples/glfw_opengl3_jp/src/main.zig)

![alt](img/glfw_opengl3_jp.png)

#### IconFontViewer

---

### glfw_opengl3_image_load
[iconFontViewer](examples/iconFontViewer/src/main.zig) with magnifying glass

![alt](img/iconFontViewer.png)

#### glfw_opengl3_image_load

---

[glfw_opengl3_image_load](examples/glfw_opengl3_image_load/src/main.zig)
[glfw_opengl3_image_load](examples/glfw_opengl3_image_load/src/main.zig) with magnifying glass

![alt](img/glfw_opengl3_image_load.png)
Image file captured would be saved in the folder `./zig-out/bin`.
Image can be saved as `JPEG / PNG / BMP / TGA` file.

### glfw_opengl3_implot
#### glfw_opengl3_implot

---

[glfw_opengl3_implot](examples/glfw_opengl3_implot/src/main.zig)

![alt](img/glfw_opengl3_implot.png)

## ImPlot Demo written in Zig lang.
### ImPlot Demo written in Zig lang.

---

Now work in progress.


### Build and run
#### Build and run

```sh
pwd
examples/imPlotDemo
make run # or zig build --release=fast run
```

### ImPlot demo source in Zig lang.
#### ImPlot demo source in Zig lang.

---

[demoAll.zig](examples/imPlotDemo/src/demoAll.zig)

### Plots Tab
#### Plots Tab

---

#### LinePlots (Dynamic)
##### LinePlots (Dynamic)

![alt](examples/imPlotDemo/img/LinePlots.png)

#### BarGroups
##### BarGroups

![alt](examples/imPlotDemo/img/BarGroups.png)

#### BarStacks
##### BarStacks

![alt](examples/imPlotDemo/img/BarStacks.png)

#### PieCharts
##### PieCharts

![alt](examples/imPlotDemo/img/PieCharts.png)

#### Heatmaps
##### Heatmaps

![alt](examples/imPlotDemo/img/Heatmaps.png)

#### Histogram2D
##### Histogram2D

![alt](examples/imPlotDemo/img/Histogram2D.png)

#### Images
##### Images

![alt](examples/imPlotDemo/img/Images.png)

### Axes Tab
#### Axes Tab

---

#### LogScale
##### LogScale

![alt](examples/imPlotDemo/img/LogScale.png)

### Subplots Tab
#### Subplots Tab

---

#### Tables (Dynamic)
##### Tables (Dynamic)

![alt](examples/imPlotDemo/img/Tables.png)

### Tools Tab
#### Tools Tab

---

#### DragRects
##### DragRects

![alt](examples/imPlotDemo/img/DragRects.png)


## Show / Hide console window
### Show / Hide console window

---

Open `build.zig` in each example folder and
Hide console window: Default,
Show console window: Commet out this line as follows,
Show console window: Comment out this line as follows,

```zig
... snip ...
Expand All @@ -230,7 +240,7 @@ Show console window: Commet out this line as follows,

and rebuild example.

## SDL libraries
### SDL libraries

---

Expand All @@ -244,7 +254,7 @@ https://github.com/mmozeiko/build-sdl3
https://github.com/JBetz/build-sdl3-win32/releases
https://github.com/JBetz/build-sdl3-win32

## My tools version
### My tools version

---

Expand All @@ -260,7 +270,7 @@ https://github.com/JBetz/build-sdl3-win32
- SDL2 ver.2.30.0
- Git version 2.43.0

## Similar project
### Similar project

---

Expand Down
18 changes: 6 additions & 12 deletions examples/glfw_opengl3/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn main () !void {
//-------------------------
// Decide GL+GLSL versions
//-------------------------
const glsl_version = "#version 130";
const glsl_version = "#version 330";
ig.glfwWindowHint(ig.GLFW_OPENGL_FORWARD_COMPAT, ig.GLFW_TRUE);
ig.glfwWindowHint(ig.GLFW_OPENGL_PROFILE, ig.GLFW_OPENGL_CORE_PROFILE);
ig.glfwWindowHint(ig.GLFW_CONTEXT_VERSION_MAJOR, 3);
Expand Down Expand Up @@ -118,8 +118,7 @@ pub fn main () !void {
var clearColor = [_]f32{0.25, 0.55,0.9,1.0};
// Input text buffer
var sTextInuputBuf = [_:0]u8{0} ** 200;
var showWindowDelay:i32 = 1;
var showWindowReq = true;
var showWindowDelay:i32 = 2; // TODO: Avoid flickering of window at startup.

//------------------------
// Select Dear ImGui style
Expand Down Expand Up @@ -222,16 +221,11 @@ pub fn main () !void {
}
}
ig.glfwSwapBuffers(window);
if(showWindowDelay > 0){
if(showWindowDelay >= 0){
showWindowDelay -= 1;
}else{
if(showWindowReq){
showWindowReq = false;
//-------------------------------
// Visible/Show main window here
//-------------------------------
ig.glfwShowWindow(window);
}
}
if(showWindowDelay == 0){ // Visible main window here at start up
ig.glfwShowWindow(window);
}


Expand Down
Binary file modified examples/glfw_opengl3_image_load/himeji-400.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 21 additions & 14 deletions examples/glfw_opengl3_image_load/src/main.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const std = @import ("std");
const builtin = @import ("builtin");
// Filse in src folder
const ig = @import("imgui.zig");
const fonts = @import("fonts.zig");
const utils = @import("utils.zig");


const TImgFormat = struct {
Expand Down Expand Up @@ -55,7 +57,7 @@ pub fn main () !void {
//-------------------------
// Decide GL+GLSL versions
//-------------------------
const glsl_version = "#version 130";
const glsl_version = "#version 330";
ig.glfwWindowHint(ig.GLFW_OPENGL_FORWARD_COMPAT, ig.GLFW_TRUE);
ig.glfwWindowHint(ig.GLFW_OPENGL_PROFILE, ig.GLFW_OPENGL_CORE_PROFILE);
ig.glfwWindowHint(ig.GLFW_CONTEXT_VERSION_MAJOR, 3);
Expand Down Expand Up @@ -136,8 +138,7 @@ pub fn main () !void {
var clearColor = [_]f32{0.25, 0.55,0.9,1.0};
// Input text buffer
var sTextInuputBuf = [_:0]u8{0} ** 200;
var showWindowDelay:i32 = 1;
var showWindowReq = true;
var showWindowDelay:i32 = 2; // TODO: Avoid flickering of window at startup.

//------------------------
// Select Dear ImGui style
Expand All @@ -158,6 +159,10 @@ pub fn main () !void {
fonts.setupFonts(); // Setup CJK fonts and Icon fonts

//const sz = ig.ImVec2 {.x = 0, .y = 0} ;

var zoomTextureID: ig.GLuint = 0; //# Must be == 0 at first
defer ig.glDeleteTextures(1, &zoomTextureID);

//---------------
// main loop GUI
//---------------
Expand Down Expand Up @@ -271,17 +276,25 @@ pub fn main () !void {
if (ig.igButton ("Close Me", .{.x = 0, .y = 0})) showAnotherWindow = false;
}

//------------------------
// Show image load window
//------------------------
if (ig.igBegin("Image load test", null, 0)) {
defer ig.igEnd();
var imageBoxPosTop:ig.ImVec2 = undefined;
var imageBoxPosEnd:ig.ImVec2 = undefined;
// Load image
const size = ig.ImVec2 {.x = @floatFromInt(textureWidth), .y = @floatFromInt(textureHeight)};
ig.igSetNextWindowSize(size, ig.ImGuiCond_Always);
const uv0 = ig.ImVec2 {.x = 0, .y = 0};
const uv1 = ig.ImVec2 {.x = 1, .y = 1};
const tint_col = ig.ImVec4 {.x = 1, .y = 1, .z = 1, .w = 1};
const border_col = ig.ImVec4 {.x = 0, .y = 0, .z = 0, .w = 0};
ig.igGetCursorScreenPos(&imageBoxPosTop);// # Get absolute pos.
ig.igImage(@intCast(textureId), size, uv0, uv1, tint_col, border_col);
ig.igGetCursorScreenPos(&imageBoxPosEnd);// # Get absolute pos.
if(ig.igIsItemHovered(ig.ImGuiHoveredFlags_DelayNone)){
utils.zoomGlass(&zoomTextureID, textureWidth, imageBoxPosTop, imageBoxPosEnd);
}
}

//-----------
Expand All @@ -305,18 +318,12 @@ pub fn main () !void {
}
ig.glfwSwapBuffers(window);

if(showWindowDelay > 0){
if(showWindowDelay >= 0){
showWindowDelay -= 1;
}else{
if(showWindowReq){
showWindowReq = false;
//-------------------------------
// Visible/Show main window here
//-------------------------------
ig.glfwShowWindow(window);
}
}

if(showWindowDelay == 0){ // Visible main window here at start up
ig.glfwShowWindow(window);
}

} // while end
} // main end
Expand Down
Loading

0 comments on commit 0a4635d

Please sign in to comment.