itemwindow.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #include "itemview.h"
  3. #define Uses_TWindow
  4. #define Uses_TRect
  5. #define Uses_TEvent
  6. #define Uses_TFrame
  7. #include <tvision/tv.h>
  8. class TItemWindow : public TWindow {
  9. TItemViewer *itemViewer, *catViewer, *weightViewer;
  10. const TRect itemViewerBounds() const {
  11. auto bounds = getExtent();
  12. TRect r(bounds.a.x, bounds.a.y, bounds.b.x / 3, bounds.b.y);
  13. r.grow(-1, -1);
  14. return r;
  15. }
  16. const TRect catViewerBounds() const {
  17. auto bounds = getExtent();
  18. TRect r(bounds.b.x / 3 - 2, bounds.a.y, 2 * bounds.b.x / 3 - 1, bounds.b.y);
  19. r.grow(-1, -1);
  20. return r;
  21. }
  22. const TRect weightViewerBounds() const {
  23. auto bounds = getExtent();
  24. TRect r(2 * bounds.b.x / 3 - 3, bounds.a.y, bounds.b.x, bounds.b.y);
  25. r.grow(-1, -1);
  26. return r;
  27. }
  28. public:
  29. TItemWindow(const char *fileName);
  30. static TFrame *initFrame(TRect r);
  31. void draw() override;
  32. virtual void handleEvent(TEvent &event) override;
  33. virtual TPalette &getPalette() const override;
  34. protected:
  35. virtual void sizeLimits(TPoint &min, TPoint &max) override {
  36. TWindow::sizeLimits(min, max);
  37. min.x = size.x / 2 + 10;
  38. };
  39. };
  40. class TCustomFrame : public TFrame {
  41. public:
  42. using TFrame::TFrame; // Inherit constructor
  43. virtual void draw() override {
  44. TFrame::draw(); // Call base class draw
  45. TDrawBuffer b;
  46. TAttrPair cNormal = getState(sfActive) ? getColor(3) : getColor(1);
  47. if (getState(sfDragging))
  48. cNormal = getColor(5);
  49. int fstSep = size.x / 3 - 2;
  50. int sndSep = 2 * size.x / 3 - 3;
  51. b.moveChar(0, ' ', cNormal, 1);
  52. b.putChar(0, (getState(sfActive) && !getState(sfDragging))
  53. ? BOX_SINGLE_HORIZONTAL_TO_DOUBLE_VERTICAL_TOP
  54. : BOX_SINGLE_HORIZONTAL_TO_SINGLE_VERTICAL_TOP);
  55. writeLine(fstSep, 0, 1, 1, b);
  56. writeLine(sndSep, 0, 1, 1, b);
  57. }
  58. };
  59. #define cpItemWindow "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x06"