Beispiel #1
0
void XPlatformWindow::draw_text(const char* text, int x, int y) {
  XDrawImageString(_display, _xwindow, _gc, x, y, text, strlen(text));
}
Beispiel #2
0
static int XRotDrawHorizontalString(Display *dpy, XFontStruct *font, Drawable drawable, GC gc, int x, int y, const char *text, int len, int align, int bg)
{
  GC my_gc;
  int nl=1, i;
  int height;
  int xp, yp;
  char *str1, *str2, *str3;
  char *str2_a="\0", *str2_b="\n\0";
  int dir, asc, desc;
  XCharStruct overall;
  
  DEBUG_PRINT1("**\nHorizontal text.\n");
  
  /* this gc has similar properties to the user's gc (including stipple) */
  my_gc=XCreateGC(dpy, drawable, 0, 0);
  XCopyGC(dpy, gc, GCForeground|GCBackground|GCFunction|GCStipple|GCFillStyle| GCTileStipXOrigin|GCTileStipYOrigin|GCPlaneMask, my_gc);
  XSetFont(dpy, my_gc, font->fid);
  
  /* count number of sections in string */
  if(align!=XR_LEFT)
    for(i=0; i<len-1; i++)
      if(text[i]=='\n')
        nl++;
      
  /* ignore newline characters if not doing alignment */
  if(align==XR_LEFT)
    str2=str2_a;
  else
    str2=str2_b;
  
  /* overall font height */
  height=font->ascent+font->descent;
  
  /* y position */
  if(align==XR_TLEFT || align==XR_TCENTRE || align==XR_TRIGHT)
    yp=y+font->ascent;
  else if(align==XR_MLEFT || align==XR_MCENTRE || align==XR_MRIGHT)
    yp=y-nl*height/2+font->ascent;
  else if(align==XR_BLEFT || align==XR_BCENTRE || align==XR_BRIGHT)
    yp=y-nl*height+font->ascent;
  else
    yp=y;
  
  str1=my_strdup(text, len);
  if(str1==NULL)
    return 1;
  
  /* loop through each section in the string */
  str3=my_strtok(str1, str2);
  do 
  {
    int len3 = strlen(str3);
    XTextExtents(font, str3, len3, &dir, &asc, &desc, &overall);
    
    /* where to draw section in x ? */
    if(align==XR_TLEFT || align==XR_MLEFT || align==XR_BLEFT || align==XR_LEFT)
      xp=x;
    else if(align==XR_TCENTRE || align==XR_MCENTRE || align==XR_BCENTRE || align==XR_CENTRE)
      xp=x-overall.rbearing/2;
    else
      xp=x-overall.rbearing;
    
    /* draw string onto bitmap */
    if(!bg)
      XDrawString(dpy, drawable, my_gc, xp, yp, str3, len3);
    else
      XDrawImageString(dpy, drawable, my_gc, xp, yp, str3, len3);
    
    /* move to next line */
    yp+=height;
    
    str3=my_strtok((char *)NULL, str2);
  } while(str3!=NULL);
  
  free(str1);
  XFreeGC(dpy, my_gc);
  
  return 0;
}
Beispiel #3
0
void DrawText(char *string, int x, int y)
{
  XDrawImageString(display, window, drawgc, x, y, string, strlen(string));
}
Beispiel #4
0
/*
 * Draw string on specified location of the screen
 */
