Divider.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright 2009-2010, Pier Luigi Fiorini. All rights reserved.
  3. * Distributed under the terms of the MIT License.
  4. *
  5. * Authors:
  6. * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
  7. */
  8. #include <Message.h>
  9. #include "Divider.h"
  10. const float kResizeWidgetRatio = 0.1f;
  11. const float kResizeWidgetPadding = 2.0f;
  12. const float kResizeWidgetCircleRadius = 2.0f;
  13. const float kResizeWidgetSpacing = 10.0f;
  14. const int kResizeWidgetCircleCount = 2;
  15. Divider::Divider(const char* name, uint32 flags)
  16. : BView(name, flags),
  17. fOrient(B_HORIZONTAL)
  18. {
  19. SetViewColor (ui_color (B_PANEL_BACKGROUND_COLOR));
  20. }
  21. Divider::Divider(BMessage* archive)
  22. : BView(archive)
  23. {
  24. if (archive->FindInt32("orientation", (int32*)&fOrient) != B_OK)
  25. fOrient = B_HORIZONTAL;
  26. }
  27. Divider::~Divider()
  28. {
  29. }
  30. void
  31. Divider::Draw(BRect updateRect)
  32. {
  33. BRect bounds = Bounds();
  34. rgb_color view_color = ViewColor();
  35. rgb_color line = tint_color(view_color, B_DARKEN_1_TINT);
  36. rgb_color shadow = tint_color(view_color, B_DARKEN_2_TINT);
  37. PushState();
  38. SetHighColor(view_color);
  39. FillRect(bounds);
  40. if (fOrient == B_HORIZONTAL) {
  41. BPoint left(bounds.left, (bounds.Height() / 2) + bounds.top);
  42. BPoint right(bounds.right, left.y);
  43. BPoint fudge(PenSize(), PenSize());
  44. left -= fudge;
  45. right -= fudge;
  46. SetHighColor(line);
  47. StrokeLine(left, right);
  48. left += fudge;
  49. right += fudge;
  50. SetHighColor(shadow);
  51. StrokeLine(left, right);
  52. } else {
  53. BPoint top((bounds.Width() / 2) + bounds.left, bounds.top);
  54. BPoint bottom(top.x, bounds.bottom);
  55. BPoint fudge(PenSize(), PenSize());
  56. top -= fudge;
  57. bottom -= fudge;
  58. SetHighColor(line);
  59. StrokeLine(top, bottom);
  60. top += fudge;
  61. bottom += fudge;
  62. SetHighColor(shadow);
  63. StrokeLine(top, bottom);
  64. }
  65. PopState();
  66. }
  67. void
  68. Divider::GetPreferredSize(float* width, float* height)
  69. {
  70. if (fOrient == B_HORIZONTAL) {
  71. *width = Bounds().Width();
  72. *height = (PenSize() * 4); // Two widths for padding (either side) + line + shadow
  73. } else {
  74. *height = Bounds().Height();
  75. *width = (PenSize() * 4); // Two widths for padding (either side) + line + shadow
  76. }
  77. }
  78. status_t
  79. Divider::Archive(BMessage* archive, bool deep) const
  80. {
  81. archive->AddInt32("orientation", fOrient);
  82. return BView::Archive(archive, false);
  83. }
  84. BArchivable*
  85. Divider::Instantiate(BMessage* archive)
  86. {
  87. BArchivable *instance = NULL;
  88. if (validate_instantiation(archive, "Divider"))
  89. instance = new Divider(archive);
  90. return instance;
  91. }
  92. orientation
  93. Divider::Orientation()
  94. {
  95. return fOrient;
  96. }
  97. void
  98. Divider::Orientation(orientation orient)
  99. {
  100. fOrient = orient;
  101. }