Reorganising cairo
This commit is contained in:
@@ -32,6 +32,8 @@ int main(int argc, char **argv) {
|
|||||||
event.reply("Could not find that command :(");
|
event.reply("Could not find that command :(");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
bot.on_button_click([&bot](const dpp::button_click_t &event) {});
|
||||||
|
|
||||||
bot.on_ready([&bot](const dpp::ready_t &event) {
|
bot.on_ready([&bot](const dpp::ready_t &event) {
|
||||||
if (dpp::run_once<struct register_bot_commands>()) {
|
if (dpp::run_once<struct register_bot_commands>()) {
|
||||||
createCommands(event, bot);
|
createCommands(event, bot);
|
||||||
|
@@ -27,12 +27,12 @@ void commandGenerateReport(const dpp::slashcommand_t &event,
|
|||||||
.set_label(BUTTON_ACCEPT)
|
.set_label(BUTTON_ACCEPT)
|
||||||
.set_type(dpp::cot_button)
|
.set_type(dpp::cot_button)
|
||||||
.set_style(dpp::component_style::cos_success)
|
.set_style(dpp::component_style::cos_success)
|
||||||
.set_id("stinky"))
|
.set_id("generate_report_confirm"))
|
||||||
.add_component(dpp::component()
|
.add_component(dpp::component()
|
||||||
.set_label(BUTTON_CANCEL)
|
.set_label(BUTTON_CANCEL)
|
||||||
.set_type(dpp::cot_button)
|
.set_type(dpp::cot_button)
|
||||||
.set_style(dpp::component_style::cos_danger)
|
.set_style(dpp::component_style::cos_danger)
|
||||||
.set_id("stinkyyy")));
|
.set_id("generate_report_deny")));
|
||||||
event.edit_response(confirmRequest);
|
event.edit_response(confirmRequest);
|
||||||
} else {
|
} else {
|
||||||
event.edit_response(
|
event.edit_response(
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
#include "CairoTools.hpp"
|
#include "CairoTools.hpp"
|
||||||
|
#include <cairo/cairo.h>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
std::string GenerateReportImage(cairo_surface_t *background,
|
std::string GenerateReportImage(cairo_surface_t *background,
|
||||||
@@ -7,13 +8,12 @@ std::string GenerateReportImage(cairo_surface_t *background,
|
|||||||
CAIRO_FORMAT_ARGB32, REPORT_WIDTH, REPORT_HEIGHT);
|
CAIRO_FORMAT_ARGB32, REPORT_WIDTH, REPORT_HEIGHT);
|
||||||
|
|
||||||
cairo_t *ctx = cairo_create(surface);
|
cairo_t *ctx = cairo_create(surface);
|
||||||
cairo_set_source_rgb(ctx, 0, 0, 0);
|
cairo_set_source_rgb(ctx, CAIRO_BLACK);
|
||||||
cairo_paint(ctx);
|
cairo_paint(ctx);
|
||||||
int imgW = 0, imgH = 0;
|
|
||||||
|
|
||||||
// Background Image
|
// Background Image
|
||||||
cairo_save(ctx);
|
cairo_save(ctx);
|
||||||
imgW = cairo_image_surface_get_width(background);
|
int imgW = cairo_image_surface_get_width(background),
|
||||||
imgH = cairo_image_surface_get_height(background);
|
imgH = cairo_image_surface_get_height(background);
|
||||||
|
|
||||||
cairo_scale(ctx, (double)REPORT_WIDTH / imgW,
|
cairo_scale(ctx, (double)REPORT_WIDTH / imgW,
|
||||||
@@ -25,15 +25,15 @@ std::string GenerateReportImage(cairo_surface_t *background,
|
|||||||
// Gradient
|
// Gradient
|
||||||
cairo_pattern_t *gradient =
|
cairo_pattern_t *gradient =
|
||||||
cairo_pattern_create_linear(0, 0, 0, REPORT_HEIGHT);
|
cairo_pattern_create_linear(0, 0, 0, REPORT_HEIGHT);
|
||||||
cairo_pattern_add_color_stop_rgba(gradient, 0.85, 0, 0, 0, 1);
|
cairo_pattern_add_color_stop_rgba(gradient, 0.85, CAIRO_BLACK, 1.0);
|
||||||
cairo_pattern_add_color_stop_rgba(gradient, 0, 0, 0, 0, 0);
|
cairo_pattern_add_color_stop_rgba(gradient, 0.0, CAIRO_BLACK, 0.0);
|
||||||
cairo_rectangle(ctx, 0, 0, REPORT_WIDTH, REPORT_HEIGHT);
|
cairo_rectangle(ctx, 0, 0, REPORT_WIDTH, REPORT_HEIGHT);
|
||||||
cairo_set_source(ctx, gradient);
|
cairo_set_source(ctx, gradient);
|
||||||
cairo_fill(ctx);
|
cairo_fill(ctx);
|
||||||
|
|
||||||
// Bumper
|
// Bumper
|
||||||
cairo_save(ctx);
|
cairo_save(ctx);
|
||||||
cairo_surface_t *bumper =
|
static cairo_surface_t *bumper =
|
||||||
cairo_image_surface_create_from_png(REPORT_RESOURCE_BUMPER_PATH);
|
cairo_image_surface_create_from_png(REPORT_RESOURCE_BUMPER_PATH);
|
||||||
|
|
||||||
imgW = cairo_image_surface_get_width(bumper);
|
imgW = cairo_image_surface_get_width(bumper);
|
||||||
@@ -71,11 +71,15 @@ std::string GenerateReportImage(cairo_surface_t *background,
|
|||||||
cairo_move_to(ctx, REPORT_TEXT_START_X,
|
cairo_move_to(ctx, REPORT_TEXT_START_X,
|
||||||
REPORT_HEIGHT -
|
REPORT_HEIGHT -
|
||||||
(REPORT_TEXT_JUMP_Y * (outputList.size() - lineCount++)));
|
(REPORT_TEXT_JUMP_Y * (outputList.size() - lineCount++)));
|
||||||
cairo_set_source_rgb(ctx, CAIRO_TEXT_WHITE);
|
cairo_set_source_rgb(ctx, CAIRO_QUARTZ);
|
||||||
cairo_show_text(ctx, line.c_str());
|
cairo_show_text(ctx, line.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string data;
|
std::string data;
|
||||||
cairo_surface_write_to_png_stream(surface, cairoOutputAsPNGStream, &data);
|
cairo_surface_write_to_png_stream(surface, cairoOutputAsPNGStream, &data);
|
||||||
|
|
||||||
|
// Ugh cleanup
|
||||||
|
cairo_surface_destroy(surface);
|
||||||
|
cairo_destroy(ctx);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,8 @@
|
|||||||
#define REPORT_TEXT_FONT_SIZE 120.0
|
#define REPORT_TEXT_FONT_SIZE 120.0
|
||||||
#define REPORT_TEXT_LENGTH 26
|
#define REPORT_TEXT_LENGTH 26
|
||||||
#define REPORT_RESOURCE_BUMPER_PATH "./assets/report_bumper.png"
|
#define REPORT_RESOURCE_BUMPER_PATH "./assets/report_bumper.png"
|
||||||
#define CAIRO_TEXT_WHITE 0.87, 0.87, 0.87
|
#define CAIRO_QUARTZ 0.87, 0.87, 0.87
|
||||||
|
#define CAIRO_BLACK 0.0, 0.0, 0.0
|
||||||
|
|
||||||
std::string GenerateReportImage(cairo_surface_t *background,
|
std::string GenerateReportImage(cairo_surface_t *background,
|
||||||
std::string headline);
|
std::string headline);
|
||||||
|
Reference in New Issue
Block a user