void DrawString(const char* msg, uint32_t length, uint32_t x, uint32_t y) {
XDrawImageString(dpy, mwWindow, copyGC, x, y, msg, length);
}
void hci_control_panel_power( int force_draw )
{
  int i;
  int temp_int;
  int power_status;
  int power_source;
  int fuel_level = -1;
  int empty_level;
  Pixel color;
  int width;
  int height;
  int x1, y1;
  int cylinder_width;
  int y_arc_top, y_arc_bottom, y_rec;
  int arc_height, rec_height;
  int arc_start_angle, arc_end_angle;
  XPoint X[6];
  char power_label [12];
  XFontStruct *fontinfo;
  hci_control_panel_object_t *rda;
  hci_control_panel_object_t *power;

  /* If RDA isn't connected, we don't know what is going on, so return. */

  if( ORPGRDA_get_wb_status( ORPGRDA_WBLNSTAT ) != RS_CONNECTED )
  {
    return;
  }

  /* Get latest power status. */

  power_status = ORPGRDA_get_status( RS_AUX_POWER_GEN_STATE );

  /* Determine power source. If power source is generator,
     get latest fuel level. */

  if( power_status & BIT_0_MASK )
  {
    power_source = AUXILLIARY_POWER;
    if( ORPGRDA_get_rda_config( NULL ) == ORPGRDA_ORDA_CONFIG )
    {
      fuel_level = hci_orda_pmd( CNVRTD_GEN_FUEL_LEVEL );
    }
    else
    {
      fuel_level = ( hci_rda_performance_data( GEN_FUEL_LEVEL ) - 51 )/204.0;
    }
  }
  else
  {
    power_source = UTILITY_POWER;
  }

  /* If something has changed (or we're being forced to redraw), redraw. */

  if( power_status != prev_power_status ||
      fuel_level != prev_fuel_level ||
      force_draw )
  {
    /* We use the RDA container object as a reference for placing
       the power source graphic. */

    rda = hci_control_panel_object( RDA_BUTTON );

    if( rda->widget == ( Widget ) NULL )
    {
      return;
    }

    power = hci_control_panel_object( POWER_OBJECT );

    /* We want to use scaled fonts so the graphic and labels can
       change with the window size. */

    fontinfo = hci_get_fontinfo( SCALED );
    height = fontinfo->ascent + fontinfo->descent;

    /* Define the position/size of the power source object based on
       the RDA container object. */

    power->pixel  = 5;
    power->scanl  = rda->scanl + rda->height/6;
    power->width  = rda->pixel - 20;
    power->height = 2*rda->height/3;

    /* Set font properties for drawing. */

    XSetFont( HCI_get_display(),
              hci_control_panel_gc(),
              hci_get_font( SCALED ) );

    /* If not on generator power... */
 
    if( power_source == UTILITY_POWER )
    {
      /* Draw box to hold power source icon. */

      XSetForeground( HCI_get_display(),
                      hci_control_panel_gc(),
                      hci_get_read_color( BUTTON_BACKGROUND ) );

      XFillRectangle( HCI_get_display(),
                      hci_control_panel_pixmap(),
                      hci_control_panel_gc(),
                      ( int ) power->pixel,
                      ( int ) power->scanl,
                      ( int ) power->width,
                      ( int ) power->height );

      /* For utility power, draw a pair of telephone poles with a
         set of wires connecting them.  Draw a line representing
         a wire from the farthest pole to the RDA box. */

      XSetForeground( HCI_get_display(),
                      hci_control_panel_gc(),
                      hci_get_read_color( BROWN ) );

      XFillRectangle( HCI_get_display(),
                      hci_control_panel_pixmap(),
                      hci_control_panel_gc(),
                      ( int ) ( power->pixel + power->width/2 ),
                      ( int ) ( power->scanl + power->height/8 ),
                      ( int ) ( power->width/3 ),
                      ( int ) ( hci_control_panel_3d()/3 ) );

      XFillRectangle( HCI_get_display(),
                      hci_control_panel_pixmap(),
                      hci_control_panel_gc(),
                      ( int ) power->pixel,
                      ( int ) ( power->scanl + power->height/2 ),
                      ( int ) ( power->width/3 ), 
                      ( int ) ( hci_control_panel_3d()/3 ) );

      temp_int = hci_control_panel_3d(); /* Prevent line wrapping. */

      XFillRectangle( HCI_get_display(),
                    hci_control_panel_pixmap(),
                    hci_control_panel_gc(),
                    ( int ) ( power->pixel + power->width/6 - temp_int/2 + 1 ),
                    ( int ) ( power->scanl + power->height/2 - temp_int ),
                    ( int ) ( hci_control_panel_3d()/2 ),
                    ( int ) ( power->height/2 ) );

      temp_int = hci_control_panel_3d()/2 + 1; /* Prevent line wrapping. */

      XFillRectangle( HCI_get_display(),
                    hci_control_panel_pixmap(), 
                    hci_control_panel_gc(),
                    ( int ) ( power->pixel + ( 4*power->width/6  ) - temp_int ),
                    ( int ) power->scanl,
                    ( int ) ( hci_control_panel_3d()/2 ),
                    ( int ) ( power->height/2 ) );

      XSetForeground( HCI_get_display(),
                      hci_control_panel_gc(),
                      hci_get_read_color( BLACK ) );

      for( i = 0; i <= power->width/3 + 1; i = i + power->width/9 )
      {
        XDrawLine( HCI_get_display(),
                   hci_control_panel_pixmap(),
                   hci_control_panel_gc(),
                   ( int ) ( power->pixel + i ),
                   ( int ) ( power->scanl + power->height/2 ),
                   ( int ) ( power->pixel + power->width/2 + i ),
                   ( int ) ( power->scanl + power->height/8 ) );
      }

      XDrawLine( HCI_get_display(),
                 hci_control_panel_pixmap(),
                 hci_control_panel_gc(),
                 (int) ( power->pixel + 5*power->width/6 ),
                 (int) power->scanl,
                 (int) rda->pixel,
                 (int) rda->scanl );

      /* Display textually the state of the auxilliary power generator. */

      XSetForeground( HCI_get_display(),
                      hci_control_panel_gc(),
                      hci_get_read_color( BUTTON_FOREGROUND ) );

      XSetBackground( HCI_get_display(),
                      hci_control_panel_gc(),
                      hci_get_read_color( BUTTON_BACKGROUND ) );

      /* Check the last RDA status message to see if the generator
         is on or off.  Display this information as a text string
         beneath the utility power icon. */

      if( power_status & BIT_2_MASK )
      {
        sprintf( power_label, "Gen On" );
      }
      else if( power_status & BIT_4_MASK )
      {
        sprintf( power_label, "Cmd Swtchvr" );
      }
      else
      {
        sprintf( power_label, "Gen Off" );
      }

      width  = XTextWidth( fontinfo, power_label, strlen( power_label ) );

      XDrawImageString( HCI_get_display(),
                        hci_control_panel_pixmap(),
                        hci_control_panel_gc(),
                        ( int ) ( power->pixel + ( power->width - width )/2 ),
                        ( int ) ( power->scanl + power->height - 2 ),
                        power_label,
                        strlen( power_label ) );
    }
    else
    {
      /* on generator power... */

      /* Draw box to hold power source icon. */

      XSetForeground( HCI_get_display(),
                      hci_control_panel_gc(),
                      hci_get_read_color( BUTTON_BACKGROUND ) );

      XFillRectangle( HCI_get_display(),
                      hci_control_panel_pixmap(),
                      hci_control_panel_gc(),
                      ( int ) power->pixel,
                      ( int ) power->scanl,
                      ( int ) power->width,
                      ( int ) power->height );

      /* For auxilliary power, draw a generator building along with
         an attached fule tank.  Indicate the amount of fuel left in
         the fuel tank.  If the fuel level drops below 25%, change
         the color of the fuel to red to indicate an alarm
         condition. */

      /* Draw fuel tank as a cylinder. Motif doesn't have a function
         to draw a cylinder, so it is represented with a rectangle
         that has a filled arc on top and bottom. All three shapes
         share the same x-coordinate and width. Each shape will have
         its own y-coordinate and height (the two arcs will have the
         same height). */

      x1 = power->width/8;
      cylinder_width = power->width/3;
      y_arc_top = power->scanl + 5*( power->height - height )/12 - 2;
      y_arc_bottom = power->scanl + 5*( power->height - height )/6 - 2;
      y_rec = power->scanl + ( power->height - height )/2 - 2;
      arc_height = power->height/6;
      rec_height = y_arc_bottom - y_arc_top;
      arc_start_angle = 0;
      arc_end_angle = -360*64;

      /* Draw fuel tank for generator next to building. */

      XSetForeground( HCI_get_display(),
                      hci_control_panel_gc(),
                      hci_get_read_color( BLACK ) );

      /* -----Draw Tank Base----- */

      XFillArc( HCI_get_display(),
                hci_control_panel_pixmap(),
                hci_control_panel_gc(),
                x1,
                y_arc_bottom,
                cylinder_width,
                arc_height, 
                arc_start_angle,
                arc_end_angle );

      /* -----Draw Fuel Level----- */

      XFillRectangle( HCI_get_display(),
                    hci_control_panel_pixmap(),
                    hci_control_panel_gc(),
                    x1,
                    y_rec,
                    cylinder_width,
                    rec_height );

      /* -----Draw Empty portion of Tank----- */

      empty_level = ( 1.0 - (fuel_level/100.0) )*power->height/3;

      color = hci_get_read_color( GRAY );

      XSetForeground( HCI_get_display(),
                      hci_control_panel_gc(),
                      color );

      XFillRectangle( HCI_get_display(),
                    hci_control_panel_pixmap(),
                    hci_control_panel_gc(),
                    x1,
                    y_rec,
                    cylinder_width,
                    empty_level );

      XFillArc( HCI_get_display(),
                hci_control_panel_pixmap(),
                hci_control_panel_gc(),
                x1,
                y_rec + empty_level - power->height/12,
                cylinder_width,
                arc_height,
                arc_start_angle,
                arc_end_angle );

      /* -----Draw Top of Tank----- */

      XFillArc( HCI_get_display(),
                hci_control_panel_pixmap(),
                hci_control_panel_gc(),
                x1,
                y_arc_top,
                cylinder_width,
                arc_height,
                arc_start_angle,
                arc_end_angle );

      XSetForeground( HCI_get_display(),
                      hci_control_panel_gc(),
                      hci_get_read_color( BLACK ) );

      XDrawArc( HCI_get_display(),
                hci_control_panel_pixmap(),
                hci_control_panel_gc(),
                x1,
                y_arc_top,
                cylinder_width,
                arc_height,
                arc_start_angle,
                arc_end_angle );

      XDrawArc( HCI_get_display(),
                hci_control_panel_pixmap(),
                hci_control_panel_gc(),
                x1,
                y_arc_bottom,
                cylinder_width,
                arc_height,
                arc_start_angle,
                arc_end_angle );

      x1 = x1 + power->width/3;
      y1 = power->scanl + power->height/2 - 2;

      /* Draw generator building. */

      XSetForeground( HCI_get_display(),
                      hci_control_panel_gc(),
                      hci_get_read_color( BROWN ) );

      X[0].x = x1;
      X[0].y = y1;
      X[1].x = x1;
      X[1].y = y1 + 5*( power->height - height )/12;
      X[2].x = x1 + power->width/2;
      X[2].y = y1 + 5*( power->height - height )/12;
      X[3].x = x1 + power->width/2;
      X[3].y = y1;
      X[4].x = x1 + power->width/4;
      X[4].y = y1 - power->height/4;

      XFillPolygon( HCI_get_display(),
                    hci_control_panel_pixmap(),
                    hci_control_panel_gc(),
                    X,
                    ( int ) 5,
                    Convex,
                    CoordModeOrigin );

      /* Draw door outline in generator building. */

      XSetForeground( HCI_get_display(),
                      hci_control_panel_gc(),
                      hci_get_read_color( BLACK ) );

      XDrawRectangle( HCI_get_display(),
                      hci_control_panel_pixmap(),
                      hci_control_panel_gc(),
                      ( int ) ( x1 + power->width/8 ),
                      ( int ) y1,
                      ( int ) ( power->width/4 ),
                      ( int ) ( 5*( power->height - height )/12 - 1 ) );

      /* Outline the left side of the building in black. */
 
      XDrawLine( HCI_get_display(),
                 hci_control_panel_pixmap(),
                 hci_control_panel_gc(),
                 ( int ) X[0].x,
                 ( int ) X[0].y,
                 ( int ) X[1].x,
                 ( int ) X[1].y );

      /* Connect line from generator building to RDA button. */
 
      XDrawLine( HCI_get_display(),
                 hci_control_panel_pixmap(),
                 hci_control_panel_gc(),
                 ( int ) ( x1 + power->width/4 ),
                 ( int ) ( y1 - power->width/4 ),
                 ( int ) rda->pixel,
                 ( int ) rda->scanl );

      /* Draw roof and 3-d effect for generator building. */

      XDrawLine( HCI_get_display(),
                 hci_control_panel_pixmap(),
                 hci_control_panel_gc(),
                 ( int ) ( x1 - 2 ),
                 ( int ) ( y1 + 2 ),
                 ( int ) ( x1 + power->width/4 ),
                 ( int ) ( y1 - power->width/4 ) );

      for( i = 0; i < hci_control_panel_3d(); i++ )
      {
        XDrawLine( HCI_get_display(),
                   hci_control_panel_pixmap(),
                   hci_control_panel_gc(),
                  ( int ) ( x1 + power->width/4 + i ),
                  ( int ) ( y1 - power->width/4 - i ),
                  ( int ) ( x1 + power->width/2 + 2 + i ),
                  ( int ) ( y1 + 2 - i ) );

        XDrawLine( HCI_get_display(),
                   hci_control_panel_pixmap(),
                   hci_control_panel_gc(),
                   ( int ) ( x1 + power->width/2 + i ),
                   ( int ) ( y1 - i ),
                   ( int ) ( x1 + power->width/2 + i ),
                   ( int ) ( y1 - i + 5*( power->height - height )/12 - 1 ) );
      }

      /* Display textually the state of the utility power beneath
         the auxilliary power icon. */

      XSetForeground( HCI_get_display(),
                      hci_control_panel_gc(),
                      hci_get_read_color( BUTTON_FOREGROUND ) );

      XSetBackground( HCI_get_display(),
                      hci_control_panel_gc(),
                      hci_get_read_color( BUTTON_BACKGROUND ) );

      if( power_status & BIT_1_MASK )
      {
        sprintf( power_label, "Util Avail" );
      }
      else if( power_status & BIT_2_MASK )
      {
        sprintf( power_label, "  Gen On  " );
      }
      else if( power_status & BIT_4_MASK )
      {
        sprintf( power_label, "Cmd Swtchvr" );
      }

      width  = XTextWidth( fontinfo, power_label, strlen( power_label ) );

      XDrawImageString( HCI_get_display(),
                        hci_control_panel_pixmap(),
                        hci_control_panel_gc(),
                        ( int ) ( power->pixel + ( power->width - width )/2 ),
                        ( int ) ( power->scanl + power->height - 2 ),
                        power_label,
                        strlen( power_label ) );
    }

    XSetForeground( HCI_get_display(),
                    hci_control_panel_gc(),
                    hci_get_read_color( BUTTON_BACKGROUND ) );

    XSetBackground( HCI_get_display(),
                    hci_control_panel_gc(),
                    hci_get_read_color( BACKGROUND_COLOR1 ) );

    XDrawRectangle( HCI_get_display(),
                    hci_control_panel_pixmap(),
                    hci_control_panel_gc(),
                    ( int ) power->pixel,
                    ( int ) power->scanl,
                    ( int ) power->width,
                    ( int ) power->height );

    /* Add 3D look around power graphic to make it more intuitive
       to the user that it can be selected. */

    hci_control_panel_draw_3d( power->pixel,
                               power->scanl,
                               power->width,
                               power->height,
                               BLACK );

    prev_power_status = power_status;
    prev_fuel_level = fuel_level;
  }
}
Beispiel #6
0
int main (int argc, char **argv)
{
	/* auti i metavliti tha periexei deikti se struct display
	 * pou epistrefetai otan dimiourgoume mia syndesi
	 *
	 * genika mporoume na dimiourgisoume syndesi me apomakrismeno
	 * systima pou tha trexei ton server alla stin periptwsi mas
	 * syndeomaste sto idio systima pou trexoume ton server */


	/* auti i metavliti tha xrisimopoiithei gia na apothikeusi
	 * tin deufault othoni apo ton X server, sinithos o X server 
	 * exei  mia othoni opote gi'autin endiaferomaste */

	int screenNum;

	/* paxos tis grammis perigrammatos se pixel */

	int borderWidth=3;
//	char *windowName = " ###	AKIS-TETRIS	###";


	/* kathe othoni exei ena rootWindow pou kaliptei oli tin othoni*/

	Window rootWindow,win,menuBar;  



	/* win --> kyriws parathyro  tou programmatos mou */
	/* menuBar ---> to parathyro pou tha periexei ta pliktra start
	 * kai exit */

	XSizeHints *win_size_hints; /* hints oson afora to size ston WM */


	XGCValues values;

	int menuBarHeight;
	int menuBarVertPos;
	/* to ypsos tou menuBar */
	/* tha tou dwsw 8% tou ypsous tou kentrikou
	 * parathyrou */

	Window exitButton, startButton;

	int buttonSize;
	int padding; // xwros metaxy twn koumpiwn sto menu


	int winWidth = 600;
	int winHeight = 500;


	/* plirofories gia font */

	XFontStruct *fontInfo;

	

	padding = borderWidth * 4;
	
	


	int x=0, y=0;


	if((display=XOpenDisplay(0))==NULL){
		fprintf(stderr,"error opening display\n");
		exit(-1);
	}


	/* vazi ton arithmo tis deufault screen tou X server */
	screenNum = XDefaultScreen(display);

	/* vriskei to id tou rootWindow */
	rootWindow = XDefaultRootWindow(display);

	myColor.white =  WhitePixel(display, screenNum);
	myColor.black = BlackPixel(display, screenNum);

	colorTable[aspro]=myColor.white;
	colorTable[mavro]=myColor.black;

	win = XCreateSimpleWindow(display, rootWindow, x,y,
										winWidth, winHeight, borderWidth,
										myColor.black,myColor.white);
										

	gameWindow = XCreateSimpleWindow(display, win, borderWidth,borderWidth, 
										250, 450, borderWidth,
										myColor.black,myColor.white);
										


assert(fontInfo = XLoadQueryFont(display, "9x15"));
		
	
	menuBarHeight = 30; /* ypsos menu 8% tou parathyrou */

	/* na thimithw na to peiraxw */
	menuBarVertPos = winHeight -menuBarHeight - 2 * borderWidth;

	menuBar = XCreateSimpleWindow(display, win, 0, menuBarVertPos,
											winWidth - 2 * borderWidth,
											menuBarHeight, borderWidth,
											myColor.black, myColor.white);

	buttonSize = menuBarHeight - 2 * borderWidth;

	exitButton = XCreateSimpleWindow(display, menuBar,
												winWidth - (padding + 2*buttonSize),
												borderWidth,
												2*buttonSize, buttonSize, 1,
												myColor.black, myColor.white);


	startButton = XCreateSimpleWindow(display, menuBar,
												padding,
												borderWidth,
												2*buttonSize, buttonSize, 1,
												myColor.black, myColor.white);
	
	win_size_hints=XAllocSizeHints();
	assert(win_size_hints);

	win_size_hints->flags=PSize|PMinSize|PMaxSize;
	win_size_hints->min_width=winWidth;
	win_size_hints->min_height=winHeight;
	win_size_hints->base_width=winWidth;
	win_size_hints->base_height=winHeight;
	win_size_hints->max_height=winHeight;
	win_size_hints->max_width=winWidth;

	XSetWMNormalHints(display,win,win_size_hints);

	/* setting up the GC */

	values.foreground= myColor.black;
	values.background = myColor.white;

	gc = XCreateGC(display, gameWindow,
					(GCForeground | GCBackground), &values); 

	buttonGc = XCreateGC(display, menuBar,
						(GCForeground | GCBackground), &values); 





	assert(gc);
	assert(buttonGc);


		XSetLineAttributes(display, gc,
							3, LineSolid, CapButt, JoinRound);

		XSetLineAttributes(display, buttonGc,
							3, LineSolid, CapButt, JoinRound);




	XMapWindow(display,win);
	XMapSubwindows(display, win);
	XMapWindow(display, menuBar);
	XMapSubwindows(display, menuBar);

XFlush(display);

	/* do some random stuff */

	XSync(display, False); /* poly simantiko!!!!! */ 


//XDrawLine(display, gameWindow, gc, 20, 20, 40, 100);
	//XDrawRectangle(display, gameWindow, gc, 0, 0, 25, 25);
//	XDrawRectangle(display, gameWindow, gc, 25, 0, 25, 25);

	XFlush(display);

	sleep(3);


			

	XDrawImageString(display, exitButton, buttonGc,
							7,
							buttonSize/2.0+(fontInfo->ascent/2.0) ,
							 "E X I T",strlen("E X I T"));

	XDrawImageString(display, startButton, buttonGc,
							7,
							buttonSize/2.0+(fontInfo->ascent/2.0) ,
							 "START",strlen("START"));

	XFlush(display);



	initMainGameTable();
	printAllBlocks();
	drawMainGameTable();


	XFlush(display);

	sleep(10);

	XFlushGC(display, gc);
	XFlushGC(display, buttonGc);
	XFreeGC(display, buttonGc);
	XFreeGC(display, gc);
	XCloseDisplay(display);
	XFree(win_size_hints);

	return 0;
}
void draw()
{
    XDrawImageString(display, main_window, gc, y/2-strlen("Draw Like A Boss"), 10, "Draw Like A Boss",
                     strlen("Draw Like A Boss"));
    XFlush(display);
}
/*
 ****************************************************************
 *	Programa principal					*
 ****************************************************************
 */
