notepad_point.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00059 CNPoint::CNPoint(int an_X, int a_Y)
00060 :
00061 x(0),
00062 y(0)
00063 {
00064
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
00085
00086 }
00087
00088
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
00099 ScbPoint CNPoint::deviceView()
00100 {
00101 ScbPoint p = {0,0};
00102 p.x = x;
00103 p.y = y;
00104 return p;
00105 }
00106
00107
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
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
00140
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;
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