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

📄 display.c

📁 树大根深三棱尽所标杆ssfsfsa fdsafs
💻 C
📖 第 1 页 / 共 3 页
字号:
                     {"memo", {173, 277, 28, 29}}};static void HandleKey(Widget w, XtPointer client_data, XEvent *event,                      Boolean *continue_to_dispatch){  unsigned key = (unsigned) client_data;  *continue_to_dispatch = True;  switch(event->type) {  case ButtonPress:    if (event->xbutton.button == 1)      xcpKeyEvent(1, key);    else if (event->xbutton.button == 3)      do_menu(event->xbutton.x_root, event->xbutton.y_root);    break;  case ButtonRelease:    if (event->xbutton.button == 1)      xcpKeyEvent(0, key);    break;  default:    fprintf(stderr, "got an unexpected event\n");    exit(1);    break;  }}static void CreateKeys(Widget w){  unsigned i;  for (i = 0; i < XtNumber(keys); i++) {    Widget key = XtVaCreateManagedWidget(keys[i].name, widgetClass, w,                                         XtNx, keys[i].bounds.x * MagFactor,                                         XtNy, keys[i].bounds.y * MagFactor,                                         XtNwidth,                                         keys[i].bounds.width * MagFactor,                                         XtNheight,                                         keys[i].bounds.height * MagFactor,                                         XtNborderWidth, 0,                                         XtNbackgroundPixmap, ParentRelative,                                         NULL);    XtAddEventHandler(key, ButtonPressMask | ButtonReleaseMask |                      OwnerGrabButtonMask, False, HandleKey, (XtPointer)i);  }}/************************************************************ * Handle a pen event                                       * * img is a pointer to the shared memory structure which    * * holds the custom registers which are shared between the  * * CPU and Display processes. down is 1 if the pen is down, * * x and y are the coordinates of the pen                   * ************************************************************/static void xcpPenEvent(shared_img *img, int down, int x, int y){  if (!img->pendown && down) {	/* pen going down */    img->pen = 1;    img->run_updateisr = 1;  } else if (img->pendown && !down) { /* pen coming up */    img->pen = 0;    img->run_updateisr = 1;  }  img->pendown = down;  img->penx = (int)(x/MagFactor);  img->peny = (int)(y/MagFactor);}static void HandleDigitizer(Widget w, XtPointer client_data, XEvent *event,                            Boolean *continue_to_dispatch){  static Time start;  *continue_to_dispatch = True;  switch(event->type) {  case ButtonPress:     /* a mouse button was pressed */    if (event->xbutton.button == 1) {      xcpPenEvent(shared, 1, event->xbutton.x, event->xbutton.y);      start = event->xbutton.time;    }    else if (event->xbutton.button == 3)      do_menu(event->xbutton.x_root, event->xbutton.y_root);    break;  case ButtonRelease:   /* a mouse button was released */    if (event->xbutton.button == 1)      xcpPenEvent(shared, 0, event->xbutton.x, event->xbutton.y);    break;  case MotionNotify:    /* mouse moved with button down */    if (!buffer_size)      xcpPenEvent(shared, 1, event->xmotion.x, event->xmotion.y);    else {      int nevents, i;      XTimeCoord *xypos;      xypos = XGetMotionEvents(XtDisplay(w), XtWindow(w), start,                               event->xmotion.time, &nevents);      start = event->xmotion.time;      for (i = 0; i < nevents; i++)        xcpPenEvent(shared, 1, xypos[i].x, xypos[i].y);      XFree(xypos);    }    break;  default:    fprintf(stderr, "got an unexpected event\n");    exit(1);    break;  }}static Widget CreateDigitizer(Widget w){  Widget digitizer = XtVaCreateManagedWidget("digitizer",                                             compositeWidgetClass, w,                                             XtNx, 32 * MagFactor,                                             XtNy, 33 * MagFactor,                                             XtNwidth, lcdwidth,                                             XtNheight, 227 * MagFactor,                                             XtNborderWidth, 0,                                             XtNbackgroundPixmap,                                             ParentRelative,                                             NULL);  XtAddEventHandler(digitizer, ButtonPressMask | ButtonReleaseMask |                    Button1MotionMask | OwnerGrabButtonMask, False,                    HandleDigitizer, NULL);  return digitizer;}static void xcpKBtoASCII(shared_img *shptr, XEvent *event){  static KeySym		keysym;  static XComposeStatus	compose;  int			count, bufsize, in;  char			buffer[8];  bufsize = 8;  count = XLookupString((XKeyEvent *) event,			buffer,			bufsize,			&keysym,			&compose);  if (count > 0) {    if (buffer[0] == '\r') {      buffer[0] = '\n';    }    in = shptr->kbin;    shptr->kb[in] = buffer[0];    shptr->kbin = (in + 1) & 7;  }}static void HandleClientMessage(Widget w, XtPointer client_data, XEvent *event,                                Boolean *continue_to_dispatch){  *continue_to_dispatch = True;  if (event->type == ClientMessage)    if (event->xclient.data.l[0] == (Atom)client_data) {      xcpCleanup();    }}static void HandleXEvents(Widget w, XtPointer client_data, XEvent *event,                          Boolean *continue_to_dispatch){  shared_img *shptr = (shared_img *)client_data;  *continue_to_dispatch = True;  switch(event->type) {  case KeyPress:    xcpKBtoASCII(shptr, event);    break;  case ButtonPress:		/* a mouse button was pressed */    if (event->xbutton.button == 3)      do_menu(event->xbutton.x_root, event->xbutton.y_root);    break;  default:    fprintf(stderr, "got an unexpected event\n");    exit(1);    break;  }}static int shmError(Display *dis, XErrorEvent *err){    hitError = 1;    return 0;}char *xcpInitialize(shared_img *shptr, XtAppContext context, Widget topWidget,                    int no_x_shm, int magfactor, int use_private_colormap,                    char *BackgroundColorName, char *BacklightColorName){  int depth, pad;  char *sbuf = NULL;  int i;  CMAP cmap;  Widget LCD;  Widget Case, digitizer;  Pixmap case_bitmap, case_mask;  static const unsigned short greylevel[7] =    { 65535, 49152, 45056, 32768, 20480, 16384, 0};  if(magfactor) MagFactor = magfactor;  casewidth *= MagFactor;  caseheight *= MagFactor;  lcdwidth *= MagFactor;  lcdheight *= MagFactor;  shared = shptr;  /*   * Attempt to open a display connection   * to the default display   */  xcpDisplay = XtDisplay(topWidget);  if(!xcpDisplay) {    fprintf(stderr, "E - open display failed\n");    return NULL;  }  /*   * Get some information about the   * display   */  xcpScreen = DefaultScreenOfDisplay(xcpDisplay);  xcpScreenNum = DefaultScreen(xcpDisplay);  depth = DefaultDepthOfScreen(xcpScreen);  xcpDepth = depth;  buffer_size = XDisplayMotionBufferSize(xcpDisplay);  cmap = CMAP_Create(xcpDisplay, xcpScreenNum,		     DefaultVisual(xcpDisplay, xcpScreenNum), AllocAll,		     use_private_colormap);  /*   * Create a window for the case   */  Case = XtVaCreateManagedWidget("case", compositeWidgetClass, topWidget,                                 XtNwidth, casewidth, XtNheight, caseheight,                                 XtNcolormap, CMAP_GetColormap(cmap),                                 XtNborder,                                 BlackPixel(xcpDisplay, xcpScreenNum),                                 NULL);  XtVaSetValues(topWidget, XtNwidth, casewidth, XtNheight, caseheight,                XtNmaxWidth, casewidth, XtNmaxHeight, caseheight,                XtNminWidth, casewidth, XtNminHeight, caseheight,                XtNcolormap, CMAP_GetColormap(cmap),                XtNinput, True,                XtNborder, BlackPixel(xcpDisplay, xcpScreenNum), NULL);  XtAddEventHandler(topWidget, ButtonPressMask | KeyPressMask |                    OwnerGrabButtonMask, False, HandleXEvents,                    (XtPointer)shptr);  /*   * Create a window for the LCD   * make it a child of the case window   * offset it by (32, 33) from TL of case window   */  /* Get colors */  /* Make the "normal" background */  if (BackgroundColorName) {    CMAP_AllocNamedColor(cmap, BackgroundColorName, &xcpGreys[0]);  } else {    xcpGreys[0].red = 0x9000;    xcpGreys[0].green = 0xb300;    xcpGreys[0].blue = 0x9800;    CMAP_AllocColor(cmap, &xcpGreys[0]);  }  /* Make the rest of the normal shades */  for(i=1;i<7;++i) {    xcpGreys[i].red = (((unsigned long)(greylevel[i]))*	((unsigned long)(xcpGreys[0].red)))/((unsigned long)(greylevel[0]));    xcpGreys[i].green = (((unsigned long)(greylevel[i]))*	((unsigned long)(xcpGreys[0].green)))/((unsigned long)(greylevel[0]));    xcpGreys[i].blue = (((unsigned long)(greylevel[i]))*	((unsigned long)(xcpGreys[0].blue)))/((unsigned long)(greylevel[0]));    CMAP_AllocColor(cmap, xcpGreys+i);  }  /* Make the "backlit" background */  if (BacklightColorName) {    CMAP_AllocNamedColor(cmap, BacklightColorName, &xcpGreys[7]);  } else {    xcpGreys[7].red = 0x8000;    xcpGreys[7].green = 0xffff;    xcpGreys[7].blue = 0x8000;    CMAP_AllocColor(cmap, &xcpGreys[7]);  }  /* Make the rest of the normal shades */  for(i=8;i<14;++i) {    xcpGreys[i].red = (((unsigned long)(greylevel[i-7]))*	((unsigned long)(xcpGreys[7].red)))/((unsigned long)(greylevel[0]));    xcpGreys[i].green = (((unsigned long)(greylevel[i-7]))*	((unsigned long)(xcpGreys[7].green)))/((unsigned long)(greylevel[0]));    xcpGreys[i].blue = (((unsigned long)(greylevel[i-7]))*	((unsigned long)(xcpGreys[7].blue)))/((unsigned long)(greylevel[0]));    CMAP_AllocColor(cmap, xcpGreys+i);  }  digitizer = CreateDigitizer(Case);  LCD = XtVaCreateManagedWidget("lcd", widgetClass, digitizer,                         XtNx, 0,                         XtNy, 0,                         XtNwidth, lcdwidth,                         XtNheight, lcdheight,                         XtNcolormap, CMAP_GetColormap(cmap),                         XtNbackground, xcpOffPixel,                         XtNborder, xcpOffPixel,                         XtNborderWidth, 0,                         NULL);  XtAddEventHandler(LCD, ExposureMask | OwnerGrabButtonMask, False,                    HandleExpose, NULL);  XtSetMappedWhenManaged(topWidget, False);  set_icon(topWidget);  XtRealizeWidget(topWidget);  /*   * Display the pixmap of the case   */  {    XpmColorSymbol symbols[10];    XpmAttributes case_attributes;    XImage *case_img, *case_img_mask, *case_img_, *case_img_mask_;    int status;    int i,j,k=0,l=0;    case_attributes.colorsymbols  = symbols;    case_attributes.colormap      = CMAP_GetColormap(cmap);    case_attributes.numsymbols    = 0;    case_attributes.valuemask     = 0;    case_attributes.valuemask    |= XpmReturnPixels;    case_attributes.valuemask    |= XpmReturnInfos;    case_attributes.valuemask    |= XpmReturnExtensions;    case_attributes.valuemask    |= XpmColormap;    case_attributes.valuemask    |= XpmCloseness; /* close enough..   */    case_attributes.closeness     = 40000;        /* ..is good enough *//* We need to have a version of Xpm the supports the colormap closures.  The * earliest one that does this is 4.9 which is also known as 3.4i. */#if XpmIncludeVersion < 30409    case_attributes.alloc_color   = CMAP_GetXPMAllocColorFunc();    case_attributes.free_colors   = CMAP_GetXPMFreeColorsFunc();    case_attributes.color_closure = CMAP_GetXPMClosure(cmap);    case_attributes.valuemask    |= XpmAllocColor;    case_attributes.valuemask    |= XpmFreeColors;    case_attributes.valuemask    |= XpmColorClosure;#endif    status = XpmCreateImageFromData(xcpDisplay, case_xpm, &case_img,                                    &case_img_mask, &case_attributes);    if (status != 0) {      fprintf(stderr, "X - XpmCreateImageFromData failed. Sorry, no case.\n");    } else {      if(MagFactor > 1) {	unsigned long pixel = 0;        sbuf = (char *)malloc(((depth + 7) / 8) * casewidth * caseheight);        case_img_ = XCreateImage(xcpDisplay,                                 DefaultVisual(xcpDisplay, xcpScreenNum),                                 depth, ZPixmap, 0, sbuf, casewidth,                                 caseheight, depth,                                 casewidth * ((depth + 7) / 8));

⌨️ 快捷键说明

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