summaryrefslogtreecommitdiff
path: root/atari/caret.c
blob: 42a35a452fe13d42854cb59fbaa7c39ac6a23918 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <stdbool.h>

#include "desktop/plot_style.h"
#include "atari/plot/plot.h"
#include "atari/caret.h"

extern struct s_vdi_sysinfo vdi_sysinfo;

static void caret_restore_background(struct s_caret *c, VdiHdl vh, GRECT *clip);

void caret_show(struct s_caret *caret, VdiHdl vh, GRECT *dimensions, GRECT *clip)
{
	GRECT visible, old_dim;
	MFDB screen;
	short pxy[8];

	struct rect old_clip;

	return;



	plot_get_clip(&old_clip);
	plot_get_dimensions(&old_dim);


	// store background:
	visible = *dimensions;
	visible.g_x += clip->g_x;
	visible.g_y += clip->g_y;

	if(!rc_intersect(clip, &visible)){
		printf("no isect...\n");
		return;
	}


	// TODO: do not alloc / free on each move...
	if (caret->background.fd_addr != NULL) {
		//caret_restore_background(caret, vh, clip);
	}

	plot_lock();
	plot_set_dimensions(clip->g_x, clip->g_y, clip->g_w, clip->g_h);

	caret->dimensions.g_x = dimensions->g_x;
	caret->dimensions.g_y = dimensions->g_y;
	caret->dimensions.g_w = visible.g_w;
	caret->dimensions.g_h = visible.g_h;

	dbg_grect("clip", clip);
	dbg_grect("visible", &visible);
	// TODO: do not alloc / free on every redraw...
	init_mfdb(vdi_sysinfo.scr_bpp, visible.g_w, visible.g_h, 0,
			&caret->background);
	init_mfdb(0, visible.g_w, visible.g_h, 0, &screen);
	pxy[0] = visible.g_x;
	pxy[1] = visible.g_y;
	pxy[2] = visible.g_x + visible.g_w;
	pxy[3] = visible.g_y + visible.g_h;
	pxy[4] = 0;
	pxy[5] = 0;
	pxy[6] = visible.g_w;
	pxy[7] = visible.g_h;
	vro_cpyfm (vh, S_ONLY, pxy, &screen, &caret->background);

	plot_line(dimensions->g_x, dimensions->g_y, dimensions->g_x,
			dimensions->g_y + dimensions->g_h, plot_style_caret);

	plot_set_dimensions(old_clip.x0, old_clip.y0, old_clip.x1, old_clip.y1);
	plot_clip(&old_clip);

	plot_unlock();
	caret->visible = true;
}

void caret_hide(struct s_caret *caret, VdiHdl vh, GRECT *clip)
{
	struct rect old_clip;
	GRECT old_dim;

	plot_lock();
	plot_get_clip(&old_clip);
	plot_get_dimensions(&old_dim);
	plot_set_dimensions(clip->g_x, clip->g_y, clip->g_w, clip->g_h);
	caret_restore_background(caret, vh, clip);
	plot_set_dimensions(old_clip.x0, old_clip.y0, old_clip.x1, old_clip.y1);
	plot_clip(&old_clip);
	plot_unlock();
	caret->visible = false;
}

static void caret_restore_background(struct s_caret *caret, VdiHdl vh, GRECT *clip)
{
	MFDB screen;
	GRECT visible;
	short pxy[8];

	visible = caret->dimensions;
	visible.g_x += clip->g_x;
	visible.g_y += clip->g_y;

	dbg_grect("restore ", &visible);

	if(!rc_intersect(clip, &visible)){
		goto exit;
	}

	// TODO: check isect

	// restore mfdb

	init_mfdb(0, caret->dimensions.g_w, caret->dimensions.g_h, 0, &screen);
	pxy[0] = 0;
	pxy[1] = 0;
	pxy[2] = caret->dimensions.g_w;
	pxy[3] = caret->dimensions.g_h;
	pxy[4] = clip->g_x + caret->dimensions.g_x;
	pxy[5] = clip->g_y + caret->dimensions.g_y;
	pxy[6] = pxy[2];
	pxy[7] = pxy[3];
	vro_cpyfm(vh, S_ONLY, pxy, &caret->background, &screen);
	// exit:
	// TODO: do not alloc / free on every redraw...

exit:
	free(caret->background.fd_addr);
	caret->background.fd_addr = NULL;
}