Changeset c2c5c77 for fmtext.c


Ignore:
Timestamp:
Mar 28, 2007, 10:54:33 PM (17 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
7f33c18
Parents:
af9b92e
Message:
Adding 256-color support. This requires a version of ncurses that
supports ABI-6. Colors beyond the first eight are refered to by
number.

Perl now has the number of colors exposed to it by way of
  BarnOwl::getnumcolors()
and also has a mechanism for undefining filters using
  BarnOwl::_remove_filter([filter-name])

You can't remove the 'all' filter or the current filter.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fmtext.c

    ra387d12e rc2c5c77  
    1212  f->textbuff=owl_malloc(5);
    1313  f->fmbuff=owl_malloc(5);
    14   f->fgcolorbuff=owl_malloc(5);
    15   f->bgcolorbuff=owl_malloc(5);
     14  f->fgcolorbuff=owl_malloc(5 * sizeof(short));
     15  f->bgcolorbuff=owl_malloc(5 * sizeof(short));
    1616  f->textbuff[0]=0;
    1717  f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
     
    6060  int i;
    6161  for (i=first; i<=last; i++) {
    62     f->fgcolorbuff[i]=(unsigned char) color;
     62    f->fgcolorbuff[i]=(short)color;
    6363  }
    6464}
     
    6868  int i;
    6969  for (i=first; i<=last; i++) {
    70     f->bgcolorbuff[i]=(unsigned char) color;
     70    f->bgcolorbuff[i]=(short)color;
    7171  }
    7272}
     
    7777      f->textbuff=owl_realloc(f->textbuff, newlen+1);
    7878      f->fmbuff=owl_realloc(f->fmbuff, newlen+1);
    79       f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+1);
    80       f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+1);
     79      f->fgcolorbuff=owl_realloc(f->fgcolorbuff, (newlen+1) * sizeof(short));
     80      f->bgcolorbuff=owl_realloc(f->bgcolorbuff, (newlen+1) * sizeof(short));
    8181      f->bufflen = newlen+1;
    8282  }
     
    151151  j=f->textlen;
    152152  for(i=0; i<j; i++) {
    153     if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = color;
     153    if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = (short)color;
    154154  }
    155155}
     
    162162  j=f->textlen;
    163163  for(i=0; i<j; i++) {
    164     if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = color;
     164    if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = (short)color;
    165165  }
    166166}
     
    230230    /* find the last char with the current format and color */
    231231    trans1=owl_util_find_trans(f->fmbuff+position, len-position);
    232     trans2=owl_util_find_trans(f->fgcolorbuff+position, len-position);
    233     trans3=owl_util_find_trans(f->bgcolorbuff+position, len-position);
     232    trans2=owl_util_find_trans_short(f->fgcolorbuff+position, len-position);
     233    trans3=owl_util_find_trans_short(f->bgcolorbuff+position, len-position);
    234234
    235235    lastsame = (trans1 < trans2) ? trans1 : trans2;
     
    252252    /* warning, this is sort of a hack */
    253253    if (owl_global_get_hascolors(&g)) {
    254       int fg, bg;
    255       short pair;
     254      short fg, bg, pair;
    256255      fg = f->fgcolorbuff[position];
    257256      bg = f->bgcolorbuff[position];
     
    259258      pair = owl_fmtext_get_colorpair(fg, bg);
    260259      if (pair != -1) {
    261         wattron(w, COLOR_PAIR(pair));
     260        wcolor_set(w,pair,NULL);
    262261      }
    263262    }
     
    402401  dst->textbuff=owl_malloc(mallocsize);
    403402  dst->fmbuff=owl_malloc(mallocsize);
    404   dst->fgcolorbuff=owl_malloc(mallocsize);
    405   dst->bgcolorbuff=owl_malloc(mallocsize);
     403  dst->fgcolorbuff=owl_malloc(mallocsize * sizeof(short));
     404  dst->bgcolorbuff=owl_malloc(mallocsize * sizeof(short));
    406405  memcpy(dst->textbuff, src->textbuff, src->textlen+1);
    407406  memcpy(dst->fmbuff, src->fmbuff, src->textlen);
    408   memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen);
    409   memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen);
     407  memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen * sizeof(short));
     408  memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen * sizeof(short));
    410409}
    411410
     
    678677{
    679678  // This could be a bitarray if we wanted to save memory.
    680   int i, j, colors;
    681   cpmgr->next = COLORS;
    682 
    683   colors = COLORS + 1; // 1 to account for "default".
    684   cpmgr->pairs = owl_malloc(colors * sizeof(int*));
    685   for(i = 0; i < colors; i++) {
    686     // Because we're going to have a pair set for any fg and the
    687     // default bg, we don't need to account for default here.
    688     cpmgr->pairs[i] = owl_malloc(COLORS * sizeof(int));
    689     for(j = 0; j < COLORS; j++) {
     679  short i, j;
     680  cpmgr->next = 8;
     681 
     682  // The test is <= because we allocate COLORS+1 entries.
     683  cpmgr->pairs = owl_malloc((COLORS+1) * sizeof(short*));
     684  for(i = 0; i <= COLORS; i++) {
     685    cpmgr->pairs[i] = owl_malloc((COLORS+1) * sizeof(short));
     686    for(j = 0; j <= COLORS; j++) {
    690687      cpmgr->pairs[i][j] = -1;
    691688    }
     689  }
     690  for(i = 0; i < 8; i++) {
     691    short fg, bg;
     692    pair_content(i, &fg, &bg);
     693    cpmgr->pairs[fg+1][bg+1] = i;
    692694  }
    693695}
     
    696698void owl_fmtext_reset_colorpairs()
    697699{
    698   int i, j, colors;
     700  short i, j;
    699701  owl_colorpair_mgr *cpmgr = owl_global_get_colorpair_mgr(&g);
    700   cpmgr->next = COLORS;
    701 
    702   colors = COLORS + 1; // 1 to account for "default".
    703   for(i = 0; i < colors; i++) {
    704     for(j = 0; j < COLORS; j++) {
     702  cpmgr->next = 8;
     703
     704  // The test is <= because we allocated COLORS+1 entries.
     705  for(i = 0; i <= COLORS; i++) {
     706    for(j = 0; j <= COLORS; j++) {
    705707      cpmgr->pairs[i][j] = -1;
    706708    }
     709  }
     710  for(i = 0; i < 8; i++) {
     711    short fg, bg;
     712    pair_content(i, &fg, &bg);
     713    cpmgr->pairs[fg+1][bg+1] = i;
    707714  }
    708715}
     
    723730#endif
    724731
    725   if (bg == default_bg) {
    726     // default bg -> use color pairs initialized by owl.c
    727     pair = fg;
    728   } else {
    729     // looking for a pair we already set up for this draw.
    730     cpmgr = owl_global_get_colorpair_mgr(&g);
    731     pair = cpmgr->pairs[fg+1][bg];
    732     if (!(pair != -1 && pair < cpmgr->next)) {
    733       // If we didn't find a pair, search for a free one to assign.
    734       // Skip the first COLORS, since they're static.
    735       // If we ever get 256 color curses, this will need more thought.
    736       pair = (cpmgr->next < COLOR_PAIRS) ? cpmgr->next : -1;
    737       if (pair != -1) {
    738         // We found a free pair, initialize it.
    739         init_pair(pair, fg, bg);
    740         cpmgr->pairs[fg+1][bg] = pair;
    741         cpmgr->next++;
    742       } else {
    743         // We still don't have a pair, drop the background color. Too bad.
    744         pair = fg;
    745       }
     732  // looking for a pair we already set up for this draw.
     733  cpmgr = owl_global_get_colorpair_mgr(&g);
     734  pair = cpmgr->pairs[fg+1][bg+1];
     735  if (!(pair != -1 && pair < cpmgr->next)) {
     736/*    owl_global_set_needrefresh(&g);*/
     737    // If we didn't find a pair, search for a free one to assign.
     738    pair = (cpmgr->next < COLOR_PAIRS) ? cpmgr->next : -1;
     739    if (pair != -1) {
     740      // We found a free pair, initialize it.
     741      init_pair(pair, fg, bg);
     742      cpmgr->pairs[fg+1][bg+1] = pair;
     743      cpmgr->next++;
     744    }
     745    else if (bg != OWL_COLOR_DEFAULT) {
     746      // We still don't have a pair, drop the background color. Too bad.
     747      owl_function_debugmsg("colorpairs: color shortage - dropping background color.");
     748      pair = owl_fmtext_get_colorpair(fg, OWL_COLOR_DEFAULT);
     749    }
     750    else {
     751      // We still don't have a pair, defaults all around.
     752      owl_function_debugmsg("colorpairs: color shortage - dropping foreground and background color.");
     753      pair = 0;
    746754    }
    747755  }
Note: See TracChangeset for help on using the changeset viewer.