00001 00002 00003 #include "vuDrawTools.h" 00004 00005 #include <iostream.h> 00006 #include <wx/dcclient.h> 00007 #include <wx/pen.h> 00008 #include <wx/bitmap.h> 00009 #include <wx/image.h> 00010 00011 //############### internal variables ######################################### 00014 static wxDC* cDC = NULL; 00015 static wxImage* img = NULL; 00016 vuMutex DrawToolMutex; 00017 vuMutex SQMutex; 00018 00019 //---------------------------------------------------------------------------- 00020 //------------------------- setPixel(int x, int y) --------------------------- 00021 //---------------------------------------------------------------------------- 00022 00023 void vuDrawTools::setPixel(int x, int y) 00024 { 00025 // DrawToolMutex.lock (); 00026 00027 if(cDC) 00028 cDC->DrawPoint(x,y); 00029 00030 //DrawToolMutex.unlock (); 00031 } 00032 00033 //---------------------------------------------------------------------------- 00034 //------------------------- setColour() -------------------------------------- 00035 //---------------------------------------------------------------------------- 00036 00037 void vuDrawTools::setColour(byte r, byte g, byte b) 00038 { 00039 //DrawToolMutex.lock (); 00040 00041 if(cDC) 00042 // cDC->SetBrush(wxBrush(wxColour(r,g,b),wxSOLID)); 00043 cDC->SetPen(wxPen(wxColour(r,g,b),1,wxSOLID|wxDOT)); 00044 00045 //DrawToolMutex.unlock (); 00046 } 00047 00048 //---------------------------------------------------------------------------- 00049 //------------------------- setBGColour() -------------------------------------- 00050 //---------------------------------------------------------------------------- 00051 00052 void vuDrawTools::setBGColour(byte r, byte g, byte b) 00053 { 00054 //DrawToolMutex.lock (); 00055 00056 if(cDC) 00057 cDC->SetBackground(wxBrush(wxColour(r,g,b),wxSOLID)); 00058 00059 // DrawToolMutex.unlock (); 00060 } 00061 00062 //---------------------------------------------------------------------------- 00063 //------------------------- clearBG() ---------------------------------------- 00064 //---------------------------------------------------------------------------- 00065 00066 void vuDrawTools::clearBG() 00067 00068 { 00069 //DrawToolMutex.lock (); 00070 00071 if(cDC) 00072 cDC->Clear(); 00073 00074 //DrawToolMutex.unlock (); 00075 } 00076 00077 //---------------------------------------------------------------------------- 00078 //------------------------- blit() ------------------------------------------- 00079 //---------------------------------------------------------------------------- 00080 00081 //#include <iostream.h> 00082 00083 void vuDrawTools::blit(const byte *buf, int sx, int sy, int px, int py) 00084 { 00085 //DrawToolMutex.lock (); 00086 00087 if(cDC && buf) 00088 { 00089 wxImage img(sx,sy, (unsigned char *) (buf), true); 00090 wxBitmap bmp(img); 00091 cDC->DrawBitmap(bmp, px, py); 00092 } 00093 00094 //DrawToolMutex.unlock (); 00095 } 00096 00097 void vuDrawTools::blit2(const byte *buf, int sx, int sy, int px, int py) 00098 { 00099 //DrawToolMutex.lock (); 00100 00101 if(cDC && buf) 00102 { 00103 wxBitmap bmp(*img); 00104 cDC->DrawBitmap(bmp, px, py); 00105 } 00106 00107 //DrawToolMutex.unlock (); 00108 } 00109 00110 void vuDrawTools::partblit (const byte *buf, int sx, int sy, int length) 00111 00112 { 00113 } 00114 00115 void vuDrawTools::finishpartblit () 00116 00117 { 00118 } 00119 00120 void vuDrawTools::setImgWidthHeight (int sx, int sy) 00121 00122 { 00123 //DrawToolMutex.lock (); 00124 00125 if (img == NULL) 00126 00127 { 00128 img = new wxImage [1]; 00129 00130 if (img == NULL) 00131 return; 00132 } 00133 00134 00135 img->Rescale (sx, sy); 00136 00137 //DrawToolMutex.unlock (); 00138 } 00139 00140 unsigned char * vuDrawTools::getData () 00141 00142 { 00143 return img->GetData (); 00144 } 00145 00146 //---------------------------------------------------------------------------- 00147 //------------------------- setDC(wxDC*) ------------------------------------- 00148 //---------------------------------------------------------------------------- 00149 void vuDrawTools::setDC(void *pDC) 00150 { 00151 // SQMutex.lock (); 00152 00153 // DrawToolMutex.lock (); 00154 00155 cDC = (wxDC*)pDC; 00156 00157 // DrawToolMutex.unlock (); 00158 } 00159 00160 //---------------------------------------------------------------------------- 00161 //------------------------- quitDC() ----------------------------------------- 00162 //---------------------------------------------------------------------------- 00163 void vuDrawTools::quitDC() 00164 { 00165 cDC = NULL; 00166 00167 // SQMutex.unlock (); 00168 } 00169 00170 //---------------------------------------------------------------------------- 00171 //------------------------- clearBGWithoutRect() ---------------------------- 00172 //---------------------------------------------------------------------------- 00173 void vuDrawTools::clearBGWithoutRect(int ox,int oy,int sx,int sy) 00174 { 00175 // DrawToolMutex.lock (); 00176 00177 if(cDC) 00178 { 00179 int w,h; 00180 cDC->GetSize(&w,&h); 00181 cDC->DrawRectangle(sx,oy,w-sx,h-oy); 00182 /* 00183 cDC->SetClippingRegion(sx,oy,w-sx,h-oy); 00184 cDC->Clear(); 00185 cDC->SetClippingRegion(0,oy+sy,sx,h-sy); 00186 cDC->Clear(); 00187 cDC->DestroyClippingRegion(); 00188 */ 00189 } 00190 00191 //DrawToolMutex.unlock (); 00192 } 00193 00194 //---------------------------------------------------------------------------- 00195 //------------------------- ------------------- 00196 //---------------------------------------------------------------------------- 00197 //---------------------------------------------------------------------------- 00198 //------------------------- setPixel(int x, int y) --------------------------- 00199 //---------------------------------------------------------------------------- 00200 /* 00201 void vuDrawToolsns::setPixel(int x, int y) 00202 { 00203 DrawToolMutexns.lock (); 00204 if(cDCns) 00205 cDCns->DrawPoint(x,y); 00206 DrawToolMutexns.unlock (); 00207 } 00208 00209 //---------------------------------------------------------------------------- 00210 //------------------------- setColour() -------------------------------------- 00211 //---------------------------------------------------------------------------- 00212 00213 void vuDrawToolsns::setColour(byte r, byte g, byte b) 00214 { 00215 DrawToolMutexns.lock (); 00216 00217 if(cDCns) 00218 // cDC->SetBrush(wxBrush(wxColour(r,g,b),wxSOLID)); 00219 cDCns->SetPen(wxPen(wxColour(r,g,b),1,wxSOLID|wxDOT)); 00220 00221 DrawToolMutexns.unlock (); 00222 } 00223 00224 //---------------------------------------------------------------------------- 00225 //------------------------- setBGColour() -------------------------------------- 00226 //---------------------------------------------------------------------------- 00227 00228 void vuDrawToolsns::setBGColour(byte r, byte g, byte b) 00229 { 00230 DrawToolMutexns.lock (); 00231 00232 if(cDCns) 00233 cDCns->SetBackground(wxBrush(wxColour(r,g,b),wxSOLID)); 00234 00235 DrawToolMutexns.unlock (); 00236 } 00237 00238 //---------------------------------------------------------------------------- 00239 //------------------------- clearBG() ---------------------------------------- 00240 //---------------------------------------------------------------------------- 00241 00242 void vuDrawToolsns::clearBG() 00243 00244 { 00245 DrawToolMutexns.lock (); 00246 00247 if(cDCns) 00248 cDCns->Clear(); 00249 00250 DrawToolMutexns.unlock (); 00251 } 00252 00253 //---------------------------------------------------------------------------- 00254 //------------------------- blit() ------------------------------------------- 00255 //---------------------------------------------------------------------------- 00256 00257 //#include <iostream.h> 00258 00259 void vuDrawToolsns::blit(const byte *buf, int sx, int sy, int px, int py) 00260 { 00261 DrawToolMutexns.lock (); 00262 // cout << "::blit " << endl; 00263 if(cDCns && buf) 00264 { 00265 // int mx, my; 00266 // faster this way, about 6 ms on Praha opposed to 11 ms for the old way. 00267 wxImage imgns(sx,sy, (unsigned char *) (buf), true); 00268 // memcpy(img.GetData(),buf,sx*sy*3); 00269 // img.SetData ((unsigned char*) (buf)); 00270 wxBitmap bmp(imgns); 00271 // wxBitmap bmp ((void *) (buf), wxBITMAP_TYPE_BMP , sx, sy);//| wxBITMAP_TYPE_BMP_RESOURCE | wxBITMAP_TYPE_GIF | wxBITMAP_TYPE_XBM | wxBITMAP_TYPE_XPM | wxBITMAP_TYPE_RESOURCE 00272 cDCns->DrawBitmap(bmp, px, py); 00273 } 00274 00275 DrawToolMutexns.unlock (); 00276 } 00277 00278 void vuDrawToolsns::blit2(const byte *buf, int sx, int sy, int px, int py) 00279 { 00280 DrawToolMutexns.lock (); 00281 00282 if(cDCns && buf) 00283 { 00284 wxBitmap bmp(*imgns); 00285 cDCns->DrawBitmap(bmp, px, py); 00286 } 00287 00288 DrawToolMutexns.unlock (); 00289 } 00290 00291 void vuDrawToolsns::partblit (const byte *buf, int sx, int sy, int length) 00292 00293 { 00294 } 00295 00296 void vuDrawToolsns::finishpartblit () 00297 00298 { 00299 } 00300 00301 void vuDrawToolsns::setImgWidthHeight (int sx, int sy) 00302 00303 { 00304 DrawToolMutexns.lock (); 00305 00306 if (imgns == NULL) 00307 00308 { 00309 imgns = new wxImage [1]; 00310 00311 if (imgns == NULL) 00312 return; 00313 } 00314 00315 00316 imgns->Rescale (sx, sy); 00317 00318 DrawToolMutexns.unlock (); 00319 } 00320 00321 unsigned char * vuDrawToolsns::getData () 00322 00323 { 00324 return imgns->GetData (); 00325 } 00326 00327 //---------------------------------------------------------------------------- 00328 //------------------------- setDC(wxDC*) ------------------------------------- 00329 //---------------------------------------------------------------------------- 00330 void vuDrawToolsns::setDC(void *pDC) 00331 { 00332 SQMutex.lock (); 00333 00334 DrawToolMutexns.lock (); 00335 00336 cDCns = (wxDC*)pDC; 00337 00338 DrawToolMutexns.unlock (); 00339 } 00340 00341 //---------------------------------------------------------------------------- 00342 //------------------------- quitDC() ----------------------------------------- 00343 //---------------------------------------------------------------------------- 00344 void vuDrawToolsns::quitDC() 00345 { 00346 cDCns = NULL; 00347 00348 SQMutex.unlock (); 00349 } 00350 00351 //---------------------------------------------------------------------------- 00352 //------------------------- clearBGWithoutRect() ---------------------------- 00353 //---------------------------------------------------------------------------- 00354 void vuDrawToolsns::clearBGWithoutRect(int ox,int oy,int sx,int sy) 00355 { 00356 DrawToolMutexns.lock (); 00357 00358 if(cDCns) 00359 { 00360 int w,h; 00361 cDCns->GetSize(&w,&h); 00362 cDCns->DrawRectangle(sx,oy,w-sx,h-oy); 00363 } 00364 00365 DrawToolMutexns.unlock (); 00366 } 00367 00368 //---------------------------------------------------------------------------- 00369 //------------------------- ------------------- 00370 //---------------------------------------------------------------------------- 00371 00372 */ 00373 00374 00375