Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #190 from inkyblackness/add-image-quad
Browse files Browse the repository at this point in the history
Add image quad
  • Loading branch information
dertseha authored Sep 22, 2022
2 parents b51a58d + de305c8 commit ee9a57b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
go-version: [ 1.12, 1.18 ]
os: [ macos-latest, windows-latest, ubuntu-latest ]
os: [ macos-latest, ubuntu-latest ]
steps:
- name: Set up Go
uses: actions/setup-go@v1
Expand Down
22 changes: 22 additions & 0 deletions DrawList.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,28 @@ func (list DrawList) AddImageV(textureID TextureID, posMin Vec2, posMax Vec2, uv
C.iggAddImage(list.handle(), C.IggTextureID(textureID), posMinArg, posMaxArg, uvMinArg, uvMaxArg, C.IggPackedColor(tintCol))
}

// AddImageQuad calls AddImageQuadV(textureID, p1, p2, p3, p4,
// Vec2{X: 0, Y: 0}, Vec2{X: 1, Y: 0}, Vec2{X: 1, Y: 1}, Vec2{X: 0, Y: 1},
// Packed(color.White)).
func (list DrawList) AddImageQuad(textureID TextureID, p1 Vec2, p2 Vec2, p3 Vec2, p4 Vec2) {
list.AddImageQuadV(textureID, p1, p2, p3, p4,
Vec2{X: 0, Y: 0}, Vec2{X: 1, Y: 0}, Vec2{X: 1, Y: 1}, Vec2{X: 0, Y: 1},
Packed(color.White))
}

// AddImageQuadV adds an image based on given texture ID, with four UV coordinates.
func (list DrawList) AddImageQuadV(textureID TextureID, p1 Vec2, p2 Vec2, p3 Vec2, p4 Vec2, uv1 Vec2, uv2 Vec2, uv3 Vec2, uv4 Vec2, tintCol PackedColor) {
p1Arg, _ := p1.wrapped()
p2Arg, _ := p2.wrapped()
p3Arg, _ := p3.wrapped()
p4Arg, _ := p4.wrapped()
uv1Arg, _ := uv1.wrapped()
uv2Arg, _ := uv2.wrapped()
uv3Arg, _ := uv3.wrapped()
uv4Arg, _ := uv4.wrapped()
C.iggAddImageQuad(list.handle(), C.IggTextureID(textureID), p1Arg, p2Arg, p3Arg, p4Arg, uv1Arg, uv2Arg, uv3Arg, uv4Arg, C.IggPackedColor(tintCol))
}

// PushClipRect performs render-level scissoring.
// It calls PushClipRectV(min, max, false).
func (list DrawList) PushClipRect(min, max Vec2) {
Expand Down
14 changes: 14 additions & 0 deletions wrapper/DrawList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ void iggAddImage(IggDrawList handle, IggTextureID textureID, IggVec2* pMin, IggV
list->AddImage(reinterpret_cast<ImTextureID>(textureID), *pMinArg, *pMaxArg, *uvMinArg, *uvMaxArg, col);
}

void iggAddImageQuad(IggDrawList handle, IggTextureID textureID, IggVec2* p1, IggVec2* p2, IggVec2* p3, IggVec2* p4, IggVec2* uv1, IggVec2* uv2, IggVec2* uv3, IggVec2* uv4, IggPackedColor col) {
Vec2Wrapper p1Arg(p1);
Vec2Wrapper p2Arg(p2);
Vec2Wrapper p3Arg(p3);
Vec2Wrapper p4Arg(p4);
Vec2Wrapper uv1Arg(uv1);
Vec2Wrapper uv2Arg(uv2);
Vec2Wrapper uv3Arg(uv3);
Vec2Wrapper uv4Arg(uv4);

ImDrawList *list = reinterpret_cast<ImDrawList *>(handle);
list->AddImageQuad(reinterpret_cast<ImTextureID>(textureID), *p1Arg, *p2Arg, *p3Arg, *p4Arg, *uv1Arg, *uv2Arg, *uv3Arg, *uv4Arg, col);
}

void iggPushClipRect(IggDrawList handle, IggVec2 const *min, IggVec2 const *max, IggBool intersectWithCurrentClipRect)
{
ImDrawList *list = reinterpret_cast<ImDrawList *>(handle);
Expand Down
1 change: 1 addition & 0 deletions wrapper/DrawList.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern void iggAddTriangle(IggDrawList handle, IggVec2 *p1, IggVec2 *p2, IggVec2
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 void iggAddImageQuad(IggDrawList handle, IggTextureID textureID, IggVec2* p1, IggVec2* p2, IggVec2* p3, IggVec2* p4, IggVec2* uv1, IggVec2* uv2, IggVec2* uv3, IggVec2* uv4, IggPackedColor col);

extern void iggPushClipRect(IggDrawList handle, IggVec2 const *min, IggVec2 const *max, IggBool intersectWithCurrentClipRect);
extern void iggPopClipRect(IggDrawList handle);
Expand Down
1 change: 1 addition & 0 deletions wrapper/Types.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
Expand Down

0 comments on commit ee9a57b

Please sign in to comment.