Ejemplo n.º 1
0
void erase_backward(uint8_t count)
{
    cclear(1); /* Erase cursor */
    gotox(wherex() - (count + 1));
    cclear(count);
    gotox(wherex() - count);
}
Ejemplo n.º 2
0
void printinfo(unsigned char n, unsigned int res)
{
    gotoxy(0,n + 1); cclear(40);
    gotoxy(0,n + 1); cprintf("%-20s %5u   ", testinfo[n].name, res);
    printpercent(res, testinfo[n].cycles * 2);
    fixscreen();
}
Ejemplo n.º 3
0
/*-----------------------------------------------------------------------------------*/
void
ctk_draw_menus(struct ctk_menus *menus)
{
  struct ctk_menu *m;

  /* Draw menus */
  (void)textcolor(MENUCOLOR);
  gotoxy(0, 0);
  revers(1);
  cputc(' ');
  for(m = menus->menus->next; m != NULL; m = m->next) {
    draw_menu(m, m == menus->open);
  }

  /* Draw desktopmenu */
  if(wherex() + strlen(menus->desktopmenu->title) + 1 >= sizex) {
    gotoxy(sizex - (unsigned char)strlen(menus->desktopmenu->title) - 1, 0);
  } else {
    cclear(sizex - wherex() -
	   (unsigned char)strlen(menus->desktopmenu->title) - 1);
  }
  draw_menu(menus->desktopmenu, menus->desktopmenu == menus->open);

  revers(0);
}
void PacketStreamReader::Stream::seekg(std::streamoff off, std::ios_base::seekdir way)
{
    if (!seekable())
        return;
    cclear();
    Base::seekg(off, way);
}
void PacketStreamReader::Stream::seekg(std::streampos target)
{
    if (!seekable())
        return;
    cclear();
    Base::seekg(target);
}
Ejemplo n.º 6
0
void printrating(void)
{
    unsigned long allresult, allcycles;
    unsigned char n;
    unsigned long r, c;
    unsigned int a,b;

    allresult = 0;
    allcycles = 0;

    n = 0;
    while (testinfo[n].generator) {
        if (testinfo[n].weight > 0) {
            allresult += testinfo[n].result / testinfo[n].weight;
            allcycles += (testinfo[n].cycles * 2) / testinfo[n].weight;
        }
        ++n;
    }

    c = ((unsigned long)allcycles) * 100L;
    r = ((unsigned long)allresult);

    a = (c / r) / 100;
    b = (c / r) % 100;

    revers(1);
    gotoxy(0,24); cclear(40);
    gotoxy(0,24); cprintf("Accumulated weighted rating: %2d.%02dx", a, b);
    revers(0);
}
Ejemplo n.º 7
0
// koffset is the first byte of the kernel on disk
void
stage2main(ulong koffset)
{
    ElfHeader *elf;
    ElfProgHeader *ph, *eph;
    void (*entry)(void);
    uchar *pa;

    cclear();

    has_ahci = ahcidetect();

    elf = (ElfHeader *)0x10000;
    readbytes((uchar *)elf, PGSIZE, koffset);

    if (elf->magic != ELF_MAGIC)
        panic("stage2main - elf magic");

    ph = (ElfProgHeader *)((char *)elf + elf->phoff);
    eph = ph + elf->phnum;

    for (; ph < eph; ph++) {
        pa = (uchar *)ph->paddr;
        readbytes(pa, ph->filesz, koffset + ph->offset);
        if (ph->memsz > ph->filesz)
            stosb(pa + ph->filesz, 0, ph->memsz - ph->filesz);
    }

    entry = (void(*)(void))elf->entry;
    entry();
}
Ejemplo n.º 8
0
/**
 * Draw a filled empty box.
 *
 * The size is incl. border
 */
