1 /* --------------------- video.c -------------------- */
5 #define clr(fg,bg) ((fg)|((bg)<<4))
9 /* -- read a rectangle of video memory into a save buffer -- */
10 void DfGetVideo(DFRECT rc
, PCHAR_INFO bf
)
16 Size
.X
= DfRectRight(rc
) - DfRectLeft(rc
) + 1;
17 Size
.Y
= DfRectBottom(rc
) - DfRectTop(rc
) + 1;
22 Rect
.Left
= DfRectLeft(rc
);
23 Rect
.Top
= DfRectTop(rc
);
24 Rect
.Right
= DfRectRight(rc
);
25 Rect
.Bottom
= DfRectBottom(rc
);
27 ReadConsoleOutput (GetStdHandle (STD_OUTPUT_HANDLE
),
34 /* -- write a rectangle of video memory from a save buffer -- */
35 void DfStoreVideo(DFRECT rc
, PCHAR_INFO bf
)
41 Size
.X
= DfRectRight(rc
) - DfRectLeft(rc
) + 1;
42 Size
.Y
= DfRectBottom(rc
) - DfRectTop(rc
) + 1;
47 Rect
.Left
= DfRectLeft(rc
);
48 Rect
.Top
= DfRectTop(rc
);
49 Rect
.Right
= DfRectRight(rc
);
50 Rect
.Bottom
= DfRectBottom(rc
);
52 WriteConsoleOutput (GetStdHandle (STD_OUTPUT_HANDLE
),
59 /* -------- read a character of video memory ------- */
60 char DfGetVideoChar(int x
, int y
)
69 ReadConsoleOutputCharacter (GetStdHandle(STD_OUTPUT_HANDLE
),
78 /* -------- write a character of video memory ------- */
79 void DfPutVideoChar(int x
, int y
, int ch
)
84 if (x
< DfScreenWidth
&& y
< DfScreenHeight
)
89 WriteConsoleOutputCharacter (GetStdHandle(STD_OUTPUT_HANDLE
),
97 BOOL
DfCharInView(DFWINDOW wnd
, int x
, int y
)
99 DFWINDOW nwnd
= DfNextWindow(wnd
);
102 int x1
= DfGetLeft(wnd
)+x
;
103 int y1
= DfGetTop(wnd
)+y
;
105 if (!DfTestAttribute(wnd
, DF_VISIBLE
))
107 if (!DfTestAttribute(wnd
, DF_NOCLIP
))
109 DFWINDOW wnd1
= DfGetParent(wnd
);
112 /* clip character to parent's borders */
113 if (!DfTestAttribute(wnd1
, DF_VISIBLE
))
115 if (!DfInsideRect(x1
, y1
, DfClientRect(wnd1
)))
117 wnd1
= DfGetParent(wnd1
);
122 if (!isHidden(nwnd
) && !DfIsAncestor(wnd
, nwnd
))
124 rc
= DfWindowRect(nwnd
);
125 if (DfTestAttribute(nwnd
, DF_SHADOW
))
130 if (!DfTestAttribute(nwnd
, DF_NOCLIP
))
133 while (DfGetParent(pwnd
))
135 pwnd
= DfGetParent(pwnd
);
136 rc
= DfSubRectangle(rc
, DfClientRect(pwnd
));
139 if (DfInsideRect(x1
,y1
,rc
))
142 nwnd
= DfNextWindow(nwnd
);
144 return (x1
< DfScreenWidth
&& y1
< DfScreenHeight
);
147 /* -------- write a character to a window ------- */
148 void DfWPutch(DFWINDOW wnd
, int c
, int x
, int y
)
150 if (DfCharInView(wnd
, x
, y
))
156 pos
.X
= DfGetLeft(wnd
)+x
;
157 pos
.Y
= DfGetTop(wnd
)+y
;
159 Attr
= clr(DfForeground
, DfBackground
);
161 WriteConsoleOutputAttribute (GetStdHandle(STD_OUTPUT_HANDLE
),
167 WriteConsoleOutputCharacter (GetStdHandle(STD_OUTPUT_HANDLE
),
175 /* ------- write a string to a window ---------- */
176 void DfWPuts(DFWINDOW wnd
, void *s
, int x
, int y
)
179 int x1
= DfGetLeft(wnd
)+x
;
181 int y1
= DfGetTop(wnd
)+y
;
183 if (x1
< DfScreenWidth
&& y1
< DfScreenHeight
&& DfIsVisible(wnd
))
190 int fg
= DfForeground
;
191 int bg
= DfBackground
;
196 if (*str
== DF_CHANGECOLOR
)
199 DfForeground
= (*str
++) & 0x7f;
200 DfBackground
= (*str
++) & 0x7f;
204 if (*str
== DF_RESETCOLOR
)
206 DfForeground
= fg
& 0x7f;
207 DfBackground
= bg
& 0x7f;
212 *ap
= (WORD
)clr(DfForeground
, DfBackground
);
213 // *cp1 = (*str & 255) | (clr(DfForeground, DfBackground) << 8);
215 // if (!DfCharInView(wnd, x, y))
216 // *cp1 = peek(video_address, vad(x2,y1));
226 if (x1
+len
> DfScreenWidth
)
227 len
= DfScreenWidth
-x1
;
229 if (!DfClipString
&& !DfTestAttribute(wnd
, DF_NOCLIP
))
231 /* -- clip the line to DfWithin ancestor windows -- */
232 DFRECT rc
= DfWindowRect(wnd
);
233 DFWINDOW nwnd
= DfGetParent(wnd
);
234 while (len
> 0 && nwnd
!= NULL
)
236 if (!DfIsVisible(nwnd
))
241 rc
= DfSubRectangle(rc
, DfClientRect(nwnd
));
242 nwnd
= DfGetParent(nwnd
);
244 while (len
> 0 && !DfInsideRect(x1
+off
,y1
,rc
))
252 while (len
&& !DfInsideRect(x2
,y1
,rc
))
267 WriteConsoleOutputAttribute (GetStdHandle(STD_OUTPUT_HANDLE
),
273 WriteConsoleOutputCharacter (GetStdHandle(STD_OUTPUT_HANDLE
),
282 /* --------- scroll the window. d: 1 = up, 0 = dn ---------- */
283 void DfScrollWindow(DFWINDOW wnd
, DFRECT rc
, int d
)
285 if (DfRectTop(rc
) != DfRectBottom(rc
))
292 ciFill
.Attributes
= clr(DfWndForeground(wnd
),DfWndBackground(wnd
));
293 ciFill
.Char
.AsciiChar
= ' ';
295 rcScroll
.Left
= DfRectLeft(rc
);
296 rcScroll
.Right
= DfRectRight(rc
);
297 rcScroll
.Top
= DfRectTop(rc
);
298 rcScroll
.Bottom
= DfRectBottom(rc
);
302 pos
.X
= DfRectLeft(rc
);
306 /* scroll 1 line down */
307 pos
.Y
= DfRectTop(rc
)+1;
311 /* scroll 1 line up */
312 pos
.Y
= DfRectTop(rc
)-1;
315 ScrollConsoleScreenBuffer (GetStdHandle(STD_OUTPUT_HANDLE
),