コード例 #1
0
ファイル: BeginBattlePhase.cpp プロジェクト: Noxalus/YAPOG
  void BeginBattlePhase::Draw (yap::IDrawingContext& context)
  {
    if (!IsVisible ())
      return;

    HandleDraw (context);
  }
コード例 #2
0
ファイル: gui.c プロジェクト: patrickmarlier/etes603-dev
int main(int argc, char *argv[])
{
  pthread_t thread;
  int screen_number;
  int i;
  XEvent event;
  struct fp_img_dev *dev;

  if (argc >= 2) {
    strFilename = argv[1];
  } else {
    strFilename = strFilenameDefault;
  }
  /* Multi-thread app */
  XInitThreads();
  dis = XOpenDisplay(NULL);
  if (NULL == dis) {
    fprintf(stderr, "unable to open display\n");
    return EXIT_FAILURE;
  }

  screen_number = DefaultScreen (dis);
  //parent = RootWindow (dis, screen_number);
  parent = DefaultRootWindow(dis);

  fg = BlackPixel(dis, screen_number);
  bg = WhitePixel(dis, screen_number);

  mainwin = XCreateSimpleWindow(dis, parent, 0, 0, win_width, win_height, 0, fg, bg);
  if (mainwin == None) {
    fprintf (stderr, "unable to create window\n");
    return EXIT_FAILURE;
  }

  gc = XCreateGC(dis, mainwin, 0, NULL);
  if (gc == NULL) {
    fprintf (stderr, "unable to allocate GC\n");
    return EXIT_FAILURE;
  }

  // set up font
  if ((font_info = XLoadQueryFont(dis, fontname)) == NULL) {
    perror("XLoadQueryFont");
    exit(1);
  }
  XSetFont(dis, gc, font_info->fid);

  // Create Cursor for Buttons
  mycursor = XCreateFontCursor(dis, XC_hand1);

  // Quit Button
  button_quit = XCreateSimpleWindow(dis, mainwin, 300, 10, BUTTON_WIDTH, BUTTON_HEIGHT, 1, fg, bg);
  XChangeWindowAttributes(dis, button_quit, CWBackingStore, &setwinattr);
  XSelectInput(dis, button_quit, BUTTON_MASK);
  XDefineCursor(dis, button_quit, mycursor);
  XMapWindow(dis, button_quit);

  // Mode Buttons
  for (i = 0 ; i < 3; i++) {
    button_modes[i] = XCreateSimpleWindow(dis, mainwin, 300+i*65, 30, BUTTON_WIDTH, BUTTON_HEIGHT, 1, fg, bg);
    XChangeWindowAttributes(dis, button_modes[i], CWBackingStore, &setwinattr);
    XSelectInput(dis, button_modes[i], BUTTON_MASK);
    XDefineCursor(dis, button_modes[i], mycursor);
    XMapWindow(dis, button_modes[i]);
  }

  // Drawing area
  draw_win = XCreateSimpleWindow(dis, mainwin, 0, 0, image_width, image_height, 1, fg, bg);
  XSelectInput(dis, draw_win, BUTTON_MASK);
  XMapWindow(dis, draw_win);
  draw_gc = XCreateGC(dis, draw_win, 0, NULL);
  if (draw_gc == NULL) {
    fprintf (stderr, "unable to allocate Draw_win GC\n");
    return EXIT_FAILURE;
  }

  // Create tuning buttons
  int y = 60, id = 0;
  MakeButton(300, y, "IncReg03", IncReg03, id);
  MakeButton(400, y, "DecReg03", DecReg03, id+1);
  y += 20; id += 2;
  MakeButton(300, y, "IncReg04", IncReg04, id);
  MakeButton(400, y, "DecReg04", DecReg04, id+1);
  y += 20; id += 2;
  MakeButton(300, y, "IncReg10", IncReg10, id);
  MakeButton(400, y, "DecReg10", DecReg10, id+1);
  y += 20; id += 2;
  MakeButton(300, y, "IncReg1A", IncReg1A, id);
  MakeButton(400, y, "DecReg1A", DecReg1A, id+1);
  y += 20; id += 2;
  MakeButton(300, y, "IncReg93", IncReg93, id);
  MakeButton(400, y, "DecReg93", DecReg93, id+1);
  y += 20; id += 2;
  MakeButton(300, y, "IncReg94", IncReg94, id);
  MakeButton(400, y, "DecReg94", DecReg94, id+1);
  y += 20; id += 2;
  MakeButton(300, y, "IncGain", IncGain, id);
  MakeButton(400, y, "DecGain", DecGain, id+1);
  y += 20; id += 2;
  MakeButton(300, y, "IncVRT", IncVRT, id);
  MakeButton(400, y, "DecVRT", DecVRT, id+1);
  y += 20; id += 2;
  MakeButton(300, y, "IncVRB", IncVRB, id);
  MakeButton(400, y, "DecVRB", DecVRB, id+1);
  y += 20; id += 2;
  MakeButton(300, y, "IncDTVRT", IncDTVRT, id);
  MakeButton(400, y, "DecDTVRT", DecDTVRT, id+1);
  y += 20; id += 2;
  MakeButton(300, y, "IncVCO_C", IncVCO_C, id);
  MakeButton(400, y, "DecVCO_C", DecVCO_C, id+1);
  y += 20; id += 2;
  MakeButton(300, y, "IncDCOff", IncDCOffset, id);
  MakeButton(400, y, "DecDCOff", DecDCOffset, id+1);

  // XSelectInput (dis, mainwin, ExposureMask | KeyPressMask | ButtonPressMask);
  XMapWindow(dis, mainwin);
  XFlush(dis);




  dev = global_init();

  if (dev == NULL || dev->udev == NULL) {
    fprintf(stderr, "Cannot open device\n");
  }

  /* create thread */
  if (dev != NULL && dev->udev != NULL)
    pthread_create(&thread, NULL, thread_entry, (void*)dev);

  while (1)
    {
      if (XCheckWindowEvent(dis, button_quit, BUTTON_MASK, &event)) {
        if (HandleQuitButton(&event))
          goto finishing;
      }
      /* All modes buttons */
      for (i = 0; i < 3; i++) {
        if (XCheckWindowEvent(dis, button_modes[i], BUTTON_MASK, &event))
          HandleModeButtons(&event, i);
      }
      /* All regs buttons */
      for (i = 0; i < 128; i++) {
        if (XCheckWindowEvent(dis, MenuButton[i].window, BUTTON_MASK, &event))
          HandleRegButton(&event, i, dev);
      }
      /* TODO not BUTTON MASK but only? */
      if (XCheckWindowEvent(dis, draw_win, BUTTON_MASK, &event))
        HandleDraw(&event);
#if 0
      XNextEvent (dis, &event);

      switch (event.type)
        {
          case ButtonPress:
            /* The man page for XButtonEvent documents this. */
            printf ("You pressed button %d\n", event.xbutton.button);
            modifyLive (dis, win, gc);
            break;
          case Expose:
            //printf ("Redrawing from Expose.\n");
            draw (dis, win, gc);
            break;
          case MapNotify:
            printf ("MapNotify Event.\n");
            break;
          case KeyPress:
            /* Close the program if q is pressed. */
            printf ("KeyPress event %d key %d\n", event.type, ((XKeyEvent)event.xkey).keycode );
            modifyLive (dis, win, gc);
#define REG_TUNE 0xE6
            if (XK_o == XLookupKeysym (&event.xkey, 0)) {
                unsigned char reg = 0;
                dev_get_regs(dev->udev, 2, REG_TUNE, &reg);
                dev_set_regs(dev->udev, 2, REG_TUNE, ++reg);
                printf("%02x: %02x\n", REG_TUNE, reg);
            }
            if (XK_l == XLookupKeysym (&event.xkey, 0)) {
                int reg;
                dev_get_regs(dev->udev, 2, REG_TUNE, &reg);
                dev_set_regs(dev->udev, 2, REG_TUNE, --reg);
                printf("%02x: %02x\n", REG_TUNE, reg);
            }
            if (XK_q == XLookupKeysym (&event.xkey, 0))
              goto finishing;
            break;
          default:
            printf ("Unknown event %d\n", event.type);
            break;
        }
#endif
    }

finishing:
  stop = 1;
  usleep(500*1000);
  if (dev != NULL && dev->udev != NULL)
    global_exit(dev);

  /* For some reason the event loop stopped before q was pressed. */
  return EXIT_FAILURE;
}