1 /* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <ui_sb_view.h>
6
7 #define WIDTH 14
8
9 typedef struct athena_sb_view {
10 ui_sb_view_t view;
11
12 int is_transparent;
13
14 } athena_sb_view_t;
15
16 /* --- static functions --- */
17
get_geometry_hints(ui_sb_view_t * view,unsigned int * width,unsigned int * top_margin,unsigned int * bottom_margin,int * up_button_y,unsigned int * up_button_height,int * down_button_y,unsigned int * down_button_height)18 static void get_geometry_hints(ui_sb_view_t *view, unsigned int *width, unsigned int *top_margin,
19 unsigned int *bottom_margin, int *up_button_y,
20 unsigned int *up_button_height, int *down_button_y,
21 unsigned int *down_button_height) {
22 *width = WIDTH;
23 *top_margin = 1;
24 *bottom_margin = 1;
25 *up_button_y = 0;
26 *up_button_height = 0;
27 *down_button_y = 0;
28 *down_button_height = 0;
29 }
30
get_default_color(ui_sb_view_t * view,char ** fg_color,char ** bg_color)31 static void get_default_color(ui_sb_view_t *view, char **fg_color, char **bg_color) {
32 *fg_color = "black";
33 *bg_color = "white";
34 }
35
realized(ui_sb_view_t * view,Display * display,int screen,Window window,GC gc,unsigned int height)36 static void realized(ui_sb_view_t *view, Display *display, int screen, Window window, GC gc,
37 unsigned int height) {
38 view->display = display;
39 view->screen = screen;
40 view->window = window;
41 view->gc = gc;
42 view->height = height;
43 }
44
resized(ui_sb_view_t * view,Window window,unsigned int height)45 static void resized(ui_sb_view_t *view, Window window, unsigned int height) {
46 view->window = window;
47 view->height = height;
48 }
49
destroy(ui_sb_view_t * view)50 static void destroy(ui_sb_view_t *view) {
51 free(view);
52 }
53
draw_scrollbar(ui_sb_view_t * view,int bar_top_y,unsigned int bar_height)54 static void draw_scrollbar(ui_sb_view_t *view, int bar_top_y, unsigned int bar_height) {
55 XPoint *points;
56 unsigned short x;
57 unsigned short y;
58 int i = 0;
59 int j;
60
61 /* clear */
62 XClearArea(view->display, view->window, 0, 0, WIDTH, view->height - 1, 0);
63
64 if ((points = malloc((WIDTH * view->height) * sizeof(XPoint))) == NULL) {
65 return;
66 }
67
68 /* bar */
69 j = 1;
70 for (y = bar_top_y; y < bar_top_y + bar_height; y++) {
71 for (x = j; x < WIDTH - 1; x += 2) {
72 points[i].x = x;
73 points[i].y = y;
74 i++;
75 }
76 j++;
77 if (j == 3) {
78 j = 1;
79 }
80 }
81 XDrawPoints(view->display, view->window, view->gc, points, i, CoordModeOrigin);
82
83 free(points);
84 }
85
86 /* --- global functions --- */
87
ui_athena_sb_view_new(void)88 ui_sb_view_t *ui_athena_sb_view_new(void) {
89 athena_sb_view_t *athena_sb;
90
91 if ((athena_sb = calloc(1, sizeof(athena_sb_view_t))) == NULL) {
92 return NULL;
93 }
94
95 athena_sb->view.version = 1;
96
97 athena_sb->view.get_geometry_hints = get_geometry_hints;
98 athena_sb->view.get_default_color = get_default_color;
99 athena_sb->view.realized = realized;
100 athena_sb->view.resized = resized;
101 athena_sb->view.destroy = destroy;
102
103 athena_sb->view.draw_scrollbar = draw_scrollbar;
104
105 return (ui_sb_view_t *)athena_sb;
106 }
107
ui_athena_transparent_sb_view_new(void)108 ui_sb_view_t *ui_athena_transparent_sb_view_new(void) {
109 athena_sb_view_t *athena_sb;
110
111 if ((athena_sb = calloc(1, sizeof(athena_sb_view_t))) == NULL) {
112 return NULL;
113 }
114
115 athena_sb->view.version = 1;
116
117 athena_sb->view.get_geometry_hints = get_geometry_hints;
118 athena_sb->view.get_default_color = get_default_color;
119 athena_sb->view.realized = realized;
120 athena_sb->view.resized = resized;
121 athena_sb->view.destroy = destroy;
122
123 athena_sb->view.draw_scrollbar = draw_scrollbar;
124
125 athena_sb->is_transparent = 1;
126
127 return (ui_sb_view_t *)athena_sb;
128 }
129