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 "xwaveview_private.h"
23
24
_rounded_view(cairo_t * cr,float x,float y,float w,float h,float lsize)25 void _rounded_view(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
_draw_waveview(void * w_,void * user_data)39 void _draw_waveview(void *w_, void* user_data) {
40 Widget_t *w = (Widget_t*)w_;
41 WaveView_t *wave_view = (WaveView_t*)w->private_struct;
42 XWindowAttributes attrs;
43 XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
44 int width_t = attrs.width;
45 int height_t = attrs.height;
46 int half_height_t = height_t/2;
47
48 cairo_text_extents_t extents;
49 cairo_set_font_size (w->crb, w->app->normal_font/w->scale.ascale);
50 cairo_text_extents(w->crb,w->label , &extents);
51
52 cairo_set_line_width(w->crb,2);
53 use_bg_color_scheme(w, NORMAL_);
54 _rounded_view(w->crb, 2, 5, width_t-4, height_t-7, extents.width+15);
55 cairo_fill_preserve(w->crb);
56 use_frame_color_scheme(w, NORMAL_);
57 cairo_stroke(w->crb);
58 cairo_move_to(w->crb,2,half_height_t);
59 cairo_line_to(w->crb, width_t-4, half_height_t);
60 cairo_stroke(w->crb);
61
62 use_text_color_scheme(w, get_color_state(w));
63 cairo_move_to (w->crb, 30, extents.height);
64 cairo_show_text(w->crb, w->label);
65 cairo_new_path (w->crb);
66
67 if (wave_view->size<1) return;
68 float step = (float)(width_t-10)/(float)wave_view->size+1;
69 float lstep = (float)(half_height_t-10.0);
70 cairo_set_line_width(w->cr,2);
71 use_fg_color_scheme(w, NORMAL_);
72 int i = 0;
73 for (;i<wave_view->size;i++) {
74 cairo_line_to(w->crb, (float)(i+0.5)*step,(float)(half_height_t)+ -wave_view->wave[i]*lstep);
75 }
76 cairo_line_to(w->crb, width_t, half_height_t);
77 cairo_line_to(w->crb, 2, half_height_t);
78 cairo_close_path(w->crb);
79 use_light_color_scheme(w, NORMAL_);
80 cairo_fill_preserve(w->crb);
81 use_fg_color_scheme(w, NORMAL_);
82 cairo_stroke(w->crb);
83 i = 0;
84 for (;i<wave_view->size;i++) {
85 cairo_line_to(w->crb, (float)(i+0.5)*step,(float)(half_height_t)+ wave_view->wave[i]*lstep);
86 }
87 cairo_line_to(w->crb, width_t, half_height_t);
88 cairo_line_to(w->crb, 2, half_height_t);
89 cairo_close_path(w->crb);
90 use_light_color_scheme(w, NORMAL_);
91 cairo_fill_preserve(w->crb);
92 use_fg_color_scheme(w, NORMAL_);
93 cairo_stroke(w->crb);
94 }
95