forked from honeydatax/DXwindow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dxwindow.h
207 lines (206 loc) · 4.56 KB
/
dxwindow.h
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#include "directX.h"
#define maxw 32
#define flagend 0
#define flagrefresh 1
#define winsw 200
#define winsh 200
#define shmhead 25
int fbfd;
#define shmp "IIXwindows"
struct windows{
char *title;
int *dc;
int x;
int y;
int w;
int h;
int r;
int g;
int b;
char wc[80];
int *shms;
};
struct cursors{
int x;
int y;
int x1;
int y1;
int *cursor;
int left;
int right;
int middle;
};
int loads=0;
struct cursors curs;
int zorder[maxw];
struct windows win[maxw];
int wcount=0;
void drawlabel(int *dc,char *title,int x,int y,int w, int h){
char c[w/9+2];
strncpy(c,title,w/9);
c[w/9+1]=0;
igputs(dc,x,y,0,0,0,c);
}
void drawWindow(char *title,int *dc,int x,int y,int w, int h,int r,int g, int b){
iboxs(0,0,w,h,dc,r,g,b);
irectangle(0,0,w,h,dc,0,0,0);
drawlabel(dc,title,0,0,w,h);
}
void runs(char *shells,char *keyss){
char runs[80];
runs[0]=0;
strcat(runs,shells);
strcat(runs," ");
strcat(runs,keyss);
strcat(runs," 2>/dev/null >/dev/null & ");
system(runs);
}
int newWindow(char *title,int x,int y,int w, int h,int r,int g, int b,char *aapplication){
int www=wcount;
if(www<maxw-1){
win[wcount].title=title;
win[wcount].x=x;
win[wcount].y=y;
win[wcount].w=w;
win[wcount].h=h;
win[wcount].r=r;
win[wcount].g=g;
win[wcount].b=b;
if(w>vinfo.xres-1)win[wcount].w=vinfo.xres-1;
if(w>vinfo.yres-1)win[wcount].h=vinfo.yres-1;
zorder[wcount]=wcount;
sprintf(win[wcount].wc,"%s%d",shmp,wcount);
int fd = shm_open(win[wcount].wc,O_CREAT | O_EXCL | O_RDWR,S_IRUSR | S_IWUSR);
if (fd==-1)return -1;
if (ftruncate(fd,(w*h)*(sizeof(int))+50)==-1)return -1;
win[wcount].shms=(int*)mmap(NULL,(w*h)*(sizeof(int))+50,PROT_WRITE | PROT_READ ,MAP_SHARED,fd,0);
if (win[wcount].shms==MAP_FAILED)return -1;
win[wcount].dc=win[wcount].shms+shmhead;
win[wcount].dc[0]=w;
win[wcount].dc[1]=h;
win[wcount].dc[2]=32;
drawWindow(win[wcount].title,win[wcount].dc,win[wcount].x,win[wcount].y,win[wcount].w,win[wcount].h,win[wcount].r,win[wcount].g,win[wcount].b);
win[wcount].shms[flagend]=0;
win[wcount].shms[1]=0;
runs(aapplication,win[wcount].wc);
if (www!=-1)wcount++;
}else{
www=-1;
}
return www;
}
void exitWindow(){
int n;
for(n=0;n<wcount;n++){
if(win[n].dc!=NULL && n<wcount) shm_unlink(win[n].wc);
}
if(curs.cursor!=NULL)free(curs.cursor);
}
void drawCursor(){
ball(curs.x+16,curs.y+16,3,128,128,128);
circle(curs.x+16,curs.y+16,3,0,0,0);
}
void showCursor(){
if (loads==0)curs.cursor=creatImage(32,32);
loads=1;
mouseEvent();
curs.x=mouseX-16;
curs.y=mouseY-16;
if(curs.x<0)curs.x=0;
if(curs.y<0)curs.y=0;
if(curs.x>=vinfo.xres-1)curs.x=vinfo.xres-33;
if(curs.y>=vinfo.yres-1)curs.y=vinfo.yres-33;
curs.x1=curs.x;
curs.y1=curs.y;
copyImage(curs.x,curs.y,curs.cursor);
drawCursor();
}
int onclick(){
int n;
int nx;
int ny;
int rets=-1;
for(n=wcount-1;n>-1;n--){
nx=win[zorder[n]].x;
ny=win[zorder[n]].y;
if (curs.x1+16>=nx && curs.y1+16>=ny && curs.x1+16<=nx+win[zorder[n]].w && curs.y1+16<=ny+win[zorder[n]].h)return zorder[n];
}
return rets;
}
int redrawCursor(){
int rets=-1;
int i=-1;
left=0;
right=0;
middle=0;
i=mouseEvent();
curs.x1=mouseX-16;
curs.y1=mouseY-16;
curs.left=left;
curs.right=right;
curs.middle=middle;
if(curs.x1<0)curs.x1=0;
if(curs.y1<0)curs.y1=0;
if(curs.x1>=vinfo.xres-1)curs.x1=vinfo.xres-33;
if(curs.y1>=vinfo.yres-1)curs.y1=vinfo.yres-33;
if(curs.x1!=curs.x || curs.y1!=curs.y){
if(curs.x1!=0 && curs.y1!=0 && curs.x1<vinfo.xres-33 && curs.y1<vinfo.yres-33){
putImage(curs.x,curs.y,curs.cursor);
curs.x=curs.x1;
curs.y=curs.y1;
copyImage(curs.x,curs.y,curs.cursor);
drawCursor();
}
}
if(i==-1 && curs.left!=0)rets=onclick();
return rets;
}
void windowsRefresh(){
int n;
int nx;
int ny;
boxs(0,0,vinfo.xres-1,vinfo.yres-1,0,0,0);
for(n=0;n<wcount;n++){
nx=win[zorder[n]].x;
ny=win[zorder[n]].y;
if(nx+win[zorder[n]].w>vinfo.xres-1)nx=0;
if(ny+win[zorder[n]].h>vinfo.yres-1)ny=0;
putImage(nx,ny,win[zorder[n]].dc);
}
showCursor();
}
void windowRefresh(int www){
int n;
int nx;
int ny;
putImage(curs.x,curs.y,curs.cursor);
n=wcount-1;
nx=win[zorder[n]].x;
ny=win[zorder[n]].y;
if(nx+win[zorder[n]].w>vinfo.xres-1)nx=0;
if(ny+win[zorder[n]].h>vinfo.yres-1)ny=0;
putImage(nx,ny,win[zorder[n]].dc);
showCursor();
}
void moveTop(int index){
int n;
int i=-1;
int t=0;
int o=0;
for (n=0;n<wcount;n++){
if(index==zorder[n]){
t=zorder[n];
o=1;
}
if(o==1){
zorder[n]=zorder[n+1];
}
}
zorder[wcount-1]=t;
}
void startwin(){
char nolls[80]=" ";
fbfd = startX(nolls);
if (fbfd == -1) exit(1);
if ((int)fbp == -1)exit(1);
}