Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DasherViewSquare.cpp

Go to the documentation of this file.
00001 // DasherViewSquare.cpp
00002 //
00004 //
00005 // Copyright (c) 2001-2002 David Ward
00006 //
00008 
00009 
00011 // DasherViewSquare.cpp: implementation of the DasherViewSquare class.
00012 // Copyright 2002 David Ward
00014 
00015 #include "DasherModel.h"
00016 #include "DasherViewSquare.h"
00017 #include <iostream>
00018 
00019 using namespace Dasher;
00020 
00021 // ARG! MSVC++ V6 doesn't seem to come with min and max in <algorithm>
00022 #ifdef _MSC_VER
00023 #ifndef max
00024 #define max(a,b) (((a) > (b)) ? (a) : (b))
00025 #endif
00026 #ifndef min
00027 #define min(a,b) (((a) < (b)) ? (a) : (b))
00028 #endif
00029 #else
00030 #include <algorithm>
00031 using std::min;
00032 using std::max;
00033 #endif
00034 
00035 
00036 CDasherViewSquare::CDasherViewSquare(CDasherScreen* DasherScreen, CDasherModel& DasherModel, Dasher::Opts::ScreenOrientations Orientation)
00037         : CDasherView(DasherScreen, DasherModel, Orientation)
00038 {
00039         ChangeScreen(DasherScreen);
00040         
00041         // tweak these if you know what you are doing
00042         m_dXmpa=0.2;   // these are for the x non-linearity
00043         m_dXmpb=0.5;
00044         m_dXmpc=0.9;
00045         m_dXmpd=0.5;   // slow X movement when accelerating Y
00046 
00047         double dY1=0.25;    // Amount of acceleration
00048         double dY2=0.95;    // Accelerate Y movement below this point
00049         double dY3=0.05;    // Accelerate Y movement above this point
00050 
00051         m_Y2=int (dY2 * (CDasherView::DasherModel().DasherY()) );
00052         m_Y3=int (dY3 * (CDasherView::DasherModel().DasherY()) );
00053         m_Y1=int(1.0/dY1);
00054 
00055 }
00056 
00057 
00058 int CDasherViewSquare::RenderNode(const symbol Character, const int Color, Opts::ColorSchemes ColorScheme,
00059         myint y1, myint y2, int& mostleft, bool& force, bool text)
00060 {
00061         int top = dashery2screen(y1);
00062         if (top>CanvasY)
00063                 return 0;
00064         if (top<0)
00065                 top=0;
00066         
00067         int bottom = dashery2screen(y2);
00068         if (bottom<0)
00069                 return 0;
00070         if (bottom>CanvasY)
00071                 bottom=CanvasY;
00072         
00073         int height=bottom-top;
00074         
00075         if (height==0 && text==true)
00076                 force=false;
00077         
00078         if (force || height>1) {
00079                 force=true;
00080 
00081                 int left=dasherx2screen(y2-y1);
00082                 
00083                 int right=CanvasX;
00084                 
00085                 int newleft=left, newtop=top, newright=right, newbottom=bottom;
00086                 MapScreen(&newleft, &newtop);
00087                 MapScreen(&newright, &newbottom);
00088                 if( !text )
00089                   Screen().DrawRectangle(newleft, newtop, newright, newbottom, Color, ColorScheme);
00090                 else
00091                   {
00092                     if (left<mostleft)
00093                       left=mostleft;
00094                     
00095                     int Size;
00096                     if (left*Screen().GetFontSize()<CanvasX*19/20) {
00097                       Size = 20*Screen().GetFontSize();
00098                     } else if (left*Screen().GetFontSize()<CanvasX*159/160) {
00099                       Size = 14*Screen().GetFontSize();
00100                     } else {
00101                       Size = 11*Screen().GetFontSize();
00102                     }
00103                     
00104                     int TextWidth, TextHeight, OriginX=0, OriginY=0;
00105                     Screen().TextSize(Character, &TextWidth, &TextHeight, Size);
00106                     UnMapScreen(&TextWidth, &TextHeight);
00107                     UnMapScreen(&OriginX, &OriginY);            
00108                     int FontHeight = abs(TextHeight-OriginY);           
00109                     int FontWidth = abs(TextWidth-OriginX);
00110                     mostleft = left + FontWidth;
00111                     
00112                     int newleft2 = left;
00113                     int newtop2 = (height-FontHeight)/2 + top;
00114                     int newright2 = left + FontWidth;
00115                     int newbottom2 = (height+FontHeight)/2 + top;
00116                     MapScreen(&newleft2, &newtop2);
00117                     MapScreen(&newright2, &newbottom2);
00118                     newleft = min(newleft2, newright2);
00119                     newtop = min(newtop2, newbottom2);
00120                     
00121                     Screen().DrawText(Character, newleft, newtop, Size);
00122                   }
00123                 
00124                 return 1;
00125         } else 
00126                 return 0;
00127 }
00128 
00129 
00130 void CDasherViewSquare::CheckForNewRoot()
00131 {
00132         CDasherNode * const root=DasherModel().Root();
00133         CDasherNode ** const children=root->Children();
00134 
00135 
00136         myint y1=DasherModel().Rootmin();
00137         myint y2=DasherModel().Rootmax();
00138         
00139         if ((y1>0 || y2 < DasherModel().DasherY() || dasherx2screen(y2-y1)>0) && root->Symbol()!=0) {
00140           DasherModel().Reparent_root(root->Lbnd(),root->Hbnd());
00141         }
00142             
00143         if (children==0)
00144                 return;
00145 
00146         int alive=0;
00147         int theone=0;
00148         unsigned int i;
00149         for (i=1;i<root->Chars();i++) {
00150                 if (children[i]->Alive()) {
00151                         alive++;
00152                         theone=i;
00153                 }
00154         }
00155         
00156         if (alive==1) {   
00157                 y1=DasherModel().Rootmin();
00158                 y2=DasherModel().Rootmax();
00159                 myint range=y2-y1;
00160                 myint newy1=y1+(range*children[theone]->Lbnd())/DasherModel().Normalization();
00161                 myint newy2=y1+(range*children[theone]->Hbnd())/DasherModel().Normalization();
00162                 if (newy1<0 && newy2> DasherModel().DasherY()) {
00163                         myint left=dasherx2screen(newy2-newy1);
00164                         if (left<0) {
00165                                 DasherModel().Make_root(theone);
00166                                 return;
00167                         }
00168                 }
00169         }
00170 }
00171 
00172 
00173 // work out the next viewpoint
00174 // move the rectangles accordingly
00175 void CDasherViewSquare::TapOnDisplay(int mousex,int mousey, unsigned long Time) 
00176 {
00177         // convert mouse (screen) coords into dasher coords
00178         if (mousex>CanvasX)
00179                 mousex=CanvasX;
00180         
00181         UnMapScreen(&mousex, &mousey);
00182         screen2dasher(&mousex,&mousey);
00183         DasherModel().Tap_on_display(mousex,mousey, Time);
00184         CheckForNewRoot();
00185 }
00186 
00187 void CDasherViewSquare::DrawMouse(int mousex, int mousey)
00188 {
00189         screen2dasher(&mousex,&mousey);
00190         mousex=dasherx2screen(mousex);
00191         mousey=dashery2screen(mousey);
00192         Screen().DrawRectangle(mousex-5, mousey-5, mousex+5, mousey+5, 0, Opts::ColorSchemes(Objects));
00193 }
00194 
00195 void CDasherViewSquare::DrawKeyboard()
00196 {
00197   CDasherScreen::point line[2];
00198   line[0].x = 200;
00199   line[0].y = 0;
00200   line[1].x = 200;
00201   line[1].y = CanvasY/2;
00202   
00203   Screen().Polyline(line,2);
00204 
00205   line[0].x = 200;
00206   line[0].y = CanvasY/2;
00207   line[1].x = 0;
00208   line[1].y = CanvasY/2;
00209 
00210   Screen().Polyline(line,2);
00211 
00212   line[0].x = 200;
00213   line[0].y = CanvasY/2;
00214   line[1].x = 200;
00215   line[1].y = CanvasY;
00216 
00217   Screen().Polyline(line,2);
00218 }
00219 
00220 void CDasherViewSquare::ChangeScreen(CDasherScreen* NewScreen)
00221 {
00222         CDasherView::ChangeScreen(NewScreen);
00223         int Width = Screen().GetWidth();
00224         int Height = Screen().GetHeight();
00225         CanvasX=9*Width/10;
00226         CanvasBorder=Width-CanvasX;
00227         CanvasY=Height;
00228 }
00229 

Generated on Sat Nov 5 16:16:00 2005 for OPIE by  doxygen 1.4.2