[ge-talk] Paged View
Zenja Solaja
solaja at gmail.com
Tue Sep 16 17:35:24 EDT 2008
Unlike other Operating Systems designed in the 80's, BeOS had designed its
view space and coordinate system to use floats instead of integers. Even
though I never actually utilised printing support under BeOS, I had a quick
look at how it works before designing my document layout program (which is
still in proof of concept prototype stage) since I figured users would like
to print their documents. Printing to a page is no different from drawing
to a BView under BeOS, with an additional "am I printing?" method returning
true in the BView. Software can change behaviour when it detects that it's
printing, but then it no longer adheres to the WYSIWYG metaphore.
Having a PrintPreview functionality is essentially identical to drawing to a
Window which has a size equivalent to the target paper size,at 72
pixels/inch. Without knowing how the PDF Printer device under BeOS was
implemented, I wouldn't be suprised to see that it actually piping the
window views to the PDF generator.
In 3D graphics rendering (like OpenGL, for example), a lot of funky effects
can be done using the render to texture technique. Essentially, all drawing
operations go to some off screen area, and the final data is treated as a
texture which can then be wrapped onto other objects. A good example is a
waving flag you see in many games.
In both of these examples, as well as the one you supplied, you can see the
common need to render to a offscreen buffer. Ideally, the drawing
operations to this buffer should be no different than drawing to a BVIew
(WYSIWYG). You've probably seen the fancy 3D Desktop effects in modern
Operating Systems these days. They are utilising the 3D rendering effect
where they utilise the offscreen buffer as a texture, and then wrap it
around some polygon, which can be the entire screen, or a set of smaller
polygons shuffled around the screen, where each represents a window on the
desktop (ala Expose on OSX). It's ridiculously easy to implement, and
extremelly effective at wow-ing the users.
Any PageView class should ideally just tap into the exposed off screen
buffer.
Regards,
Zenja.
2008/9/17 all4god <all4god at web.de>
> Hi,
>
> just again some ideas for the future of haiku.
> It would be great to have a Paged View Class.
> So that Developer can use this View to
> display Content easily in a print preview inside the
> running program (user can still change things)
>
> Back in days I tried to code something like this.
> But I know that it don't work but maybe just to get
> an idea how I mean.
>
> Something else wich also would be really really cool
> is:
> to have a "Duplex" preview (maby also in the running Programm).
>
> Just happened to my wife and me that we mixed up the layout
> for duplex (eg. If you print a flyer with answer card.. and the
> back of the answercard is on the wrong side)
>
> So if you would have a duplex preview wich you can turn on
> in paged view, this will not happen again, and you can
> layout stuff better :).
>
> eg. That the View becomes kind of translucenced so that you can
> see the backside through the front side.
>
>
> Or like the 3dmov demo that you can turn over a Page ...
>
> Just thoughts :)
>
> Keep on the good work - Bless you all
> Matthias
>
> --
> Matthias Lindner
> Lazarettstr. 10
>
> 45127 Essen
>
> Tel/Fax.: 0201-2480986
> www.online-mit-gott.dewww.fishers-girl.dewww.projectconceptor.de
>
>
> #include <interface/GraphicsDefs.h>
> #include <math.h>
> #include <Debug.h>
>
> #include "PagedView.h"
>
>
>
> PagedView::PagedView(BRect _rect,char *_name,uint32 resizingMode,uint32
> flags,page_layout _pageLayout):BView(_rect,_name,resizingMode,flags){
> pageLayout=_pageLayout;
> TRACE();
> Init();
> }
>
> void PagedView::Init(void){
> TRACE();
> printRect = BRect();
> pageRect = BRect();;
> renderBitmap = new BBitmap(Bounds(),B_RGB32,true);
> drawView = new BView(BRect(Bounds()),"drawView",0,0);
> colums = 1;
> rows = 1;
> paged = true;
> margin = 10.0;
> childList = vector<PagedRect>();
> }
>
> void PagedView::AttachedToWindow(void){
> TRACE();
> SetViewColor(230,230,230,255);
> SetHighColor(0,0,0,255);
> SetLowColor(255,255,255,255);
> SetDrawingMode(B_OP_ALPHA);
> }
>
>
> void PagedView::Draw(BRect updateRect)
> {
>
>
> renderBitmap->Lock();
> for (int32 i = 0; i<renderBitmap->CountChildren(); i++) {
> renderBitmap->ChildAt(i)->Draw(Bounds());
> renderBitmap->ChildAt(i)->Sync();
> }
> renderBitmap->Unlock();
> if ((paged) && (!IsPrinting()))
> DrawPages(updateRect);
> else
> DrawBitmap(renderBitmap,updateRect,updateRect);
>
> }
>
> void PagedView::MouseDown(BPoint where)
> {
> BView *found = NULL;
> if (paged){
> //find the page the user clicked on :)
> vector<PagedRect>::iterator it;
> for ( it=childList.begin() ; (it < childList.end()) &&
> (found == NULL); it++ ){
> if ((*it).PageRect().Contains(where))
> found =
> renderBitmap->FindView(where-(*it).DiffOffset());
> }
> }
> else
> found = renderBitmap->FindView(where);
> if (found!=NULL)
> found->MouseDown(where);
> Invalidate();
> }
>
>
> void PagedView::MouseMoved( BPoint where, uint32 code, const BMessage
> *a_message)
> {
> BView *found = NULL;
> if (paged){
> //find the page the user clicked on :)
> vector<PagedRect>::iterator it;
> for ( it=childList.begin() ; (it < childList.end()) &&
> (found == NULL); it++ ){
> if ((*it).PageRect().Contains(where))
> found =
> renderBitmap->FindView(where-(*it).DiffOffset());
> }
> }
> else
> found = renderBitmap->FindView(where);
> if (found!=NULL)
> found->MouseMoved( where, code, a_message);
> }
>
> void PagedView::MouseUp(BPoint where)
> {
> BView *found = NULL;
> if (paged){
> //find the page the user clicked on :)
> vector<PagedRect>::iterator it;
> for ( it=childList.begin() ; (it < childList.end()) &&
> (found == NULL); it++ ){
> if ((*it).PageRect().Contains(where))
> found =
> renderBitmap->FindView(where-(*it).DiffOffset());
> }
> }
> else
> found = renderBitmap->FindView(where);
> if (found!=NULL)
> found->MouseUp(where);
> Invalidate();
> }
>
> void PagedView::MessageReceived(BMessage *message)
> {
> switch(message->what)
> {
> default:
> BView::MessageReceived(message);
> break;
> }
> }
>
> void PagedView::FrameResized(float width, float height)
> {
> TRACE();
> //**pass all Resize stuff through;
> CalculatePages();
> }
>
>
> void PagedView::DrawPages(BRect updateRect)
> {
> vector<PagedRect>::iterator it;
> BRect sourceRect;
> BRect printingRect;
> BRect paperRect;
> BRect drawRect;
> rgb_color restoreHighColor;
> for ( it=childList.begin() ; it < childList.end(); it++ ){
> paperRect =(*it).PageRect();
> printingRect =(*it).PrintRect();
> if (paperRect.Intersects(updateRect)){
> paperRect.OffsetBy(3,3);
> restoreHighColor=HighColor();
> SetHighColor(100,100,100,100);
> FillRect(paperRect);
> paperRect.OffsetBy(-3,-3);
> FillRect(paperRect,B_SOLID_LOW);
> SetHighColor(restoreHighColor);
>
> StrokeRect(paperRect);
> }
> drawRect = printingRect & updateRect;
> if (drawRect.IsValid()){
> sourceRect = drawRect;
> sourceRect.OffsetBy((*it).DiffOffset());
>
> DrawBitmapAsync(renderBitmap,sourceRect,printingRect);
> restoreHighColor=HighColor();
> SetHighColor(55,55,200,100);
> // SetPenSize(1.0);
> StrokeRect(printingRect);
> SetHighColor(restoreHighColor);
> }
> }
> Sync();
> }
>
> void PagedView::SetPageRect(BRect _pageRect){
> if (_pageRect.IsValid()){
> pageRect=_pageRect;
> CalculatePages();
> }
> }
>
> void PagedView::SetPrintRect(BRect _printRect){
> if (_printRect.IsValid()){
> printRect=_printRect;
> CalculatePages();
> }
> }
>
>
> void PagedView::CalculatePages(void){
> TRACE();
> BRect sourceArea;
> BRect printArea;
> BRect paperArea;
> PagedRect *pageArea;
> int32 q, i, cx, cy,count;
> float x, y, nx, ny;
> float leftDiff, topDiff;
> leftDiff = printRect.left - pageRect.left;
> topDiff = printRect.top - pageRect.top;
> colums = ceil(Bounds().Width()/printRect.Width());
> rows = ceil(Bounds().Height()/printRect.Height());
> childList.clear();
> for (q=0; q< rows; q++)
> for (i=0;i<colums;i++)
> {
> x=i*printRect.Width();
> y=q*printRect.Height();
> sourceArea =
> BRect(x,y,x+printRect.Width(),y+printRect.Height());
> count = q*colums+i;
> if (pageLayout == COL_AS_NEEDED){
> cy = q;
> cx = i;
> }
> else {
> cx = count % pageLayout;
> cy = (int32)floor(count / pageLayout);
> }
>
> nx = (cx*pageRect.Width())+cx*margin+margin;
> ny = (cy*pageRect.Height())+cy*margin+margin;
> printArea = BRect
> (nx+leftDiff,ny+topDiff,nx+leftDiff+printRect.Width(),ny+topDiff+printRect.Height());
> paperArea =
> BRect(nx,ny,nx+pageRect.Width(),ny+pageRect.Height());
>
> childList.push_back(PagedRect(paperArea,printArea,sourceArea));
> }
>
> }
>
> #ifndef PAGED_VIEW_H
> #define PAGED_VIEW_H
> /*
> * @author Paradoxon powered by Jesus Christ
> */
> #include <app/Message.h>
> #include <interface/Bitmap.h>
> #include <interface/View.h>
> #include <interface/Rect.h>
> #include <vector.h>
>
> enum page_layout{
> ONE_COL = 1,
> TWO_COL = 2,
> COL_AS_NEEDED = -1
> };
>
> class PagedRect
> {
> public:
> PagedRect(void){
> pageRect
> = BRect();
> printRect
> = BRect();
> sourceRect
> = BRect();
> };
> PagedRect(BRect
> _pageRect,BRect _printRect,BRect _sourceRect){
> pageRect
> =_pageRect;
> printRect
> =_printRect;
> sourceRect
> = _sourceRect;
> };
> float LeftBorder(void){return
> printRect.left-pageRect.left;};
> float TopBorder(void){return
> printRect.top-pageRect.top;};
> float RightBorder(void){return
> pageRect.right-printRect.right;};
> float BottomBorder(void){return
> pageRect.bottom-printRect.bottom;};
> BRect PageRect(void){return
> pageRect;};
> BRect PrintRect(void){return
> printRect;};
> BRect SourceRect(void){return
> sourceRect;};
> void SetPageRect(BRect
> _pageRect){pageRect=_pageRect;};
> void SetPrintRect(BRect
> _printRect){printRect=_printRect;};
> void SetSourceRect(BRect
> _sourceRect){sourceRect=_sourceRect;};
> BPoint DiffOffset(void){return
> BPoint(sourceRect.left-printRect.left,sourceRect.top-printRect.top);};
>
>
> private:
> BRect pageRect;
> BRect printRect;
> BRect sourceRect;
>
> };
>
> class PagedView : public BView
> {
>
> public:
> PagedView(BRect
> _rect,char *_name,uint32 resizingMode,uint32 flags,page_layout _pageLayout =
> ONE_COL);
>
> //++++++++++++++++BView
> virtual void AttachedToWindow(void);
>
> virtual void Draw(BRect updateRect);
>
> virtual void MouseDown(BPoint where);
> virtual void MouseMoved( BPoint where, uint32
> code, const BMessage *a_message);
> virtual void MouseUp(BPoint where);
>
> virtual void MessageReceived(BMessage *msg);
>
> virtual void FrameResized(float width, float
> height);
> //----------------BView
> /**
> * Pass the Rect wich defines the new Size of the Page
> * This Rect must enclose the whole printRect
> *@see SetPrintRect(BRect _printRect);
> */
> void SetPageRect(BRect
> _pageRect);
> /**
> * Pass the Rect wich defines the new Size of the Printable Rect
> * This Rect must be smaller than the PageRect
> *@see SetPageRect(BRect _printRect);
> */
> void SetPrintRect(BRect
> _printRect);
>
> protected:
> void Init(void);
> void DrawPages(BRect);
> void CalculatePages(void);
> BBitmap *renderBitmap;
> BView *drawView;
>
>
> private:
> bool paged;
> BRect pageRect;
> BRect printRect;
> int32 rows, colums;
> page_layout pageLayout;
> float margin;
> vector<PagedRect> childList;
>
> };
> #endif
>
> _______________________________________________
> glasselevator-talk mailing list
> glasselevator-talk at bug-br.org.br
> http://www.bug-br.org.br/mailman/listinfo/glasselevator-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.bug-br.org.br/pipermail/glasselevator-talk/attachments/20080917/a0826fae/attachment-0001.html
More information about the glasselevator-talk
mailing list