void screenPrintBox(uint8_t x, uint8_t y, uint8_t w, uint8_t h)
{
    uint8_t i;

    screenPrintBorder(x, y, w, h);

    w -= 2;
    ++x;

    for (i = h - 2; i; --i)
    {
        gotoxy(x, ++y);
        cclear(w);
    }
}
Ejemplo n.º 9
0
/*-----------------------------------------------------------------------------------*/
void
ctk_draw_menus(struct ctk_menus *menus)
{
  struct ctk_menu *m;  

  
  /* Draw menus */
  textcolor(VNC_OUT_MENUCOLOR);
  gotoxy(0, 0);
  revers(1);
  cputc(' ');
  for(m = menus->menus->next; m != NULL; m = m->next) {
    if(m != menus->open) {
      update_area(wherex(), 0, strlen(m->title) + 1, 1);
      cputs(m->title);
      cputc(' ');
    } else {
      draw_menu(m);
    }
  }


  if(wherex() + strlen(menus->desktopmenu->title) + 1>= sizex) {
    gotoxy(sizex - strlen(menus->desktopmenu->title) - 1, 0);
  } else {
    cclear(sizex - wherex() -
	   strlen(menus->desktopmenu->title) - 1);
    update_area(wherex(), 0, sizex - wherex() -
		strlen(menus->desktopmenu->title) - 1, 1);
  }
  
  /* Draw desktopmenu */
  if(menus->desktopmenu != menus->open) {
    update_area(wherex(), 0, strlen(menus->desktopmenu->title) + 1, 1);
    cputs(menus->desktopmenu->title);
    cputc(' ');
  } else {
    draw_menu(menus->desktopmenu);
  }

  revers(0);



}
Ejemplo n.º 10
0
void printstringf(char *ss, int w, FILE *fff)
{
    char *sss ;
    char *sx ;

    ZALLOC(sss, w+1, char) ;
    cclear((unsigned char*)sss, CNULL, w+1) ;

    sx = ss ;
    for (;;) {
        strncpy(sss, sx, w) ;
        if (strlen(sss) <= 0) break ;
        sx += w ;
        fprintf(fff, "%s\n", sss) ;
    }

    free (sss) ;
}
Ejemplo n.º 11
0
static void ProgressMeter (unsigned Val)
/* Print the progress bar. */
{
    gotoxy (X, Y);
    cprintf (" %5lu/65536\r\n", (unsigned long) Val);
    revers (1);
    cclear (Val / (unsigned)(65536U / BAR_ELEMENTS));

/* Commodore and Atari computers can show eight times greater precision. */
#if defined(__CBM__)
    Val = (Val / (unsigned)(65536U / BAR_ELEMENTS / 8)) % 8;
    revers (revers_bar[Val]);
    cputc (small_bar[Val]);

#elif defined(__ATARI__)
#endif

    revers (0);
}
Ejemplo n.º 12
0
static void
draw_menu(struct ctk_menu *m, unsigned char open)
{
  unsigned char x, x2, y;

  if(open) {
    x = x2 = wherex();
    if(x2 + CTK_CONF_MENUWIDTH > sizex) {
      x2 = sizex - CTK_CONF_MENUWIDTH;
    }

    for(y = 0; y < m->nitems; ++y) {
      if(y == m->active) {
	(void)textcolor(ACTIVEMENUITEMCOLOR);
	revers(0);
      } else {
	(void)textcolor(MENUCOLOR);	  
	revers(1);
      }
      gotoxy(x2, y + 1);
      if(m->items[y].title[0] == '-') {
	chline(CTK_CONF_MENUWIDTH);
      } else {
	cputs(m->items[y].title);
      }
      if(x2 + CTK_CONF_MENUWIDTH > wherex()) {
	cclear(x2 + CTK_CONF_MENUWIDTH - wherex());
      }
    }

    gotoxy(x, 0);
    (void)textcolor(OPENMENUCOLOR);
    revers(0);
  }

  cputs(m->title);
  cputc(' ');
  (void)textcolor(MENUCOLOR);
  revers(1);
}
Ejemplo n.º 13
0
/*-----------------------------------------------------------------------------------*/
static void
draw_menu(struct ctk_menu *m)
{
  unsigned char x, x2, y;

  textcolor(VNC_OUT_MENUCOLOR);
  x = wherex();
  cputs(m->title);
  cputc(' ');
  x2 = wherex();
  if(x + CTK_CONF_MENUWIDTH > sizex) {
    x = sizex - CTK_CONF_MENUWIDTH;
  }
  
  
  for(y = 0; y < m->nitems; ++y) {
    if(y == m->active) {
      textcolor(VNC_OUT_ACTIVEMENUCOLOR);
      revers(0);
    } else {
      textcolor(VNC_OUT_MENUCOLOR);	  
    }
    gotoxy(x, y + 1);
    if(m->items[y].title[0] == '-') {
      chline(CTK_CONF_MENUWIDTH);
    } else {
      cputs(m->items[y].title);
    }
    if(x + CTK_CONF_MENUWIDTH > wherex()) {
      cclear(x + CTK_CONF_MENUWIDTH - wherex());
    }
    revers(1);
  }
  
  gotoxy(x2, 0);
  textcolor(VNC_OUT_MENUCOLOR);  

  update_area(x, 0, CTK_CONF_MENUWIDTH, m->nitems + 1);
}
Ejemplo n.º 14
0
void csw() {
	cclear();
	printf(ANSI_COLOR_RESET);
	char buf[74];
	FILE *file;
	size_t nread;
	int line=0;
	file = fopen("telnetTest.txt", "r");
	if (file) {
		while ((nread = fread(buf, 1, sizeof buf, file)) > 0){
			fwrite(buf, 1, nread, stdout);
			line++;
			if(line==19){
				line=0;
				usleep(300000);
			}
		}
		if (ferror(file)) {
			printf("Desaparecio la cinta!\n");
			return;
		}
		fclose(file);
	}
}
Ejemplo n.º 15
0
/* Same as "gotoxy (x, y); cclear (length);" */
void __fastcall__ cclearxy( unsigned char x, unsigned char y, unsigned char length )
{
	gotoxy( x, y );
	cclear( length );
}
Ejemplo n.º 16
0
/**
 * Show or update a box with the current action.
 */
