Skip to content
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ build/
install/
.vscode/
.vs/
out/
out/
CMakeSettings.json
cmake-build-*/
8 changes: 4 additions & 4 deletions src/D2DPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ void D2DPainter::line(float x1, float y1, float x2, float y2, float thickness, u
m_context->DrawLine({x1, y1}, {x2, y2}, m_brush.Get(), thickness);
}

void D2DPainter::image(std::shared_ptr<D2DImage>& image, float x, float y) {
void D2DPainter::image(std::shared_ptr<D2DImage>& image, float x, float y, float alpha) {
auto [w, h] = image->size();
m_context->DrawBitmap(image->bitmap().Get(), {x, y, x + w, y + h});
m_context->DrawBitmap(image->bitmap().Get(), {x, y, x + w, y + h}, alpha);
}

void D2DPainter::image(std::shared_ptr<D2DImage>& image, float x, float y, float w, float h) {
m_context->DrawBitmap(image->bitmap().Get(), {x, y, x + w, y + h});
void D2DPainter::image(std::shared_ptr<D2DImage>& image, float x, float y, float w, float h, float alpha) {
m_context->DrawBitmap(image->bitmap().Get(), {x, y, x + w, y + h}, alpha);
}

void D2DPainter::fill_circle(float centerX, float centerY, float radius, unsigned int color) {
Expand Down
4 changes: 2 additions & 2 deletions src/D2DPainter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class D2DPainter {
void quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float thickness, unsigned int color);
void fill_quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, unsigned int color);
void line(float x1, float y1, float x2, float y2, float thickness, unsigned int color);
void image(std::shared_ptr<D2DImage>& image, float x, float y);
void image(std::shared_ptr<D2DImage>& image, float x, float y, float w, float h);
void image(std::shared_ptr<D2DImage>& image, float x, float y, float alpha);
void image(std::shared_ptr<D2DImage>& image, float x, float y, float w, float h, float alpha);
void fill_circle(float centerX, float centerY, float radius, unsigned int color);
void fill_circle(float centerX, float centerY, float radiusX, float radiusY, unsigned int color);
void circle(float centerX, float centerY, float radius, float thickness, unsigned int color);
Expand Down
3 changes: 2 additions & 1 deletion src/DrawList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,14 @@ void DrawList::CommandLock::line(float x1, float y1, float x2, float y2, float t
commands.emplace_back(std::move(cmd));
}

void DrawList::CommandLock::image(std::shared_ptr<D2DImage>& image, float x, float y, float w, float h) {
void DrawList::CommandLock::image(std::shared_ptr<D2DImage>& image, float x, float y, float w, float h, float alpha) {
Command cmd{};
cmd.type = CommandType::IMAGE;
cmd.image.x = x;
cmd.image.y = y;
cmd.image.w = w;
cmd.image.h = h;
cmd.image.alpha = alpha;
cmd.image_resource = image;
commands.emplace_back(std::move(cmd));
}
Expand Down
3 changes: 2 additions & 1 deletion src/DrawList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class DrawList {
float y{};
float w{};
float h{};
float alpha{1.0f};
} image;
struct {
float x{};
Expand Down Expand Up @@ -164,7 +165,7 @@ class DrawList {
void quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float thickness, unsigned int color);
void fill_quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, unsigned int color);
void line(float x1, float y1, float x2, float y2, float thickness, unsigned int color);
void image(std::shared_ptr<D2DImage>& image, float x, float y, float w, float h);
void image(std::shared_ptr<D2DImage>& image, float x, float y, float w, float h, float alpha = 1.0f);
void fill_circle(float x, float y, float radiusX, float radiusY, unsigned int color);
void circle(float x, float y, float radiusX, float radiusY, float thickness, unsigned int color);
void pie(float x, float y, float r, float startAngle, float sweepAngle, unsigned int color, bool clockwise);
Expand Down
27 changes: 16 additions & 11 deletions src/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,24 @@ void on_ref_lua_state_created(lua_State* l) try {
d2d["line"] = [](float x1, float y1, float x2, float y2, float thickness, unsigned int color) {
g_plugin->cmds->line(x1, y1, x2, y2, thickness, color);
};
d2d["image"] = [](std::shared_ptr<D2DImage>& image, float x, float y, sol::object w_obj, sol::object h_obj) {
auto [w, h] = image->size();
d2d["image"] = [](std::shared_ptr<D2DImage>& image, float x, float y, sol::object w_obj, sol::object h_obj, sol::object alpha_obj) {
auto [w, h] = image->size();
float alpha = 1.0f;

if (w_obj.is<float>()) {
w = w_obj.as<float>();
}
if (w_obj.is<float>()) {
w = w_obj.as<float>();
}

if (h_obj.is<float>()) {
h = h_obj.as<float>();
}
if (h_obj.is<float>()) {
h = h_obj.as<float>();
}

g_plugin->cmds->image(image, x, y, w, h);
};
if (alpha_obj.is<float>()) {
alpha = alpha_obj.as<float>();
}

g_plugin->cmds->image(image, x, y, w, h, alpha);
};
d2d["fill_circle"] = [](float x, float y, float r, unsigned int color) { g_plugin->cmds->fill_circle(x, y, r, r, color); };
d2d["circle"] = [](float x, float y, float r, float thickness, unsigned int color) {
g_plugin->cmds->circle(x, y, r, r, thickness, color);
Expand Down Expand Up @@ -303,7 +308,7 @@ void on_ref_frame() try {
break;

case DrawList::CommandType::IMAGE:
g_plugin->d2d->image(cmd.image_resource, cmd.image.x, cmd.image.y, cmd.image.w, cmd.image.h);
g_plugin->d2d->image(cmd.image_resource, cmd.image.x, cmd.image.y, cmd.image.w, cmd.image.h, cmd.image.alpha);
break;

case DrawList::CommandType::FILL_CIRCLE:
Expand Down