📄 garnish.c
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved. *//* GARNISH: $Revision: 1.6 $ ; $Date: 2006/11/07 23:20:45 $ */#include "par.h"#include <X11/Xlib.h>#include <X11/Xutil.h>#include "xwindow.h"#include "garnish.h"#include "picking.h"/*****************************************************************************//** 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 **//*****************************************************************************/voidDrawButton(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; if (light.blue > 1) light.blue += 20000; light.flags = COLOR_FLAGS; colors[loop][3] = light; XAllocColor(display, colormap, &colors[loop][3]); light = colors[loop][3]; } else { dark = colors[index][1]; medium = colors[index][2]; light = colors[index][3]; } bw = 3; bh = 3; XSetLineAttributes(display, gc, 1,LineSolid,CapRound,JoinMiter); /** Draw the main text rectangle **/ if (state == UP) XSetForeground(display, gc, color.pixel); else XSetForeground(display, gc, medium.pixel); XFillRectangle(display, win, gc, x,y,width,height); /** Place the text in the rectangle **/ if (((int) strlen(text)) > 0) { if (mode == FIXED) tx = 0; else tx = width/2-(((int) strlen(text))*c_width)/2; ty = height - (height - c_height)/2; XSetForeground(display, gc, textcolor.pixel); XDrawString(display, win, gc, x+tx,y+ty,text,(int) strlen(text)); } /** Draw the upper highlight border **/ if (state == UP) XSetForeground(display, gc, light.pixel); else XSetForeground(display, gc, dark.pixel); XFillRectangle(display, win, gc, x-bw, y-bh+1,bw,height+bh); for(loop = 0; loop < bh; loop++) XDrawLine(display, win, gc, x, y-loop,x+width+loop,y-loop); if (state == UP) XSetForeground(display, gc, dark.pixel); else XSetForeground(display, gc, light.pixel); XFillRectangle(display, win, gc, x-bw, y+height,width+bw*2,bh); for(loop = 0; loop < bw; loop++) XDrawLine(display, win, gc, x+width+loop, y-loop,x+width+loop, y+height);}voidDrawScrollBar(Window win,int x,int y,int width,int height,int pos,XColor color){ XColor accentuate; XColor foreground; if ((((unsigned int) (color.red)) + ((unsigned int) color.blue) + ((unsigned int) color.green)) < ((unsigned int) 90000)) foreground.red = foreground.blue = foreground.green = 0; else foreground.red = foreground.blue = foreground.green = 65000; XAllocColor(display, colormap, &foreground); accentuate.red = color.red; accentuate.green = color.green; accentuate.blue = color.blue; accentuate.flags = COLOR_FLAGS; if (accentuate.red > 1) accentuate.red -= 15000; if (accentuate.green > 1) accentuate.green -= 15000; if (accentuate.blue > 1) accentuate.blue -= 15000; XAllocColor(display, colormap, &accentuate); XSetForeground(display, gc, color.pixel); XFillRectangle(display, win, gc, x,y,width,height); /** Draw the Arrows Boxes **/ XSetForeground(display, gc, accentuate.pixel); XFillRectangle(display, win, gc, x,y,20,width); XFillRectangle(display, win, gc, x,y+height-20,20,width); XSetForeground(display, gc, foreground.pixel);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -