libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xplayhead_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 "xplayhead_private.h"
23 
24 
25 void _create_playhead_image(Widget_t *w, int width, int height) {
26  w->image = cairo_surface_create_similar (w->surface,
27  CAIRO_CONTENT_COLOR_ALPHA, width, height*2);
28  cairo_t *cri = cairo_create (w->image);
30 
31  //cairo_rectangle(cri,0.0, 0.0, width, height*2);
32  //cairo_set_source_rgba (cri, c->bg[0], c->bg[1], c->bg[2], c->bg[3]);
33  //cairo_fill(cri);
34 
35  cairo_set_source_rgba (cri, c->shadow[0], c->shadow[1], c->shadow[2], c->shadow[3]);
36 
37  int h = height ;
38  int ci = h-2;
39 
40  int i = 1;
41  for(;i<width;) {
42  cairo_rectangle(cri,i,1,2,ci);
43  cairo_fill(cri);
44  i +=3;
45  }
46 
47  cairo_set_source_rgba (cri, c->text[0], c->text[1], c->text[2], c->text[3]);
48 
49  i = 1;
50  for(;i<width;) {
51  cairo_rectangle(cri,i,height+1,2,ci);
52  cairo_fill(cri);
53  i +=3;
54  }
55 
56  cairo_destroy(cri);
57 }
58 
59 void _draw_playhead(void *w_, void* user_data) {
60  Widget_t *w = (Widget_t*)w_;
61 
62  int width = cairo_xlib_surface_get_width(w->image);
63  int height = cairo_xlib_surface_get_height(w->image);
64  double state = adj_get_state(w->adj);
65  double clip = adj_get_state(w->adj_x);
66  double cut = adj_get_state(w->adj_y);
68  cairo_set_source_surface (w->crb, w->image, 0, 0);
69  cairo_rectangle(w->crb,0, 0, width, height/2);
70  cairo_fill(w->crb);
71  cairo_set_source_surface (w->crb, w->image, 0, -height/2);
72  cairo_rectangle(w->crb, width*state,0,3, height/2);
73  cairo_fill(w->crb);
74 
75  cairo_set_source_rgba (w->crb, 0.5, 0.0, 0.0, 0.4);
76  cairo_rectangle(w->crb, 0,0,width*clip, height/2);
77  cairo_fill(w->crb);
78 
79  cairo_rectangle(w->crb, width,0,(width*cut)-width, height/2);
80  cairo_fill(w->crb);
81 
83 }
Colors::text
double text[4]
Definition: xcolor.h:77
Widget_t::image
cairo_surface_t * image
Definition: xwidget.h:320
adj_get_state
float adj_get_state(Adjustment_t *adj)
adj_get_state - get the current state of the Adjustment_t
Definition: xadjustment.c:148
widget_set_scale
void widget_set_scale(Widget_t *w)
widget_set_scale - set scaling mode to scale a image surface to the size of the Widget_t surface
Definition: xwidget.c:141
Widget_t::crb
cairo_t * crb
Definition: xwidget.h:318
Widget_t::adj
Adjustment_t * adj
Definition: xwidget.h:334
_draw_playhead
void _draw_playhead(void *w_, void *user_data)
_draw_playhead - internal draw the playhead to the buffer
Definition: xplayhead_private.c:59
Widget_t::app
Xputty * app
Definition: xwidget.h:300
Colors
Color_t - struct used to set cairo color for Widget_t.
Definition: xcolor.h:73
_create_playhead_image
void _create_playhead_image(Widget_t *w, int width, int height)
_create_playhead_image - internal draw the playhead image to the cairo image surface
Definition: xplayhead_private.c:25
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
NORMAL_
@ NORMAL_
Definition: xcolor.h:39
widget_reset_scale
void widget_reset_scale(Widget_t *w)
widget_reset_scale - used to reset scaling mode after a image surface is drawn to the Widget_t surfac...
Definition: xwidget.c:137
Widget_t::surface
cairo_surface_t * surface
Definition: xwidget.h:312
Widget_t::adj_y
Adjustment_t * adj_y
Definition: xwidget.h:332
get_color_scheme
Colors * get_color_scheme(Xputty *main, Color_state st)
get_color_scheme - get pointer to the Colors struct to use in relation to the Color_state
Definition: xcolor.c:130
xplayhead_private.h
Widget_t::adj_x
Adjustment_t * adj_x
Definition: xwidget.h:330
Colors::shadow
double shadow[4]
Definition: xcolor.h:78