⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 garnish.c

📁 地震波正演和显示模块
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "../include/par.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifndef EGSTERN
#define EGSTERN extern
#endif/*EGSTERN*/

#define MAX_BOX_THICK 30

/***************************************************/
/** These definitions are for the garnish buttons **/
/***************************************************/
#define SHADOW 30000
#define RADIO_SHADOW 15000
#define SHRINK 0
#define EXPAND 1
#define RIGHT 3
#define LEFT 2
#define UP 1
#define DOWN 0
#define RELATIVE 1
#define FIXED 2
#define TOP 3
#define BOTTOM 14

#ifndef EGSTERN
#define EGSTERN extern
#endif

#define COLOR_FLAGS DoRed | DoGreen | DoBlue
#define COMMAND_WIDTH 100
#define BUTTON_HEIGHT 30
#define BUTTON_WIDTH  90
#define BUTTON_BRIGHTNESS 60000
#define FONT_NAME "9x15"
#define PICK_MODE 1
#define REGULAR_MODE 0
#define ADD_MODE 1
#define DELETE_MODE 0
#define DRAW_FLAG 1
#define ERASE_FLAG 0

EGSTERN int char_width, char_height;
EGSTERN XColor grey_color, black_color,red_color,blue_color;
EGSTERN unsigned long grey_pixel,black_pixel,red_pixel,blue_pixel;
EGSTERN GC blue_r_gc;
EGSTERN GC red_r_gc;

typedef struct pick_tag {
  float x2;
  float time;
  int picked;
} pick_t;


#ifndef X_WINDOW_H
#define X_WINDOW_H
#ifndef EGSTERN
#define EGSTERN extern
#endif/*EGSTERN*/


#define CELLS 2 /** this is how many color cells we want to grab **/
/***************************************************/
/** These definitions are for the garnish buttons **/
/***************************************************/
#define SHADOW 30000
#define RADIO_SHADOW 15000
#define SHRINK 0
#define EXPAND 1
#define RIGHT 3
#define LEFT 2
#define UP 1 
#define DOWN 0
#define RELATIVE 1
#define FIXED 2
#define TOP 3
#define BOTTOM 14
/***************************************************/
#define COLOR_FLAGS DoRed | DoGreen | DoBlue
#define XEVENT_MASK ButtonPressMask | KeyPressMask | ExposureMask | PointerMotionMask | ButtonReleaseMask | KeyReleaseMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask

EGSTERN Display     		*display;
EGSTERN Visual			*visual;
EGSTERN Window    	        window,win2;
EGSTERN Window                  inwin;
EGSTERN GC 	      		gc;
EGSTERN Colormap    		colormap;
EGSTERN XColor      		generic, foreground_color, background_color;
EGSTERN XEvent      		event;
EGSTERN Pixmap                  draw;
EGSTERN Pixmap                  highlight;
EGSTERN Pixmap                  escherknot;
EGSTERN XImage			*image;
EGSTERN KeySym      		key;
EGSTERN XSizeHints  		hint;
EGSTERN XWMHints                wmhint;
EGSTERN Cursor                  standard_cursor, busy_cursor;
EGSTERN Cursor                  grid_cursor, mutate_cursor;
EGSTERN Status      		result;
EGSTERN Font 			font;
EGSTERN XFontStruct             *font_struct;
EGSTERN Time                    time_stamp;
EGSTERN unsigned long		width,height;
EGSTERN int			xhot,yhot,status,x;
EGSTERN unsigned long 		plane_mask,depth;
EGSTERN unsigned long 		pixel;
EGSTERN unsigned long 		foreground, background;
EGSTERN int			bitmap_pad;
EGSTERN int         		screen;
EGSTERN int                     cells;
EGSTERN int                     current_pixel;
EGSTERN char                    text[11]; /** the text read from keyboard **/

/***************************************************/

EGSTERN XColor generic;

typedef struct _textset {
  Window win;                /* window text set resides in                   */
  Font font;                 /* font for use in the text set                 */
  int startx;                /* startign x position of the text set          */
  int starty;                /* starting y position of the text set          */
  int number;                /* number of text lines in the set              */
  int space;                 /* space between the text lines                 */
  int max;                   /* max characters displayable at a time         */
  int char_width;            /* character width                              */
  int char_height;           /* character height                             */
  int currently_pointed;     /* current text line being pointed to           */
  int char_pos;              /* current "pointer" position on the line       */
  unsigned long foreground;  /* forground pixel                              */
  unsigned long background;  /* background pixel                             */
  char text[40][200];        /* Text for the text lines                      */
  int view_start[40];        /* position in string of first visible char     */
} TextSet;

EGSTERN TextSet *CurrentTextSet;     /* Currently indicated Text Set                 */

/* Prototypes */
void TextLineBack(TextSet *set);
void TextLineForward(TextSet *set);
int TextLineUp(TextSet *set);
int TextLineDown(TextSet *set);
void DeleteTextSetChar(TextSet *set);
void AddTextSetChar(TextSet *set, char c);
TextSet *CreateTextSet(Window wind, int startx, int starty, int number,
		       int space, int max, Font font, int char_width,
		       int char_height, unsigned long foreground,
		       unsigned long background);
