19 #include <rdtk/config.h>
23 #include <winpr/wlog.h>
24 #include <winpr/assert.h>
25 #include <winpr/cast.h>
26 #include <rdtk/rdtk.h>
29 #include <X11/Xutil.h>
31 #define TAG "rdtk.sample"
33 int 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 rdtk_surface_fill(surface, 0, 0, width, height, 0x3BB9FF);
94 rdtk_label_draw(surface, 16, 16, 128, 32, NULL,
"label", 0, 0);
95 rdtk_button_draw(surface, 16, 64, 128, 32, NULL,
"button");
96 rdtk_text_field_draw(surface, 16, 128, 128, 32, NULL,
"text field");
98 window = XCreateSimpleWindow(display, root_window, x, y, width, height, 1, border, background);
100 XSelectInput(display, window, ExposureMask | KeyPressMask);
101 XMapWindow(display, window);
103 XSetFunction(display, gc, GXcopy);
104 XSetFillStyle(display, gc, FillSolid);
106 pixmap = XCreatePixmap(display, window, width, height, (
unsigned)depth);
108 image = XCreateImage(display, visual, (
unsigned)depth, ZPixmap, 0, (
char*)buffer, width, height,
113 XNextEvent(display, &event);
115 if (event.type == Expose)
117 XPutImage(display, pixmap, gc, image, 0, 0, 0, 0, width, height);
118 XCopyArea(display, pixmap, window, gc, 0, 0, width, height, 0, 0);
121 if (event.type == KeyPress)
124 if (event.type == ClientMessage)
133 XDestroyImage(image);
134 XCloseDisplay(display);
136 rdtk_surface_free(surface);
139 rdtk_engine_free(engine);