frinit.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <draw.h>
  12. #include <thread.h>
  13. #include <mouse.h>
  14. #include <frame.h>
  15. void
  16. frinit(Frame *f, Rectangle r, Font *ft, Image *b, Image *cols[NCOL])
  17. {
  18. f->font = ft;
  19. f->display = b->display;
  20. f->maxtab = 8*stringwidth(ft, "0");
  21. f->nbox = 0;
  22. f->nalloc = 0;
  23. f->nchars = 0;
  24. f->nlines = 0;
  25. f->p0 = 0;
  26. f->p1 = 0;
  27. f->box = 0;
  28. f->lastlinefull = 0;
  29. if(cols != 0)
  30. memmove(f->cols, cols, sizeof f->cols);
  31. frsetrects(f, r, b);
  32. if(f->tick==nil && f->cols[BACK]!=0)
  33. frinittick(f);
  34. }
  35. void
  36. frinittick(Frame *f)
  37. {
  38. Image *b;
  39. Font *ft;
  40. b = f->display->screenimage;
  41. ft = f->font;
  42. if(f->tick)
  43. freeimage(f->tick);
  44. f->tick = allocimage(f->display, Rect(0, 0, FRTICKW, ft->height), b->chan, 0, DWhite);
  45. if(f->tick == nil)
  46. return;
  47. if(f->tickback)
  48. freeimage(f->tickback);
  49. f->tickback = allocimage(f->display, f->tick->r, b->chan, 0, DWhite);
  50. if(f->tickback == 0){
  51. freeimage(f->tick);
  52. f->tick = 0;
  53. return;
  54. }
  55. /* background color */
  56. draw(f->tick, f->tick->r, f->cols[BACK], nil, ZP);
  57. /* vertical line */
  58. draw(f->tick, Rect(FRTICKW/2, 0, FRTICKW/2+1, ft->height), f->cols[TEXT], nil, ZP);
  59. /* box on each end */
  60. draw(f->tick, Rect(0, 0, FRTICKW, FRTICKW), f->cols[TEXT], nil, ZP);
  61. draw(f->tick, Rect(0, ft->height-FRTICKW, FRTICKW, ft->height), f->cols[TEXT], nil, ZP);
  62. }
  63. void
  64. frsetrects(Frame *f, Rectangle r, Image *b)
  65. {
  66. f->b = b;
  67. f->entire = r;
  68. f->r = r;
  69. f->r.max.y -= (r.max.y-r.min.y)%f->font->height;
  70. f->maxlines = (r.max.y-r.min.y)/f->font->height;
  71. }
  72. void
  73. frclear(Frame *f, int freeall)
  74. {
  75. if(f->nbox)
  76. _frdelbox(f, 0, f->nbox-1);
  77. if(f->box)
  78. free(f->box);
  79. if(freeall){
  80. freeimage(f->tick);
  81. freeimage(f->tickback);
  82. f->tick = 0;
  83. f->tickback = 0;
  84. }
  85. f->box = 0;
  86. f->ticked = 0;
  87. }