1 /* --------------------- video.c -------------------- */
3 #include "dflat32/dflat.h"
5 #define clr(fg,bg) ((fg)|((bg)<<4))
9 /* -- read a rectangle of video memory into a save buffer -- */
10 void GetVideo(DFRECT rc
, PCHAR_INFO bf
)
16 Size
.X
= RectRight(rc
) - RectLeft(rc
) + 1;
17 Size
.Y
= RectBottom(rc
) - RectTop(rc
) + 1;
22 Rect
.Left
= RectLeft(rc
);
23 Rect
.Top
= RectTop(rc
);
24 Rect
.Right
= RectRight(rc
);
25 Rect
.Bottom
= RectBottom(rc
);
27 ReadConsoleOutput (GetStdHandle (STD_OUTPUT_HANDLE
),
34 /* -- write a rectangle of video memory from a save buffer -- */
35 void StoreVideo(DFRECT rc
, PCHAR_INFO bf
)
41 Size
.X
= RectRight(rc
) - RectLeft(rc
) + 1;
42 Size
.Y
= RectBottom(rc
) - RectTop(rc
) + 1;
47 Rect
.Left
= RectLeft(rc
);
48 Rect
.Top
= RectTop(rc
);
49 Rect
.Right
= RectRight(rc
);
50 Rect
.Bottom
= RectBottom(rc
);
52 WriteConsoleOutput (GetStdHandle (STD_OUTPUT_HANDLE
),
59 /* -------- read a character of video memory ------- */
60 char GetVideoChar(int x
, int y
)
69 ReadConsoleOutputCharacter (GetStdHandle(STD_OUTPUT_HANDLE
),
78 /* -------- write a character of video memory ------- */
79 void PutVideoChar(int x
, int y
, int ch
)
84 if (x
< sScreenWidth
&& y
< sScreenHeight
)
89 WriteConsoleOutputCharacter (GetStdHandle(STD_OUTPUT_HANDLE
),
97 BOOL
CharInView(DFWINDOW wnd
, int x
, int y
)
99 DFWINDOW nwnd
= NextWindow(wnd
);
102 int x1
= GetLeft(wnd
)+x
;
103 int y1
= GetTop(wnd
)+y
;
105 if (!TestAttribute(wnd
, VISIBLE
))
107 if (!TestAttribute(wnd
, NOCLIP
))
109 DFWINDOW wnd1
= GetParent(wnd
);
112 /* clip character to parent's borders */
113 if (!TestAttribute(wnd1
, VISIBLE
))
115 if (!InsideRect(x1
, y1
, ClientRect(wnd1
)))
117 wnd1
= GetParent(wnd1
);
122 if (!isHidden(nwnd
) && !isAncestor(wnd
, nwnd
))
124 rc
= WindowRect(nwnd
);
125 if (TestAttribute(nwnd
, SHADOW
))
130 if (!TestAttribute(nwnd
, NOCLIP
))
133 while (GetParent(pwnd
))
135 pwnd
= GetParent(pwnd
);
136 rc
= subRectangle(rc
, ClientRect(pwnd
));
139 if (InsideRect(x1
,y1
,rc
))
142 nwnd
= NextWindow(nwnd
);
144 return (x1
< sScreenWidth
&& y1
< sScreenHeight
);
147 /* -------- write a character to a window ------- */
148 void wputch(DFWINDOW wnd
, int c
, int x
, int y
)
150 if (CharInView(wnd
, x
, y
))
156 pos
.X
= GetLeft(wnd
)+x
;
157 pos
.Y
= GetTop(wnd
)+y
;
159 Attr
= clr(foreground
, background
);
161 WriteConsoleOutputAttribute (GetStdHandle(STD_OUTPUT_HANDLE
),
167 WriteConsoleOutputCharacter (GetStdHandle(STD_OUTPUT_HANDLE
),
175 /* ------- write a string to a window ---------- */
176 void wputs(DFWINDOW wnd
, void *s
, int x
, int y
)
179 int x1
= GetLeft(wnd
)+x
;
181 int y1
= GetTop(wnd
)+y
;
183 if (x1
< sScreenWidth
&& y1
< sScreenHeight
&& isVisible(wnd
))
189 unsigned char *str
= s
;
196 if (*str
== CHANGECOLOR
)
199 foreground
= (*str
++) & 0x7f;
200 background
= (*str
++) & 0x7f;
204 if (*str
== RESETCOLOR
)
206 foreground
= fg
& 0x7f;
207 background
= bg
& 0x7f;
212 *ap
= (WORD
)clr(foreground
, background
);
213 // *cp1 = (*str & 255) | (clr(foreground, background) << 8);
215 // if (!CharInView(wnd, x, y))
216 // *cp1 = peek(video_address, vad(x2,y1));
226 if (x1
+len
> sScreenWidth
)
227 len
= sScreenWidth
-x1
;
229 if (!ClipString
&& !TestAttribute(wnd
, NOCLIP
))
231 /* -- clip the line to within ancestor windows -- */
232 DFRECT rc
= WindowRect(wnd
);
233 DFWINDOW nwnd
= GetParent(wnd
);
234 while (len
> 0 && nwnd
!= NULL
)
236 if (!isVisible(nwnd
))
241 rc
= subRectangle(rc
, ClientRect(nwnd
));
242 nwnd
= GetParent(nwnd
);
244 while (len
> 0 && !InsideRect(x1
+off
,y1
,rc
))
252 while (len
&& !InsideRect(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 scroll_window(DFWINDOW wnd
, DFRECT rc
, int d
)
285 if (RectTop(rc
) != RectBottom(rc
))
292 ciFill
.Attributes
= clr(WndForeground(wnd
),WndBackground(wnd
));
293 ciFill
.Char
.AsciiChar
= ' ';
295 rcScroll
.Left
= RectLeft(rc
);
296 rcScroll
.Right
= RectRight(rc
);
297 rcScroll
.Top
= RectTop(rc
);
298 rcScroll
.Bottom
= RectBottom(rc
);
302 pos
.X
= RectLeft(rc
);
306 /* scroll 1 line down */
307 pos
.Y
= RectTop(rc
)+1;
311 /* scroll 1 line up */
312 pos
.Y
= RectTop(rc
)-1;
315 ScrollConsoleScreenBuffer (GetStdHandle(STD_OUTPUT_HANDLE
),