Skip to content

Commit

Permalink
intial move logic, client area repaint works
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomaz Stih committed Aug 8, 2015
1 parent 7b6c97e commit bc5701a
Show file tree
Hide file tree
Showing 16 changed files with 398 additions and 112 deletions.
141 changes: 112 additions & 29 deletions buddy/buddy.c
Expand Up @@ -12,6 +12,9 @@
#include "mouse.h"
#include "stdwnd.h"

extern yx_t *yx;

buddy_op_t buddy_op;

void temp_shit() {
static window_t *w1, *w2, *w3, *w4, *w5, *w6, *w7, *w8;
Expand Down Expand Up @@ -101,6 +104,9 @@ void buddy_init() {

temp_shit();

/* buddy vars */
buddy_op.op = BUDDY_OP_NONE;

/* draw desktop */
window_draw(window_desktop);

Expand All @@ -117,6 +123,10 @@ void buddy_harvest_events() {
mouse_scan(&mi);
if (mouse_rect.x0!=mi.x || mouse_rect.y0!=mi.y) { /* coord changed */

/* operation in progress? */
if (buddy_op.op==BUDDY_OP_MOVING)
buddy_xor_op_rect(); /* del old rect */

/* first repaint mouse */
mouse_hide_cursor();
mouse_show_cursor(mi.x, mi.y, current_cursor);
Expand All @@ -141,41 +151,114 @@ void buddy_harvest_events() {
}

void buddy_dispatch(byte id, word param1, word param2) {

window_t *w;

window_t *affectedwnd, *appwnd;
boolean lr,ud;
byte dx,dy;
byte hit=WND_HIT_NONE;

switch (id) {
case MSG_MOUSE_LUP:
if (w=buddy_get_window_xy(
window_desktop,
(byte)param1,
(byte)param2)) {

if (w!=window_desktop && w!=window_desktop->first_child) {
window_select(w);
window_draw(w);

case MSG_MOUSE_LDOWN:
/* find affected window */
affectedwnd=window_find_xy(window_desktop,(byte)param1,(byte)param2);

if (affectedwnd==window_desktop) { /* desktop i.e. root */
message_post(window_desktop,id,param1,param2);
} else { /* not desktop */

/* if child window of non active desktop window then
activate first */
if ((appwnd=window_get_app_wnd(affectedwnd))!=window_desktop->first_child) {
window_select(appwnd); /* bring to front */
window_draw(appwnd);
}

/* hit test window for system areas? */
message_send(affectedwnd,MSG_WND_HITTEST,(word)&hit,0);

/* store mouse to current operation (whatever) */
buddy_op.mx=(byte)param1;
buddy_op.my=(byte)param2;

switch(hit) {
case WND_HIT_NONE: /* just forward message */
message_post(affectedwnd,id,param1,param2);
break;
case WND_HIT_TITLE: /* start window drag operation */
buddy_op.op=BUDDY_OP_MOVE;
buddy_op.wnd=appwnd;
buddy_op.ix=buddy_op.mx;
buddy_op.iy=buddy_op.my;
yx->copy(
(void*)affectedwnd->graphics->area,
(void*)&(buddy_op.rect),
sizeof(rect_t)
);
break;
}
message_post(w,id,param1,param2);
}
break;
}
}
break;

case MSG_MOUSE_LUP:
if (buddy_op.op==BUDDY_OP_MOVING) { /* the end of the draw event */

window_t *buddy_get_window_xy(window_t* root, byte absx, byte absy) {
/* clean last drag */
buddy_xor_op_rect();

window_t *child;
window_t *result=NULL;
/* move window */
if (lr=(buddy_op.ix > (byte)param1))
dx=buddy_op.ix - (byte)param1;
else
dx=(byte)param1 - buddy_op.ix;
if (ud=(buddy_op.iy > (byte)param2))
dy=buddy_op.iy - (byte)param2;
else
dy=(byte)param2 - buddy_op.iy;
window_move(buddy_op.wnd, dx, lr, dy, ud);

child=root->first_child;
while (child) {
if (!(result=buddy_get_window_xy(child, absx, absy)))
child=child->next;
else
return result;
/* redraw all for now */
window_draw(window_desktop);

} else {
/* find affected window */
affectedwnd=window_find_xy(window_desktop,(byte)param1,(byte)param2);

/* post message */
message_post(affectedwnd,id,param1,param2);

/* if on the same location, then it is click */
if (buddy_op.mx==(byte)param1 && buddy_op.my==(byte)param2)
message_post(affectedwnd,MSG_MOUSE_CLICK,param1,param2);
}

/* end of all operations */
buddy_op.op=BUDDY_OP_NONE;

break;

case MSG_MOUSE_MOVE:

if (buddy_op.op==BUDDY_OP_MOVE) /* initial move */
buddy_op.op=BUDDY_OP_MOVING;

if (buddy_op.op==BUDDY_OP_MOVING) {
/* calculate new position */
rect_delta_offset(&(buddy_op.rect), buddy_op.mx, (byte)param1, buddy_op.my, (byte)param2);

/* store new coords */
buddy_op.mx=(byte)param1;
buddy_op.my=(byte)param2;

/* and draw */
buddy_xor_op_rect();
}
break;
}
/* not found */
if (rect_contains(root->graphics->area, absx, absy))
return root;
else
return NULL;
}


void buddy_xor_op_rect() {
/* draw on desktop */
graphics_draw_rect(window_desktop->graphics, &(buddy_op.rect), 0xff, MODE_XOR);
}
23 changes: 22 additions & 1 deletion buddy/buddy.h
Expand Up @@ -11,9 +11,30 @@
#include "types.h"
#include "window.h"

/*
* operation in progress (multiple mouse events comms)
*/
#define BUDDY_OP_NONE 0
#define BUDDY_OP_MOVE 1
#define BUDDY_OP_MOVING 2
#define BUDDY_OP_SIZE 3
#define BUDDY_OP_SIZING 4
typedef struct buddy_op_s buddy_op_t;
struct buddy_op_s {
boolean op; /* op code */
rect_t rect; /* affected */
window_t *wnd; /* affected wnd */
byte mx; /* for generic op */
byte my; /* for generic op */
byte ix; /* initial x */
byte iy; /* initial y */
};

extern buddy_op_t buddy_op;

extern void buddy_init();
extern void buddy_harvest_events();
extern void buddy_dispatch(byte id, word param1, word param2);
extern window_t *buddy_get_window_xy(window_t* root, byte absx, byte absy);
extern void buddy_xor_op_rect();

#endif /* _BUDDY_H */
17 changes: 17 additions & 0 deletions buddy/graphics/masks.s
@@ -0,0 +1,17 @@
;; masks.s
;; graphical masks
;;
;; tomaz stih, thu aug 6 2015
.module masks

.globl _msk_empty_8x8
.globl _msk_full_8x8
.globl _msk_percent50_8x8

.area _CODE
_msk_empty_8x8::
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
_msk_full_8x8::
.byte 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
_msk_percent50_8x8::
.byte 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55
52 changes: 52 additions & 0 deletions buddy/graphics/rect.c
Expand Up @@ -24,6 +24,39 @@ rect_t* rect_intersect(rect_t *a, rect_t *b, rect_t *intersect) {
} else return NULL;
}

rect_t* rect_inflate(rect_t* rect, sbyte dx, sbyte dy) __naked {
__asm
pop de /* ret address */
pop hl /* rect */
pop bc /* c=dx, b=dy */
/* restore stack */
push bc
push hl
push de

push hl /* store ptr to rect */
ld a,(hl) /* a=x0 */
sub c /* x0=x0-dx */
ld (hl),a
inc hl
ld a,(hl) /* a=y0 */
sub b /* y0=y0-dy */
ld (hl),a
inc hl
ld a,(hl) /* a=x1 */
add c /* x1=x1+dx */
ld (hl),a
inc hl
ld a,(hl) /* a=y1 */
add b /* y1=y1+dy */
ld (hl),a

pop hl /* hl back to rect_t* */
ret
__endasm;
}


rect_t* rect_rel2abs(rect_t* abs, rect_t* rel, rect_t* out) __naked {
abs, rel, out;
__asm
Expand Down Expand Up @@ -139,3 +172,22 @@ void rect_subtract(
result++;
}
}

/* TODO: careful at scren edges */
void rect_delta_offset(rect_t *rect, byte oldx, byte newx, byte oldy, byte newy) {
if (oldx > newx) { /* move left */
rect->x0 = rect->x0 - (oldx-newx);
rect->x1 = rect->x1 - (oldx-newx);
} else { /* move right */
rect->x0 = rect->x0 + (newx-oldx);
rect->x1 = rect->x1 + (newx-oldx);
}

if (oldy > newy) { /* move up */
rect->y0 = rect->y0 - (oldy-newy);
rect->y1 = rect->y1 - (oldy-newy);
} else { /* move down */
rect->y0 = rect->y0 + (newy-oldy);
rect->y1 = rect->y1 + (newy-oldy);
}
}
8 changes: 6 additions & 2 deletions buddy/graphics/vector.s
Expand Up @@ -97,12 +97,16 @@ vl_shift_done: ; we have correct mask in a
ld b,e ; b=counter
ld c,a ; store a (mask)
vl_loop: ; to screen
and d ; line pattern
ex af,af'
cp #MODE_XOR ; xor mode?
jr z,vl_xor ; indeed!
ex af,af'
or (hl)
cpl ; 0 where there is 1
and (hl) ; clear screen
ld (hl),a ; to screen
ld a,c ; mask back
and d ; line pattern
or (hl) ; screen
jr vl_tovmem
vl_xor:
ex af,af'
Expand Down
11 changes: 6 additions & 5 deletions buddy/include/errors.h
Expand Up @@ -10,11 +10,12 @@
#include "types.h"

#define SUCCESS 00
#define DONT_OWN 01
#define OUT_OF_MEMORY 02
#define CANT_LOCK 03
#define INVALID_PARAMETER 04
#define NOT_FOUND 05
#define NOT_PROCESSED 01
#define DONT_OWN 02
#define OUT_OF_MEMORY 03
#define CANT_LOCK 04
#define INVALID_PARAMETER 05
#define NOT_FOUND 06

extern result last_error; /* last error, 0 = success */

Expand Down
16 changes: 16 additions & 0 deletions buddy/include/masks.h
@@ -0,0 +1,16 @@
/*
* masks.h
* graphical brushes
*
* tomaz stih thu aug 6 2015
*/
#ifndef _MASKS_H
#define _MASKS_H

#include "types.h"

extern byte* msk_empty_8x8;
extern byte* msk_full_8x8;
extern byte* msk_percent50_8x8;

#endif /* _MASKS_H */
1 change: 1 addition & 0 deletions buddy/include/mouse.h
Expand Up @@ -16,6 +16,7 @@
#define MOUSE_CURSOR_WIDTH 8
#define MOUSE_CURSOR_HEIGHT 10

/* mouse info */
typedef struct mouse_info_s mouse_info_t;
struct mouse_info_s {
byte x;
Expand Down
7 changes: 5 additions & 2 deletions buddy/include/rect.h
Expand Up @@ -9,17 +9,20 @@

#include "types.h"

typedef struct rect_s {
typedef struct rect_s rect_t;
struct rect_s {
byte x0;
byte y0;
byte x1;
byte y1;
} rect_t;
};

extern boolean rect_contains(rect_t *r, byte x, byte y);
extern boolean rect_overlap(rect_t *a, rect_t *b);
extern rect_t* rect_inflate(rect_t* rect, sbyte dx, sbyte dy) __naked;
extern rect_t* rect_intersect(rect_t *a, rect_t *b, rect_t *intersect);
extern rect_t* rect_rel2abs(rect_t* abs, rect_t* rel, rect_t* out) __naked;
extern void rect_subtract(rect_t *outer, rect_t *inner, rect_t *result, byte *num);
extern void rect_delta_offset(rect_t *rect, byte oldx, byte newx, byte oldy, byte newy);

#endif /* _RECT_H */
2 changes: 2 additions & 0 deletions buddy/include/types.h
Expand Up @@ -24,7 +24,9 @@ typedef unsigned long int uint32_t;
/* usual */
typedef uint8_t boolean;
typedef uint8_t byte;
typedef int8_t sbyte;
typedef uint16_t word;
typedef int16_t sword;
typedef uint8_t* string;
typedef uint8_t result;
typedef uint16_t handle;
Expand Down
2 changes: 1 addition & 1 deletion buddy/message.c
Expand Up @@ -58,7 +58,7 @@ void message_dispatch() {
if (message_first==NULL) return;
m = yx->lremfirst((void **)&message_first);
if (m!=NULL) {
message_send(m->window,m->id,m->param1,m->param2);
message_send(m->window,m->id,m->param1,m->param2);
message_destroy(m);
}
}

0 comments on commit bc5701a

Please sign in to comment.