![]() |
TX Library Help – Version: 00173a, Revision: 174
|
00001 //{=========================================================================== 00014 //}=========================================================================== 00015 00016 #include "proto.h" 00017 00018 #define ANOTHER_PEER_IP "localhost" //Меняйте адрес тут :) 00019 00020 void NetPaint (TX_SOCKET paint_peer); 00021 00022 void CursorDraw (NetCursor_t cursor, COLORREF color); 00023 void CursorMove (NetCursor_t* cursor); 00024 00025 int main() 00026 { 00027 txCreateWindow (1024, 768); 00028 00029 printf ("Searching for server...\n"); 00030 00031 TX_SOCKET paint_peer = txCreateSocket (TX_CLIENT, ANOTHER_PEER_IP); 00032 00033 printf ("Start draw meow.\n"); 00034 00035 if (txnAssert (paint_peer) == TXN_NOT_CREATED) 00036 { 00037 printf ("Can't find server on this IP address.\n"); 00038 return -1; 00039 } 00040 00041 NetPaint (paint_peer); 00042 00043 return 0; 00044 } 00045 00046 void NetPaint (TX_SOCKET paint_peer) 00047 { 00048 NetCursor_t cursor = {100, 100, -1, -1, CUR_NOP}; 00049 NetCursor_t peer_cursor = {100, 100, -1, -1, CUR_NOP}; 00050 00051 while (!GetAsyncKeyState (VK_SPACE)) 00052 { 00053 if (peer_cursor.action == CUR_EXIT) 00054 break; 00055 00056 CursorDraw(cursor, TX_LIGHTGREEN); 00057 CursorDraw(peer_cursor, TX_LIGHTRED); 00058 00059 CursorMove (&cursor); 00060 00061 txRecvFrom (paint_peer, &peer_cursor, sizeof(peer_cursor)); 00062 txSendTo (paint_peer, &cursor , sizeof(cursor)); 00063 00064 txSleep (10); 00065 } 00066 00067 cursor.action = CUR_EXIT; 00068 txSendTo (paint_peer, &cursor, sizeof(cursor)); 00069 } 00070 00071 void CursorMove(NetCursor_t* cursor) 00072 { 00073 cursor->old_x = cursor->x; 00074 cursor->old_y = cursor->y; 00075 00076 cursor->x = txMouseX(); 00077 cursor->y = txMouseY(); 00078 00079 if (txMouseButtons() == 1) 00080 cursor->action = CUR_DRAW; 00081 else 00082 cursor->action = CUR_NOP; 00083 } 00084 00085 void CursorDraw (NetCursor_t cursor, COLORREF color) 00086 { 00087 txSetFillColor (color); 00088 txSetColor (color, 10); 00089 00090 if (cursor.action == 1) 00091 txLine (cursor.old_x, cursor.old_y, cursor.x, cursor.y); 00092 }