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

📄 garnish.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 2 页
字号:
  XSetLineAttributes(display, gc, 1,LineSolid,CapRound,JoinMiter);  /** Draw up arrow **/  XDrawLine(display, win, gc, x+width/2,y+18,x+width/2,y+2);  XDrawLine(display, win, gc, x+width/2-4,y+6,x+width/2,y+2);  XDrawLine(display, win, gc, x+width/2+4,y+6,x+width/2,y+2);  /** Draw down arrow **/  XDrawLine(display, win, gc, x+width/2,y+height-2,x+width/2,y+height-18);  XDrawLine(display, win, gc, x+width/2-4,y+height-6,x+width/2,y+height-2);  XDrawLine(display, win, gc, x+width/2+4,y+height-6,x+width/2,y+height-2);  /** Draw the position marker **/  XSetForeground(display, gc, foreground.pixel);  XFillRectangle(display, win, gc, x+2,y+20+pos*(height-40)/40,		 width-4,(height-40)/40);}void RefreshTextLine(TextSet *set, int which){  int x, y,l;  char stemp[80];  int state;  XColor fore,back;  if (which == set->currently_pointed)     state = DOWN;  else    state = UP;  fore.pixel = set->foreground;  back.pixel = set->background;  fore.flags = back.flags = COLOR_FLAGS;  XQueryColor(display, colormap, &fore);  XQueryColor(display, colormap, &back);  x = set->startx; y = set->starty;  y += which*(set->space + set->char_height);  XSetForeground(display,  gc, set->background);/*  XFillRectangle(display, set->win, gc, set->startx-3, y-set->char_height,		 set->max*set->char_width+6,set->char_height+4); */  XSetFont(display, gc, set->font);  XSetForeground(display, gc, set->foreground);  XSetBackground(display, gc, set->background);/*  XDrawLine(display, set->win, gc, x, y+1, x+set->max*set->char_width, y+1);*/  l = (int) strlen(&set->text[which][set->view_start[which]]);  memset(stemp, 0, sizeof(stemp));  if (l < set->max)    strncpy(stemp, &set->text[which][set->view_start[which]],	    l);  else    strncpy(stemp, &set->text[which][set->view_start[which]],	    set->max);  NewButton(set->win, x, y-set->char_height/*-set->space/3*/, 	    set->max*set->char_width,	    set->char_height, state, back, fore, 	    stemp, set->char_width, set->char_height,FIXED);  XSetForeground(display, gc, set->foreground);  if (which == set->currently_pointed) {    int loop;    x += (set->char_pos-set->view_start[set->currently_pointed])*      set->char_width;    y -= 2;    for (loop = 0; loop < 4; loop++) {      XDrawLine(display, set->win, gc, x-loop, y+loop, x,y);      XDrawLine(display, set->win, gc, x-loop, y+loop, x+loop,y+loop);      XDrawLine(display, set->win, gc, x+loop, y+loop, x, y);    }  }}/*****************************************************************************//** This procedure refreshes the entire test set.                           **//*****************************************************************************/void RefreshTextSet(TextSet *set){  int loop;  for (loop = 0; loop < set->number; loop++)     RefreshTextLine(set, loop);}void CheckTextSet(TextSet *set, int x, int y){  int dist; /* distance of pointer from start of line */  dist = x-set->startx;  if (x < set->startx || x > set->startx+set->max*set->char_width)    return;  if (y < set->starty - set->char_height ||      y > set->starty + (set->char_height*set->number-1)+      (set->space*(set->number-1)))    return;  if (y > set->starty-set->char_height && y < set->starty)  {    int i;    i = set->currently_pointed;    set->currently_pointed = 0;        set->char_pos = set->view_start[set->currently_pointed] +      (dist/set->char_width);    if (set->char_pos > (((int) strlen(set->text[set->currently_pointed]))-1))      set->char_pos = (int) strlen(set->text[set->currently_pointed]);    if (i >= 0)      RefreshTextLine(set, i);    if (set->number != 1)      RefreshTextLine(set, 0);  }  else {    int i;        if (set->number < 2)       return;    y = y - set->starty;    y = y / (set->char_height+set->space);    i = set->currently_pointed;    if (y >= set->number-1)  return;    set->currently_pointed = y+1;    set->char_pos = set->view_start[set->currently_pointed]      + (dist/set->char_width);    if (set->char_pos > (((int) strlen(set->text[set->currently_pointed]))-1))      set->char_pos = (int) strlen(set->text[set->currently_pointed]);    if (i >= 0 && i < set->number)      RefreshTextLine(set, i);    if (y+1 < set->number)    RefreshTextLine(set, y+1);  }  /*   * As we may have several text sets operational at once, we need to   * remember which one was last indicated.   */  CurrentTextSet = set;}int SetTextSetLine(TextSet *set, int which) {  if (which > -1 && which < set->number)    set->currently_pointed = which;  else    return 0;  return 1;}int GetTextSetLine(set)      TextSet *set;{  if (!set) return -1;  return set->currently_pointed;}void GetTextLineString(TextSet *set, int which, char *str){  memset(str, 0,  strlen(str)); strcpy(str, set->text[which]);}void AddTextSetString(TextSet *set, char *str){  if (set->currently_pointed == -1) {    fprintf(stderr, "ERROR : Currently pointed is -1!\n");    exit(0);  }  strcpy(set->text[set->currently_pointed], str);  RefreshTextLine(set, set->currently_pointed);}TextSet *QueryCurrentTextSet(){  return CurrentTextSet;}void SetCurrentTextSet(TextSet *set, int dir){  if (CurrentTextSet != NULL)    RefreshTextSet(CurrentTextSet);  if (CurrentTextSet == set)    return;  if (CurrentTextSet != NULL)    CurrentTextSet->currently_pointed = -1;  if (CurrentTextSet != NULL)    RefreshTextSet(CurrentTextSet);  if (dir == UP)    set->currently_pointed = set->number-1;  else    set->currently_pointed = 0;  if (CurrentTextSet != NULL)    set->char_pos = CurrentTextSet->char_pos;  else    set->char_pos = 0;  CurrentTextSet = set;  if (set->text[set->currently_pointed][0] == '\0')    set->char_pos = 0;  else if (set->char_pos > (((int) strlen(set->text[set->currently_pointed]))-1))    set->char_pos = (int) strlen(set->text[set->currently_pointed]);  RefreshTextSet(set);}/*****************************************************************************//** This procedure adds a character to the currently pointed text line in   **//** the indicated set.  If the set is NULL then the CurrentTextSet is used. **//*****************************************************************************/void AddTextSetChar(TextSet *set, char c){  char stemp[180];  if (!set)     set = CurrentTextSet;  if (set->currently_pointed == -1)    return;  memset(stemp, 0, sizeof(stemp));  strncpy(stemp, set->text[set->currently_pointed], set->char_pos);  stemp[set->char_pos] = c;  strcat(stemp, &set->text[set->currently_pointed][set->char_pos]);  strcpy(set->text[set->currently_pointed], stemp);  set->char_pos++;  if (set->char_pos > set->view_start[set->currently_pointed]+set->max)    set->view_start[set->currently_pointed]++;  RefreshTextLine(set, set->currently_pointed);}void TextLineBack(TextSet *set){  if (!set)     set = CurrentTextSet;  if (set->char_pos == 0) return;  if (set->char_pos == set->view_start[set->currently_pointed]) {    set->char_pos --;    set->view_start[set->currently_pointed] --;  }  else    set->char_pos--;  RefreshTextLine(set, set->currently_pointed);}void TextLineForward(TextSet *set){  if (!set)     set = CurrentTextSet;  if (set->char_pos > (((int) strlen(set->text[set->currently_pointed]))-1))    return;  set->char_pos++;  if ((set->char_pos - set->view_start[set->currently_pointed]) > set->max)     set->view_start[set->currently_pointed]++;  RefreshTextLine(set, set->currently_pointed);}int TextLineUp(TextSet *set){  if (!set)     set = CurrentTextSet;  if (set->currently_pointed == 0)    return -1;  set->currently_pointed--;  if (set->char_pos >  (((int) strlen(set->text[set->currently_pointed]))-1))    set->char_pos = (int) strlen(set->text[set->currently_pointed]);  RefreshTextLine(set, set->currently_pointed+1);  RefreshTextLine(set, set->currently_pointed);  return EXIT_SUCCESS;}int TextLineDown(TextSet *set){  if (!set)     set = CurrentTextSet;  if (set->currently_pointed < set->number-1) {    set->currently_pointed ++;    if (set->char_pos >  (((int) strlen(set->text[set->currently_pointed]))-1))      set->char_pos = (int) strlen(set->text[set->currently_pointed]);    RefreshTextLine(set, set->currently_pointed-1);    RefreshTextLine(set, set->currently_pointed);    return 0;  }  return -1;}void DeleteTextSetChar(TextSet *set){  char stemp[180];      if (!set)     set = CurrentTextSet;  if (!set->char_pos) return;  set->char_pos--;  memset(stemp, 0, sizeof(stemp));  if (set->char_pos - set->view_start[set->currently_pointed] < 0)    set->view_start[set->currently_pointed]--;  strncpy(stemp, set->text[set->currently_pointed], set->char_pos);  strcat(stemp, &set->text[set->currently_pointed][set->char_pos+1]);  strcpy(set->text[set->currently_pointed], stemp);  RefreshTextLine(set, set->currently_pointed);}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 loop;  TextSet *ret;    ret = (TextSet *) malloc(sizeof(TextSet));  ret->win         = wind;  ret->startx      = startx;  ret->starty      = starty;  ret->number      = number;  ret->space       = space;  ret->max         = max;  ret->font        = font;  ret->char_width  = char_width;  ret->char_height = char_height;  ret->currently_pointed = 1;  ret->char_pos    = 0;  ret->foreground  = foreground;  ret->background  = background;  for (loop = 0; loop < number; loop ++) {    ret->text[loop][0] = '\0';    ret->view_start[loop]  = 0;  }  CurrentTextSet=ret;  return ret;}

⌨️ 快捷键说明

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