Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3621 sourcerer 1
/*
2
 * Copyright 2013 SoUrcerer sourcerer@bk.ru
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
#include 
10
#include 
11
 
12
#include "libnsfb.h"
13
#include "libnsfb_event.h"
14
#include "libnsfb_plot.h"
15
#include "libnsfb_plot_util.h"
16
 
17
#include "nsfb.h"
18
#include "surface.h"
19
#include "palette.h"
20
#include "plot.h"
21
#include "cursor.h"
22
 
23
 
24
#include 
25
 
26
 
27
 
28
unsigned char * pixels;
29
 
30
 inline void f65(unsigned x, unsigned y, unsigned w, unsigned h, char *d)
31
{
32
asm("pusha");
33
asm ("nop"::"D"(0), "c"(w*65536+h), "d"(x*65536+y), "b"(d));
34
asm ("xor %eax, %eax");
35
asm ("movl %eax, %ebp");
36
asm ("pushl $32");
37
asm ("popl %esi");
38
asm ("int $0x40"::"a"(65));
39
asm("popa");
40
}
41
 
42
 
43
void kolibri_redraw(nsfb_t *nsfb){
44
 
45
 __menuet__window_redraw(1);
46
 __menuet__define_window(100,100,nsfb->width,nsfb->height,0x43000080,0x800000FF,0x000080);
47
 __menuet__write_text(3,3,0xFFFFFF,"Netsurf",7);
48
__menuet__debug_out("f65 is mighty!\n");
49
 
50
//here put image pixels! it's 32bpp
51
 f65(0,0, nsfb->width, nsfb->height, pixels);
52
 __menuet__window_redraw(2);
53
}
54
 
55
 
56
static bool
57
kolibricopy(nsfb_t *nsfb, nsfb_bbox_t *srcbox, nsfb_bbox_t *dstbox)
58
{
59
 
60
    char *pixels = nsfb->surface_priv;
61
    nsfb_bbox_t allbox;
62
    struct nsfb_cursor_s *cursor = nsfb->cursor;
63
 
64
    nsfb_plot_add_rect(srcbox, dstbox, &allbox);
65
 
66
	int x,y,w,h;
67
    x = srcbox->x0;
68
    y = srcbox->y0;
69
    w = srcbox->x1 - srcbox->x0;
70
    h = srcbox->y1 - srcbox->y0;
71
 
72
    int tx, ty, tw, th;
73
 
74
    tx = dstbox->x0;
75
    ty = dstbox->y0;
76
    tw = dstbox->x1 - dstbox->x0;
77
    th = dstbox->y1 - dstbox->y0;
78
 
79
    char pst[255];
80
    sprintf (pst, "Src %d,%d %dx%d Dst %d,%d %dx%d \n", x,y,w,h,tx,ty,tw,th);
81
    __menuet__debug_out(pst);
82
 
83
    int px, py, pp;
84
 
85
 
86
 
87
    for (px=x; px
88
		for (py=y;py
89
			for (pp=0; pp<4; pp++) {
90
 
91
				pixels[4*(px+tx)*nsfb->width+4*(py+ty)+pp]=pixels[4*px*nsfb->width+4*py+pp];
92
 
93
 
94
			}
95
 
96
 
97
 
98
 
99
	kolibri_redraw(nsfb);
100
 
101
    return true;
102
 
103
}
104
 
105
static int kolibri_set_geometry(nsfb_t *nsfb, int width, int height,
106
        enum nsfb_format_e format)
107
{
108
    if (nsfb->surface_priv != NULL)
109
        return -1; /* fail if surface already initialised */
110
 
111
    nsfb->width = width;
112
    nsfb->height = height;
113
    nsfb->format = format;
114
 
115
	pixels=(char *)malloc(width*height*4);
116
 
117
    /* select default sw plotters for format */
118
    select_plotters(nsfb);
119
 
120
    //nsfb->plotter_fns->copy = kolibricopy;
121
 
122
    return 0;
123
}
124
unsigned pz, pb;
125
 
