1 #include "PagesView.h" 2 3 static const float kWidth = 80; 4 static const float kHeight = 30; 5 6 static const float kPageWidth = 16; 7 static const float kPageHeight = 16; 8 9 static const float kPageHorizontalIndent = 7; 10 static const float kPageVerticalIndent = 5; 11 12 PagesView::PagesView(BRect frame, const char* name, uint32 resizeMask, uint32 flags) 13 : BView(frame, name, resizeMask, flags), 14 fCollate(false), 15 fReverse(false) 16 { 17 SetViewColor(B_TRANSPARENT_COLOR); 18 } 19 20 void PagesView::GetPreferredSize(float *width, float *height) 21 { 22 *width = kWidth; 23 *height = kHeight; 24 } 25 26 void PagesView::Draw(BRect rect) 27 { 28 rgb_color backgroundColor = {255, 255, 255}; 29 // inherit view color from parent if available 30 if (Parent() != NULL) { 31 backgroundColor = Parent()->ViewColor(); 32 } 33 SetHighColor(backgroundColor); 34 FillRect(rect); 35 36 BFont font(be_plain_font); 37 font.SetSize(8); 38 SetFont(&font); 39 40 BPoint position(3, 3); 41 if (fCollate) { 42 BPoint next(kPageWidth + kPageHorizontalIndent * 2 + 10, 0); 43 DrawPages(position, 1, 3); 44 position += next; 45 DrawPages(position, 1, 3); 46 } else { 47 BPoint next(kPageWidth + kPageHorizontalIndent * 1 + 10, 0); 48 for (int i = 1; i <= 3; i ++) { 49 int page = fReverse ? 4 - i : i; 50 DrawPages(position, page, 2); 51 position += next; 52 } 53 } 54 } 55 56 void PagesView::DrawPages(BPoint position, int number, int count) 57 { 58 position.x += kPageHorizontalIndent * (count - 1); 59 BPoint next(-kPageHorizontalIndent, kPageVerticalIndent); 60 if (fCollate) { 61 for (int i = 0; i < count; i ++) { 62 int page; 63 if (fReverse) { 64 page = 1 + i; 65 } else { 66 page = count - i; 67 } 68 DrawPage(position, page); 69 position += next; 70 } 71 } else { 72 for (int i = 0; i < count; i ++) { 73 DrawPage(position, number); 74 position += next; 75 } 76 } 77 } 78 79 void PagesView::DrawPage(BPoint position, int number) 80 { 81 const rgb_color pageBackgroundColor = {255, 255, 255}; 82 const rgb_color pageBorderColor = {0, 0, 0}; 83 const rgb_color pageNumberColor = {0, 0, 0}; 84 85 BPoint page[5]; 86 page[0].x = position.x + 3; 87 page[0].y = position.y; 88 page[4].x = position.x; 89 page[4].y = position.y + 3; 90 page[1].x = position.x + kPageWidth - 1; 91 page[1].y = position.y; 92 page[2].x = position.x + kPageWidth - 1; 93 page[2].y = position.y + kPageHeight - 1; 94 page[3].x = position.x; 95 page[3].y = position.y + kPageHeight - 1; 96 97 SetHighColor(pageBackgroundColor); 98 FillPolygon(page, 5); 99 100 SetHighColor(pageBorderColor); 101 StrokePolygon(page, 5); 102 StrokeLine(position + BPoint(3, 1), position + BPoint(3, 3)); 103 StrokeLine(position + BPoint(3, 3), position + BPoint(1, 3)); 104 105 SetHighColor(pageNumberColor); 106 SetLowColor(pageBackgroundColor); 107 DrawChar('0' + number, 108 position + 109 BPoint(kPageWidth - kPageHorizontalIndent + 1, kPageHeight - 2)); 110 } 111 112 void PagesView::setCollate(bool collate) 113 { 114 fCollate = collate; 115 Invalidate(); 116 } 117 118 void PagesView::setReverse(bool reverse) 119 { 120 fReverse = reverse; 121 Invalidate(); 122 } 123