TextureView.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #import "qedefs.h"
  2. /*
  3. NOTE: I am specifically not using cached image reps, because the data is also needed for texturing the views, and a cached rep would waste tons of space.
  4. */
  5. @implementation TextureView
  6. - init
  7. {
  8. deselectIndex = -1;
  9. return self;
  10. }
  11. - setParent:(id)from
  12. {
  13. parent_i = from;
  14. return self;
  15. }
  16. - (BOOL)acceptsFirstMouse
  17. {
  18. return YES;
  19. }
  20. - drawSelf:(const NXRect *)rects :(int)rectCount
  21. {
  22. int i;
  23. int max;
  24. id list_i;
  25. texpal_t *t;
  26. int x;
  27. int y;
  28. NXPoint p;
  29. NXRect r;
  30. int selected;
  31. selected = [parent_i getSelectedTexture];
  32. list_i = [parent_i getList];
  33. PSselectfont("Helvetica-Medium",FONTSIZE);
  34. PSrotate(0);
  35. PSsetgray(NX_LTGRAY);
  36. PSrectfill(rects->origin.x, rects->origin.y,
  37. rects->size.width, rects->size.height);
  38. if (!list_i) // WADfile didn't init
  39. return self;
  40. if (deselectIndex != -1)
  41. {
  42. t = [list_i elementAt:deselectIndex];
  43. r = t->r;
  44. r.origin.x -= TEX_INDENT;
  45. r.origin.y -= TEX_INDENT;
  46. r.size.width += TEX_INDENT*2;
  47. r.size.height += TEX_INDENT*2;
  48. PSsetgray(NXGrayComponent(NX_COLORLTGRAY));
  49. PSrectfill(r.origin.x, r.origin.y,
  50. r.size.width, r.size.height);
  51. p = t->r.origin;
  52. p.y += TEX_SPACING;
  53. [t->image drawAt:&p];
  54. PSsetgray(0);
  55. x = t->r.origin.x;
  56. y = t->r.origin.y + 7;
  57. PSmoveto(x,y);
  58. PSshow(t->name);
  59. PSstroke();
  60. deselectIndex = -1;
  61. }
  62. max = [list_i count];
  63. PSsetgray(0);
  64. for (i = 0;i < max; i++)
  65. {
  66. t = [list_i elementAt:i];
  67. r = t->r;
  68. r.origin.x -= TEX_INDENT/2;
  69. r.size.width += TEX_INDENT;
  70. r.origin.y += 4;
  71. if (NXIntersectsRect(&rects[0],&r) == YES &&
  72. t->display)
  73. {
  74. if (selected == i)
  75. {
  76. PSsetgray(1);
  77. PSrectfill(r.origin.x,r.origin.y,
  78. r.size.width,r.size.height);
  79. PSsetrgbcolor(1,0,0);
  80. PSrectstroke(r.origin.x, r.origin.y,
  81. r.size.width, r.size.height);
  82. PSsetgray(0);
  83. }
  84. p = t->r.origin;
  85. p.y += TEX_SPACING;
  86. [t->image drawAt:&p];
  87. x = t->r.origin.x;
  88. y = t->r.origin.y + 7;
  89. PSmoveto(x,y);
  90. PSshow(t->name);
  91. }
  92. }
  93. PSstroke();
  94. return self;
  95. }
  96. - deselect
  97. {
  98. deselectIndex = [parent_i getSelectedTexture];
  99. return self;
  100. }
  101. - mouseDown:(NXEvent *)theEvent
  102. {
  103. NXPoint loc;
  104. int i;
  105. int max;
  106. int oldwindowmask;
  107. texpal_t *t;
  108. id list;
  109. NXRect r;
  110. oldwindowmask = [window addToEventMask:NX_LMOUSEDRAGGEDMASK];
  111. loc = theEvent->location;
  112. [self convertPoint:&loc fromView:NULL];
  113. list = [parent_i getList];
  114. max = [list count];
  115. for (i = 0;i < max; i++)
  116. {
  117. t = [list elementAt:i];
  118. r = t->r;
  119. if (NXPointInRect(&loc,&r) == YES)
  120. {
  121. [self deselect];
  122. [parent_i setSelectedTexture:i];
  123. break;
  124. }
  125. }
  126. [window setEventMask:oldwindowmask];
  127. return self;
  128. }
  129. @end