Skip to content

Instantly share code, notes, and snippets.

@ZakomakotheZBH
Last active April 10, 2026 21:30
Show Gist options
  • Select an option

  • Save ZakomakotheZBH/77719dd98df2dca2fb23212a553815fb to your computer and use it in GitHub Desktop.

Select an option

Save ZakomakotheZBH/77719dd98df2dca2fb23212a553815fb to your computer and use it in GitHub Desktop.
A library you can install in your c or c++ projects to make graphical or web interfaces
/* * ZTL_CORE.H - Zako Technology Labs Universal Library
* A single-file hybrid library for C Graphics and C++ Web/Zyntra
*/
#ifndef ZTL_CORE_H
#define ZTL_CORE_H
// --- SHARED DATA STRUCTURES ---
typedef struct {
unsigned char r, g, b, a;
} ZColor;
// ============================================================================
// C SECTION: GRAPHICS (Works in C and C++)
// ============================================================================
#ifdef __cplusplus
extern "C" {
#endif
// Initialize a virtual buffer (Width, Height)
void z_init_graphics(int w, int h);
// Core Drawing Functions
void z_draw_pixel(int x, int y, ZColor color);
void z_draw_rect(int x, int y, int w, int h, ZColor color);
void z_clear(ZColor color);
// Cleanup
void z_free_graphics();
#ifdef __cplusplus
}
#endif
// ============================================================================
// C++ SECTION: WEB & ZYNTRA BRIDGE (Only visible to C++ compilers)
// ============================================================================
#ifdef __cplusplus
#include <string>
#include <vector>
#include <sstream>
class ZyntraBridge {
public:
// Generates a basic HTML tag
std::string tag(std::string name, std::string content, std::string attr = "") {
return "<" + name + " " + attr + ">" + content + "</" + name + ">";
}
// Connects your C++ logic to your Zyntra/Zyria JS library
std::string inject_zyntra(std::string component_name, std::string data) {
std::stringstream ss;
ss << "<script>";
ss << "Zyntra.mount('" << component_name << "', { data: '" << data << "' });";
ss << "</script>";
return ss.str();
}
// Quick helper for ZewpolOS UI components
std::string create_window(std::string title, std::string body) {
return tag("div", tag("h2", title) + tag("p", body), "class='z-window'");
}
};
#endif
#endif // ZTL_CORE_H
// ============================================================================
// IMPLEMENTATION SECTION
// This part only compiles in ONE file where you #define ZTL_IMPLEMENTATION
// ============================================================================
#ifdef ZTL_IMPLEMENTATION
#include <stdio.h>
#include <stdlib.h>
// --- C GRAPHICS LOGIC ---
static ZColor* _z_buffer = NULL;
static int _z_width = 0;
static int _z_height = 0;
void z_init_graphics(int w, int h) {
_z_width = w;
_z_height = h;
_z_buffer = (ZColor*)malloc(w * h * sizeof(ZColor));
}
void z_draw_pixel(int x, int y, ZColor color) {
if (x >= 0 && x < _z_width && y >= 0 && y < _z_height) {
_z_buffer[y * _z_width + x] = color;
}
}
void z_draw_rect(int x, int y, int w, int h, ZColor color) {
for (int i = y; i < y + h; i++) {
for (int j = x; j < x + w; j++) {
z_draw_pixel(j, i, color);
}
}
}
void z_clear(ZColor color) {
for (int i = 0; i < _z_width * _z_height; i++) {
_z_buffer[i] = color;
}
}
void z_free_graphics() {
if (_z_buffer) free(_z_buffer);
}
#endif // ZTL_IMPLEMENTATION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment