Subversion Repositories Kolibri OS

Rev

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