Advertisement
Aslai

media CMD

Dec 23rd, 2011
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 14.22 KB | None | 0 0
  1. #include "engine/media.h"
  2. #include "engine/mediaCMD.h"
  3.  
  4. void _cmd_init ( Context* me )
  5. {
  6.     me->_internal_draw_circle           = _cmd_draw_circle;
  7.     me->_internal_create_screen         = _cmd_create_screen;
  8.     me->_internal_draw_ellipse          = _cmd_draw_ellipse;
  9.     me->_internal_draw_image            = _cmd_draw_image;
  10.     me->_internal_draw_image_part       = _cmd_draw_image_part;
  11.     me->_internal_draw_line             = _cmd_draw_line;
  12.     me->_internal_draw_rectangle        = _cmd_draw_rectangle;
  13.     me->_internal_draw_surface          = _cmd_draw_surface;
  14.     me->_internal_draw_surface_part     = _cmd_draw_surface_part;
  15.     me->_internal_handle_io             = _cmd_handle_io;
  16.     me->_internal_image_from_surface    = _cmd_image_from_surface;
  17.     me->_internal_image_height          = _cmd_image_height;
  18.     me->_internal_image_load            = _cmd_image_load;
  19.     me->_internal_image_load_mem        = _cmd_image_load_mem;
  20.     me->_internal_image_unload          = _cmd_image_unload;
  21.     me->_internal_image_width           = _cmd_image_width;
  22.     me->_internal_repaint               = _cmd_repaint;
  23.     me->_internal_sound_getlength       = _cmd_sound_getlength;
  24.     me->_internal_sound_getsamplerate   = _cmd_sound_getsamplerate;
  25.     me->_internal_sound_load            = _cmd_sound_load;
  26.     me->_internal_sound_load_mem        = _cmd_sound_load_mem;
  27.     me->_internal_sound_play            = _cmd_sound_play;
  28.     me->_internal_sound_unload          = _cmd_sound_unload;
  29.     me->_internal_surface_create        = _cmd_surface_create;
  30.     me->_internal_surface_free          = _cmd_surface_free;
  31.     me->_internal_surface_from_image    = _cmd_surface_from_image;
  32.     me->_internal_surface_height        = _cmd_surface_height;
  33.     me->_internal_surface_width         = _cmd_surface_width;
  34.     me->_internal_cleanup               = _cmd_cleanup;
  35.     me->_internal_init_sound            = _cmd_init_sound;
  36.     me->_internal_sound_set_callback    = _cmd_sound_set_callback;
  37.     me->_internal_set_caption           = _cmd_set_caption;
  38.  
  39.     me->EventInfo.Mouse.Button.Left          = VK_LBUTTON;
  40.     me->EventInfo.Mouse.Button.Middle        = VK_MBUTTON;
  41.     me->EventInfo.Mouse.Button.Right         = VK_RBUTTON;
  42.     me->EventInfo.Mouse.Button.X1            =
  43.     me->EventInfo.Mouse.Button.X2            =
  44.     me->EventInfo.Mouse.Button.WheelUp       =
  45.     me->EventInfo.Mouse.Button.WheelDown     = 0;
  46.  
  47.  
  48.     me->EventInfo.Keyboard.Key.Escape        = VK_ESCAPE;
  49.     me->EventInfo.Keyboard.Key.F1            = VK_F1;
  50.     me->EventInfo.Keyboard.Key.F2            = VK_F2;
  51.     me->EventInfo.Keyboard.Key.F3            = VK_F3;
  52.     me->EventInfo.Keyboard.Key.F4            = VK_F4;
  53.     me->EventInfo.Keyboard.Key.F5            = VK_F5;
  54.     me->EventInfo.Keyboard.Key.F6            = VK_F6;
  55.     me->EventInfo.Keyboard.Key.F7            = VK_F7;
  56.     me->EventInfo.Keyboard.Key.F8            = VK_F8;
  57.     me->EventInfo.Keyboard.Key.F9            = VK_F9;
  58.     me->EventInfo.Keyboard.Key.F10           = VK_F10;
  59.     me->EventInfo.Keyboard.Key.F11           = VK_F11;
  60.     me->EventInfo.Keyboard.Key.F12           = VK_F12;
  61.     me->EventInfo.Keyboard.Key.F13           = VK_F13;
  62.     me->EventInfo.Keyboard.Key.F14           = VK_F14;
  63.     me->EventInfo.Keyboard.Key.F15           = VK_F15;
  64.     me->EventInfo.Keyboard.Key.F16           = VK_F16;
  65.     me->EventInfo.Keyboard.Key.F17           = VK_F17;
  66.     me->EventInfo.Keyboard.Key.F18           = VK_F18;
  67.     me->EventInfo.Keyboard.Key.F19           = VK_F19;
  68.     me->EventInfo.Keyboard.Key.F20           = VK_F20;
  69.     me->EventInfo.Keyboard.Key.PrintScreen   = VK_PRINT;
  70.     me->EventInfo.Keyboard.Key.ScrollLock    = VK_SCROLL;
  71.     me->EventInfo.Keyboard.Key.Pause         = VK_PAUSE;
  72.     me->EventInfo.Keyboard.Key.Tilde         = 0;
  73.     me->EventInfo.Keyboard.Key.K_1           = '1';
  74.     me->EventInfo.Keyboard.Key.K_2           = '2';
  75.     me->EventInfo.Keyboard.Key.K_3           = '3';
  76.     me->EventInfo.Keyboard.Key.K_4           = '4';
  77.     me->EventInfo.Keyboard.Key.K_5           = '5';
  78.     me->EventInfo.Keyboard.Key.K_6           = '6';
  79.     me->EventInfo.Keyboard.Key.K_7           = '7';
  80.     me->EventInfo.Keyboard.Key.K_8           = '8';
  81.     me->EventInfo.Keyboard.Key.K_9           = '9';
  82.     me->EventInfo.Keyboard.Key.K_0           = '0';
  83.     me->EventInfo.Keyboard.Key.Dash          = VK_SUBTRACT;
  84.     me->EventInfo.Keyboard.Key.Equals        = 0;
  85.     me->EventInfo.Keyboard.Key.Backspace     = VK_BACK;
  86.     me->EventInfo.Keyboard.Key.Tab           = VK_TAB;
  87.     me->EventInfo.Keyboard.Key.Q             = 'Q';
  88.     me->EventInfo.Keyboard.Key.W             = 'W';
  89.     me->EventInfo.Keyboard.Key.E             = 'E';
  90.     me->EventInfo.Keyboard.Key.R             = 'R';
  91.     me->EventInfo.Keyboard.Key.T             = 'T';
  92.     me->EventInfo.Keyboard.Key.Y             = 'Y';
  93.     me->EventInfo.Keyboard.Key.U             = 'U';
  94.     me->EventInfo.Keyboard.Key.I             = 'I';
  95.     me->EventInfo.Keyboard.Key.O             = 'O';
  96.     me->EventInfo.Keyboard.Key.P             = 'P';
  97.     me->EventInfo.Keyboard.Key.BracketOpen   = VK_OEM_4;
  98.     me->EventInfo.Keyboard.Key.BracketClosed = VK_OEM_6;
  99.     me->EventInfo.Keyboard.Key.FSlash        = VK_OEM_5;
  100.     me->EventInfo.Keyboard.Key.ForwardSlash  = VK_OEM_5;
  101.     me->EventInfo.Keyboard.Key.CapsLock      = VK_CAPITAL;
  102.     me->EventInfo.Keyboard.Key.A             = 'A';
  103.     me->EventInfo.Keyboard.Key.S             = 'S';
  104.     me->EventInfo.Keyboard.Key.D             = 'D';
  105.     me->EventInfo.Keyboard.Key.F             = 'F';
  106.     me->EventInfo.Keyboard.Key.G             = 'G';
  107.     me->EventInfo.Keyboard.Key.H             = 'H';
  108.     me->EventInfo.Keyboard.Key.J             = 'J';
  109.     me->EventInfo.Keyboard.Key.K             = 'K';
  110.     me->EventInfo.Keyboard.Key.L             = 'L';
  111.     me->EventInfo.Keyboard.Key.Colon         = VK_OEM_1;
  112.     me->EventInfo.Keyboard.Key.Quote         = VK_OEM_7;
  113.     me->EventInfo.Keyboard.Key.Enter         = VK_RETURN;
  114.     me->EventInfo.Keyboard.Key.LShift        = VK_LSHIFT;
  115.     me->EventInfo.Keyboard.Key.Z             = 'Z';
  116.     me->EventInfo.Keyboard.Key.X             = 'X';
  117.     me->EventInfo.Keyboard.Key.C             = 'C';
  118.     me->EventInfo.Keyboard.Key.V             = 'V';
  119.     me->EventInfo.Keyboard.Key.B             = 'B';
  120.     me->EventInfo.Keyboard.Key.N             = 'N';
  121.     me->EventInfo.Keyboard.Key.M             = 'M';
  122.     me->EventInfo.Keyboard.Key.Comma         = 0;//VK_OEM_COMMA;
  123.     me->EventInfo.Keyboard.Key.Period        = 0;//VK_OEM_PERIOD;
  124.     me->EventInfo.Keyboard.Key.Slash         = 0;//VK_OEM_2;
  125.     me->EventInfo.Keyboard.Key.RShift        = VK_RSHIFT;
  126.     me->EventInfo.Keyboard.Key.LControl      = VK_LCONTROL;
  127.     me->EventInfo.Keyboard.Key.LAlt          = VK_LMENU;
  128.     me->EventInfo.Keyboard.Key.Space         = VK_SPACE;
  129.     me->EventInfo.Keyboard.Key.RAlt          = VK_RMENU;
  130.     me->EventInfo.Keyboard.Key.RControl      = VK_RCONTROL;
  131.     me->EventInfo.Keyboard.Key.Insert        = VK_INSERT;
  132.     me->EventInfo.Keyboard.Key.Home          = VK_HOME;
  133.     me->EventInfo.Keyboard.Key.PageUp        = VK_PRIOR;
  134.     me->EventInfo.Keyboard.Key.Delete        = VK_DELETE;
  135.     me->EventInfo.Keyboard.Key.End           = VK_END;
  136.     me->EventInfo.Keyboard.Key.PageDown      = VK_NEXT;
  137.     me->EventInfo.Keyboard.Key.NumLock       = VK_NUMLOCK;
  138.     me->EventInfo.Keyboard.Key.NumSlash      = VK_OEM_2;
  139.     me->EventInfo.Keyboard.Key.NumStar       = VK_OEM_CLEAR;
  140.     me->EventInfo.Keyboard.Key.NumMinus      = 0;//VK_OEM_MINUS;
  141.     me->EventInfo.Keyboard.Key.Num7          = VK_NUMPAD7;
  142.     me->EventInfo.Keyboard.Key.Num8          = VK_NUMPAD8;
  143.     me->EventInfo.Keyboard.Key.Num9          = VK_NUMPAD9;
  144.     me->EventInfo.Keyboard.Key.NumPlus       = 0;//VK_OEM_PLUS;
  145.     me->EventInfo.Keyboard.Key.Num4          = VK_NUMPAD4;
  146.     me->EventInfo.Keyboard.Key.Num5          = VK_NUMPAD5;
  147.     me->EventInfo.Keyboard.Key.Num6          = VK_NUMPAD6;
  148.     me->EventInfo.Keyboard.Key.Num1          = VK_NUMPAD1;
  149.     me->EventInfo.Keyboard.Key.Num2          = VK_NUMPAD2;
  150.     me->EventInfo.Keyboard.Key.Num3          = VK_NUMPAD3;
  151.     me->EventInfo.Keyboard.Key.NumEnter      = VK_RETURN;
  152.     me->EventInfo.Keyboard.Key.Num0          = VK_NUMPAD0;
  153.     me->EventInfo.Keyboard.Key.Up            = VK_UP;
  154.     me->EventInfo.Keyboard.Key.Down          = VK_DOWN;
  155.     me->EventInfo.Keyboard.Key.Left          = VK_LEFT;
  156.     me->EventInfo.Keyboard.Key.Right         = VK_RIGHT;
  157.     me->EventInfo.Keyboard.Key.NumPeriod     = 0;
  158.     _CMD_KEYBUF(me) = (char*) malloc( 1000 );
  159.     for( int i = 0; i < 1000; i ++ ){
  160.         _CMD_KEYBUF(me)[i] = 0;
  161.     }
  162. }
  163.  
  164. void _cmd_handle_io ( Context* me )
  165. {
  166.  
  167. }
  168. void _cmd_handle_io_thread ( void* vme )
  169. {
  170.     Context* me = (Context*) vme;
  171.     while( true ){
  172.         Sleep(1);
  173.         int* beg = &(me->EventInfo.Keyboard.Key.F13);
  174.         int* last = &(me->EventInfo.Keyboard.Key.NumPeriod);
  175.         int i = 0;
  176.         while( beg != last ){
  177.             if( _CMD_KEYBUF(me)[i] != ( abs(GetKeyState( *beg )) > 100 ) ){
  178.                 _CMD_KEYBUF(me)[i] = ( abs(GetKeyState( *beg )) > 100 );
  179.                 if( _CMD_KEYBUF(me)[i] == 0 )
  180.                     me->listener_push_event( me->EventInfo.Type.Keyboard, me->EventInfo.Keyboard.Type.KeyUp, 2, *beg, *beg );
  181.                 else
  182.                     me->listener_push_event( me->EventInfo.Type.Keyboard, me->EventInfo.Keyboard.Type.KeyDown, 2, *beg, *beg );
  183.             }
  184.             i++;
  185.             beg ++;
  186.         }
  187.     }
  188. }
  189.  
  190. void _cmd_create_screen ( Context* me, int width, int height, bool fullscreen, bool border, bool resizable )
  191. {
  192.     HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE) ;
  193.     COORD size = { width, height } ;
  194.     SetConsoleScreenBufferSize( hStdout, size );
  195.     _CMD_SCREEN(me) = (int*) malloc( width * height * sizeof( int ) );
  196.     memset( _CMD_SCREEN(me), 0, width * height * sizeof( int ) );
  197.     _CMD_SCREEN2(me) = (int*) malloc( width * height * sizeof( int ) );
  198.     memset( _CMD_SCREEN2(me), 0, width * height * sizeof( int ) );
  199.     _CMD_SCREENWID(me) = width;
  200.     _CMD_SCREENHIG(me) = height;
  201.     _beginthread( _cmd_handle_io_thread, 0, (void*) me );
  202. }
  203.  
  204. Context::Image* _cmd_image_load ( Context* me, const char* fname )
  205. {
  206.  
  207. }
  208.  
  209. Context::Image* _cmd_image_load_mem ( Context* me, void* mem, int len )
  210. {
  211.  
  212. }
  213.  
  214. Context::Surface* _cmd_surface_create ( Context* me, int w, int h)
  215. {
  216.     void* surf = malloc( w*h );
  217.     return me->push_surface( surf );
  218. }
  219.  
  220. Context::Surface* _cmd_surface_from_image ( Context* me, Context::Image* in)
  221. {
  222.  
  223. }
  224.  
  225. Context::Image* _cmd_image_from_surface ( Context* me, Context::Image* in)
  226. {
  227.  
  228. }
  229.  
  230. Context::Sound* _cmd_sound_load ( Context* me, const char* fname )
  231. {
  232.  
  233. }
  234.  
  235. Context::Sound* _cmd_sound_load_mem ( Context* me, void*, int len )
  236. {
  237.  
  238. }
  239.  
  240. int _cmd_sound_unload ( Context* me, Context::Sound*)
  241. {
  242.  
  243. }
  244.  
  245. int _cmd_image_unload ( Context* me, Context::Image* img)
  246. {
  247.     free( img->getdata() );
  248.     return true;
  249. }
  250.  
  251. int _cmd_surface_free ( Context* me, Context::Surface* img)
  252. {
  253.     free( img->getdata() );
  254.     return true;
  255. }
  256.  
  257. void _cmd_draw_rectangle ( Context* me, int x, int y, int w, int h, Context::Color color, bool filled )
  258. {
  259.     bool intense = (color.r > 200 || color.g > 200 || color.b > 200 );
  260.  
  261.     int attrib = ( BACKGROUND_BLUE | FOREGROUND_BLUE ) * ( color.b > 25 ) |
  262.                  ( BACKGROUND_RED  | FOREGROUND_RED  ) * ( color.r > 25 ) |
  263.                  ( BACKGROUND_GREEN| FOREGROUND_GREEN) * ( color.g > 25 ) |
  264.                  ( FOREGROUND_INTENSITY | BACKGROUND_INTENSITY ) * intense;
  265.     for( int i = 0; i < h; i ++ ){
  266.         for( int j = 0; j < w; j ++ )
  267.             _CMD_SCREEN2(me)[(x + j)+(y + i)*_CMD_SCREENWID(me)] = attrib;
  268.     }
  269. }
  270.  
  271. void _cmd_draw_line ( Context* me, int x1, int y1, int x2, int y2, Context::Color color )
  272. {
  273.  
  274. }
  275.  
  276. void _cmd_draw_circle ( Context* me, int x, int y, int r, Context::Color color, bool filled )
  277. {
  278.  
  279. }
  280.  
  281. void _cmd_draw_ellipse ( Context* me, int x1, int y1, int x2, int y2, Context::Color color, bool filled )
  282. {
  283.  
  284. }
  285.  
  286. void _cmd_draw_image ( Context* me, int x, int y, Context::Image* img )
  287. {
  288.  
  289. }
  290.  
  291. void _cmd_draw_image_part ( Context* me, int x, int y, int left, int top, int w, int h, Context::Image* img )
  292. {
  293.  
  294. }
  295.  
  296. void _cmd_draw_surface ( Context* me, int x, int y, Context::Surface* img )
  297. {
  298.  
  299. }
  300.  
  301. void _cmd_draw_surface_part ( Context* me, int x, int y, int left, int top, int w, int h, Context::Surface* img )
  302. {
  303.  
  304. }
  305.  
  306. int _cmd_sound_play ( Context* me, Context::Sound* )
  307. {
  308.  
  309. }
  310.  
  311. void _cmd_repaint ( Context* me, int x, int y, int w, int h )
  312. {
  313.     HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE) ;
  314.     COORD position = { x, y } ;
  315.     SetConsoleCursorPosition( hStdout, position ) ;
  316.     //SetConsoleTextAttribute( hStdout, attrib );
  317.     //int jm = min( h, _CMD_SCREENHIG(me) - y );
  318.     //int im = min( w, _CMD_SCREENWID(me) - x );
  319.  
  320.     for( int j = 0; j < _CMD_SCREENHIG(me); j ++ ){
  321.         for( int i = 0; i < _CMD_SCREENWID(me); i ++ ){
  322.             if( _CMD_SCREEN(me)[i+j*_CMD_SCREENWID(me)] != _CMD_SCREEN2(me)[i+j*_CMD_SCREENWID(me)] ){
  323.                 _CMD_SCREEN(me)[i+j*_CMD_SCREENWID(me)] = _CMD_SCREEN2(me)[i+j*_CMD_SCREENWID(me)];
  324.                 position = { i, j } ;
  325.                 SetConsoleCursorPosition( hStdout, position ) ;
  326.                 SetConsoleTextAttribute( hStdout, _CMD_SCREEN(me)[i+j*_CMD_SCREENWID(me)] );
  327.                 putchar(' ');
  328.             }
  329.         }
  330.     }
  331. }
  332.  
  333. int _cmd_image_width ( Context::Image* me )
  334. {
  335.  
  336. }
  337.  
  338. int _cmd_image_height ( Context::Image* me )
  339. {
  340.  
  341. }
  342.  
  343. int _cmd_sound_getlength ( Context::Sound* me )
  344. {
  345.  
  346. }
  347.  
  348. int _cmd_sound_getsamplerate ( Context::Sound* me )
  349. {
  350.  
  351. }
  352.  
  353. int _cmd_surface_width ( Context::Surface* me )
  354. {
  355.  
  356. }
  357.  
  358. int _cmd_surface_height ( Context::Surface* me )
  359. {
  360.  
  361. }
  362.  
  363. void _cmd_cleanup ( Context* me )
  364. {
  365.  
  366. }
  367.  
  368. void _cmd_audiomixercallback(void* userdata, unsigned char *stream, int len)
  369. {
  370.  
  371. }
  372.  
  373. int _cmd_init_sound ( Context* me, int freq, int rate, int bitrate ) //bitrate & 0x80 equals whether or not it's a signed value
  374. {
  375.  
  376. }
  377. void _cmd_sound_set_callback ( Context* me, void* userdata, void (*audiomixercallbacka)(void*,unsigned char *stream, int len) )
  378. {
  379.  
  380. }
  381. void _cmd_set_caption ( Context* me, char* title, char* icon )
  382. {
  383.     SetConsoleTitle( title );
  384. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement