frinit.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <draw.h>
  4. #include <thread.h>
  5. #include <mouse.h>
  6. #include <frame.h>
  7. void
  8. frinit(Frame *f, Rectangle r, Font *ft, Image *b, Image *cols[NCOL])
  9. {
  10. f->font = ft;
  11. f->display = b->display;
  12. f->maxtab = 8*stringwidth(ft, "0");
  13. f->nbox = 0;
  14. f->nalloc = 0;
  15. f->nchars = 0;
  16. f->nlines = 0;
  17. f->p0 = 0;
  18. f->p1 = 0;
  19. f->box = 0;
  20. f->lastlinefull = 0;
  21. if(cols != 0)
  22. memmove(f->cols, cols, sizeof f->cols);
  23. frsetrects(f, r, b);
  24. if(f->tick==nil && f->cols[BACK]!=0)
  25. frinittick(f);
  26. }
  27. void
  28. frinittick(Frame *f)
  29. {
  30. Image *b;
  31. Font *ft;
  32. b = f->display->screenimage;
  33. ft = f->font;
  34. if(f->tick)
  35. freeimage(f->tick);
  36. f->tick = allocimage(f->display, Rect(0, 0, FRTICKW, ft->height), b->chan, 0, DWhite);
  37. if(f->tick == nil)
  38. return;
  39. if(f->tickback)
  40. freeimage(f->tickback);
  41. f->tickback = allocimage(f->display, f->tick->r, b->chan, 0, DWhite);
  42. if(f->tickback == 0){
  43. freeimage(f->tick);
  44. f->tick = 0;
  45. return;
  46. }
  47. /* background color */
  48. draw(f->tick, f->tick->r, f->cols[BACK], nil, ZP);
  49. /* vertical line */
  50. draw(f->tick, Rect(FRTICKW/2, 0, FRTICKW/2+1, ft->height), f->display->black, nil, ZP);
  51. /* box on each end */
  52. draw(f->tick, Rect(0, 0, FRTICKW, FRTICKW), f->cols[TEXT], nil, ZP);
  53. draw(f->tick, Rect(0, ft->height-FRTICKW, FRTICKW, ft->height), f->cols[TEXT], nil, ZP);
  54. }
  55. void
  56. frsetrects(Frame *f, Rectangle r, Image *b)
  57. {
  58. f->b = b;
  59. f->entire = r;
  60. f->r = r;
  61. f->r.max.y -= (r.max.y-r.min.y)%f->font->height;
  62. f->maxlines = (r.max.y-r.min.y)/f->font->height;
  63. }
  64. void
  65. frclear(Frame *f, int freeall)
  66. {
  67. if(f->nbox)
  68. _frdelbox(f, 0, f->nbox-1);
  69. if(f->box)
  70. free(f->box);
  71. if(freeall){
  72. freeimage(f->tick);
  73. freeimage(f->tickback);
  74. f->tick = 0;
  75. f->tickback = 0;
  76. }
  77. f->box = 0;
  78. f->ticked = 0;
  79. }