8000 Add a few more DrawList functions by pwiecz · Pull Request #136 · inkyblackness/imgui-go · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Dec 31, 2022. It is now read-only.

Add a few more DrawList functions #136

Merged
merged 4 commits into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion DrawList.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package imgui
// #include "wrapper/DrawList.h"
import "C"
import (
"image/color"
"unsafe"
)

// DrawList is a draw-command list.
// This is the low-level list of polygons that ImGui functions are filling.
// At the end of the frame, all command lists are passed to your render function for rendering.
//
// Each ImGui window contains its own DrawList. You can use GetWindowDrawList() to access
// Each ImGui window contains its own DrawList. You can use WindowDrawList() to access
// the current window draw list and draw custom primitives.
//
// You can interleave normal ImGui calls and adding primitives to the current draw list.
Expand Down Expand Up @@ -91,6 +92,11 @@ func WindowDrawList() DrawList {
return DrawList(C.iggGetWindowDrawList())
}

// BackgroundDrawList returns the DrawList for the background behind all windows.
func BackgroundDrawList() DrawList {
return DrawList(C.iggGetBackgroundDrawList())
}

// This is a list of DrawCornerFlags.
const (
DrawCornerFlagsNone = 0x0
Expand Down Expand Up @@ -199,3 +205,17 @@ func (list DrawList) AddText(pos Vec2, col PackedColor, text string) {
posArg, _ := pos.wrapped()
C.iggAddText(list.handle(), posArg, C.IggPackedColor(col), (*C.char)(CString.ptr), C.int(CString.size)-1)
}

// AddImage calls AddImageV(textureId, posMin, posMax, Vec2{0,0}, Vec2{1,1}, Packed(color.White)).
func (list DrawList) AddImage(textureID TextureID, posMin Vec2, posMax Vec2) {
list.AddImageV(textureID, posMin, posMax, Vec2{X: 0, Y: 0}, Vec2{X: 1, Y: 1}, Packed(color.White))
}

// AddImageV adds an image based on given texture ID.
func (list DrawList) AddImageV(textureID TextureID, posMin Vec2, posMax Vec2, uvMin Vec2, uvMax Vec2, tintCol PackedColor) {
posMinArg, _ := posMin.wrapped()
posMaxArg, _ := posMax.wrapped()
uvMinArg, _ := uvMin.wrapped()
uvMaxArg, _ := uvMax.wrapped()
C.iggAddImage(list.handle(), C.IggTextureID(textureID), posMinArg, posMaxArg, uvMinArg, uvMaxArg, C.IggPackedColor(tintCol))
}
15 changes: 15 additions & 0 deletions wrapper/DrawList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,22 @@ void iggAddText(IggDrawList handle, IggVec2 const *pos, IggPackedColor col, cons
list->AddText(*posArg, col, text, text + length);
}

void iggAddImage(IggDrawList handle, IggTextureID textureID, IggVec2* pMin, IggVec2* pMax, IggVec2* uvMin, IggVec2* uvMax, IggPackedColor col) {
Vec2Wrapper pMinArg(pMin);
Vec2Wrapper pMaxArg(pMax);
< B9F0 /td> Vec2Wrapper uvMinArg(uvMin);
Vec2Wrapper uvMaxArg(uvMax);

ImDrawList* list = reinterpret_cast<ImDrawList *>(handle);
list->AddImage(reinterpret_cast<ImTextureID>(textureID), *pMinArg, *pMaxArg, *uvMinArg, *uvMaxArg, col);
}

IggDrawList iggGetWindowDrawList()
{
return static_cast<IggDrawList>(const_cast<ImDrawList *>(ImGui::GetWindowDrawList()));
}

IggDrawList iggGetBackgroundDrawList()
{
return static_cast<IggDrawList>(const_cast<ImDrawList *>(ImGui::GetBackgroundDrawList()));
}
2 changes: 2 additions & 0 deletions wrapper/DrawList.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ extern void iggAddCircleFilled(IggDrawList handle, IggVec2 const *center, float
extern void iggAddTriangle(IggDrawList handle, IggVec2 *p1, IggVec2 *p2, IggVec2 *p3, IggPackedColor col, float thickness);
extern void iggAddTriangleFilled(IggDrawList handle, IggVec2 *p1, IggVec2 *p2, IggVec2 *p3, IggPackedColor col);
extern void iggAddText(IggDrawList handle, IggVec2 const *pos, IggPackedColor col, const char *text, int length);
extern void iggAddImage(IggDrawList handle, IggTextureID textureID, IggVec2* pMin, IggVec2* pMax, IggVec2* uvMin, IggVec2* uvMax, IggPackedColor col);

extern IggDrawList iggGetWindowDrawList();
extern IggDrawList iggGetBackgroundDrawList();

#ifdef __cplusplus
}
Expand Down
0