summaryrefslogtreecommitdiffstats
path: root/test/copyrecttest.c
blob: 5521595d6d837ef7e25e6710fc2ce4fd82f2cb05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifdef __STRICT_ANSI__
#define _BSD_SOURCE
#endif
#include <rfb/rfb.h>
#include <math.h>

static void initBackground(rfbScreenInfoPtr server)
{
  unsigned int i,j;

  for(i=0;i<server->width;i++)
    for(j=0;j<server->height;j++) {
      server->frameBuffer[(j*server->width+i)*4+0]=i&0xff;
      server->frameBuffer[(j*server->width+i)*4+1]=j&0xff;
      server->frameBuffer[(j*server->width+i)*4+2]=(i*j)&0xff;
    }
}

int main(int argc,char** argv)
{             
  int width=400,height=300,w=20,x,y;
  double r,phi=0;
  
  rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,width,height,8,3,4);
  server->frameBuffer=(char*)malloc(width*height*4);
  initBackground(server);
  server->deferUpdateTime=0;
  rfbInitServer(server);

  r=0;
  while(1) {
    if(r<=0) {
      initBackground(server);
      rfbMarkRectAsModified(server,0,0,width,height);
      r=0.43;
      phi=0;
    } else {
      r-=0.0001;
      phi+=0.02;
      if(phi>2*M_PI)
	phi-=2*M_PI;
    }
    x=width*(0.5+cos(phi)*r);
    y=height*(0.5+sin(phi)*r);
    if(x>=0 && y>=0 && x+w<=width && y+w<=height) {
      unsigned int dx=width*0.5*(1-cos(phi)*r)-x,
      		dy=height*0.5*(1-sin(phi)*r)-y;
      rfbDoCopyRect(server,x,y,x+w,y+w,-dx,-dy);
    }
    rfbProcessEvents(server,50000);
  }
  return(0);
}