Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3584 | sourcerer | 1 | /* |
2 | * Copyright 2010 Vincent Sanders |
||
3 | * |
||
4 | * This file is part of libnsfb, http://www.netsurf-browser.org/ |
||
5 | * Licenced under the MIT License, |
||
6 | * http://www.opensource.org/licenses/mit-license.php |
||
7 | */ |
||
8 | |||
9 | /** \file |
||
10 | * cursor (implementation). |
||
11 | */ |
||
12 | |||
13 | #include |
||
14 | #include |
||
15 | |||
16 | #include "libnsfb.h" |
||
17 | #include "libnsfb_plot.h" |
||
18 | #include "libnsfb_cursor.h" |
||
19 | |||
20 | #include "nsfb.h" |
||
21 | #include "cursor.h" |
||
22 | #include "plot.h" |
||
23 | #include "surface.h" |
||
24 | |||
25 | bool nsfb_cursor_init(nsfb_t *nsfb) |
||
26 | { |
||
27 | if (nsfb->cursor != NULL) |
||
28 | return false; |
||
29 | |||
30 | nsfb->cursor = calloc(1, sizeof(struct nsfb_cursor_s)); |
||
31 | if (nsfb->cursor == NULL) |
||
32 | return false; |
||
33 | |||
34 | nsfb->cursor->loc.x0 = nsfb->width / 2; |
||
35 | nsfb->cursor->loc.y0 = nsfb->height / 2; |
||
36 | return true; |
||
37 | } |
||
38 | |||
39 | bool nsfb_cursor_set(nsfb_t *nsfb, const nsfb_colour_t *pixel, |
||
40 | int bmp_width, int bmp_height, int bmp_stride, |
||
41 | int hotspot_x, int hotspot_y) |
||
42 | { |
||
43 | if (nsfb->cursor == NULL) |
||
44 | return false; |
||
45 | |||
46 | nsfb->cursor->pixel = pixel; |
||
47 | nsfb->cursor->bmp_width = bmp_width; |
||
48 | nsfb->cursor->bmp_height = bmp_height; |
||
49 | nsfb->cursor->bmp_stride = bmp_stride; |
||
50 | nsfb->cursor->loc.x1 = nsfb->cursor->loc.x0 + nsfb->cursor->bmp_width; |
||
51 | nsfb->cursor->loc.y1 = nsfb->cursor->loc.y0 + nsfb->cursor->bmp_height; |
||
52 | |||
53 | nsfb->cursor->hotspot_x = hotspot_x; |
||
54 | nsfb->cursor->hotspot_y = hotspot_y; |
||
55 | |||
56 | return nsfb->surface_rtns->cursor(nsfb, nsfb->cursor); |
||
57 | } |
||
58 | |||
59 | bool nsfb_cursor_loc_set(nsfb_t *nsfb, const nsfb_bbox_t *loc) |
||
60 | { |
||
61 | if (nsfb->cursor == NULL) |
||
62 | return false; |
||
63 | |||
64 | nsfb->cursor->loc = *loc; |
||
65 | nsfb->cursor->loc.x1 = nsfb->cursor->loc.x0 + nsfb->cursor->bmp_width; |
||
66 | nsfb->cursor->loc.y1 = nsfb->cursor->loc.y0 + nsfb->cursor->bmp_height; |
||
67 | |||
68 | return nsfb->surface_rtns->cursor(nsfb, nsfb->cursor); |
||
69 | } |
||
70 | |||
71 | bool nsfb_cursor_loc_get(nsfb_t *nsfb, nsfb_bbox_t *loc) |
||
72 | { |
||
73 | if (nsfb->cursor == NULL) |
||
74 | return false; |
||
75 | |||
76 | *loc = nsfb->cursor->loc; |
||
77 | return true; |
||
78 | } |
||
79 | |||
80 | /* documented in cursor.h */ |
||
81 | bool nsfb_cursor_plot(nsfb_t *nsfb, struct nsfb_cursor_s *cursor) |
||
82 | { |
||
83 | int sav_size; |
||
84 | nsfb_bbox_t sclip; /* saved clipping area */ |
||
85 | |||
86 | nsfb->plotter_fns->get_clip(nsfb, &sclip); |
||
87 | nsfb->plotter_fns->set_clip(nsfb, NULL); |
||
88 | |||
89 | /* offset cursor rect for hotspot */ |
||
90 | cursor->loc.x0 -= cursor->hotspot_x; |
||
91 | cursor->loc.y0 -= cursor->hotspot_y; |
||
92 | cursor->loc.x1 -= cursor->hotspot_x; |
||
93 | cursor->loc.y1 -= cursor->hotspot_y; |
||
94 | |||
95 | cursor->savloc = cursor->loc; |
||
96 | |||
97 | cursor->sav_width = cursor->savloc.x1 - cursor->savloc.x0; |
||
98 | cursor->sav_height = cursor->savloc.y1 - cursor->savloc.y0; |
||
99 | |||
100 | sav_size = cursor->sav_width * cursor->sav_height * sizeof(nsfb_colour_t); |
||
101 | if (cursor->sav_size < sav_size) { |
||
102 | cursor->sav = realloc(cursor->sav, sav_size); |
||
103 | cursor->sav_size = sav_size; |
||
104 | } |
||
105 | |||
106 | nsfb->plotter_fns->readrect(nsfb, &cursor->savloc, cursor->sav); |
||
107 | cursor->sav_width = cursor->savloc.x1 - cursor->savloc.x0; |
||
108 | cursor->sav_height = cursor->savloc.y1 - cursor->savloc.y0; |
||
109 | |||
110 | nsfb->plotter_fns->set_clip(nsfb, NULL); |
||
111 | nsfb->plotter_fns->bitmap(nsfb, |
||
112 | &cursor->loc, |
||
113 | cursor->pixel, |
||
114 | cursor->bmp_width, |
||
115 | cursor->bmp_height, |
||
116 | cursor->bmp_stride, |
||
117 | true); |
||
118 | |||
119 | /* undo hotspot offset */ |
||
120 | cursor->loc.x0 += cursor->hotspot_x; |
||
121 | cursor->loc.y0 += cursor->hotspot_y; |
||
122 | cursor->loc.x1 += cursor->hotspot_x; |
||
123 | cursor->loc.y1 += cursor->hotspot_y; |
||
124 | |||
125 | nsfb->plotter_fns->set_clip(nsfb, &sclip); |
||
126 | |||
127 | cursor->plotted = true; |
||
128 | |||
129 | return true; |
||
130 | } |
||
131 | |||
132 | bool nsfb_cursor_clear(nsfb_t *nsfb, struct nsfb_cursor_s *cursor) |
||
133 | { |
||
134 | nsfb_bbox_t sclip; /* saved clipping area */ |
||
135 | |||
136 | nsfb->plotter_fns->get_clip(nsfb, &sclip); |
||
137 | nsfb->plotter_fns->set_clip(nsfb, NULL); |
||
138 | |||
139 | nsfb->plotter_fns->bitmap(nsfb, |
||
140 | &cursor->savloc, |
||
141 | cursor->sav, |
||
142 | cursor->sav_width, |
||
143 | cursor->sav_height, |
||
144 | cursor->sav_width, |
||
145 | false); |
||
146 | |||
147 | nsfb->plotter_fns->set_clip(nsfb, &sclip); |
||
148 | |||
149 | cursor->plotted = false; |
||
150 | return true; |
||
151 | |||
152 | }> |