Ejemplo n.º 1
0
/*
 * draw_menu - draw menu on screen
 *
 * Returns MENU_CANCEL if the user cancelled, or the item number of the
 * selected item.
 *
 */
static void draw_menu(char *title, char **items, size_t num_items)  {
  size_t i;
  int x, y, w, h, by;

  /* draw the outline */
  gfx_fillRect(0xaf,MENU_X + 1, MENU_Y + 1, MENU_WIDTH, MENU_HEIGHT); // fillrect(0xaf,SHADOW_RECT);
  gfx_fillRect(0x00,MENU_X, MENU_Y, MENU_WIDTH, MENU_HEIGHT);   // fillrect(0x00,MENU_RECT);
  gfx_drawRect(0xff,MENU_X, MENU_Y, MENU_WIDTH, MENU_HEIGHT);   // drawrect(0xff,MENU_RECT);

  /* calculate x/y */
  x = MENU_X + MENU_ITEM_PAD;
  y = MENU_Y + MENU_ITEM_PAD * 2;
  getstringsize(title, &w, &h);
  h += MENU_ITEM_PAD * 2;

  /* draw menu stipple */
  for (i = MENU_Y; i < (size_t) y + h; i += 2)
    drawline(MENU_X, i, MENU_X + MENU_WIDTH-1, i,0xff);

  /* clear title rect */
  fillrect((OSD_BITMAP1_WIDTH - w) / 2 - 2, y - 2, w + 4, h,0x00);

  /* draw centered title on screen */
  putsxy((OSD_BITMAP1_WIDTH - w)/2, y, title);

  /* calculate base Y for items */
  by = y + h + MENU_ITEM_PAD;
  
  /* iterate over each item and draw it on the screen */
  for (i = 0; i < num_items; i++)
    putsxy(x+2, by + h * i, items[i]);
}
Ejemplo n.º 2
0
/*
 * select_item - select menu item (after deselecting current item)
 */
static void select_item(char *title, int curr_item, size_t item_i) {
  int x, y, w, h;

  /* get size of title, use that as height ofr all lines */
  getstringsize(title, &w, &h);
  h += MENU_ITEM_PAD * 2;

  /* calc x and width */
  x = MENU_X + MENU_ITEM_PAD;
  w = MENU_WIDTH - 2 * MENU_ITEM_PAD;

  /* if there is a current item, then deselect it */
  if (curr_item >= 0) {
    /* deselect old item */
    y = MENU_Y + h + MENU_ITEM_PAD * 2; /* account for title */
    y += h * curr_item;
    drawrect(x, y, w, h,0x00);
  }

  /* select new item */
  curr_item = item_i;

  /* select new item */
  y = MENU_Y + h + MENU_ITEM_PAD * 2; /* account for title */
  y += h * curr_item;
  drawrect(x, y, w, h,0xf9);
}
Ejemplo n.º 3
0
int 
xwindow_text_width(XWindow *xw, char *text) {
  float size = 0;
  xwindow_font_load(xw);
  switch(xw->font->type) {
  case XFONT_TYPE_SOFTWARE:
    getstringsize(text, strlen(text), &size);
    return view_to_x11_x( size, xw );
  case XFONT_TYPE_CORE:
    return xwindow_text_width_core(xw, text);
    break;
  case XFONT_TYPE_XFT:
    return xwindow_text_width_xft(xw, text);
    break;
  default:
    fprintf(stderr, "SAC: Unknown X11 Font Subsystem\n");
    break;
  }
  return 0;
}
Ejemplo n.º 4
0
void browser(char * rom) {
  int x, y, w, h, by;
  size_t i;

  int btn, sel_item=0, curr_item, num_items=6, nb=0,pos=0;
  char title[]="Start...";
  char (*items)[17];
  char (*list)[MAX_PATH];
  bool done = false;
  struct dirent *romdir;
  DIR * romd=NULL;

items = malloc(MAX_PATH*6);
list = malloc(MAX_PATH);

romd=opendir("/aoboy/roms");
if(romd) printf("Dir /aoboy/roms/ opened!\n");
else {
  mkdir("/aoboy/roms",0);
  if(romd) printf("Dir /aoboy/roms/ created and opened!\n");
  else printf("Dir error!\n");
}


  while((romdir=readdir(romd))!=NULL) {
     if(!(romdir->attribute & ATTR_DIRECTORY)) {
     list[nb][0]='\0';
     strcat(list[nb],romdir->d_name);
     nb++;
     list = realloc(list,MAX_PATH*(nb+1));
     }
  }

  gfx_fillRect(0xaf,11,9,140,128);
  gfx_fillRect(0x00,10,8,140,128);
  gfx_drawRect(0xff,10,8,140,128);

  x = 10 + 2;
  y = 8 + 2 * 2;
  getstringsize(title, &w, &h);
  h += 2 * 2;

  for (i = 8; i < (size_t) y + h; i += 2)
    drawline(10, i, 10 + 139, i,0xff);

  fillrect((160 - w) / 2 - 2, y - 2, w + 4, h,0x00);
  putsxy((160 - w)/2, y, title);

  by = y + h + 2;
  


while(!done) {
  if(pos > (nb-6)) num_items=nb-pos;
  else num_items=6;
//  for(i=0;i<num_items;i++) {items[i][0]='\0'; strcat(items[i],list[i+pos]);}
  for(i=0;i<num_items;i++) {strncpy(items[i],list[i+pos],16); items[i][16]='\0';}

  gfx_fillRect(0x00,11,29,138,106);
  for (i = 0; i < num_items; i++)
    putsxy(x+2, by + h * i, items[i]);

  curr_item = -1;
  select_item(title, curr_item, sel_item);
  curr_item = sel_item;

  while (1) {
    while (btn_readState());
    while(!(btn = btn_readState()));

    if(btn & BTMASK_DOWN) {
        sel_item = curr_item + 1;
        if (sel_item >= (int) num_items) {
           if(pos < (nb-6)) {sel_item=0;pos+=6;break;}
           else {sel_item = curr_item;}
        }
        else {
           select_item(title, curr_item, sel_item);
           curr_item = sel_item;
        }
      }
      else if(btn & BTMASK_UP) {
        sel_item = curr_item - 1;
        if (sel_item < 0) {
           if(pos > 0) {sel_item=5;pos-=6;break;}
           else {sel_item = curr_item;}
        }
        else {
           select_item(title, curr_item, sel_item);
           curr_item = sel_item;
        }
      }
      else if(btn & BTMASK_RIGHT) {
        done = true;
        break;
      }
      else if(btn & BTMASK_LEFT) {
      }

  }
  }

  rom[0]='\0';
  strcat(rom,"/AOBOY/ROMS/");
  strcat(rom,list[curr_item+pos]);
  strcat(rom,"\0");
  closedir(romd);
  free(items);
  free(list);
  return;
}