xref: /haiku/src/libs/print/libprint/PagesView.cpp (revision 26db1794f9199838b3d4c8e6199f72dcf9cfec08)
112fd6cc2SKarsten Heimrich #include "PagesView.h"
212fd6cc2SKarsten Heimrich 
312fd6cc2SKarsten Heimrich static const float kWidth  = 80;
412fd6cc2SKarsten Heimrich static const float kHeight = 30;
512fd6cc2SKarsten Heimrich 
612fd6cc2SKarsten Heimrich static const float kPageWidth  = 16;
712fd6cc2SKarsten Heimrich static const float kPageHeight = 16;
812fd6cc2SKarsten Heimrich 
912fd6cc2SKarsten Heimrich static const float kPageHorizontalIndent = 7;
1012fd6cc2SKarsten Heimrich static const float kPageVerticalIndent = 5;
1112fd6cc2SKarsten Heimrich 
PagesView(BRect frame,const char * name,uint32 resizeMask,uint32 flags)1212fd6cc2SKarsten Heimrich PagesView::PagesView(BRect frame, const char* name, uint32 resizeMask, uint32 flags)
1312fd6cc2SKarsten Heimrich 	:	BView(frame, name, resizeMask, flags),
1412fd6cc2SKarsten Heimrich 		fCollate(false),
1512fd6cc2SKarsten Heimrich 		fReverse(false)
1612fd6cc2SKarsten Heimrich {
1712fd6cc2SKarsten Heimrich 	SetViewColor(B_TRANSPARENT_COLOR);
1812fd6cc2SKarsten Heimrich }
1912fd6cc2SKarsten Heimrich 
GetPreferredSize(float * width,float * height)2012fd6cc2SKarsten Heimrich void PagesView::GetPreferredSize(float *width, float *height)
2112fd6cc2SKarsten Heimrich {
2212fd6cc2SKarsten Heimrich 	*width  = kWidth;
2312fd6cc2SKarsten Heimrich 	*height = kHeight;
2412fd6cc2SKarsten Heimrich }
2512fd6cc2SKarsten Heimrich 
Draw(BRect rect)2612fd6cc2SKarsten Heimrich void PagesView::Draw(BRect rect)
2712fd6cc2SKarsten Heimrich {
2812fd6cc2SKarsten Heimrich 	rgb_color backgroundColor = {255, 255, 255};
2912fd6cc2SKarsten Heimrich 	// inherit view color from parent if available
3012fd6cc2SKarsten Heimrich 	if (Parent() != NULL) {
3112fd6cc2SKarsten Heimrich 		backgroundColor = Parent()->ViewColor();
3212fd6cc2SKarsten Heimrich 	}
3312fd6cc2SKarsten Heimrich 	SetHighColor(backgroundColor);
3412fd6cc2SKarsten Heimrich 	FillRect(rect);
3512fd6cc2SKarsten Heimrich 
3612fd6cc2SKarsten Heimrich 	BFont font(be_plain_font);
3712fd6cc2SKarsten Heimrich 	font.SetSize(8);
3812fd6cc2SKarsten Heimrich 	SetFont(&font);
3912fd6cc2SKarsten Heimrich 
4012fd6cc2SKarsten Heimrich 	BPoint position(3, 3);
4112fd6cc2SKarsten Heimrich 	if (fCollate) {
4212fd6cc2SKarsten Heimrich 		BPoint next(kPageWidth + kPageHorizontalIndent * 2 + 10, 0);
43*4410ee12SMichael Pfeiffer 		_DrawPages(position, 1, 3);
4412fd6cc2SKarsten Heimrich 		position += next;
45*4410ee12SMichael Pfeiffer 		_DrawPages(position, 1, 3);
4612fd6cc2SKarsten Heimrich 	} else {
4712fd6cc2SKarsten Heimrich 		BPoint next(kPageWidth + kPageHorizontalIndent * 1 + 10, 0);
4812fd6cc2SKarsten Heimrich 		for (int i = 1; i <= 3; i ++) {
4912fd6cc2SKarsten Heimrich 			int page = fReverse ? 4 - i : i;
50*4410ee12SMichael Pfeiffer 			_DrawPages(position, page, 2);
5112fd6cc2SKarsten Heimrich 			position += next;
5212fd6cc2SKarsten Heimrich 		}
5312fd6cc2SKarsten Heimrich 	}
5412fd6cc2SKarsten Heimrich }
5512fd6cc2SKarsten Heimrich 
_DrawPages(BPoint position,int number,int count)56*4410ee12SMichael Pfeiffer void PagesView::_DrawPages(BPoint position, int number, int count)
5712fd6cc2SKarsten Heimrich {
5812fd6cc2SKarsten Heimrich 	position.x += kPageHorizontalIndent * (count - 1);
5912fd6cc2SKarsten Heimrich 	BPoint next(-kPageHorizontalIndent, kPageVerticalIndent);
6012fd6cc2SKarsten Heimrich 	if (fCollate) {
6112fd6cc2SKarsten Heimrich 		for (int i = 0; i < count; i ++) {
6212fd6cc2SKarsten Heimrich 			int page;
6312fd6cc2SKarsten Heimrich 			if (fReverse) {
6412fd6cc2SKarsten Heimrich 				page = 1 + i;
6512fd6cc2SKarsten Heimrich 			} else {
6612fd6cc2SKarsten Heimrich 				page = count - i;
6712fd6cc2SKarsten Heimrich 			}
68*4410ee12SMichael Pfeiffer 			_DrawPage(position, page);
6912fd6cc2SKarsten Heimrich 			position += next;
7012fd6cc2SKarsten Heimrich 		}
7112fd6cc2SKarsten Heimrich 	} else {
7212fd6cc2SKarsten Heimrich 		for (int i = 0; i < count; i ++) {
73*4410ee12SMichael Pfeiffer 			_DrawPage(position, number);
7412fd6cc2SKarsten Heimrich 			position += next;
7512fd6cc2SKarsten Heimrich 		}
7612fd6cc2SKarsten Heimrich 	}
7712fd6cc2SKarsten Heimrich }
7812fd6cc2SKarsten Heimrich 
_DrawPage(BPoint position,int number)79*4410ee12SMichael Pfeiffer void PagesView::_DrawPage(BPoint position, int number)
8012fd6cc2SKarsten Heimrich {
8112fd6cc2SKarsten Heimrich 	const rgb_color pageBackgroundColor = {255, 255, 255};
8212fd6cc2SKarsten Heimrich 	const rgb_color pageBorderColor = {0, 0, 0};
8312fd6cc2SKarsten Heimrich 	const rgb_color pageNumberColor = {0, 0, 0};
8412fd6cc2SKarsten Heimrich 
8512fd6cc2SKarsten Heimrich 	BPoint page[5];
8612fd6cc2SKarsten Heimrich 	page[0].x = position.x + 3;
8712fd6cc2SKarsten Heimrich 	page[0].y = position.y;
8812fd6cc2SKarsten Heimrich 	page[4].x = position.x;
8912fd6cc2SKarsten Heimrich 	page[4].y = position.y + 3;
9012fd6cc2SKarsten Heimrich 	page[1].x = position.x + kPageWidth - 1;
9112fd6cc2SKarsten Heimrich 	page[1].y = position.y;
9212fd6cc2SKarsten Heimrich 	page[2].x = position.x + kPageWidth - 1;
9312fd6cc2SKarsten Heimrich 	page[2].y = position.y + kPageHeight - 1;
9412fd6cc2SKarsten Heimrich 	page[3].x = position.x;
9512fd6cc2SKarsten Heimrich 	page[3].y = position.y + kPageHeight - 1;
9612fd6cc2SKarsten Heimrich 
9712fd6cc2SKarsten Heimrich 	SetHighColor(pageBackgroundColor);
9812fd6cc2SKarsten Heimrich 	FillPolygon(page, 5);
9912fd6cc2SKarsten Heimrich 
10012fd6cc2SKarsten Heimrich 	SetHighColor(pageBorderColor);
10112fd6cc2SKarsten Heimrich 	StrokePolygon(page, 5);
10212fd6cc2SKarsten Heimrich 	StrokeLine(position + BPoint(3, 1), position + BPoint(3, 3));
10312fd6cc2SKarsten Heimrich 	StrokeLine(position + BPoint(3, 3), position + BPoint(1, 3));
10412fd6cc2SKarsten Heimrich 
10512fd6cc2SKarsten Heimrich 	SetHighColor(pageNumberColor);
10612fd6cc2SKarsten Heimrich 	SetLowColor(pageBackgroundColor);
10712fd6cc2SKarsten Heimrich 	DrawChar('0' + number,
10812fd6cc2SKarsten Heimrich 		position +
10912fd6cc2SKarsten Heimrich 		BPoint(kPageWidth - kPageHorizontalIndent + 1, kPageHeight - 2));
11012fd6cc2SKarsten Heimrich }
11112fd6cc2SKarsten Heimrich 
SetCollate(bool collate)112*4410ee12SMichael Pfeiffer void PagesView::SetCollate(bool collate)
11312fd6cc2SKarsten Heimrich {
11412fd6cc2SKarsten Heimrich 	fCollate = collate;
11512fd6cc2SKarsten Heimrich 	Invalidate();
11612fd6cc2SKarsten Heimrich }
11712fd6cc2SKarsten Heimrich 
SetReverse(bool reverse)118*4410ee12SMichael Pfeiffer void PagesView::SetReverse(bool reverse)
11912fd6cc2SKarsten Heimrich {
12012fd6cc2SKarsten Heimrich 	fReverse = reverse;
12112fd6cc2SKarsten Heimrich 	Invalidate();
12212fd6cc2SKarsten Heimrich }
123