void
main (int argc, const char *argv[])
{
	Display		*dp;
	Window		win;
	int		screen;
	ulong		fg, bg;
	GC		gc;
	XEvent		ev;
	Font		font;
	KeySym		key;
	char		text[80];
	int		doneflag, len, opt, exitval;

	/*
	 *	Inicializa opções.
	 */
	exitval = 0;

	/*
	 *	Analisa as opções de execução.
	 */
	while ((opt = getopt (argc, argv, "G:f:MH")) != EOF)
	{
		switch (opt)
		{
		    case 'M':
			exit (0);

		    case 'H':
			help (0);
			break;

		    case 'f':
			fontname = (char *)optarg;
			break;

		    case 'G':
			get_geometry (optarg);
			break;

		    default:
			putc ('\n', stderr);
			help (2);

		}	/* end switch (opt) */

	}	/* while ((opt = getopt (...))) */

	/*
	 *	Conecta-se ao servidor.
	 */
	if ((dp = XOpenDisplay (NULL)) == (Display *)NULL)
		msg ("$Não consegui conectar-me ao servidor");

	screen = DefaultScreen (dp);

	bg = WhitePixel (dp, screen);
	fg = BlackPixel (dp, screen);

	win =	XCreateSimpleWindow
		(	dp,
			DefaultRootWindow (dp), 
			x, y, dx, dy,
			2,
			fg, bg			/* cores: frente e fundo */
		);

	gc = DefaultGC (dp, screen);

	if (fontname != NOSTR)
	{
		if (font = XLoadFont (dp, fontname))
			XSetFont (dp, gc, font);
	}

	XSelectInput (dp, win, ButtonPressMask|KeyPressMask|ExposureMask);

	XMapRaised (dp, win);

	for (doneflag = 0; doneflag == 0; /* sem incremento */)
	{
		XNextEvent (dp, &ev);

		switch (ev.type)
		{
		    case Expose:
			break;

		    case ButtonPress:
			sprintf
			(	text,
#if (0)	/****************************************************/
				"(%d, %d), (%d, %d)",
				ev.xbutton.x_root, ev.xbutton.y_root,
#endif	/****************************************************/
				"(%d, %d)",
				ev.xbutton.x, ev.xbutton.y
			);

			XDrawImageString
			(	dp, win, gc,
				ev.xbutton.x, ev.xbutton.y,
				text, strlen (text)
			);

			break;

		    case KeyPress:
			len = XLookupString (&ev.xkey, text, 10, &key, 0);

			if (len == 1 && text[0] == 'q')
				doneflag++;
			break;
		}
	}


	XDestroyWindow (dp, win);
	XCloseDisplay (dp);

	exit (0);

}	/* end main */
void hci_control_panel_USERS_button( int force_draw )
{
  int	width;
  int	height;
  XFontStruct	*fontinfo;
  hci_control_panel_object_t	*top;
  hci_control_panel_object_t	*rpg;
  hci_control_panel_object_t	*users;
  hci_control_panel_object_t	*comms;

  /* Get the widget ID for the main drawing area widget. */

  top = hci_control_panel_object( TOP_WIDGET );

  if( top->widget == ( Widget ) NULL )
  {
    return;
  }

  /* Get the widget ID for the RPG container since we use this to
     position the USERS container. */

  rpg = hci_control_panel_object( RPG_BUTTONS_BACKGROUND );

  /* Get the widget ID for the USERS container. */

  users = hci_control_panel_object( USERS_BUTTON );

  /* Get the widget ID for the Comms button. */

  comms = hci_control_panel_object( COMMS_BUTTON );

  if( comms->widget == ( Widget ) NULL )
  {
    return;
  }

  if( force_draw )
  {
    /* Resize and display the background area for the Users container. */

    users->widget = comms->widget;
    users->pixel  = rpg->pixel + 2*rpg->width + 8;
    users->scanl  = top->height/2 - 5;
    users->width  = top->width/9;
    users->height = top->height/8;

    /* Draw/fill container box. */

    XSetForeground( HCI_get_display(),
                    hci_control_panel_gc(),
                    hci_get_read_color( SEAGREEN ) );

    XFillRectangle( HCI_get_display(),
                    hci_control_panel_pixmap(),
                    hci_control_panel_gc(),
                    users->pixel,
                    users->scanl,
                    users->width,
                    users->height );

    /* Set background/foreground colors. */

    XSetForeground( HCI_get_display(),
                    hci_control_panel_gc(),
                    hci_get_read_color( TEXT_FOREGROUND ) );

    XSetBackground( HCI_get_display(),
                    hci_control_panel_gc(),
                    hci_get_read_color( SEAGREEN ) );

    /* Set font properties. */

    fontinfo = hci_get_fontinfo( SCALED );
    width = XTextWidth( fontinfo, "USERS", 5 );
    height = fontinfo->ascent + fontinfo->descent;

    /* Draw "USERS" name on container. */

    XDrawImageString( HCI_get_display(),
                      hci_control_panel_pixmap(),
                      hci_control_panel_gc(),
                      ( int ) ( users->pixel + users->width/2 - width/2 ),
                      ( int ) ( users->scanl + height ),
                      "USERS",
                      5 );

    /* Make the background looked raised from the main window
       background by adding the 3-D border along the top and right. */

    hci_control_panel_draw_3d( users->pixel,
                               users->scanl,
                               users->width,
                               users->height,
                               BLACK );

    /* Update the properties for the distribution comms object. */

    comms->pixel  = users->pixel + users->width/16;
    comms->scanl  = users->scanl + users->height/3 ;
    comms->width  = 3*users->width/4;
    comms->height = users->height/2;

    XtVaSetValues( comms->widget,
                   XmNwidth, comms->width,
                   XmNheight, comms->height,
                   XmNx, comms->pixel,
                   XmNy, comms->scanl,
                   XmNfontList, hci_get_fontlist( SCALED ),
                   NULL );

    /* Add 3d effect around the distribution comms object. */

    hci_control_panel_draw_3d( comms->pixel,
                               comms->scanl,
                               comms->width,
                               comms->height,
                               BLACK );
  }
}
void handleCrush(XInfo xinfo, Ship ship, int flag)
{
	int current_w;		// current size
	int current_h;
	
	Pixmap ship_crush[5];
	
	ship_crush[0] = loadbitmap(xinfo, (char *)"bitmap/crush/ship_crush1.xbm");

	ship_crush[1] = loadbitmap(xinfo, (char *)"bitmap/crush/ship_crush2.xbm");

    ship_crush[2] = loadbitmap(xinfo, (char *)"bitmap/crush/ship_crush3.xbm");

    ship_crush[3] = loadbitmap(xinfo, (char *)"bitmap/crush/ship_crush4.xbm");

    ship_crush[4] = loadbitmap(xinfo, (char *)"bitmap/crush/ship_crush5.xbm");

    ship_crush[5] = loadbitmap(xinfo, (char *)"bitmap/crush/ship_crush6.xbm");

	int i;
	int j;
	
	for (i = 0; i<=5; i++) {
		for (j = 0; j <10000; j ++)
		{
		XCopyPlane(xinfo.display, ship_crush[i], xinfo.window, xinfo.gc[0],
                    0, 0, 20, 20, ship.x, ship.y, 1);
		}
		//usleep(1000000);
	
	
	}
	

	std::string text("YOUR SHIP CRUSHED!!!");
	XDrawImageString( xinfo.display, xinfo.window, xinfo.gc[0],
                		xinfo.current_w/2 - 10, xinfo.current_h/2 - 10, text.c_str(), text.length()  );
/*    
    if (flag == 0) 
	    text=("You let the ship crush on the mountain, you failed to save the planet... you should feel the guilt now, and you should definitely try again and beat the game");
	else if (flag == 1) 
	    text=("It was such a tragic... you tried so hard and get so far... but the speed was too fast...");

 	XDrawImageString( xinfo.display, xinfo.window, xinfo.gc[0], xinfo.current_w/2 - 100, xinfo.current_h/2 + 20, text.c_str(), text.length()  );    
                	*/
    
    Pixmap end;
    
    if (flag == 0)
    {
    	Pixmap end = loadbitmap(xinfo, (char*) "bitmap/others/mountain.xbm");
			XCopyPlane(xinfo.display, end, xinfo.window, xinfo.gc[0],
                    0, 0, 800,600, (xinfo.current_w-800)/2, (xinfo.current_h-600)/2,1);
	}
	
	else if (flag == 1)
    {
    	Pixmap end = loadbitmap(xinfo, (char*) "bitmap/others/speed.xbm");
			XCopyPlane(xinfo.display, end, xinfo.window, xinfo.gc[0],
                    0, 0, 800,600, (xinfo.current_w-800)/2, (xinfo.current_h-600)/2,1);
	}
	
	text=("Press space to try again");
	XDrawImageString( xinfo.display, xinfo.window, xinfo.gc[1],
                		xinfo.current_w/2 - 65, xinfo.current_h/2 + 270, text.c_str(), text.length()  );
}
void handleTooSmall(XInfo &xinfo, XEvent event)
{
	int x = 0;
	XEvent event2;
	unsigned long lastRepaint = 0;
	int inside = 0;
		XFillRectangle(xinfo.display, xinfo.window, xinfo.gc[0], 0, 0, 800, 600);
		
		std::string text_pause("--Pause--");
		XDrawImageString( xinfo.display, xinfo.window, xinfo.gc[1], xinfo.current_w/2, xinfo.current_h/2, text_pause.c_str(), text_pause.length()  );
		std::string text_resume("The window is too small, please resize the window");
			XDrawImageString( xinfo.display, xinfo.window, xinfo.gc[1], xinfo.current_w/2, xinfo.current_h/2 + 20, text_resume.c_str(), text_resume.length()  );

		while (x == 0) { // stay looping untill window size exceed 800*600
		
		
		// print to the screen notify user the game window is too small
		
		
			if (XPending(xinfo.display) > 0) {
				XNextEvent( xinfo.display, &event2 );
				switch( event2.type ) {
					case ConfigureNotify:
					{
						XConfigureEvent xce = event2.xconfigure;
						fprintf(stderr, "Handling resize  w=%d  h=%d\n", xce.width, xce.height);
						xinfo.current_w = xce.width;
						xinfo.current_h = xce.height;
						if (xce.width >= 800 && xce.height >= 600) 
						{
							printf("w > 800 and h > 600 resuming the game!!\n");
							x = 1;

						}
						else 
						{
							XFillRectangle(xinfo.display, xinfo.window, xinfo.gc[0], 0, 0, 800, 600);
		
							std::string text_pause("--Pause--");
							XDrawImageString( xinfo.display, xinfo.window, xinfo.gc[1], xinfo.current_w/2, xinfo.current_h/2, text_pause.c_str(), text_pause.length()  );
							std::string text_resume("The window is too small");
							XDrawImageString( xinfo.display, xinfo.window, xinfo.gc[1], xinfo.current_w/2-30, xinfo.current_h/2 + 20, text_resume.c_str(), text_resume.length()  );
							text_resume="Please resize to continue";
							XDrawImageString( xinfo.display, xinfo.window, xinfo.gc[1], xinfo.current_w/2-35, xinfo.current_h/2 + 40, text_resume.c_str(), text_resume.length()  );
							
						
						}
						break;
					}
					case KeyPress:
					{
						KeySym key;
						char text[BufferSize];
						int i = XLookupString((XKeyEvent *)&event2,text,BufferSize,&key,NULL);		
						if ( i == 1) {
							if (text[0] == 'q') {
								error("Terminating normally.");
							}
						}
						break;
					}

				} // switch
			}// if xpending
		} // while

} // end handleTooSmall
Beispiel #12
0
/*---------------------------- HandleEvent --------------------------*/
int HandleEvent(XEvent *event)
{
  int	i;
    
  if(theEvent.xany.window==mainW) {

    switch (event->type) {
    case Expose: {
      XExposeEvent *exp_event = (XExposeEvent *) event;
 
      if (exp_event->window==mainW) {
	DrawWindow(exp_event->x,exp_event->y,
		   exp_event->width, exp_event->height);
      }
    }
    break;

    case EnterNotify: {
      if (Selected_Visual_Class==DirectColor)
	XStoreColors(theDisp,NewCmap,newC,ColorMapSize);
      if (Selected_Visual_Class!=TrueColor)
	XInstallColormap(theDisp,NewCmap);
    }
    break;
    
    case LeaveNotify: {
      if (Selected_Visual_Class==DirectColor)
	XStoreColors(theDisp,NewCmap,rootC,ColorMapSize); 
    }
    break;

    case KeyPress: {	/* allow a quit from the image window */
      Handle_KeyPress(event);
    }
    break;

    case MotionNotify: {
      Handle_Motion(event);
    }
    break;

    case ConfigureNotify: {
      XConfigureEvent *conf_event = (XConfigureEvent *) event;

      if (conf_event->window == cmdW && 
	  (conf_event->width != cmd_width ||
	   conf_event->height != cmd_height))
	XResizeWindow(theDisp,cmdW,cmd_width,cmd_height);
      if (conf_event->window == mainW && 
	  (conf_event->width != zWidth+(color_bar?color_bar_width:0) ||
	   conf_event->height != zHeight+info_height))
	Resize(conf_event->width-(color_bar?color_bar_width:0),
	       conf_event->height-info_height);
    }
    break;

    case ButtonPress: {
      if (theEvent.xbutton.button==Button1) {
	if (selzoom_active) {
	  Selective_Zoom((caddr_t)&one);
	  break;
	}
	XDefineCursor(theDisp,mainW,roiCursor);
	XFlush(theDisp);
	if (roi_present) draw_roi(roi_x1, roi_y1, roi_x2, roi_y2);
	roi_active = 1;
	roi_x1 = theEvent.xmotion.x < zWidth ?
	  (theEvent.xmotion.x>0 ?
	   theEvent.xmotion.x : 0) : zWidth-1;
	roi_y1 = theEvent.xmotion.y < zHeight ?
	  (theEvent.xmotion.y>0 ?
	   theEvent.xmotion.y : 0) : zHeight-1;
	roi_x2 = roi_x1;
	roi_y2 = roi_y1;
	draw_roi(roi_x1, roi_y1, roi_x2, roi_y2);
	break;
      } 
      if (theEvent.xbutton.button==Button2) {
	XDefineCursor(theDisp,mainW,wlCursor);
	XClearArea(theDisp,mainW,0,zHeight,
		   zWidth,zHeight+info_height,False);
	XDrawImageString(theDisp,mainW,theMGC,
			 zWidth-XTextWidth(ol_text_finfo,
					   wl_msg,strlen(wl_msg))-4,
			 zHeight+info_height-4,wl_msg,strlen(wl_msg));
	XDrawImageString(theDisp,mainW,theMGC,4,
			 zHeight+info_height-4,loc_msg,strlen(loc_msg));
	XFlush(theDisp);
	break;
      } 
      if (theEvent.xbutton.button==Button3) {
	/* note: not really 'iconic' anymore, simply map or unmap */
	if (cmdW_State==NormalState) {
	  XUnmapWindow(theDisp,cmdW);
	  cmdW_State = IconicState;
	}
	else {
	  XMapWindow(theDisp,cmdW);
	  cmdW_State = NormalState;
	}
	break;
      } 
    }
    break;

    case ButtonRelease: {
      int xa, xb, ya, yb;
      if (theEvent.xbutton.button==Button1 && roi_active) {
	roi_active = 0;
	xa = roi_x1*(Width-1)/(zWidth-1);
	xb = roi_x2*(Width-1)/(zWidth-1);
	ya = roi_y1*(Height-1)/(zHeight-1);
	yb = roi_y2*(Height-1)/(zHeight-1);
	roi_stats(xa, ya, xb, yb, 0);
	XDefineCursor(theDisp,mainW,mainCursor);
	XFlush(theDisp);
      }
      if (theEvent.xbutton.button==Button2) {
	XDefineCursor(theDisp,mainW,mainCursor);
	XFlush(theDisp);               
	if (Scale_Data && (oUpper != Upper || oLower != Lower)) {
	  Rescale();
	  Window_Level(Lower,Upper); 
	  oLower=Lower; oUpper=Upper; 
	}
	XClearArea(theDisp,mainW,0,zHeight,
		   zWidth,zHeight+info_height,False);
	if (wl_display) 
	  XDrawImageString(theDisp,mainW,theMGC,
			   zWidth-XTextWidth(ol_text_finfo,wl_msg,strlen(wl_msg))-4,
			   zHeight+info_height-4,wl_msg,strlen(wl_msg));
	XDrawImageString(theDisp,mainW,theMGC,4,
			 zHeight+info_height-4,loc_msg,strlen(loc_msg));
	update_sliders();
	update_msgs();
      }
    }
    break;

    case UnmapNotify: {
      if (bitmap_pad==8) {
	if (Interpolation_Type==BILINEAR) {
	  bilinear_byte_to_byte(byte_Image, Width, Height,
				icon_byte_image, ICON_WIDTH, ICON_HEIGHT);
	}
	else {
	  nneighbour_byte_to_byte(byte_Image, Width, Height,
				  icon_byte_image, ICON_WIDTH, ICON_HEIGHT);
	}
      }
      else {
	if (Interpolation_Type==BILINEAR) {
	  bilinear_rgbp_to_rgbp(byte_Image, Width, Height,
				icon_byte_image, ICON_WIDTH, ICON_HEIGHT);
	}
	else {
	  nneighbour_rgbp_to_rgbp(byte_Image, Width, Height,
				  icon_byte_image, ICON_WIDTH, ICON_HEIGHT);
	}
      }
      XPutImage(theDisp,iconW,theMGC,iconImage,0,0,0,0,
		ICON_WIDTH, ICON_HEIGHT);
    }
    break;
                
    case CirculateNotify:
    case MapNotify:
    case DestroyNotify:
    case GravityNotify:
    case ReparentNotify:
    default: 
    break;
    }  /* end of switch */
  }

  /* other command Window events */
  if(theEvent.xany.window==cmdW) {

    switch (event->type) {
    case Expose: {
      update_msgs();
    }
    break;

    case EnterNotify: {
      if (Selected_Visual_Class==DirectColor)
	XStoreColors(theDisp,NewCmap,newC,ColorMapSize); 
      if (Selected_Visual_Class!=TrueColor)
	XInstallColormap(theDisp,NewCmap);
    }
    break;

    case LeaveNotify: {
      if (Selected_Visual_Class==DirectColor)
	XStoreColors(theDisp,NewCmap,rootC,ColorMapSize); 
    }
    break;

    case UnmapNotify: {
      cmdW_State = IconicState;
    }
    break;
            
    case MapNotify: {
      cmdW_State = NormalState;
    }
    break;

    case ConfigureNotify: {
      XConfigureEvent *conf_event = (XConfigureEvent *) event;

      if (conf_event->window == cmdW && 
	  (conf_event->width != cmd_width ||
	   conf_event->height != cmd_height))
	XResizeWindow(theDisp,cmdW,cmd_width,cmd_height);
    }
    break;

    default: break;
    }
  }

  /* button press events */
  if (XFindContext(theDisp, theEvent.xany.window, xwin_context,
		   (caddr_t *) &which_xwin)==0) {
    if(*(which_xwin->event_handler)!=NULL)
      (*(which_xwin->event_handler))(which_xwin);
    if (Scale_Data && (oUpper != Upper || oLower != Lower)) {
      Rescale();
      oLower=Lower; oUpper=Upper;
    }
  }
}
Beispiel #13
0
void *register_monitor_main(void *arg)
{
  Display *display;
  struct regmon_args *args = arg;

  if (args && (display = XOpenDisplay(NULL))) {
    int screen_num = DefaultScreen(display);
    Window window;
    GC localgc;
    XGCValues gcvalues;
    int divider = strlen(args->label)*6 + 2;
    fd_set read_fds;
    struct timeval timeout;

    window = XCreateSimpleWindow(display, args->root, args->x, args->y,
				 args->width, args->height,
				 0, BlackPixel(display, screen_num),
				 WhitePixel(display, screen_num));

    localgc = XCreateGC(display, window, 0, &gcvalues);

    XSelectInput(display, window,
		 ExposureMask | EnterWindowMask | FocusChangeMask |
		 ButtonPressMask | ButtonReleaseMask);

    XMapWindow(display, window);

    FD_ZERO(&read_fds);

    while (1) {
      char string[30];
      XEvent event;

      FD_SET(ConnectionNumber(display), &read_fds);
      timeout.tv_sec = 1;
      timeout.tv_usec = 0;

      if (select(ConnectionNumber(display) + 1, &read_fds, NULL, NULL, &timeout) < 0) {
	fprintf(stderr, "selection error\n");
	break;
      }

      while (XCheckMaskEvent(display, ~0, &event)) {

	switch(event.type) {
	case Expose:

	  if (event.xexpose.count) {
	    break;
	  }

	  XSetForeground(display, localgc, WhitePixel(display, screen_num));

	  XFillRectangle(display, window, localgc,
			 divider, 0, args->width - divider, args->height);
	  
	  XSetForeground(display, localgc, args->backgroundPixel);
	  XFillRectangle(display, window, localgc,
			 0, 0, divider, args->height);

	  XDrawLine(display, window, localgc,
		    divider, args->height-2, args->width-2, args->height-2);
	  XDrawLine(display, window, localgc,
		    args->width-2, args->height-2, args->width-2, 0);

	  XSetForeground(display, localgc, args->shadowPixel);
	  XDrawLine(display, window, localgc,
		  divider, args->height-2, divider, 0);
	  XDrawLine(display, window, localgc,
		    divider+1, args->height-3, divider+1, 0);
	  XDrawLine(display, window, localgc,
		    divider+1, 0, args->width-1, 0);
	  XDrawLine(display, window, localgc,
		    divider+1, 1, args->width-2, 1);

	  XSetForeground(display, localgc, BlackPixel(display, screen_num));

	  XDrawImageString(display, window, args->labelgc,
			   0, 12, args->label, strlen(args->label));

	  break;
	default:
	  break;
	}
      }
      sprintf(string, "%08x", *(args->addr));
	  
      XDrawImageString(display, window, args->boxgc,
		       divider + 5, 12, string, strlen(string));

      XFlush(display);
    }
  } else {
    fprintf(stderr, "register_monitor_main failed\n");
  }
  return(NULL);
}