Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "engine/media.h"
- #include "engine/mediaCMD.h"
- void _cmd_init ( Context* me )
- {
- me->_internal_draw_circle = _cmd_draw_circle;
- me->_internal_create_screen = _cmd_create_screen;
- me->_internal_draw_ellipse = _cmd_draw_ellipse;
- me->_internal_draw_image = _cmd_draw_image;
- me->_internal_draw_image_part = _cmd_draw_image_part;
- me->_internal_draw_line = _cmd_draw_line;
- me->_internal_draw_rectangle = _cmd_draw_rectangle;
- me->_internal_draw_surface = _cmd_draw_surface;
- me->_internal_draw_surface_part = _cmd_draw_surface_part;
- me->_internal_handle_io = _cmd_handle_io;
- me->_internal_image_from_surface = _cmd_image_from_surface;
- me->_internal_image_height = _cmd_image_height;
- me->_internal_image_load = _cmd_image_load;
- me->_internal_image_load_mem = _cmd_image_load_mem;
- me->_internal_image_unload = _cmd_image_unload;
- me->_internal_image_width = _cmd_image_width;
- me->_internal_repaint = _cmd_repaint;
- me->_internal_sound_getlength = _cmd_sound_getlength;
- me->_internal_sound_getsamplerate = _cmd_sound_getsamplerate;
- me->_internal_sound_load = _cmd_sound_load;
- me->_internal_sound_load_mem = _cmd_sound_load_mem;
- me->_internal_sound_play = _cmd_sound_play;
- me->_internal_sound_unload = _cmd_sound_unload;
- me->_internal_surface_create = _cmd_surface_create;
- me->_internal_surface_free = _cmd_surface_free;
- me->_internal_surface_from_image = _cmd_surface_from_image;
- me->_internal_surface_height = _cmd_surface_height;
- me->_internal_surface_width = _cmd_surface_width;
- me->_internal_cleanup = _cmd_cleanup;
- me->_internal_init_sound = _cmd_init_sound;
- me->_internal_sound_set_callback = _cmd_sound_set_callback;
- me->_internal_set_caption = _cmd_set_caption;
- me->EventInfo.Mouse.Button.Left = VK_LBUTTON;
- me->EventInfo.Mouse.Button.Middle = VK_MBUTTON;
- me->EventInfo.Mouse.Button.Right = VK_RBUTTON;
- me->EventInfo.Mouse.Button.X1 =
- me->EventInfo.Mouse.Button.X2 =
- me->EventInfo.Mouse.Button.WheelUp =
- me->EventInfo.Mouse.Button.WheelDown = 0;
- me->EventInfo.Keyboard.Key.Escape = VK_ESCAPE;
- me->EventInfo.Keyboard.Key.F1 = VK_F1;
- me->EventInfo.Keyboard.Key.F2 = VK_F2;
- me->EventInfo.Keyboard.Key.F3 = VK_F3;
- me->EventInfo.Keyboard.Key.F4 = VK_F4;
- me->EventInfo.Keyboard.Key.F5 = VK_F5;
- me->EventInfo.Keyboard.Key.F6 = VK_F6;
- me->EventInfo.Keyboard.Key.F7 = VK_F7;
- me->EventInfo.Keyboard.Key.F8 = VK_F8;
- me->EventInfo.Keyboard.Key.F9 = VK_F9;
- me->EventInfo.Keyboard.Key.F10 = VK_F10;
- me->EventInfo.Keyboard.Key.F11 = VK_F11;
- me->EventInfo.Keyboard.Key.F12 = VK_F12;
- me->EventInfo.Keyboard.Key.F13 = VK_F13;
- me->EventInfo.Keyboard.Key.F14 = VK_F14;
- me->EventInfo.Keyboard.Key.F15 = VK_F15;
- me->EventInfo.Keyboard.Key.F16 = VK_F16;
- me->EventInfo.Keyboard.Key.F17 = VK_F17;
- me->EventInfo.Keyboard.Key.F18 = VK_F18;
- me->EventInfo.Keyboard.Key.F19 = VK_F19;
- me->EventInfo.Keyboard.Key.F20 = VK_F20;
- me->EventInfo.Keyboard.Key.PrintScreen = VK_PRINT;
- me->EventInfo.Keyboard.Key.ScrollLock = VK_SCROLL;
- me->EventInfo.Keyboard.Key.Pause = VK_PAUSE;
- me->EventInfo.Keyboard.Key.Tilde = 0;
- me->EventInfo.Keyboard.Key.K_1 = '1';
- me->EventInfo.Keyboard.Key.K_2 = '2';
- me->EventInfo.Keyboard.Key.K_3 = '3';
- me->EventInfo.Keyboard.Key.K_4 = '4';
- me->EventInfo.Keyboard.Key.K_5 = '5';
- me->EventInfo.Keyboard.Key.K_6 = '6';
- me->EventInfo.Keyboard.Key.K_7 = '7';
- me->EventInfo.Keyboard.Key.K_8 = '8';
- me->EventInfo.Keyboard.Key.K_9 = '9';
- me->EventInfo.Keyboard.Key.K_0 = '0';
- me->EventInfo.Keyboard.Key.Dash = VK_SUBTRACT;
- me->EventInfo.Keyboard.Key.Equals = 0;
- me->EventInfo.Keyboard.Key.Backspace = VK_BACK;
- me->EventInfo.Keyboard.Key.Tab = VK_TAB;
- me->EventInfo.Keyboard.Key.Q = 'Q';
- me->EventInfo.Keyboard.Key.W = 'W';
- me->EventInfo.Keyboard.Key.E = 'E';
- me->EventInfo.Keyboard.Key.R = 'R';
- me->EventInfo.Keyboard.Key.T = 'T';
- me->EventInfo.Keyboard.Key.Y = 'Y';
- me->EventInfo.Keyboard.Key.U = 'U';
- me->EventInfo.Keyboard.Key.I = 'I';
- me->EventInfo.Keyboard.Key.O = 'O';
- me->EventInfo.Keyboard.Key.P = 'P';
- me->EventInfo.Keyboard.Key.BracketOpen = VK_OEM_4;
- me->EventInfo.Keyboard.Key.BracketClosed = VK_OEM_6;
- me->EventInfo.Keyboard.Key.FSlash = VK_OEM_5;
- me->EventInfo.Keyboard.Key.ForwardSlash = VK_OEM_5;
- me->EventInfo.Keyboard.Key.CapsLock = VK_CAPITAL;
- me->EventInfo.Keyboard.Key.A = 'A';
- me->EventInfo.Keyboard.Key.S = 'S';
- me->EventInfo.Keyboard.Key.D = 'D';
- me->EventInfo.Keyboard.Key.F = 'F';
- me->EventInfo.Keyboard.Key.G = 'G';
- me->EventInfo.Keyboard.Key.H = 'H';
- me->EventInfo.Keyboard.Key.J = 'J';
- me->EventInfo.Keyboard.Key.K = 'K';
- me->EventInfo.Keyboard.Key.L = 'L';
- me->EventInfo.Keyboard.Key.Colon = VK_OEM_1;
- me->EventInfo.Keyboard.Key.Quote = VK_OEM_7;
- me->EventInfo.Keyboard.Key.Enter = VK_RETURN;
- me->EventInfo.Keyboard.Key.LShift = VK_LSHIFT;
- me->EventInfo.Keyboard.Key.Z = 'Z';
- me->EventInfo.Keyboard.Key.X = 'X';
- me->EventInfo.Keyboard.Key.C = 'C';
- me->EventInfo.Keyboard.Key.V = 'V';
- me->EventInfo.Keyboard.Key.B = 'B';
- me->EventInfo.Keyboard.Key.N = 'N';
- me->EventInfo.Keyboard.Key.M = 'M';
- me->EventInfo.Keyboard.Key.Comma = 0;//VK_OEM_COMMA;
- me->EventInfo.Keyboard.Key.Period = 0;//VK_OEM_PERIOD;
- me->EventInfo.Keyboard.Key.Slash = 0;//VK_OEM_2;
- me->EventInfo.Keyboard.Key.RShift = VK_RSHIFT;
- me->EventInfo.Keyboard.Key.LControl = VK_LCONTROL;
- me->EventInfo.Keyboard.Key.LAlt = VK_LMENU;
- me->EventInfo.Keyboard.Key.Space = VK_SPACE;
- me->EventInfo.Keyboard.Key.RAlt = VK_RMENU;
- me->EventInfo.Keyboard.Key.RControl = VK_RCONTROL;
- me->EventInfo.Keyboard.Key.Insert = VK_INSERT;
- me->EventInfo.Keyboard.Key.Home = VK_HOME;
- me->EventInfo.Keyboard.Key.PageUp = VK_PRIOR;
- me->EventInfo.Keyboard.Key.Delete = VK_DELETE;
- me->EventInfo.Keyboard.Key.End = VK_END;
- me->EventInfo.Keyboard.Key.PageDown = VK_NEXT;
- me->EventInfo.Keyboard.Key.NumLock = VK_NUMLOCK;
- me->EventInfo.Keyboard.Key.NumSlash = VK_OEM_2;
- me->EventInfo.Keyboard.Key.NumStar = VK_OEM_CLEAR;
- me->EventInfo.Keyboard.Key.NumMinus = 0;//VK_OEM_MINUS;
- me->EventInfo.Keyboard.Key.Num7 = VK_NUMPAD7;
- me->EventInfo.Keyboard.Key.Num8 = VK_NUMPAD8;
- me->EventInfo.Keyboard.Key.Num9 = VK_NUMPAD9;
- me->EventInfo.Keyboard.Key.NumPlus = 0;//VK_OEM_PLUS;
- me->EventInfo.Keyboard.Key.Num4 = VK_NUMPAD4;
- me->EventInfo.Keyboard.Key.Num5 = VK_NUMPAD5;
- me->EventInfo.Keyboard.Key.Num6 = VK_NUMPAD6;
- me->EventInfo.Keyboard.Key.Num1 = VK_NUMPAD1;
- me->EventInfo.Keyboard.Key.Num2 = VK_NUMPAD2;
- me->EventInfo.Keyboard.Key.Num3 = VK_NUMPAD3;
- me->EventInfo.Keyboard.Key.NumEnter = VK_RETURN;
- me->EventInfo.Keyboard.Key.Num0 = VK_NUMPAD0;
- me->EventInfo.Keyboard.Key.Up = VK_UP;
- me->EventInfo.Keyboard.Key.Down = VK_DOWN;
- me->EventInfo.Keyboard.Key.Left = VK_LEFT;
- me->EventInfo.Keyboard.Key.Right = VK_RIGHT;
- me->EventInfo.Keyboard.Key.NumPeriod = 0;
- _CMD_KEYBUF(me) = (char*) malloc( 1000 );
- for( int i = 0; i < 1000; i ++ ){
- _CMD_KEYBUF(me)[i] = 0;
- }
- }
- void _cmd_handle_io ( Context* me )
- {
- }
- void _cmd_handle_io_thread ( void* vme )
- {
- Context* me = (Context*) vme;
- while( true ){
- Sleep(1);
- int* beg = &(me->EventInfo.Keyboard.Key.F13);
- int* last = &(me->EventInfo.Keyboard.Key.NumPeriod);
- int i = 0;
- while( beg != last ){
- if( _CMD_KEYBUF(me)[i] != ( abs(GetKeyState( *beg )) > 100 ) ){
- _CMD_KEYBUF(me)[i] = ( abs(GetKeyState( *beg )) > 100 );
- if( _CMD_KEYBUF(me)[i] == 0 )
- me->listener_push_event( me->EventInfo.Type.Keyboard, me->EventInfo.Keyboard.Type.KeyUp, 2, *beg, *beg );
- else
- me->listener_push_event( me->EventInfo.Type.Keyboard, me->EventInfo.Keyboard.Type.KeyDown, 2, *beg, *beg );
- }
- i++;
- beg ++;
- }
- }
- }
- void _cmd_create_screen ( Context* me, int width, int height, bool fullscreen, bool border, bool resizable )
- {
- HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE) ;
- COORD size = { width, height } ;
- SetConsoleScreenBufferSize( hStdout, size );
- _CMD_SCREEN(me) = (int*) malloc( width * height * sizeof( int ) );
- memset( _CMD_SCREEN(me), 0, width * height * sizeof( int ) );
- _CMD_SCREEN2(me) = (int*) malloc( width * height * sizeof( int ) );
- memset( _CMD_SCREEN2(me), 0, width * height * sizeof( int ) );
- _CMD_SCREENWID(me) = width;
- _CMD_SCREENHIG(me) = height;
- _beginthread( _cmd_handle_io_thread, 0, (void*) me );
- }
- Context::Image* _cmd_image_load ( Context* me, const char* fname )
- {
- }
- Context::Image* _cmd_image_load_mem ( Context* me, void* mem, int len )
- {
- }
- Context::Surface* _cmd_surface_create ( Context* me, int w, int h)
- {
- void* surf = malloc( w*h );
- return me->push_surface( surf );
- }
- Context::Surface* _cmd_surface_from_image ( Context* me, Context::Image* in)
- {
- }
- Context::Image* _cmd_image_from_surface ( Context* me, Context::Image* in)
- {
- }
- Context::Sound* _cmd_sound_load ( Context* me, const char* fname )
- {
- }
- Context::Sound* _cmd_sound_load_mem ( Context* me, void*, int len )
- {
- }
- int _cmd_sound_unload ( Context* me, Context::Sound*)
- {
- }
- int _cmd_image_unload ( Context* me, Context::Image* img)
- {
- free( img->getdata() );
- return true;
- }
- int _cmd_surface_free ( Context* me, Context::Surface* img)
- {
- free( img->getdata() );
- return true;
- }
- void _cmd_draw_rectangle ( Context* me, int x, int y, int w, int h, Context::Color color, bool filled )
- {
- bool intense = (color.r > 200 || color.g > 200 || color.b > 200 );
- int attrib = ( BACKGROUND_BLUE | FOREGROUND_BLUE ) * ( color.b > 25 ) |
- ( BACKGROUND_RED | FOREGROUND_RED ) * ( color.r > 25 ) |
- ( BACKGROUND_GREEN| FOREGROUND_GREEN) * ( color.g > 25 ) |
- ( FOREGROUND_INTENSITY | BACKGROUND_INTENSITY ) * intense;
- for( int i = 0; i < h; i ++ ){
- for( int j = 0; j < w; j ++ )
- _CMD_SCREEN2(me)[(x + j)+(y + i)*_CMD_SCREENWID(me)] = attrib;
- }
- }
- void _cmd_draw_line ( Context* me, int x1, int y1, int x2, int y2, Context::Color color )
- {
- }
- void _cmd_draw_circle ( Context* me, int x, int y, int r, Context::Color color, bool filled )
- {
- }
- void _cmd_draw_ellipse ( Context* me, int x1, int y1, int x2, int y2, Context::Color color, bool filled )
- {
- }
- void _cmd_draw_image ( Context* me, int x, int y, Context::Image* img )
- {
- }
- void _cmd_draw_image_part ( Context* me, int x, int y, int left, int top, int w, int h, Context::Image* img )
- {
- }
- void _cmd_draw_surface ( Context* me, int x, int y, Context::Surface* img )
- {
- }
- void _cmd_draw_surface_part ( Context* me, int x, int y, int left, int top, int w, int h, Context::Surface* img )
- {
- }
- int _cmd_sound_play ( Context* me, Context::Sound* )
- {
- }
- void _cmd_repaint ( Context* me, int x, int y, int w, int h )
- {
- HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE) ;
- COORD position = { x, y } ;
- SetConsoleCursorPosition( hStdout, position ) ;
- //SetConsoleTextAttribute( hStdout, attrib );
- //int jm = min( h, _CMD_SCREENHIG(me) - y );
- //int im = min( w, _CMD_SCREENWID(me) - x );
- for( int j = 0; j < _CMD_SCREENHIG(me); j ++ ){
- for( int i = 0; i < _CMD_SCREENWID(me); i ++ ){
- if( _CMD_SCREEN(me)[i+j*_CMD_SCREENWID(me)] != _CMD_SCREEN2(me)[i+j*_CMD_SCREENWID(me)] ){
- _CMD_SCREEN(me)[i+j*_CMD_SCREENWID(me)] = _CMD_SCREEN2(me)[i+j*_CMD_SCREENWID(me)];
- position = { i, j } ;
- SetConsoleCursorPosition( hStdout, position ) ;
- SetConsoleTextAttribute( hStdout, _CMD_SCREEN(me)[i+j*_CMD_SCREENWID(me)] );
- putchar(' ');
- }
- }
- }
- }
- int _cmd_image_width ( Context::Image* me )
- {
- }
- int _cmd_image_height ( Context::Image* me )
- {
- }
- int _cmd_sound_getlength ( Context::Sound* me )
- {
- }
- int _cmd_sound_getsamplerate ( Context::Sound* me )
- {
- }
- int _cmd_surface_width ( Context::Surface* me )
- {
- }
- int _cmd_surface_height ( Context::Surface* me )
- {
- }
- void _cmd_cleanup ( Context* me )
- {
- }
- void _cmd_audiomixercallback(void* userdata, unsigned char *stream, int len)
- {
- }
- int _cmd_init_sound ( Context* me, int freq, int rate, int bitrate ) //bitrate & 0x80 equals whether or not it's a signed value
- {
- }
- void _cmd_sound_set_callback ( Context* me, void* userdata, void (*audiomixercallbacka)(void*,unsigned char *stream, int len) )
- {
- }
- void _cmd_set_caption ( Context* me, char* title, char* icon )
- {
- SetConsoleTitle( title );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement