notepad_point.cpp

Go to the documentation of this file.
00001 /*
00002  * File Name: notepad_point.cpp
00003  */
00004 
00005 /*
00006  * This file is part of notepad.
00007  *
00008  * notepad is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * notepad is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2010 IREX Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 #include "notepad_point.h"
00028 #include "log.h"
00029 
00030 #define CNMAX(x,y) (x < y)? y: x
00031 
00032 namespace notepad 
00033 {
00034     CNPoint::CNPoint()
00035         :
00036             x(0),
00037             y(0)
00038     {
00039     }
00040 
00041     CNPoint::~CNPoint()
00042     {
00043     }
00044 
00045     CNPoint::CNPoint(const CNPoint& src)
00046     {
00047         x = src.x;
00048         y = src.y;
00049     }
00050 
00051     CNPoint& CNPoint::operator=(const CNPoint& rhs)
00052     {
00053         x = rhs.x;
00054         y = rhs.y;
00055         return *this;
00056     }
00057 
00058     // use this constructor to init from window view -> X and Y are coordinates within a gdk_window
00059     CNPoint::CNPoint(int an_X, int a_Y)
00060         :
00061             x(0),
00062             y(0)
00063     {
00064         //LOGPRINTF("X = %d, Y = %d", an_X, a_Y);
00065 
00066         if ( rotation == NP_PORTRAIT )
00067         {
00068             x = an_X + left_border;
00069             y = a_Y + top_border;
00070         }
00071         else if ( rotation == NP_CLOCKWISE) 
00072         {
00073             x = a_Y + top_border;
00074             y = screen_width - an_X - left_border;
00075         }
00076         else if ( rotation == NP_ANTICLOCKWISE) 
00077         {
00078             x = screen_height - a_Y - bottom_border;
00079             y = an_X + left_border;
00080         }
00081 
00082         clipToMaxBorder();
00083  
00084         // Post: instance inv. holds: x and y delta coordinates
00085         //LOGPRINTF("this->x = %d, this->y = %d", x,y);
00086     }
00087 
00088     // use this contructor to init from storageView -> p.x and p.y are coordinates from a point from a stroke from liberscribble
00089     CNPoint::CNPoint(const ScbPoint& p)
00090         :
00091             x(0),
00092             y(0)
00093     {
00094         x = p.x + left_border;
00095         y = p.y + top_border; 
00096     }
00097 
00098     // this is the deltaview: x and y are always in portrait and absolute screen (delta fb) coordinates
00099     ScbPoint CNPoint::deviceView()
00100     {
00101         ScbPoint p = {0,0};
00102         p.x = x;
00103         p.y = y;
00104         return p;
00105     }
00106 
00107     // this is the windowView: x and y are dependant of orientation and borders and as such relative to the window coordinates
00108     ScbPoint CNPoint::windowView()
00109     {
00110         ScbPoint p = {0,0};
00111         if ( rotation == NP_PORTRAIT )
00112         {
00113             p.x = x - left_border;
00114             p.y = y - top_border;
00115         }
00116         else if ( rotation == NP_CLOCKWISE) 
00117         {
00118             p.x = screen_width - y - left_border;
00119             p.y = x - top_border;
00120         }
00121         else if ( rotation == NP_ANTICLOCKWISE) 
00122         {
00123             p.x = y - left_border;
00124             p.y = screen_height - bottom_border - x;
00125         }
00126         return p;
00127     }
00128     // this is the storageview: x and y are absolute and always in portrait and absolute screen coordinates
00129     ScbPoint CNPoint::storageView()
00130     {
00131         ScbPoint p = {0,0};
00132         p.x = x - left_border;
00133         p.y = y - top_border;
00134         return p;
00135     }
00136 
00137     void CNPoint::setRotation(np_rotation aRotation)
00138     {
00139         // there are only 4 relevant transitions.
00140         // others do not happen (e.g. landscape clockwise to landscape anticlockwise
00141         if (rotation == NP_PORTRAIT)
00142         {
00143             if (aRotation != rotation )
00144             {
00145                 int temp = screen_width;
00146                 screen_width = screen_height;
00147                 screen_height = temp;
00148             }
00149         }
00150         rotation = aRotation;
00151         LOGPRINTF("width = %d, height = %d, left = %d, right = %d, top = %d, bottom = %d", screen_width, screen_height, left_border, right_border, top_border, bottom_border);
00152     }
00153 
00154     void CNPoint::setBorders(int left, int right, int top, int bottom)
00155     {
00156         max_border = 0;
00157 
00158         left_border = left;
00159         right_border = right;
00160         top_border = top;
00161         bottom_border = bottom;
00162 
00163         max_border = CNMAX(max_border, left_border);
00164         max_border = CNMAX(max_border, right_border);
00165         max_border = CNMAX(max_border, top_border);
00166         max_border = CNMAX(max_border, bottom_border);
00167     }
00168 
00169     void CNPoint::setClipBorder(int border)
00170     {
00171         max_border = border+1; // just 1px within
00172     }
00173 
00174     void CNPoint::setScreen(int w, int h)
00175     {
00176         CNPoint::screen_width = w;
00177         CNPoint::screen_height = h;
00178     }
00179 
00180     void CNPoint::clipToMaxBorder()
00181     {
00182         int w = screen_width - max_border;
00183         int h = screen_height - max_border;
00184         if ( rotation != NP_PORTRAIT )
00185         {
00186             h = screen_width - max_border;
00187             w = screen_height - max_border;
00188         }
00189 
00190         if ( x < max_border ) x = max_border;
00191         if ( y < max_border ) y = max_border;
00192         if ( x > w ) x = w;
00193         if ( y > h ) y = h;
00194 
00195     }
00196 
00197     np_rotation CNPoint::rotation = NP_PORTRAIT;
00198     int CNPoint::left_border = 0;
00199     int CNPoint::right_border = 0;
00200     int CNPoint::top_border = 0;
00201     int CNPoint::bottom_border = 0;
00202     int CNPoint::max_border = 0;
00203     int CNPoint::screen_width = 0;
00204     int CNPoint::screen_height = 0;
00205 
00206 }
00207 
00208 
Generated by  doxygen 1.6.2-20100208