static void refreshStatusLine(void)
{
    gotoxy (1, 23);
    cputs(strStatus);
    cclear(39 - wherex());
}
Ejemplo n.º 17
0
/*-----------------------------------------------------------------------------------*/
static void
draw_widget(struct ctk_widget *w,
	    unsigned char x, unsigned char y,
	    unsigned char clipx, unsigned char clipy,
	    unsigned char clipy1, unsigned char clipy2,
	    unsigned char focus)
{
  unsigned char xpos, ypos, xscroll;
  unsigned char i, j;
  char c, *text;
  unsigned char wfocus;
#if CTK_CONF_ICONS
  unsigned char len;
#endif /* CTK_CONF_ICONS */

  wfocus = 0;
  if(focus & CTK_FOCUS_WINDOW) {    
    (void)textcolor(WIDGETCOLOR_FWIN);
    if(focus & CTK_FOCUS_WIDGET) {
      (void)textcolor(WIDGETCOLOR_FOCUS);
      wfocus = 1;
    }
#if CTK_CONF_WINDOWS
  } else if(focus & CTK_FOCUS_DIALOG) {
    (void)textcolor(WIDGETCOLOR_DIALOG);
    if(focus & CTK_FOCUS_WIDGET) {
      (void)textcolor(WIDGETCOLOR_FOCUS);
      wfocus = 1;
    }
#endif /* CTK_CONF_WINDOWS */
  } else {
    (void)textcolor(WIDGETCOLOR);
  }
  
  xpos = x + w->x;
  ypos = y + w->y;
    
  switch(w->type) {
  case CTK_WIDGET_SEPARATOR:
    if(ypos >= clipy1 && ypos < clipy2) {
      chlinexy(xpos, ypos, w->w);
    }
    break;
  case CTK_WIDGET_LABEL:
    text = w->widget.label.text;
    for(i = 0; i < w->h; ++i) {
      if(ypos >= clipy1 && ypos < clipy2) {
	gotoxy(xpos, ypos);
	cputsn(text, w->w);
	if(w->w - (wherex() - xpos) > 0) {
	  cclear(w->w - (wherex() - xpos));
	}
      }
      ++ypos;
      text += w->w;
    }
    break;
  case CTK_WIDGET_BUTTON:
    if(ypos >= clipy1 && ypos < clipy2) {
      revers(wfocus != 0);
      cputcxy(xpos, ypos, '[');
      cputsn(w->widget.button.text, w->w);
      cputc(']');
      revers(0);
    }
    break;
  case CTK_WIDGET_HYPERLINK:
    if(ypos >= clipy1 && ypos < clipy2) {
      revers(wfocus == 0);
      gotoxy(xpos, ypos);
      (void)textcolor(WIDGETCOLOR_HLINK);
      cputsn(w->widget.button.text, w->w);
      revers(0);
    }
    break;
  case CTK_WIDGET_TEXTENTRY:
    text = w->widget.textentry.text;
    xscroll = 0;
    if(w->widget.textentry.xpos >= w->w - 1) {
      xscroll = w->widget.textentry.xpos - w->w + 1;
    }
    for(j = 0; j < w->h; ++j) {
      if(ypos >= clipy1 && ypos < clipy2) {
	if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT &&
	   w->widget.textentry.ypos == j) {
	  revers(0);
	  cputcxy(xpos, ypos, '>');
	  c = 1;
	  for(i = 0; i < w->w; ++i) {
	    if(c != 0) {
	      c = text[i + xscroll];
	    }
	    revers(i == w->widget.textentry.xpos - xscroll);
	    if(c == 0) {
	      cputc(' ');
	    } else {
	      cputc(c);
	    }
	  }
	  revers(0);
	  cputc('<');
	} else {
	  revers(wfocus != 0 && j == w->widget.textentry.ypos);
	  cvlinexy(xpos, ypos, 1);
	  gotoxy(xpos + 1, ypos);          
	  cputsn(text, w->w);
	  i = wherex();
	  if(i - xpos - 1 < w->w) {
	    cclear(w->w - (i - xpos) + 1);
	  }
	  cvline(1);
	}
      }
      ++ypos;
      text += w->widget.textentry.len + 1;
    }
    revers(0);
    break;
#if CTK_CONF_ICONS
  case CTK_WIDGET_ICON:
    if(ypos >= clipy1 && ypos < clipy2) {
      revers(wfocus != 0);
#if CTK_CONF_ICON_TEXTMAPS
      if(w->widget.icon.textmap != NULL) {
	for(i = 0; i < 3; ++i) {
	  gotoxy(xpos, ypos);
	  if(ypos >= clipy1 && ypos < clipy2) {
	    cputc(w->widget.icon.textmap[0 + 3 * i]);
	    cputc(w->widget.icon.textmap[1 + 3 * i]);
	    cputc(w->widget.icon.textmap[2 + 3 * i]);
	  }
	  ++ypos;
	}
      }
#endif /* CTK_CONF_ICON_TEXTMAPS */
  
      len = (unsigned char)strlen(w->widget.icon.title);
      if(xpos + len >= sizex) {
	xpos = sizex - len;
      }

      gotoxy(xpos, ypos);
      if(ypos >= clipy1 && ypos < clipy2) {
	cputs(w->widget.icon.title);
      }
      revers(0);
    }
    break;
#endif /* CTK_CONF_ICONS */

  default:
    break;
  }
}
Ejemplo n.º 18
0
int 
mergeit(SNP **snpm1, SNP **snpm2, Indiv ***pindm1, Indiv **indm2, 
 int nums1, int nums2, int numi1, int numi2)   
{
   SNP *cupt1, *cupt2 ;
   int k, x, g, t  ;
   double y ;
   long rlen, packlen ; 
   static unsigned char *packg ;
   unsigned char *buff ;
   Indiv **indm1 ;
   static Indiv **indivmarkers ;
   int numindivs, numsnps ;

   indm1 = *pindm1 ;
   numindivs = numi1 + numi2 ;
   numsnps = nums1 ;
   ZALLOC(indivmarkers, numindivs, Indiv *) ;

   t = 0 ;
   for (x=0; x<numi1; ++x)  {  
    indivmarkers[t] = indm1[x]  ;
    ++t ;
   }
   for (x=0; x<numi2; ++x)  {  
    indivmarkers[t] = indm2[x]  ;
    ++t ;
   }
// we don't bother with a destructor here.   Sloppy code

   y = (double) (numindivs * 2) / (8 * (double) sizeof (char)) ;
   rlen = nnint(ceil(y)) ;
   rlen = MAX(rlen, 48)  ;
   packlen = numsnps*rlen ;
   ZALLOC(packg, packlen, unsigned char) ;
   cclear((unsigned char *) packg, 0XFF, packlen) ;
// wipe to invalid

   buff = packg ;
   for (k=0; k<nums1; k++) {  
    cupt1 = snpm1[k] ;
    x = cupt1 -> tagnumber ;
    if (x < 0 ) cupt1 -> ignore = YES ;
    if (cupt1 -> ignore) continue ;
    cupt2 = snpm2[x] ; 
    if (cupt2 -> isrfake) { 
     if (phasedmode == NO)  flipalleles(cupt2) ;
     if (phasedmode == YES)  flipalleles_phased(cupt2) ;
    }
    for (t=0; t<numi1; ++t) {  
      g = getgtypes(cupt1, t) ;
      if (g<0) continue ;
      wbuff((unsigned char *)buff, t, g) ;
    }
    for (t=0; t<numi2; ++t) {  
      g = getgtypes(cupt2, t) ;
      if (g<0) continue ;
      wbuff((unsigned char *)buff, numi1+t, g) ;
    }
    cupt1 -> ngtypes = numindivs ;
    cupt1 -> pbuff = (char *) buff ;
    buff += rlen ;
   }
   *pindm1 = indivmarkers ;
   return numindivs ;
}
Ejemplo n.º 19
0
Archivo: main.c Proyecto: cpehle/chalk
int kernel_main() {
  ConsoleDesc cd = {0, 0xf0, (unsigned short *)0xb8000};
  Console c = &cd;
  cclear(c,0xff);

  {
    const u16 com1 = 0x3f8;
    outb(com1 + 1, 0x00);    // Disable all interrupts
    outb(com1 + 3, 0x80);    // Enable DLAB (set baud rate divisor)
    outb(com1 + 0, 0x03);    // Set divisor to 3 (lo byte) 38400 baud
    outb(com1 + 1, 0x00);    //                  (hi byte)
    outb(com1 + 3, 0x03);    // 8 bits, no parity, one stop bit
    outb(com1 + 2, 0xC7);    // Enable FIFO, clear them, with 14-byte threshold
    outb(com1 + 4, 0x0B);    // IRQs enabled, RTS/DSR set
    if (0) {
    for (;;) {
      if(inb(com1 + 5) & 1) {
        char ch = inb(com1);
        cputc(c, ch);
      }
    }
    }

  }

  pciscan(c); // This is to test pci traversal.
  // Ethernet
  if (0) {
    PciConf eth = pciconfread(0, 3);
    cprintpciconf(c, eth);
    e1000init(0, &eth, c);
  }
  // for (;;);

  // Instead of a proper memory allocator we just allocate permanently
  // from one large Arena, this is only a temporary solution.
  // Eventually we want to guarantee that processes and tasks get
  // different arenas with potential overlap in a single address
  // space.
  Arena* a;
  arenainit(a, 1000*1000*1000*sizeof(u8), (void *)0x100000);
  // Functions that need to allocate memory need to be passed a memory
  // arena as part of their execution context.

  // initialize all known hardware, so far there is no dynamic device
  // discovery, instead we hardcode the locations of the devices on
  // the pci bus

  // AcpiDesc acpi = {};
  // acpiinit(&acpi, c);

  // nvme
  if (0) {
    PciConf conf = pciconfread(0,3);
    cprintpciconf(c, conf);
    nvmepciinit(a, c, conf);
  }

  // Ahci code doesn't work yet.
  // ahcipciinit(a, c, 0, 4);

  // Eventually we want to enable all CPU features found during detection.
  cpudetect(c);

  {
    M44 m = (M44){1,1,0,0,
                  0,1,0,0,
                  0,0,1,0,
                  0,0,0,1};
    V4 v = {1,
            0,
            0,
            0};
    V4 w = {0,
            1,
            0,
            0};
    V4 u = v4avv(v, w);
    cprintv4(c, u);
    cprintv4(c, v4msv(2, u));
    cprintv4(c, v4mmv(m44i(), u));
    cprintm44(c, m44i());
    cprintm44(c, v4msm(2, m44i()));
    cprintm44(c, v4mmm(v4msm(2, m44i()), m44i()));
    cprintm44(c, v4mmm(m, m));
  }

  for (;;);
  // Graphics only work with bochs emulator
  {
    u32 *framebufferaddr;
    {
       // 0x1234:0x1111
      PciConf vesa = pciconfread(0, 2);
      framebufferaddr = (u32 *)vesa.dev.base_address_register[0].address;
    }
    vbeset(1920, 1200, 32);
    int offset = 0;
// clear the screen to light grey
    for (int i = 0; i < 1920; ++i) {
      for (int j = 0; j<1200; ++j) {
      offset = (j * 1920 + i);
      // Format is 0x00rrggbb, can use first byte for alpha blending / z-buffering
      framebufferaddr[offset] = 0x00eeeeee;
      }
    }
    // draw a "line"
    for (int i = 0; i < 1920; ++i) {
      offset = (50 * 1920 + i);
      // Format is 0x00rrggbb, can use first byte for alpha blending
      framebufferaddr[offset] = 0x00ff0000;
    }


    {
      float t = 0;
      BezierData b = {
          4,
          {{50, 68, 0, 0}, {70, 220, 0, 0}, {80, 40, 0, 0}, {90, 100, 0, 0}}};
      while (t < 1) {
        V4 v = evcubicbezier(b, t);
        int offset = (u32)(v.v[1]) * 1920 + (u32)(v.v[0]);
        framebufferaddr[offset] = 0x000000ff;
        t += 0.00001;
      }
    }
    {
      float t = 0;
      BezierData b = {
        4,
        {{10, 20, 0, 0}, {70, 10, 0, 0}, {80, 40, 0, 0}, {90, 100, 0, 0}}};
      while (t < 1) {
        V4 v = evcubicbezier(b, t);
        int offset = (u32)(v.v[1]) * 1920 + (u32)(v.v[0]);
        framebufferaddr[offset] = 0x0000ff00;
        t += 0.00001;
      }
    }
    for (;;);
    u32* buf = renderglyphs(a);
    copyrect(framebufferaddr, buf, 0, 20, 98);
    rendertext(framebufferaddr, buf, "Hello World.", 0, 50);
    rendertext(framebufferaddr, buf, "Hello World.", 0, 66);
    rendertext(framebufferaddr, buf, "This is a test.", 0, 96);
    rendertext(framebufferaddr, buf, "Hello World.", 8*20, 82);
    rendertext(framebufferaddr, buf, "12 23 45 332", 8*20, 60*16);
  }
  for (;;) {}
}
Ejemplo n.º 20
0
static void ClearLine (void)
/* Clear the screen line the cursor is on */
{
    cputc ('\r');
    cclear (ScreenX);
}
Ejemplo n.º 21
0
/*-----------------------------------------------------------------------------------*/
void
cclearxy(unsigned char x, unsigned char y, unsigned char length)
{
  gotoxy(x, y);
  cclear(length);
}
Ejemplo n.º 22
0
/**
 * Show or update pCurrentMenu.
 *
 * Return the number of entries in the menu.
 */
