19 #include <rdtk/config.h>
23 #include <winpr/wlog.h>
24 #include <rdtk/rdtk.h>
27 #include <X11/Xutil.h>
29 #define TAG "rdtk.sample"
31 int main(
int argc,
char** argv)
40 uint8_t* buffer = NULL;
46 Screen* screen = NULL;
47 Visual* visual = NULL;
49 int screen_number = 0;
50 Display* display = NULL;
52 Window root_window = 0;
53 rdtkEngine* engine = NULL;
54 rdtkSurface* surface = NULL;
55 unsigned long border = 0;
56 unsigned long background = 0;
57 XPixmapFormatValues* pf = NULL;
58 XPixmapFormatValues* pfs = NULL;
63 display = XOpenDisplay(NULL);
67 WLog_ERR(TAG,
"Cannot open display");
76 screen_number = DefaultScreen(display);
77 screen = ScreenOfDisplay(display, screen_number);
78 visual = DefaultVisual(display, screen_number);
79 gc = DefaultGC(display, screen_number);
80 depth = DefaultDepthOfScreen(screen);
81 root_window = RootWindow(display, screen_number);
82 border = BlackPixel(display, screen_number);
83 background = WhitePixel(display, screen_number);
87 pfs = XListPixmapFormats(display, &pf_count);
89 for (
int index = 0; index < pf_count; index++)
93 if (pf->depth == depth)
95 scanline_pad = pf->scanline_pad;
102 engine = rdtk_engine_new();
106 scanline = width * 4;
107 buffer = (uint8_t*)calloc(height, scanline);
111 surface = rdtk_surface_new(engine, buffer, width, height, scanline);
113 rdtk_surface_fill(surface, 0, 0, width, height, 0x3BB9FF);
114 rdtk_label_draw(surface, 16, 16, 128, 32, NULL,
"label", 0, 0);
115 rdtk_button_draw(surface, 16, 64, 128, 32, NULL,
"button");
116 rdtk_text_field_draw(surface, 16, 128, 128, 32, NULL,
"text field");
118 window = XCreateSimpleWindow(display, root_window, x, y, width, height, 1, border, background);
120 XSelectInput(display, window, ExposureMask | KeyPressMask);
121 XMapWindow(display, window);
123 XSetFunction(display, gc, GXcopy);
124 XSetFillStyle(display, gc, FillSolid);
126 pixmap = XCreatePixmap(display, window, width, height, depth);
128 image = XCreateImage(display, visual, depth, ZPixmap, 0, (
char*)buffer, width, height,
133 XNextEvent(display, &event);
135 if (event.type == Expose)
137 XPutImage(display, pixmap, gc, image, 0, 0, 0, 0, width, height);
138 XCopyArea(display, pixmap, window, gc, 0, 0, width, height, 0, 0);
141 if (event.type == KeyPress)
144 if (event.type == ClientMessage)
153 XDestroyImage(image);
154 XCloseDisplay(display);
156 rdtk_surface_free(surface);
159 rdtk_engine_free(engine);