19#include <rdtk/config.h>
23#include <winpr/wlog.h>
24#include <winpr/assert.h>
25#include <winpr/cast.h>
31#define TAG "rdtk.sample"
33int main(
int argc,
char** argv)
41 rdtkSurface* surface = NULL;
46 Display* display = XOpenDisplay(NULL);
50 WLog_ERR(TAG,
"Cannot open display");
56 const UINT32 width = 640;
57 const UINT32 height = 480;
59 const int screen_number = DefaultScreen(display);
60 const Screen* screen = ScreenOfDisplay(display, screen_number);
61 Visual* visual = DefaultVisual(display, screen_number);
62 const GC gc = DefaultGC(display, screen_number);
63 const int depth = DefaultDepthOfScreen(screen);
64 const Window root_window = RootWindow(display, screen_number);
65 const unsigned long border = BlackPixel(display, screen_number);
66 const unsigned long background = WhitePixel(display, screen_number);
70 XPixmapFormatValues* pfs = XListPixmapFormats(display, &pf_count);
72 for (
int index = 0; index < pf_count; index++)
74 XPixmapFormatValues* pf = &pfs[index];
76 if (pf->depth == depth)
78 scanline_pad = pf->scanline_pad;
85 rdtkEngine* engine = rdtk_engine_new();
86 const size_t scanline = width * 4ULL;
87 uint8_t* buffer = (uint8_t*)calloc(height, scanline);
88 if (!engine || !buffer || (depth < 0))
91 surface = rdtk_surface_new(engine, buffer, width, height, scanline);
93 if (rdtk_surface_fill(surface, 0, 0, width, height, 0x3BB9FF) < 0)
95 if (rdtk_label_draw(surface, 16, 16, 128, 32, NULL,
"label", 0, 0) < 0)
97 if (rdtk_button_draw(surface, 16, 64, 128, 32, NULL,
"button") < 0)
99 if (rdtk_text_field_draw(surface, 16, 128, 128, 32, NULL,
"text field") < 0)
102 window = XCreateSimpleWindow(display, root_window, x, y, width, height, 1, border, background);
104 XSelectInput(display, window, ExposureMask | KeyPressMask);
105 XMapWindow(display, window);
107 XSetFunction(display, gc, GXcopy);
108 XSetFillStyle(display, gc, FillSolid);
110 pixmap = XCreatePixmap(display, window, width, height, (
unsigned)depth);
112 image = XCreateImage(display, visual, (
unsigned)depth, ZPixmap, 0, (
char*)buffer, width, height,
117 XNextEvent(display, &event);
119 if (event.type == Expose)
121 XPutImage(display, pixmap, gc, image, 0, 0, 0, 0, width, height);
122 XCopyArea(display, pixmap, window, gc, 0, 0, width, height, 0, 0);
125 if (event.type == KeyPress)
128 if (event.type == ClientMessage)
137 XDestroyImage(image);
138 XCloseDisplay(display);
140 rdtk_surface_free(surface);
143 rdtk_engine_free(engine);