int SetTextSetLine(TextSet *set, int which);
void SetCurrentTextSet(TextSet *set, int dir);
void AddTextSetString(TextSet *set, char *str);
void RefreshTextSet(TextSet *set);
void NewButton(Window win, int x, int y, int width, int height, int state,
	  XColor color, XColor textcolor, char text[], int c_width,
	  int c_height, int mode);
void GetTextLineString(TextSet *set, int which, char *str);
void DrawRadio(int state, int x, int y, XColor color, int size);
int DrawShadowedBox(Window win,XColor color, int thick, int xcorner,
		     int ycorner, int length, int height);
void DisplayRadioButtonSet(int x, int y, int number, int space, int size,
		      int state[], XColor color);
void DrawScrollBar(Window win,int x,int y,int width,int height,int pos,
		   XColor color);
void RefreshTextLine(TextSet *set, int which);
void CheckTextSet(TextSet *set, int x, int y);

#endif

/*****************************************************************************/
/** This will draw shaded buttons of either "fixed" length or the length of **/
/** the string to be written in them.  The choice is made through style     **/
/*****************************************************************************/
void
DrawButton(window,style,state,x,y,textheight, textwidth, fixed, text, color)
     Window			window;
     int			style,state,x,y,textheight,textwidth,fixed;
     char			text[];
     XColor			color;
{
  int 				w;

  XFlush(display);
  XSetFillStyle(display, gc, FillSolid);
  XSetLineAttributes(display, gc, 3,LineSolid,CapRound,JoinMiter);
  XClearArea(display, window, x,y,textwidth*((int) strlen(text))+6,textheight + 6,False);
  generic.flags = DoRed | DoBlue | DoGreen;
  generic.red = color.red; generic.green = color.green; generic.blue = color.blue;
  if (generic.red > 0) generic.red -= SHADOW;
  if (generic.blue > 0) generic.blue -= SHADOW;
  if (generic.green > 0) generic.green -= SHADOW;
  (void) XAllocColor(display, colormap, &generic);
  if (style == RELATIVE)
    w = textwidth*((int) strlen(text));
  else
    w = fixed;
  if (state == UP) {
    XSetForeground(display, gc, color.pixel);
    XFillRectangle(display, window, gc, x+3, y+3,(w), textheight+12);
    XSetForeground(display, gc, generic.pixel);
    XDrawRectangle(display, window, gc, x,y,(w+6), textheight+14);
    XSetForeground(display, gc, BlackPixel(display, DefaultScreen(display)));
    XSetBackground(display, gc, color.pixel);
    XDrawImageString(display, window, gc, x+3,y+textheight+3,text,(int) strlen(text));
  }
  else {
    XSetForeground(display, gc, generic.pixel);
    XFillRectangle(display, window, gc, x+3, y+3,(w), textheight+12);
    XSetForeground(display, gc, color.pixel);
    XDrawRectangle(display, window, gc, x,y,(w+6), textheight+14);
    XSetForeground(display, gc, BlackPixel(display, DefaultScreen(display)));
    XSetBackground(display, gc, generic.pixel);
    XDrawImageString(display, window, gc, x+4,y+textheight+3,text,(int) strlen(text));
  }
  XSync(display,0);
  XFlush(display);
}


void DrawRadio(int state, int x, int y, XColor color, int size) 
{
  generic.flags = DoRed | DoBlue | DoGreen;
  generic.red =color.red;generic.green=color.green;generic.blue = color.blue;
  if (generic.red > 0) generic.red -= RADIO_SHADOW;
  if (generic.blue > 0) generic.blue -= RADIO_SHADOW;
  if (generic.green > 0) generic.green -= RADIO_SHADOW;
  XAllocColor(display, colormap, &generic);
  if (state == UP) {
    XSetForeground(display, gc, color.pixel);
    XFillRectangle(display, window, gc, x, y, size,size);
    XSetForeground(display, gc, generic.pixel);
    XFillRectangle(display, window, gc, x+2, y+2,size-4,size-4);
  }
  else {
    XSetForeground(display, gc, generic.pixel);
    XFillRectangle(display, window, gc, x, y, size,size);
    XSetForeground(display, gc, color.pixel);
    XFillRectangle(display, window, gc, x+2, y+2,size-4,size-4);
  }
}

