2 * Acess GUI (AxWin) Version 2
3 * By John Hodge (thePowersGang)
7 #include <acess/devices/terminal.h>
11 void Video_Setup(void);
12 void Video_Update(void);
13 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color);
18 void Video_Setup(void)
23 giTerminalFD = open(gsTerminalDevice, OPENFLAG_READ|OPENFLAG_WRITE);
24 if( giTerminalFD == -1 )
26 fprintf(stderr, "ERROR: Unable to open '%s' (%i)\n", gsTerminalDevice, _errno);
31 tmpInt = giScreenWidth;
32 tmpInt = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, &tmpInt );
33 if(tmpInt != giScreenWidth)
35 fprintf(stderr, "Warning: Selected width (%i) is invalid, clipped to %i\n",
36 giScreenWidth, tmpInt);
37 giScreenWidth = tmpInt;
41 tmpInt = giScreenHeight;
42 tmpInt = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, &tmpInt );
43 if(tmpInt != giScreenHeight)
45 fprintf(stderr, "Warning: Selected height (%i) is invalid, clipped to %i\n",
46 giScreenHeight, tmpInt);
47 giScreenHeight = tmpInt;
51 tmpInt = TERM_MODE_FB;
52 ioctl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt );
54 // Force VT8 to be shown
55 ioctl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL );
57 // Create local framebuffer (back buffer)
58 gpScreenBuffer = malloc( giScreenWidth*giScreenHeight*4 );
59 memset32( gpScreenBuffer, 0x8888FF, giScreenWidth*giScreenHeight );
63 void Video_Update(void)
65 //seek(giTerminalFD, 0, SEEK_SET);
66 seek(giTerminalFD, 0, 1);
67 write(giTerminalFD, giScreenWidth*giScreenHeight*4, gpScreenBuffer);
70 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color)
72 uint32_t *buf = gpScreenBuffer + Y*giScreenWidth + X;
74 _SysDebug("Video_FillRect: (X=%i, Y=%i, W=%i, H=%i, Color=%08x)",
77 if(W < 0 || X < 0 || X >= giScreenWidth) return ;
78 if(X + W > giScreenWidth) W = giScreenWidth - X;
80 if(H < 0 || Y < 0 || Y >= giScreenHeight) return ;
81 if(Y + H > giScreenHeight) H = giScreenHeight - Y;
85 memset32( buf, Color, W );
90 void Video_DrawRect(short X, short Y, short W, short H, uint32_t Color)
92 Video_FillRect(X, Y, W, 1, Color);
93 Video_FillRect(X, Y+H-1, W, 1, Color);
94 Video_FillRect(X, Y, 1, H, Color);
95 Video_FillRect(X+W-1, Y, 1, H, Color);
99 * \brief Draw text to the screen
101 void Video_DrawText(short X, short Y, short W, short H, void *Font, int Point, uint32_t Color, char *Text)
107 * \brief Draw an image to the screen
108 * \todo Maybe have support for an offset in the image
110 void Video_DrawImage(short X, short Y, short W, short H, tImage *Image)
113 uint8_t *buf = (uint8_t *)(gpScreenBuffer + Y*giScreenWidth + X);
114 uint8_t *data = Image->Data;
117 if( X >= giScreenWidth ) return ;
118 if( Y >= giScreenHeight ) return ;
120 // Wrap to image size
121 if( W > Image->Width ) W = Image->Width;
122 if( H > Image->Height ) H = Image->Height;
124 // Wrap to screen size
125 if( X + W > giScreenWidth ) W = giScreenWidth - X;
126 if( Y + H > giScreenHeight ) H = giScreenHeight - Y;
128 switch( Image->Format )
131 for( y = 0; y < H; y ++ )
133 int r, g, b, a; // New
134 int or, og, ob; // Original
135 for( x = 0; x < W; x ++ ) {
136 b = data[x*4+0]; g = data[x*4+1]; r = data[x*4+2]; a = data[x*4+3];
137 if( a == 0 ) continue; // 100% transparent
138 ob = buf[x*4+0]; og = buf[x*4+1]; or = buf[x*4+2];
142 // Transparent: Handled above
153 r = (or * (255-a) + r * a) / 255;
154 g = (og * (255-a) + g * a) / 255;
155 b = (ob * (255-a) + b * a) / 255;
158 buf[x*4+0] = b; buf[x*4+1] = g; buf[x*4+2] = r;
160 data += Image->Width * 4;
161 buf += giScreenWidth * 4;
167 for( y = 0; y < H; y ++ )
169 for( x = 0; x < W; x ++ ) {
170 buf[x*4+0] = data[x*3+2]; // Blue
171 buf[x*4+1] = data[x*3+1]; // Green
172 buf[x*4+2] = data[x*3+0]; // Red
175 buf += giScreenWidth * 4;