This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this software; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef WIN32
#define sleep Sleep
#else
#include <unistd.h>
#endif
#ifdef __IRIX__
#include <netdb.h>
#endif
#include <signal.h>
static const int bpp=4;
static int maxx=800, maxy=600;
static int maintain_connection = 1;
static void initBuffer(unsigned char* buffer)
{
int i,j;
for(j=0;j<maxy;++j) {
for(i=0;i<maxx;++i) {
buffer[(j*maxx+i)*bpp+0]=(i+j)*128/(maxx+maxy);
buffer[(j*maxx+i)*bpp+1]=i*128/maxx;
buffer[(j*maxx+i)*bpp+2]=j*256/maxy;
}
buffer[j*maxx*bpp+0]=0xff;
buffer[j*maxx*bpp+1]=0xff;
buffer[j*maxx*bpp+2]=0xff;
buffer[j*maxx*bpp+3]=0xff;
}
}
static void clientgone(rfbClientPtr cl)
{
free(cl->clientData);
cl->clientData = NULL;
}
{
cl->clientData = (
void*)calloc(
sizeof(
ClientData),1);
cl->clientGoneHook = clientgone;
}
static void newframebuffer(rfbScreenInfoPtr screen,
int width,
int height)
{
unsigned char *oldfb, *newfb;
oldfb = (unsigned char*)screen->frameBuffer;
newfb = (unsigned char*)malloc(maxx * maxy * bpp);
initBuffer(newfb);
free(oldfb);
}
static void drawline(unsigned char* buffer,int rowstride,int bpp,int x1,int y1,int x2,int y2)
{
int i,j;
i=x1-x2; j=y1-y2;
if(i==0 && j==0) {
for(i=0;i<bpp;i++)
buffer[y1*rowstride+x1*bpp+i]=0xff;
return;
}
if(i<0) i=-i;
if(j<0) j=-j;
if(i<j) {
if(y1>y2) { i=y2; y2=y1; y1=i; i=x2; x2=x1; x1=i; }
for(j=y1;j<=y2;j++)
for(i=0;i<bpp;i++)
buffer[j*rowstride+(x1+(j-y1)*(x2-x1)/(y2-y1))*bpp+i]=0xff;
} else {
if(x1>x2) { i=y2; y2=y1; y1=i; i=x2; x2=x1; x1=i; }
for(i=x1;i<=x2;i++)
for(j=0;j<bpp;j++)
buffer[(y1+(i-x1)*(y2-y1)/(x2-x1))*rowstride+i*bpp+j]=0xff;
}
}
static void doptr(
int buttonMask,
int x,
int y,rfbClientPtr cl)
{
if(
x>=0 &&
y>=0 &&
x<maxx &&
y<maxy) {
if(buttonMask) {
int i,j,x1,x2,y1,y2;
drawline((unsigned char*)cl->screen->frameBuffer,cl->screen->paddedWidthInBytes,bpp,
} else {
int w=cl->screen->paddedWidthInBytes;
x1=
x-buttonMask;
if(x1<0) x1=0;
x2=
x+buttonMask;
if(x2>maxx) x2=maxx;
y1=
y-buttonMask;
if(y1<0) y1=0;
y2=
y+buttonMask;
if(y2>maxy) y2=maxy;
for(i=x1*bpp;i<x2*bpp;i++)
for(j=y1;j<y2;j++)
cl->screen->frameBuffer[j*w+i]=(char)0xff;
}
}
}
}
#include "radon.h"
{
if(down) {
initBuffer((unsigned char*)cl->screen->frameBuffer);
}
else if (key ==
XK_Up) {
if (maxx < 1024) {
if (maxx < 800) {
newframebuffer(cl->screen, 800, 600);
} else {
newframebuffer(cl->screen, 1024, 768);
}
}
if (maxx > 640) {
if (maxx > 800) {
newframebuffer(cl->screen, 800, 600);
} else {
newframebuffer(cl->screen, 640, 480);
}
}
} else if(key>=' ' && key<0x100) {
cd->
oldx+=
rfbDrawCharWithClip(cl->screen,&radonFont,cd->
oldx,cd->
oldy,(
char)key,0,0,cl->screen->width,cl->screen->height,0x00ffffff,0x00ffffff);
}
}
}
#ifdef JUST_AN_EXAMPLE
static int exampleXCursorWidth=9,exampleXCursorHeight=7;
static char exampleXCursor[]=
" "
" xx xx "
" xx xx "
" xxx "
" xx xx "
" xx xx "
" ";
#endif
static void MakeRichCursor(rfbScreenInfoPtr rfbScreen)
{
int i,j,w=32,h=32;
rfbCursorPtr c;
char bitmap[]=
" "
" xxxxxx "
" xxxxxxxxxxxxxxxxx "
" xxxxxxxxxxxxxxxxxxxxxx "
" xxxxx xxxxxxxx xxxxxxxx "
" xxxxxxxxxxxxxxxxxxxxxxxxxxx "
" xxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
" xxxxx xxxxxxxxxxx xxxxxxx "
" xxxx xxxxxxxxx xxxxxx "
" xxxxx xxxxxxxxxxx xxxxxxx "
" xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
" xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
" xxxxxxxxxxxx xxxxxxxxxxxxxxx "
" xxxxxxxxxxxxxxxxxxxxxxxxxxxx "
" xxxxxxxxxxxxxxxxxxxxxxxxxxxx "
" xxxxxxxxxxx xxxxxxxxxxxxxx "
" xxxxxxxxxx xxxxxxxxxxxx "
" xxxxxxxxx xxxxxxxxx "
" xxxxxxxxxx xxxxxxxxx "
" xxxxxxxxxxxxxxxxxxx "
" xxxxxxxxxxxxxxxxxxx "
" xxxxxxxxxxxxxxxxxxx "
" xxxxxxxxxxxxxxxxx "
" xxxxxxxxxxxxxxx "
" xxxx xxxxxxxxxxxxx "
" xx x xxxxxxxxxxx "
" xxx xxxxxxxxxxx "
" xxxx xxxxxxxxxxx "
" xxxxxx xxxxxxxxxxxx "
" xxxxxxxxxxxxxxxxxxxxxx "
" xxxxxxxxxxxxxxxx "
" ";
c->xhot = 16; c->yhot = 24;
c->richSource = (unsigned char*)malloc(w*h*bpp);
if(!c->richSource)
return;
c->cleanupRichSource =
TRUE;
for(j=0;j<h;j++) {
for(i=0;i<w;i++) {
c->richSource[j*w*bpp+i*bpp+0]=i*0xff/w;
c->richSource[j*w*bpp+i*bpp+1]=(i+j)*0xff/(w+h);
c->richSource[j*w*bpp+i*bpp+2]=j*0xff/h;
c->richSource[j*w*bpp+i*bpp+3]=0;
}
}
}
maintain_connection = 0;
}
int main(
int argc,
char** argv)
{
rfbScreenInfoPtr rfbScreen =
rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp);
if(!rfbScreen)
return 1;
rfbScreen->desktopName = "LibVNCServer Example";
rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp);
rfbScreen->alwaysShared =
TRUE;
rfbScreen->ptrAddEvent = doptr;
rfbScreen->kbdAddEvent = dokey;
rfbScreen->newClientHook = newclient;
rfbScreen->httpDir = "../webclients";
rfbScreen->httpEnableProxyConnect =
TRUE;
initBuffer((unsigned char*)rfbScreen->frameBuffer);
rfbDrawString(rfbScreen,&radonFont,20,100,
"Hello, World!",0xffffff);
MakeRichCursor(rfbScreen);
#ifndef BACKGROUND_LOOP_TEST
#ifdef USE_OWN_LOOP
{
int i;
fprintf(stderr,"%d\r",i);
}
}
#else
#endif
#else
#if !defined(LIBVNCSERVER_HAVE_LIBPTHREAD) && !defined(LIBVNCSERVER_HAVE_WIN32THREADS)
#error "I need pthreads or win32 threads for that."
#endif
fprintf(stderr, "Running background loop...\n");
while (maintain_connection) {
sleep(5);
}
fprintf(stderr, "\nShutting down...\n");
#endif
free(rfbScreen->frameBuffer);
return(0);
}
void intHandler(int dummy)
int main(int argc, char **argv)
void rfbInitServer(rfbScreenInfoPtr rfbScreen)
void rfbRunEventLoop(rfbScreenInfoPtr screenInfo, long usec, rfbBool runInBackground)
int rfbDrawCharWithClip(rfbScreenInfoPtr rfbScreen, rfbFontDataPtr font, int x, int y, unsigned char c, int x1, int y1, int x2, int y2, rfbPixel colour, rfbPixel backColour)
if colour==backColour, background is transparent
void rfbCloseClient(rfbClientPtr cl)
void rfbMarkRectAsModified(rfbScreenInfoPtr rfbScreen, int x1, int y1, int x2, int y2)
void rfbShutdownServer(rfbScreenInfoPtr rfbScreen, rfbBool disconnectClients)
void rfbDefaultPtrAddEvent(int buttonMask, int x, int y, rfbClientPtr cl)
cursor handling for the pointer
void rfbScreenCleanup(rfbScreenInfoPtr screenInfo)
rfbScreenInfoPtr rfbGetScreen(int *argc, char **argv, int width, int height, int bitsPerSample, int samplesPerPixel, int bytesPerPixel)
rfbBool rfbIsActive(rfbScreenInfoPtr screenInfo)
rfbBool rfbProcessEvents(rfbScreenInfoPtr screenInfo, long usec)
void rfbDrawString(rfbScreenInfoPtr rfbScreen, rfbFontDataPtr font, int x, int y, const char *string, rfbPixel colour)
void rfbNewFramebuffer(rfbScreenInfoPtr rfbScreen, char *framebuffer, int width, int height, int bitsPerSample, int samplesPerPixel, int bytesPerPixel)
rfbCursorPtr rfbMakeXCursor(int width, int height, char *cursorString, char *maskString)
void rfbFontBBox(rfbFontDataPtr font, unsigned char c, int *x1, int *y1, int *x2, int *y2)