126
static int kolibri_initialise(nsfb_t *nsfb)
127
{
128
    enum nsfb_format_e fmt;
129
 
130
pz=0;
131
pb=0;
132
 
133
__menuet__debug_out("Start UI\n");
134
 
135
    if (nsfb->surface_priv != NULL)
136
        return -1;
137
 
138
    /* sanity checked depth. */
139
    if ((nsfb->bpp != 32) ) {
140
 
141
		__menuet__debug_out("Wrong bpp\n");
142
        return -1; }
143
 
144
 
145
	        fmt = NSFB_FMT_XRGB8888;
146
 
147
    /* If we didn't get what we asked for, reselect plotters */
148
    if (nsfb->format != fmt) {
149
        nsfb->format = fmt;
150
 
151
        if (kolibri_set_geometry(nsfb, nsfb->width, nsfb->height,
152
                nsfb->format) != 0) {
153
 
154
					__menuet__debug_out("can't set geometry\n");
155
            return -1;
156
        }
157
    }
158
 
159
    nsfb->surface_priv = pixels;
160
 
161
    nsfb->ptr = pixels;
162
    nsfb->linelen = (nsfb->width * nsfb->bpp) / 8;
163
 
164
    __menuet__debug_out("Redraw\n");
165
    kolibri_redraw(nsfb);
166
 
167
    __menuet__set_bitfield_for_wanted_events(EVENT_REDRAW|EVENT_KEY|EVENT_BUTTON|EVENT_MOUSE_CHANGE);
168
 
169
    return 0;
170
}
171
 
172
 
173
 
174
static int kolibri_finalise(nsfb_t *nsfb)
175
{
176
    nsfb=nsfb;
177
    __menuet__sys_exit();
178
    return 0;
179
}
180
 
181
 
182
unsigned kol_mouse_posw()
183
{
184
unsigned error;
185
asm volatile ("int $0x40":"=a"(error):"a"(37), "b"(1));
186
return error;
187
}
188
 
189
 
190
unsigned kol_mouse_btn()
191
{
192
unsigned error;
193
asm volatile ("int $0x40":"=a"(error):"a"(37), "b"(2));
194
return error;
195
}
196
 
197
 
198
 
