Work on WM's sizing code, not quite complete yet
[tpg/acess2.git] / Usermode / Applications / axwin2_src / WM / video.c
1 /*
2  * Acess GUI (AxWin) Version 2
3  * By John Hodge (thePowersGang)
4  */
5 #include "common.h"
6 #include <acess/sys.h>
7 #include <acess/devices/terminal.h>
8
9 // === PROTOTYPES ===
10 void    Video_Setup(void);
11 void    Video_Update(void);
12 void    Video_FillRect(short X, short Y, short W, short H, uint32_t Color);
13
14 // === GLOBALS ===
15
16 // === CODE ===
17 void Video_Setup(void)
18 {
19          int    tmpInt;
20         
21         // Open terminal
22         giTerminalFD = open(gsTerminalDevice, OPENFLAG_READ|OPENFLAG_WRITE);
23         if( giTerminalFD == -1 )
24         {
25                 fprintf(stderr, "ERROR: Unable to open '%s' (%i)\n", gsTerminalDevice, _errno);
26                 exit(-1);
27         }
28         
29         // Set width
30         tmpInt = giScreenWidth;
31         tmpInt = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, &tmpInt );
32         if(tmpInt != giScreenWidth)
33         {
34                 fprintf(stderr, "Warning: Selected width (%i) is invalid, clipped to %i\n",
35                         giScreenWidth, tmpInt);
36                 giScreenWidth = tmpInt;
37         }
38         
39         // Set height
40         tmpInt = giScreenHeight;
41         tmpInt = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, &tmpInt );
42         if(tmpInt != giScreenHeight)
43         {
44                 fprintf(stderr, "Warning: Selected height (%i) is invalid, clipped to %i\n",
45                         giScreenHeight, tmpInt);
46                 giScreenHeight = tmpInt;
47         }
48         
49         // Set mode to video
50         tmpInt = TERM_MODE_FB;
51         ioctl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt );
52         
53         // Force VT8 to be shown
54         ioctl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL );
55         
56         // Create local framebuffer (back buffer)
57         gpScreenBuffer = malloc( giScreenWidth*giScreenHeight*4 );
58         memset32( gpScreenBuffer, 0x8888FF, giScreenWidth*giScreenHeight );
59         Video_Update();
60 }
61
62 void Video_Update(void)
63 {
64         //seek(giTerminalFD, 0, SEEK_SET);
65         seek(giTerminalFD, 0, 1);
66         write(giTerminalFD, giScreenWidth*giScreenHeight*4, gpScreenBuffer);
67 }
68
69 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color)
70 {
71         uint32_t        *buf = gpScreenBuffer + Y*giScreenWidth + X;
72         
73         _SysDebug("Video_FillRect: (X=%i, Y=%i, W=%i, H=%i, Color=%08x)",
74                 X, Y, W, H, Color);
75         
76         if(W < 0 || X < 0 || X >= giScreenWidth)        return ;
77         if(X + W > giScreenWidth)       W = giScreenWidth - X;
78         
79         if(H < 0 || Y < 0 || Y >= giScreenHeight)       return ;
80         if(Y + H > giScreenHeight)      H = giScreenHeight - Y;
81         
82         while( H -- )
83         {
84                 memset32( buf, Color, W );
85                 buf += giScreenWidth;
86         }
87 }
88
89 void Video_DrawRect(short X, short Y, short W, short H, uint32_t Color)
90 {       
91         Video_FillRect(X, Y, W, 1, Color);
92         Video_FillRect(X, Y+H-1, W, 1, Color);
93         Video_FillRect(X, Y, 1, H, Color);
94         Video_FillRect(X+W-1, Y, 1, H, Color);
95 }
96
97 void Video_DrawText(short X, short Y, short W, short H, void *Font, int Point, uint32_t Color, char *Text)
98 {
99         // TODO!
100 }

UCC git Repository :: git.ucc.asn.au