static uint8_t screenPrintCurrentMenu(void)
{
    uint8_t nEntry, nEntries;
    uint8_t tmp;
    uint8_t len;
    uint8_t x, y, textColor;
    char    c;
    const ScreenMenuEntry* pEntry;
    const char* pStr;
    const char* p;

    // calculate length of longest entry
    len = 2;
    nEntries = 0;
    pEntry = pCurrentMenu->entries;
    while ((pStr = pEntry->pStrLabel) != NULL)
    {
        tmp = strlen(pStr);
        if (tmp > len)
            len = tmp;
        ++nEntries;
        ++pEntry;
    }

    /* hack: only 1 more instead of 2 because of the '&' in each entry */
    len += 1;

    x = pCurrentMenu->x;
    y = pCurrentMenu->y;

    screenPrintBorder(x, y, len + 2, nEntries + 2);

    ++x;

    pEntry = pCurrentMenu->entries;
    for (nEntry = 0; nEntry != nEntries; ++nEntry)
    {
        gotoxy(x, ++y);

        pStr      = pEntry->pStrLabel;
        textColor = pEntry->pCheckFunction() ?
            COLOR_FOREGROUND : COLOR_GRAY1;
        textcolor(textColor);

        if (nEntry == pCurrentMenu->nSelected)
            revers(1);

        cputc(' ');

        p = pStr;
        while ((c = *p) != 0)
        {
            if (c == '&')
            {
                textcolor(COLOR_EXTRA);
            }
            else
            {
                cputc(c);
                textcolor(textColor);
            }
            ++p;
        }
        cclear(len + x - wherex());

        revers(0);
        ++pEntry;
    }
    textcolor(COLOR_FOREGROUND);
    return nEntries;
}
Ejemplo n.º 23
0
/*-----------------------------------------------------------------------------------*/
static void
draw_widget(struct ctk_widget *w,
	    unsigned char x, unsigned char y,
	    unsigned char clipx,
	    unsigned char clipy,
	    unsigned char clipy1, unsigned char clipy2,
	    unsigned char focus)
{
  unsigned char xpos, ypos, xscroll;
  unsigned char i, j;
  unsigned char iconnum;
  char c, *text;
  unsigned char len;

  /*
  if(focus & CTK_FOCUS_WINDOW) {    
    textcolor(WIDGETCOLOR_FWIN);
    if(focus & CTK_FOCUS_WIDGET) {
      textcolor(WIDGETCOLOR_FOCUS);
    }
  } else if(focus & CTK_FOCUS_DIALOG) {
    textcolor(WIDGETCOLOR_DIALOG);
    if(focus & CTK_FOCUS_WIDGET) {
      textcolor(WIDGETCOLOR_FOCUS);
    }
  } else {
    textcolor(WIDGETCOLOR);
  }
*/  
  xpos = x + w->x;
  ypos = y + w->y;
    
  switch(w->type) {
  case CTK_WIDGET_SEPARATOR:
    textcolor(VNC_OUT_SEPARATORCOLOR + focus);
    if(ypos >= clipy1 && ypos < clipy2) {
      /*      chlinexy(xpos, ypos, w->w);*/
      gotoxy(xpos, ypos);
      for(i = 0; i < w->w; ++i) {
	cputc(CH_SEPARATOR);
      }
    }
    break;
  case CTK_WIDGET_LABEL:
    textcolor(VNC_OUT_LABELCOLOR + focus);
    text = w->widget.label.text;
    for(i = 0; i < w->h; ++i) {
      if(ypos >= clipy1 && ypos < clipy2) {
	gotoxy(xpos, ypos);
	cputsn(text, w->w);
	if(w->w - (wherex() - xpos) > 0) {
	  cclear(w->w - (wherex() - xpos));
	}
      }
      ++ypos;
      text += w->w;
    }
    break;
  case CTK_WIDGET_BUTTON:
    textcolor(VNC_OUT_BUTTONCOLOR + focus);
    if(ypos >= clipy1 && ypos < clipy2) {
      if(focus & CTK_FOCUS_WIDGET) {
	revers(1);
      } else {
	revers(0);
      }
      cputcxy(xpos, ypos, CH_BUTTONLEFT);
      cputsn(w->widget.button.text, w->w);
      cputc(CH_BUTTONRIGHT);
      revers(0);
    }
    break;
  case CTK_WIDGET_HYPERLINK:
    textcolor(VNC_OUT_HYPERLINKCOLOR + focus);
    if(ypos >= clipy1 && ypos < clipy2) {
      /*      if(focus & CTK_FOCUS_WIDGET) {
	textcolor(WIDGETCOLOR_HLINK_FOCUS);
	revers(0);	
      } else {
	textcolor(WIDGETCOLOR_HLINK);
	revers(1);
	}*/
      gotoxy(xpos, ypos);
      cputsn(w->widget.button.text, w->w);
      revers(0);
    }
    break;
  case CTK_WIDGET_TEXTENTRY:
    textcolor(VNC_OUT_TEXTENTRYCOLOR + focus);
    text = w->widget.textentry.text;
    xscroll = 0;
    if(w->widget.textentry.xpos >= w->w - 1) {
      xscroll = w->widget.textentry.xpos - w->w + 1;
    }
    for(j = 0; j < w->h; ++j) {
      if(ypos >= clipy1 && ypos < clipy2) {
	if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT &&
	   w->widget.textentry.ypos == j) {
	  revers(0);
	  cputcxy(xpos, ypos, '>');
	  c = 1;
	  for(i = 0; i < w->w; ++i) {
	    if(c != 0) {
	      c = text[i + xscroll];
	    }
	    if(i == w->widget.textentry.xpos - xscroll) {
	      textcolor(VNC_OUT_TEXTENTRYCOLOR + (focus ^ 0x01));
	      revers(1);
	    } else {
	      revers(0);
	    }
	    if(c == 0) {
	      cputc(' ');
	    } else {
	      cputc(c);
	    }
	    revers(0);
	    textcolor(VNC_OUT_TEXTENTRYCOLOR + focus);
	  }
	  cputc('<');
	} else {
	  if(focus & CTK_FOCUS_WIDGET && j == w->widget.textentry.ypos) {
	    revers(1);
	  } else {
	    revers(0);
	  }
	  cvlinexy(xpos, ypos, 1);
	  gotoxy(xpos + 1, ypos);          
	  cputsn(text, w->w);
	  i = wherex();
	  if(i - xpos - 1 < w->w) {
	    cclear(w->w - (i - xpos) + 1);
	  }
	  cvline(1);
	}
      }
      ++ypos;
      text += w->widget.textentry.len + 1;
    }
    revers(0);
    break;
#if CTK_CONF_ICONS
  case CTK_WIDGET_ICON:
    if(ypos >= clipy1 && ypos < clipy2) {
      textcolor(VNC_OUT_ICONCOLOR + focus);
      if(focus & 1) {
	revers(1);
      } else {
	revers(0);
      }

      x = xpos;
      len = strlen(w->widget.icon.title);
      if(x + len >= sizex) {
	x = sizex - len;
      }

      gotoxy(x, ypos + 3);
      if(ypos >= clipy1 && ypos < clipy2) {
	cputs(w->widget.icon.title);
      }

#if CTK_CONF_ICON_BITMAPS
      if(w->widget.icon.bitmap != NULL) {
	iconnum = vnc_out_add_icon((struct ctk_icon *)w);
	textcolor(iconnum | (focus << 6));
	gotoxy(xpos, ypos);
	cputc(0x80);
	cputc(0x81);
	cputc(0x82);
	cputc(0x83);
	++ypos;
	gotoxy(xpos, ypos);
	cputc(0x90);
	cputc(0x91);
	cputc(0x92);
	cputc(0x93);
	++ypos;
	gotoxy(xpos, ypos);
	cputc(0xa0);
	cputc(0xa1);
	cputc(0xa2);
	cputc(0xa3);
	++ypos;
	textcolor(0);
	/*	for(i = 0; i < 3; ++i) {

	  if(ypos >= clipy1 && ypos < clipy2) {
	    cputc(w->widget.icon.textmap[0 + 3 * i]);
	    cputc(w->widget.icon.textmap[1 + 3 * i]);
	    cputc(w->widget.icon.textmap[2 + 3 * i]);
	  }
	  ++ypos;
	  }*/
      }
#endif /* CTK_CONF_ICON_BITMAPS */

      revers(0);
    }
    break;
#endif /* CTK_CONF_ICONS */

  default:
    break;
  }
}
Ejemplo n.º 24
0
/**
 * Print a free line at y between xStart and xEnd (incl).
 *
 * ++++++++
 * +      + <= This one
 * ++++++++
 * +      +
 * ++++++++
 */
void screenPrintFreeLine(uint8_t xStart, uint8_t xEnd, uint8_t y)
{
    cputcxy(xStart, y, 0x7d);
    cclear(xEnd - xStart - 1);
    cputc(0x7d);
}