199
static bool kolibri_input(nsfb_t *nsfb, nsfb_event_t *event, int timeout)
200
{
201
    int got_event;
202
 
203
 
204
    nsfb = nsfb; /* unused */
205
 
206
       got_event = __menuet__check_for_event();
207
 
208
    if (got_event == 0) {
209
        return false;
210
    }
211
 
212
    event->type = NSFB_EVENT_NONE;
213
 
214
	 if (got_event==1) { //key pressed
215
    kolibri_redraw(nsfb);
216
 
217
	}
218
 
219
    if (got_event==2) { //key pressed
220
    event->type = NSFB_EVENT_KEY_UP;
221
	event->value.keycode = __menuet__getkey();
222
	return true;
223
	}
224
 
225
	if (got_event==3) { //key pressed
226
    if (__menuet__get_button_id()==1) kolibri_finalise(nsfb);
227
	return true;
228
	}
229
 
230
	if (got_event==6) { //key pressed
231
	unsigned z=kol_mouse_posw();
232
	unsigned b=kol_mouse_btn();
233
 
234
 
235
		if (pz!=z) {
236
			event->type = NSFB_EVENT_MOVE_ABSOLUTE;
237
			event->value.vector.x = (z&0xffff0000)>>16; //sdlevent.motion.x;
238
			event->value.vector.y = z&0xffff; //sdlevent.motion.y;
239
			event->value.vector.z = 0;
240
			pz=z;
241
			return true;
242
		}
243
 
244
 
245
		if (pb!=b) {
246
			unsigned t=b&1;
247
			if (t==0) {
248
				event->type = NSFB_EVENT_KEY_UP;
249
			    event->value.keycode = NSFB_KEY_MOUSE_1;
250
			} else {
251
				event->type = NSFB_EVENT_KEY_DOWN;
252
			    event->value.keycode = NSFB_KEY_MOUSE_1;
253
			}
254
			pb=b;
255
			return true;
256
		}
257
 
258
	}
259
 
260
    /*
261
 
262
    case SDL_MOUSEBUTTONDOWN:
263
	event->type = NSFB_EVENT_KEY_DOWN;
264
 
265
	switch (sdlevent.button.button) {
266
 
267
	case SDL_BUTTON_LEFT:
268
	    event->value.keycode = NSFB_KEY_MOUSE_1;
269
	    break;
270
 
271
	case SDL_BUTTON_MIDDLE:
272
	    event->value.keycode = NSFB_KEY_MOUSE_2;
273
	    break;
274
 
275
	case SDL_BUTTON_RIGHT:
276
	    event->value.keycode = NSFB_KEY_MOUSE_3;
277
	    break;
278
 
279
	}
280
	break;
281
 
282
    case SDL_MOUSEBUTTONUP:
283
	event->type = NSFB_EVENT_KEY_UP;
284
 
285
	switch (sdlevent.button.button) {
286
 
287
	case SDL_BUTTON_LEFT:
288
	    event->value.keycode = NSFB_KEY_MOUSE_1;
289
	    break;
290
 
291
	case SDL_BUTTON_MIDDLE:
292
	    event->value.keycode = NSFB_KEY_MOUSE_2;
293
	    break;
294
 
295
	case SDL_BUTTON_RIGHT:
296
	    event->value.keycode = NSFB_KEY_MOUSE_3;
297
	    break;
298
 
299
	}
300
	break;
301
 
302
    case SDL_MOUSEMOTION:
303
	event->type = NSFB_EVENT_MOVE_ABSOLUTE;
304
	event->value.vector.x = sdlevent.motion.x;
305
	event->value.vector.y = sdlevent.motion.y;
306
	event->value.vector.z = 0;
307
	break;
308
 
309
    case SDL_QUIT:
310
	event->type = NSFB_EVENT_CONTROL;
311
	event->value.controlcode = NSFB_CONTROL_QUIT;
312
	break;
313
 
314
    case SDL_USEREVENT:
315
	event->type = NSFB_EVENT_CONTROL;
316
	event->value.controlcode = NSFB_CONTROL_TIMEOUT;
317
	break;
318
 
319
    }
320
	*/
321
    return true;
322
}
323
 
324
 
325
static int kolibri_claim(nsfb_t *nsfb, nsfb_bbox_t *box)
326
{
327
	/*
328
    if ((cursor != NULL) &&
329
        (cursor->plotted == true) &&
330
        (nsfb_plot_bbox_intersect(box, &cursor->loc))) {
331
        nsfb_cursor_clear(nsfb, cursor);
332
    } */
333
	return 0; //stub yet
334
}
335
 
336
static int kolibri_cursor(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
337
{
338
	return true; //stub yet
339
}
340
 
341
 
342
 
343
static int kolibri_update(nsfb_t *nsfb, nsfb_bbox_t *box)
344
{
345
    /*SDL_Surface *sdl_screen = nsfb->surface_priv;
346
    struct nsfb_cursor_s *cursor = nsfb->cursor;
347
 
348
    if ((cursor != NULL) &&
349
	(cursor->plotted == false)) {
350
        nsfb_cursor_plot(nsfb, cursor);
351
    }
352
 
353
    SDL_UpdateRect(sdl_screen,
354
                   box->x0,
355
                   box->y0,
356
                   box->x1 - box->x0,
357
                   box->y1 - box->y0);
358
  */
359
 
360
  //Ask for window redraw here!
361
 
362
	kolibri_redraw(nsfb);
363
    return 0;
364
}
365
 
366
const nsfb_surface_rtns_t kolibri_rtns = {
367
    .initialise = kolibri_initialise,
368
    .finalise = kolibri_finalise,
369
    .input = kolibri_input,
370
    .claim = kolibri_claim,
371
    .update = kolibri_update,
372
    .cursor = kolibri_cursor,
373
    .geometry = kolibri_set_geometry,
374
};
375
 
376
NSFB_SURFACE_DEF(kolibri, NSFB_SURFACE_KOLIBRI, &kolibri_rtns)
377
 
378
/*
379
 * Local variables:
380
 *  c-basic-offset: 4
381
 *  tab-width: 8
382
 * End:
383
 */