2 * Acess GUI (AxWin) Version 2
3 * By John Hodge (thePowersGang)
7 #include <acess/devices/terminal.h>
9 #include "resources/cursor.h"
12 void Video_Setup(void);
13 void Video_SetCursorPos(short X, short Y);
14 void Video_Update(void);
15 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color);
16 void Video_DrawRect(short X, short Y, short W, short H, uint32_t Color);
23 void Video_Setup(void)
28 giTerminalFD = open(gsTerminalDevice, OPENFLAG_READ|OPENFLAG_WRITE);
29 if( giTerminalFD == -1 )
31 fprintf(stderr, "ERROR: Unable to open '%s' (%i)\n", gsTerminalDevice, _errno);
36 tmpInt = giScreenWidth;
37 tmpInt = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, &tmpInt );
38 if(tmpInt != giScreenWidth)
40 fprintf(stderr, "Warning: Selected width (%i) is invalid, clipped to %i\n",
41 giScreenWidth, tmpInt);
42 giScreenWidth = tmpInt;
46 tmpInt = giScreenHeight;
47 tmpInt = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, &tmpInt );
48 if(tmpInt != giScreenHeight)
50 fprintf(stderr, "Warning: Selected height (%i) is invalid, clipped to %i\n",
51 giScreenHeight, tmpInt);
52 giScreenHeight = tmpInt;
56 tmpInt = TERM_MODE_FB;
57 ioctl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt );
59 // Force VT to be shown
60 ioctl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL );
62 // Create local framebuffer (back buffer)
63 gpScreenBuffer = malloc( giScreenWidth*giScreenHeight*4 );
64 memset32( gpScreenBuffer, 0x8888FF, giScreenWidth*giScreenHeight );
66 // Set cursor position and bitmap
67 ioctl(giTerminalFD, TERM_IOCTL_SETCURSORBITMAP, &cCursorBitmap);
68 Video_SetCursorPos( giScreenWidth/2, giScreenHeight/2 );
73 void Video_Update(void)
75 //seek(giTerminalFD, 0, SEEK_SET);
76 seek(giTerminalFD, 0, 1);
77 write(giTerminalFD, gpScreenBuffer, giScreenWidth*giScreenHeight*4);
80 void Video_SetCursorPos(short X, short Y)
86 pos.x = giVideo_CursorX = X;
87 pos.y = giVideo_CursorY = Y;
88 ioctl(giTerminalFD, TERM_IOCTL_GETSETCURSOR, &pos);
91 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color)
93 uint32_t *buf = gpScreenBuffer + Y*giScreenWidth + X;
95 _SysDebug("Video_FillRect: (X=%i, Y=%i, W=%i, H=%i, Color=%08x)",
98 if(W < 0 || X < 0 || X >= giScreenWidth) return ;
99 if(X + W > giScreenWidth) W = giScreenWidth - X;
101 if(H < 0 || Y < 0 || Y >= giScreenHeight) return ;
102 if(Y + H > giScreenHeight) H = giScreenHeight - Y;
106 memset32( buf, Color, W );
107 buf += giScreenWidth;
111 void Video_DrawRect(short X, short Y, short W, short H, uint32_t Color)
113 Video_FillRect(X, Y, W, 1, Color);
114 Video_FillRect(X, Y+H-1, W, 1, Color);
115 Video_FillRect(X, Y, 1, H, Color);
116 Video_FillRect(X+W-1, Y, 1, H, Color);
120 * \brief Draw an image to the screen
121 * \todo Maybe have support for an offset in the image
123 void Video_DrawImage(short X, short Y, short W, short H, tImage *Image)
126 uint8_t *buf = (uint8_t *)(gpScreenBuffer + Y*giScreenWidth + X);
134 if( X >= giScreenWidth ) return ;
135 if( Y >= giScreenHeight ) return ;
137 // Wrap to image size
138 if( W > Image->Width ) W = Image->Width;
139 if( H > Image->Height ) H = Image->Height;
141 // Wrap to screen size
142 if( X + W > giScreenWidth ) W = giScreenWidth - X;
143 if( Y + H > giScreenHeight ) H = giScreenHeight - Y;
147 switch( Image->Format )
150 for( y = 0; y < H; y ++ )
152 int r, g, b, a; // New
153 int or, og, ob; // Original
154 for( x = 0; x < W; x ++ )
156 b = data[x*4+0]; g = data[x*4+1]; r = data[x*4+2]; a = data[x*4+3];
157 if( a == 0 ) continue; // 100% transparent
158 ob = buf[x*4+0]; og = buf[x*4+1]; or = buf[x*4+2];
162 // Transparent: Handled above
173 r = (or * (255-a) + r * a) / 255;
174 g = (og * (255-a) + g * a) / 255;
175 b = (ob * (255-a) + b * a) / 255;
178 buf[x*4+0] = b; buf[x*4+1] = g; buf[x*4+2] = r;
180 data += Image->Width * 4;
181 buf += giScreenWidth * 4;
187 for( y = 0; y < H; y ++ )
189 for( x = 0; x < W; x ++ )
191 buf[x*4+0] = data[x*3+2]; // Blue
192 buf[x*4+1] = data[x*3+1]; // Green
193 buf[x*4+2] = data[x*3+0]; // Red
196 buf += giScreenWidth * 4;
200 _SysDebug("ERROR: Unknown image format %i\n", Image->Format);