libxputty 0.1
Loading...
Searching...
No Matches
xframe_private.c
Go to the documentation of this file.
1/*
2 * 0BSD
3 *
4 * BSD Zero Clause License
5 *
6 * Copyright (c) 2019 Hermann Meyer
7 *
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted.
10
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 *
19 */
20
21
22#include "xframe_private.h"
23
24
25void _rounded_frame(cairo_t *cr,float x, float y, float w, float h, float lsize) {
26 cairo_new_path (cr);
27 float r = 20.0;
28 cairo_move_to(cr, x+lsize+r,y);
29 cairo_line_to(cr, x+w-r,y);
30 cairo_curve_to(cr, x+w,y,x+w,y,x+w,y+r);
31 cairo_line_to(cr, x+w,y+h-r);
32 cairo_curve_to(cr, x+w,y+h,x+w,y+h,x+w-r,y+h);
33 cairo_line_to(cr, x+r,y+h);
34 cairo_curve_to(cr, x,y+h,x,y+h,x,y+h-r);
35 cairo_line_to(cr, x,y+r);
36 cairo_curve_to(cr, x,y,x,y,x+r,y);
37}
38
39void _draw_frame(void *w_, void* user_data) {
40 Widget_t *w = (Widget_t*)w_;
41 Metrics_t metrics;
42 os_get_window_metrics(w, &metrics);
43 int width_t = metrics.width;
44 int height_t = metrics.height;
45
46 if (w->image) {
47 int width, height;
48 os_get_surface_size(w->image, &width, &height);
49 double x = (double)width_t/(double)(width);
50 double y = (double)height_t/(double)height;
51 double x1 = (double)(width)/(double)width_t;
52 double y1 = (double)height/(double)height_t;
53 cairo_scale(w->crb, x,y);
54 cairo_set_source_surface (w->crb, w->image, 0, 0);
55 _rounded_frame(w->crb, 5/x, 5/y, (width_t-10)/x, (height_t-10)/y, 0);
56 cairo_close_path (w->crb);
57 cairo_fill (w->crb);
58 cairo_scale(w->crb, x1,y1);
59 }
60
61 cairo_text_extents_t extents;
63 cairo_set_font_size (w->crb, w->app->normal_font/w->scale.ascale);
64 cairo_text_extents(w->crb,w->label , &extents);
65 cairo_move_to (w->crb, 30, extents.height);
66 cairo_show_text(w->crb, w->label);
67 cairo_new_path (w->crb);
68
69 cairo_set_line_width(w->crb,3);
71 _rounded_frame(w->crb, 5, 5, width_t-10, height_t-10, extents.width+10);
72 cairo_stroke(w->crb);
73}
Metrics_t - struct to receive window size, position & visibility Pass this struct to os_get_window_...
float ascale
Definition xwidget.h:369
Widget_t - struct to hold the basic Widget_t info.
Definition xwidget.h:457
Resize_t scale
Definition xwidget.h:525
cairo_surface_t * image
Definition xwidget.h:491
cairo_t * crb
Definition xwidget.h:489
const char * label
Definition xwidget.h:463
Xputty * app
Definition xwidget.h:465
int normal_font
Definition xputty.h:248
void use_frame_color_scheme(Widget_t *w, Color_state st)
use_frame_color_scheme - use frame Colors to paint on Widget_t
Definition xcolor.c:280
Color_state get_color_state(Widget_t *wid)
get_color_state - get the Color_state to use in relation to the Widget_t state
Definition xcolor.c:222
void use_text_color_scheme(Widget_t *w, Color_state st)
use_text_color_scheme - use text Colors to paint on Widget_t
Definition xcolor.c:266
@ INSENSITIVE_
Definition xcolor.h:48
void _draw_frame(void *w_, void *user_data)
_draw_frame - internal draw the frame to the buffer
void _rounded_frame(cairo_t *cr, float x, float y, float w, float h, float lsize)
void os_get_window_metrics(Widget_t *w, Metrics_t *metrics)
os_get_window_metrics - Get the Merics_t struct related to a Widget_t
void os_get_surface_size(cairo_surface_t *surface, int *width, int *height)
os_get_surface_size - get the size of the cairo surface