libxputty 0.1
Loading...
Searching...
No Matches
xtabbox_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 "xtabbox_private.h"
23
24
25void _rounded_box(cairo_t *cr,float x, float y, float w, float h, float lsize) {
26 cairo_new_path (cr);
27 float r = 10.0;
28 cairo_move_to(cr, x+lsize,y);
29 cairo_line_to(cr, x+w,y);
30 cairo_curve_to(cr, x+w,y,x+w,y,x+w,y);
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,y);
37}
38
39void _draw_tabbox(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 if (!metrics.visible) return;
46
47 int tabsize = 1;
48 int elem = w->childlist->elem;
49 if (elem) tabsize = width_t/elem;
50 int v = (int)adj_get_value(w->adj);
51
52 cairo_new_path (w->crb);
53 cairo_set_line_width(w->crb,1);
55 _rounded_box(w->crb, 1, 21, width_t-2, height_t-22, (v+1)*tabsize);
56 cairo_stroke(w->crb);
57
58 cairo_text_extents_t extents;
60 cairo_set_font_size (w->crb, w->app->normal_font/w->scale.ascale);
61 int i = 0;
62 int t = 0;
63 for(;i<elem;i++) {
64 Widget_t *wi = w->childlist->childs[i];
65 if(v == i) {
66 cairo_move_to (w->crb, t+1, 21);
67 cairo_line_to(w->crb, t+1, 1);
68 cairo_line_to(w->crb, t+tabsize-1, 1);
69 cairo_line_to(w->crb, t+tabsize-1, 21);
71 cairo_stroke(w->crb);
74 } else {
76 cairo_rectangle(w->crb, t+2, 1, tabsize-4, 20);
77 cairo_fill_preserve(w->crb);
79 cairo_stroke(w->crb);
81 widget_hide(wi);
82 }
83
84 cairo_text_extents(w->crb,"Äy" , &extents);
85 cairo_move_to (w->crb, 5+t, 2+extents.height);
86 cairo_show_text(w->crb, wi->label);
87 cairo_new_path (w->crb);
88 t += tabsize;
89 }
90}
91
92void _draw_tab(void *w_, void* user_data) {
93 Widget_t *w = (Widget_t*)w_;
94 Widget_t *p = (Widget_t*)w->parent;
95 _draw_tabbox(p, NULL);
96}
97
98void _tab_button_released(void *w_, void* button_, void* user_data) {
99 Widget_t *w = (Widget_t*)w_;
100 Metrics_t metrics;
101 os_get_window_metrics(w, &metrics);
102 int width_t = metrics.width;
103 if (w->flags & HAS_POINTER) {
104 XButtonEvent *xbutton = (XButtonEvent*)button_;
105 if (xbutton->y < 20) {
106 int tabsize = width_t;
107 int elem = w->childlist->elem;
108 if (elem) tabsize = width_t/elem;
109 adj_set_value(w->adj,(float)(xbutton->x/tabsize));
110 expose_widget(w);
111 }
112 }
113
114}
Widget_t ** childs
Definition xchildlist.h:51
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
Adjustment_t * adj
Definition xwidget.h:497
void * parent
Definition xwidget.h:471
cairo_t * crb
Definition xwidget.h:489
Childlist_t * childlist
Definition xwidget.h:499
long long flags
Definition xwidget.h:461
const char * label
Definition xwidget.h:463
Xputty * app
Definition xwidget.h:465
int normal_font
Definition xputty.h:248
void adj_set_value(Adjustment_t *adj, float value)
adj_set_value - set the current value to the Adjustment_t
float adj_get_value(Adjustment_t *adj)
adj_get_value - get the current value of the Adjustment_t
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
void use_bg_color_scheme(Widget_t *w, Color_state st)
use_bg_color_scheme - use background Colors to paint on Widget_t
Definition xcolor.c:252
@ NORMAL_
Definition xcolor.h:44
@ INSENSITIVE_
Definition xcolor.h:48
@ ACTIVE_
Definition xcolor.h:47
void _draw_tabbox(void *w_, void *user_data)
_draw_tabbox - draw the tabbox on expose call
void _rounded_box(cairo_t *cr, float x, float y, float w, float h, float lsize)
void _draw_tab(void *w_, void *user_data)
_draw_tab - draw a single tab on expose call
void _tab_button_released(void *w_, void *button_, void *user_data)
_tab_button_released - select the tab to show (hide all other)
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 expose_widget(Widget_t *w)
expose_widgets - send a expose event (EXPOSE) to a Widget_t
Definition xwidget.c:445
@ HAS_POINTER
Definition xwidget.h:402
void widget_show_all(Widget_t *w)
widget_show_all - map/show Widget_t with all childs
Definition xwidget.c:386
void widget_hide(Widget_t *w)
widget_hide - unmap/hide a Widget_t
Definition xwidget.c:368