MwStringPrintIntoBuffer
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
This commit is contained in:
parent
87c870a6c0
commit
35d2b4bb76
21 changed files with 233 additions and 331 deletions
|
|
@ -721,7 +721,7 @@ void MwDispatchError(int code, const char* message) {
|
|||
} else {
|
||||
#ifdef _WIN32
|
||||
char buffer[1024];
|
||||
sprintf(buffer, "Error: %s\r\nCode : %d\r\n\r\nMilsko is exiting.", message, code);
|
||||
MwPrintIntoBuffer(buffer, 1024, "Error: %s\r\nCode : %d\r\n\r\nMilsko is exiting.", message, code);
|
||||
MessageBox(NULL, buffer, "Error", MB_ICONERROR | MB_OK);
|
||||
#else
|
||||
fprintf(stderr, "Error: %s\nCode : %d\n\nMilsko is exiting.", message, code);
|
||||
|
|
|
|||
|
|
@ -173,13 +173,13 @@ static void color_picker_click(MwWidget handle, void* user, void* call) {
|
|||
picker->chosen_color.green = picker->color_picker_image_data[i + 1];
|
||||
picker->chosen_color.blue = picker->color_picker_image_data[i + 2];
|
||||
|
||||
sprintf(hexColor, "#%02X%02X%02X", picker->chosen_color.red & 0xff, picker->chosen_color.green & 0xff, picker->chosen_color.blue & 0xff);
|
||||
MwPrintIntoBuffer(hexColor, 8, "#%02X%02X%02X", picker->chosen_color.red & 0xff, picker->chosen_color.green & 0xff, picker->chosen_color.blue & 0xff);
|
||||
|
||||
fr = picker->chosen_color.red > 128 ? 0 : 255;
|
||||
fg = picker->chosen_color.green > 128 ? 0 : 255;
|
||||
fb = picker->chosen_color.blue > 128 ? 0 : 255;
|
||||
|
||||
sprintf(fgColor, "#%02X%02X%02X", fr, fg, fb);
|
||||
MwPrintIntoBuffer(fgColor, 8, "#%02X%02X%02X", fr, fg, fb);
|
||||
MwSetText(picker->color_display_text, MwNforeground, fgColor);
|
||||
|
||||
MwSetText(picker->color_display_text, MwNbackground, hexColor);
|
||||
|
|
@ -247,7 +247,7 @@ static void color_display_text_change(MwWidget handle, void* user,
|
|||
fg = color->common.green > 128 ? 0 : 255;
|
||||
fb = color->common.blue > 128 ? 0 : 255;
|
||||
|
||||
sprintf(fgColor, "#%02X%02X%02X", fr, fg, fb);
|
||||
MwPrintIntoBuffer(fgColor, 9, "#%02X%02X%02X", fr, fg, fb);
|
||||
MwSetText(picker->color_display_text, MwNforeground, fgColor);
|
||||
|
||||
MwSetText(picker->color_display_text, MwNbackground, hexColor);
|
||||
|
|
|
|||
23
src/error.c
23
src/error.c
|
|
@ -1,23 +0,0 @@
|
|||
#include <Mw/Milsko.h>
|
||||
#include "error_internal.h"
|
||||
|
||||
#define MAX_ERROR_LEN 512
|
||||
|
||||
/* buffer for holding the error. +1 to ensure there's always a null terminator. */
|
||||
char error[MAX_ERROR_LEN + 1] = {0};
|
||||
|
||||
const char* MwGetLastError(void) {
|
||||
return error;
|
||||
}
|
||||
|
||||
void setLastError(const char* fmt, ...) {
|
||||
va_list va;
|
||||
char out[MAX_ERROR_LEN];
|
||||
memset(out, 0, MAX_ERROR_LEN);
|
||||
|
||||
va_start(va, fmt);
|
||||
vsprintf(out, fmt, va);
|
||||
va_end(va);
|
||||
|
||||
memcpy(error, out, MAX_ERROR_LEN);
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#ifndef __MW_ERROR_INTERNAL_H__
|
||||
#define __MW_ERROR_INTERNAL_H__
|
||||
|
||||
/**
|
||||
* This is not to be documented or exposed publically.
|
||||
* This contains an internal function for setting the error,
|
||||
* something the user shouldn't want to do and thus we don't want them to.
|
||||
* (hence also, its placement in the src directory)
|
||||
*/
|
||||
|
||||
#include <Mw/Error.h>
|
||||
|
||||
void setLastError(const char* fmt, ...);
|
||||
|
||||
#endif
|
||||
12
src/string.c
12
src/string.c
|
|
@ -37,3 +37,15 @@ void MwStringTime(char* out, time_t t) {
|
|||
sprintf(out, "%s %2d %02d:%02d %d", months[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, 1900 + tm->tm_year);
|
||||
}
|
||||
}
|
||||
void MwPrintIntoBuffer(char* out, MwU32 size, const char* fmt, ...) {
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
|
||||
#if __STDC_VERSION__ >= 199901L
|
||||
vsnprintf(out, size, fmt, va);
|
||||
#else
|
||||
vsprintf(out, fmt, va);
|
||||
#endif
|
||||
|
||||
va_end(va);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -103,9 +103,9 @@ static void mouse_up(MwWidget handle, void* ptr) {
|
|||
if(e->mouse.x >= (w - e->right)) {
|
||||
char s[512];
|
||||
if(e->mouse.y >= (h / 2)) {
|
||||
sprintf(s, "%g", atof(str) - 1);
|
||||
MwPrintIntoBuffer(s, 512, "%g", atof(str) - 1);
|
||||
} else {
|
||||
sprintf(s, "%g", atof(str) + 1);
|
||||
MwPrintIntoBuffer(s, 512, "%g", atof(str) + 1);
|
||||
}
|
||||
MwSetText(handle, MwNtext, s);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/Vulkan.h>
|
||||
|
||||
#include "../error_internal.h"
|
||||
|
||||
/**
|
||||
* ioixd maintains this file. nishi doesn't know vulkan at all
|
||||
*/
|
||||
|
|
@ -49,15 +47,19 @@ MwVulkanConfig vulkan_config = {
|
|||
#define VK_CMD(func) \
|
||||
vk_res = func; \
|
||||
if(vk_res != VK_SUCCESS) { \
|
||||
setLastError("Vulkan error (%s:%d): %s\n", __FILE__, __LINE__, string_VkResult(vk_res)); \
|
||||
return MwEerror; \
|
||||
char buf[1024]; \
|
||||
MwPrintIntoBuffer(buf, 1024, "Vulkan error (%s:%d): %s\n", __FILE__, __LINE__, string_VkResult(vk_res)); \
|
||||
MwDispatchError(1, buf); \
|
||||
return 1; \
|
||||
}
|
||||
#else
|
||||
#define VK_CMD(func) \
|
||||
vk_res = func; \
|
||||
if(vk_res != VK_SUCCESS) { \
|
||||
setLastError("Vulkan error (%s:%d): (error %d)\n", __FILE__, __LINE__, vk_res); \
|
||||
return MwEerror; \
|
||||
char buf[1024]; \
|
||||
MwPrintIntoBuffer(buf, 1024, "Vulkan error (%s:%d): (error %d)\n", __FILE__, __LINE__, vk_res); \
|
||||
MwDispatchError(1, buf); \
|
||||
return 1; \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -69,8 +71,10 @@ MwVulkanConfig vulkan_config = {
|
|||
/* convienence macro to return an error if an assert goes wrong */
|
||||
#define VK_ASSERT(val) \
|
||||
if(!val) { \
|
||||
setLastError("Vulkan error (%s:%d): Assertion Failed (%s != NULL)\n", __FILE__, __LINE__, #val); \
|
||||
return MwEerror; \
|
||||
char buf[1024]; \
|
||||
MwPrintIntoBuffer(buf, 1024, "Vulkan error (%s:%d): Assertion Failed (%s != NULL)\n", __FILE__, __LINE__, #val); \
|
||||
MwDispatchError(1, buf); \
|
||||
return 1; \
|
||||
}
|
||||
|
||||
const char** enabledExtensions;
|
||||
|
|
@ -116,17 +120,17 @@ static int create(MwWidget handle) {
|
|||
memset(o, 0, sizeof(*o));
|
||||
|
||||
err = vulkan_instance_setup(handle, o);
|
||||
if(err != MwEsuccess) {
|
||||
if(err != 0) {
|
||||
printf("%s", MwGetLastError());
|
||||
return 1;
|
||||
}
|
||||
err = vulkan_surface_setup(handle, o);
|
||||
if(err != MwEsuccess) {
|
||||
if(err != 0) {
|
||||
printf("%s", MwGetLastError());
|
||||
return 1;
|
||||
}
|
||||
err = vulkan_devices_setup(handle, o);
|
||||
if(err != MwEsuccess) {
|
||||
if(err != 0) {
|
||||
printf("%s", MwGetLastError());
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -156,12 +160,12 @@ static MwErrorEnum _destroy(MwWidget handle) {
|
|||
|
||||
free(o);
|
||||
|
||||
return MwEsuccess;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void destroy(MwWidget handle) {
|
||||
MwErrorEnum err = _destroy(handle);
|
||||
if(err == MwEerror) {
|
||||
if(err == 1) {
|
||||
printf("[Vulkan Widget] %s", MwGetLastError());
|
||||
}
|
||||
}
|
||||
|
|
@ -199,7 +203,7 @@ static MwErrorEnum vulkan_instance_setup(MwWidget handle, vulkan_t* o) {
|
|||
o->vulkanLibrary = vulkan_lib_load();
|
||||
if(!o->vulkanLibrary) {
|
||||
vulkan_supported = VULKAN_SUPPORTED_NO;
|
||||
setLastError("Vulkan not found.");
|
||||
MwDispatchError(1, "Vulkan not found.");
|
||||
} else {
|
||||
vulkan_supported = VULKAN_SUPPORTED_YES;
|
||||
}
|
||||
|
|
@ -292,7 +296,7 @@ static MwErrorEnum vulkan_instance_setup(MwWidget handle, vulkan_t* o) {
|
|||
instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
|
||||
VK_CMD(_vkCreateInstance(&instance_create_info, NULL, &o->vkInstance));
|
||||
return MwEsuccess;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static MwErrorEnum vulkan_surface_setup(MwWidget handle, vulkan_t* o) {
|
||||
|
|
@ -341,7 +345,7 @@ static MwErrorEnum vulkan_surface_setup(MwWidget handle, vulkan_t* o) {
|
|||
VK_CMD(_vkCreateWaylandSurfaceKHR(o->vkInstance, &createInfo, NULL, &o->vkSurface));
|
||||
}
|
||||
#endif
|
||||
return MwEsuccess;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static MwErrorEnum vulkan_devices_setup(MwWidget handle, vulkan_t* o) {
|
||||
|
|
@ -400,8 +404,8 @@ static MwErrorEnum vulkan_devices_setup(MwWidget handle, vulkan_t* o) {
|
|||
}
|
||||
if(!has_graphics && !has_present) {
|
||||
/* rare, yes, but idk maybe some shitty drivers will present this dillema idk. */
|
||||
setLastError("There were no devices with either a graphics or presentation queue.\n");
|
||||
return MwEerror;
|
||||
MwDispatchError(1, "There were no devices with either a graphics or presentation queue.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* create the logical device */
|
||||
|
|
@ -461,7 +465,7 @@ static MwErrorEnum vulkan_devices_setup(MwWidget handle, vulkan_t* o) {
|
|||
_vkGetDeviceQueue(o->vkLogicalDevice, o->vkPresentFamilyIDX, 0, &o->vkPresentQueue);
|
||||
}
|
||||
free(devices);
|
||||
return MwEsuccess;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MwVulkanConfigure(MwVulkanConfig cfg) {
|
||||
|
|
@ -495,6 +499,7 @@ VkBool32 MwVulkanSupported(void) {
|
|||
|
||||
static void* mwVulkanGetFieldImpl(MwWidget handle, MwVulkanField field, MwErrorEnum* out) {
|
||||
vulkan_t* o = handle->internal;
|
||||
char buf[1024];
|
||||
|
||||
switch(field) {
|
||||
case MwVulkanField_GetInstanceProcAddr:
|
||||
|
|
@ -516,14 +521,15 @@ static void* mwVulkanGetFieldImpl(MwWidget handle, MwVulkanField field, MwErrorE
|
|||
case MwVulkanField_PresentQueue:
|
||||
return o->vkPresentQueue;
|
||||
default:
|
||||
setLastError("Unknown vulkan field request (%d given)", field);
|
||||
MwPrintIntoBuffer(buf, 1024, "Unknown vulkan field request (%d given)", field);
|
||||
MwDispatchError(1, buf);
|
||||
if(out != NULL) {
|
||||
*out = MwEerror;
|
||||
*out = 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
if(out != NULL) {
|
||||
*out = MwEsuccess;
|
||||
*out = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue