graphics.c (2071B)
1 /* 2 * Copyright (c) 2021 lumidify <nobody@lumidify.org> 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #include <X11/Xlib.h> 18 #include <X11/Xutil.h> 19 #include <stdint.h> 20 21 #include "color.h" 22 #include "rect.h" 23 #include "widget.h" 24 #include "ltk.h" 25 26 void 27 ltk_fill_widget_rect(ltk_widget *widget, ltk_color *color, ltk_rect rect) { 28 ltk_window *win = widget->window; 29 XSetForeground(win->dpy, win->gc, color->xcolor.pixel); 30 XFillRectangle(win->dpy, widget->pixmap, win->gc, rect.x, rect.y, rect.w, rect.h); 31 } 32 33 void 34 ltk_draw_widget_rect(ltk_widget *widget, ltk_color *color, ltk_rect rect, int border_width) { 35 ltk_window *win = widget->window; 36 if (border_width <= 0) 37 return; 38 XSetForeground(win->dpy, win->gc, color->xcolor.pixel); 39 XSetLineAttributes(win->dpy, win->gc, border_width, LineSolid, CapButt, JoinMiter); 40 XDrawRectangle( 41 win->dpy, widget->pixmap, win->gc, 42 border_width / 2, border_width / 2, 43 rect.w - border_width, rect.h - border_width 44 ); 45 } 46 47 void 48 ltk_copy_clipped(ltk_widget *widget, ltk_rect clip) { 49 ltk_window *win = widget->window; 50 ltk_rect clip_final = ltk_rect_intersect(clip, widget->rect); 51 if (clip_final.w <= 0 || clip_final.h <= 0) 52 return; 53 XCopyArea( 54 win->dpy, widget->pixmap, win->drawable, win->gc, 55 clip_final.x - widget->rect.x, clip_final.y - widget->rect.y, 56 clip_final.w, clip_final.h, clip_final.x, clip_final.y 57 ); 58 }