/*********************************************************************/
/** This procedure draws a shadowed border box of 'thick' thickness **/
/** Placed at the coordinates indicated by 'xcorner', 'ycorner'.The **/
/** shadowed box will be 'length' long and 'height' high.           **/
/*********************************************************************/
int DrawShadowedBox(Window win,XColor color, int thick, int xcorner,
		     int ycorner, int length, int height)
{
  int count, increment,max=0;
  static int first = True;
  static XColor colors[MAX_BOX_THICK];
  
  if (thick > MAX_BOX_THICK) {
    fprintf(stderr, "ERROR : shadow box thickness specified too large.\n");
    return -1;
  }
  if (first) {
    first = False;
    count = 0;
    increment = 30000/(MAX_BOX_THICK/2);
    while (count < MAX_BOX_THICK) {
      if (count < MAX_BOX_THICK/2) {
	if (color.red > 1) color.red += increment;
	if (color.green > 1) color.green += increment;
	if (color.blue > 1) color.blue += increment;
      }
      else {
	if (color.red > 1) color.red -= increment; 
	if (color.green > 1) color.green -= increment;
	if (color.blue > 1) color.blue -= increment;
      }
      colors[count] = color;
      XAllocColor(display, colormap, &colors[count]);
      count++;
    }
  }
  increment = 0;
  count = 0; 
  while (count < thick) {
    XSetForeground(display, gc, colors[increment].pixel);
    
    /** Draw left border **/
    XDrawLine(display, win, gc, xcorner+count, ycorner, 
	      xcorner+count, ycorner+height+thick*2);
    /** Draw top border **/
    XDrawLine(display, win, gc, xcorner, ycorner+count, 
	      xcorner+length+thick*2, ycorner+count);
    /** Draw right border **/
    XDrawLine(display, win, gc, xcorner+length+thick+count, ycorner,
	      xcorner+thick+length+count, ycorner+height+thick*2);
    /** Draw bottom border **/
    XDrawLine(display, win, gc, xcorner, ycorner+height+count+thick,
	      xcorner+length+thick*2, ycorner+height+count+thick);
    if (count <= thick/2) {
      increment ++;
      max = increment;
    }
    else {
      if (increment == max)
	increment = MAX_BOX_THICK/2+(MAX_BOX_THICK/2-increment);
      else
	increment ++;
    }
    count++;
  }
  return EXIT_SUCCESS;
}
 
/*************************************************************************/
/** This procedure sets up a radio button set.  The programmer sends in **/
/** the number of buttons desired, the space between buttons, and the   **/
/** size of the buttons.  Note that currently you can only get          **/
/** vertically distributed radio buttons.                               **/
/*************************************************************************/
void DisplayRadioButtonSet(int x, int y, int number, int space, int size,
		      int state[], XColor color)
{
  int loop;

  XSetForeground(display, gc, color.pixel);
  XSetLineAttributes(display, gc, 1,LineSolid,CapRound,JoinMiter);
  for(loop = 0; loop < number; loop++) {
    XSetForeground(display, gc, background);
    XFillArc(display, window, gc, x, y, size,size,0,64*360);
    XSetForeground(display, gc, color.pixel);
    if (state[loop] == UP) 
      XDrawArc(display, window, gc, x, y, size,size,0,64*360);
    else
      XFillArc(display, window, gc, x, y, size,size,0,64*360);
    y += (size+space);
  }
}
    


/********************************************************************/
/** This procedure checks the radio button set specified with the  **/
/** coordinates given.  It returns 0 on failure, or 1-n depending  **/
/** on which radio button the coordinates corrospond to.           **/
/********************************************************************/
int CheckRadioButtonSet(x,y,number,space,size,xpos,ypos)
     int x,y,number,space,size,xpos,ypos;
{
  int ret,diff,extra;

  if (xpos < x || xpos > x+size) return 0; /** Not within the x-range **/
  if (ypos < y) return 0;  /** Too high **/
  if (ypos > y+(number*size)+(space*(number-1))) return 0; /** Too low **/

  diff = ypos-y;
  ret = diff/(size+space)+1;
  extra = diff%size;
  if (extra > size) return 0; /** coordinate was in the space between **/
  return ret;
}  

void NewButton(Window win, int x, int y, int width, int height, int state,
	  XColor color, XColor textcolor, char text[], int c_width,
	  int c_height, int mode)
{
  static XColor dark;
  static XColor medium;
  static XColor light;
  int tx,ty;
  int bw,bh;
  int loop;
  int index = 0;
  static int count = 0;
  static XColor colors[5][4];

  XSetFillStyle(display, gc, FillSolid);
  for (loop = 0; loop < count; loop++) {
    if (colors[loop][0].pixel == color.pixel) {
      index = loop;
      loop = count+1;
    }
  }
  if (loop == count) {
    count++;
    colors[loop][0] = color;
    dark.red = color.red; dark.green = color.green; dark.blue = color.blue; 
    if (dark.red > 1) dark.red -= 20000;
    if (dark.green > 1) dark.green -= 20000;
    if (dark.blue > 1) dark.blue -= 20000;
    dark.flags = COLOR_FLAGS;
    colors[loop][1] = dark;
    XAllocColor(display, colormap, &colors[loop][1]);
    dark = colors[loop][1];
    
    medium = dark;
    if (medium.red > 1) medium.red += 16000;
    if (medium.green > 1) medium.green += 16000;
    if (medium.blue > 1) medium.blue += 16000;
    colors[loop][2] = medium;
    XAllocColor(display, colormap, &colors[loop][2]);
    medium = colors[loop][2];
    

    light.red = color.red; light.green = color.green; light.blue = color.blue;
    if (light.red > 1) light.red += 20000;
    if (light.green > 1) light.green += 20000;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -