TX Library Help – Version: 00173a, Revision: 174
 ALL  Windows graphics in a sandbox

Example02/server.cpp

См. документацию.
00001 //{===========================================================================
00012 //}===========================================================================
00013 
00014 #include "proto.h"
00015 
00016 void NetPaint (TX_SOCKET paint_peer);
00017 
00018 void CursorDraw (NetCursor_t cursor, COLORREF color);
00019 void CursorMove (NetCursor_t* cursor);
00020 
00021 int main()
00022 {
00023 txCreateWindow (1024, 768);
00024 
00025 printf ("Searching for client...\n");
00026 
00027 TX_SOCKET paint_peer = txCreateSocket (TX_SERVER, "");
00028 
00029 printf ("Start draw meow.\n");
00030 
00031 if (txnAssert (paint_peer) == TXN_NOT_CREATED)
00032     {
00033     printf ("Can't create socket. Maybe, port are busy.\n");
00034     return -1;
00035     }
00036 
00037 NetPaint (paint_peer);
00038 
00039 return 0;
00040 }
00041 
00042 void NetPaint (TX_SOCKET paint_peer)
00043 {
00044 NetCursor_t cursor        = {100, 100, -1, -1, CUR_NOP};
00045 NetCursor_t peer_cursor   = {100, 100, -1, -1, CUR_NOP};
00046 
00047 while (!GetAsyncKeyState (VK_ESCAPE))
00048     {
00049     if (peer_cursor.action == CUR_EXIT)
00050         break;
00051 
00052     CursorDraw(cursor, TX_LIGHTGREEN);
00053     CursorDraw(peer_cursor, TX_LIGHTRED);
00054 
00055     CursorMove (&cursor);
00056 
00057     txSendTo    (paint_peer, &cursor     , sizeof(cursor));
00058     txRecvFrom  (paint_peer, &peer_cursor, sizeof(peer_cursor));
00059 
00060     txSleep (10);
00061     }
00062 
00063 cursor.action = CUR_EXIT;
00064 txSendTo (paint_peer, &cursor, sizeof(cursor));
00065 }
00066 
00067 void CursorMove(NetCursor_t* cursor)
00068 {
00069 cursor->old_x = cursor->x;
00070 cursor->old_y = cursor->y;
00071 
00072 cursor->x = txMouseX();
00073 cursor->y = txMouseY();
00074 
00075 if (txMouseButtons() == 1)
00076     cursor->action = CUR_DRAW;
00077 else
00078     cursor->action = CUR_NOP;
00079 }
00080 
00081 void CursorDraw (NetCursor_t cursor, COLORREF color)
00082 {
00083 txSetFillColor (color);
00084 txSetColor     (color, 10);
00085 
00086 if (cursor.action == CUR_DRAW)
00087     txLine (cursor.old_x, cursor.old_y, cursor.x, cursor.y);
00088 }