1352 const staticCameraMeta* cam = &g_staticCameras[m_camera]; |
1352 const staticCameraMeta* cam = &g_staticCameras[m_camera]; |
1353 return (y) ? cam->axisY : cam->axisX; |
1353 return (y) ? cam->axisY : cam->axisX; |
1354 } |
1354 } |
1355 |
1355 |
1356 // ============================================================================= |
1356 // ============================================================================= |
1357 void GLRenderer::setupOverlay () { |
1357 bool GLRenderer::setupOverlay ( GL::Camera cam, str file, int x, int y, int w, int h ) |
1358 if (camera () == Free) |
1358 { |
1359 return; |
1359 QImage* img = new QImage( file ); |
1360 |
1360 overlayMeta& info = getOverlay( cam ); |
1361 OverlayDialog dlg; |
1361 |
1362 |
1362 if( img->isNull() ) |
1363 if (!dlg.exec ()) |
1363 { |
1364 return; |
|
1365 |
|
1366 QImage* img = new QImage (dlg.fpath ()); |
|
1367 overlayMeta& info = getOverlay (camera ()); |
|
1368 |
|
1369 if (img->isNull ()) { |
|
1370 critical ("Failed to load overlay image!"); |
1364 critical ("Failed to load overlay image!"); |
1371 delete img; |
1365 delete img; |
1372 return; |
1366 return false; |
1373 } |
1367 } |
1374 |
1368 |
1375 delete info.img; // delete the old image |
1369 delete info.img; // delete the old image |
1376 |
1370 |
1377 info.fname = dlg.fpath (); |
1371 info.fname = file; |
1378 info.lw = dlg.lwidth (); |
1372 info.lw = w; |
1379 info.lh = dlg.lheight (); |
1373 info.lh = h; |
1380 info.ox = dlg.ofsx (); |
1374 info.ox = x; |
1381 info.oy = dlg.ofsy (); |
1375 info.oy = y; |
1382 info.img = img; |
1376 info.img = img; |
1383 |
1377 |
1384 if (info.lw == 0) |
1378 if( info.lw == 0 ) |
1385 info.lw = (info.lh * img->width ()) / img->height (); |
1379 info.lw = ( info.lh * img->width() ) / img->height(); |
1386 else if (info.lh == 0) |
1380 else if( info.lh == 0 ) |
1387 info.lh = (info.lw * img->height ()) / img->width (); |
1381 info.lh = ( info.lw * img->height() ) / img->width(); |
1388 |
1382 |
1389 const Axis x2d = cameraAxis (false), |
1383 const Axis x2d = cameraAxis( false ), |
1390 y2d = cameraAxis (true); |
1384 y2d = cameraAxis( true ); |
1391 |
1385 |
1392 double negXFac = g_staticCameras[m_camera].negX ? -1 : 1, |
1386 double negXFac = g_staticCameras[m_camera].negX ? -1 : 1, |
1393 negYFac = g_staticCameras[m_camera].negY ? -1 : 1; |
1387 negYFac = g_staticCameras[m_camera].negY ? -1 : 1; |
1394 |
1388 |
1395 info.v0 = info.v1 = g_origin; |
1389 info.v0 = info.v1 = g_origin; |
1396 info.v0[x2d] = -(info.ox * info.lw * negXFac) / img->width (); |
1390 info.v0[x2d] = -( info.ox * info.lw * negXFac ) / img->width(); |
1397 info.v0[y2d] = (info.oy * info.lh * negYFac) / img->height (); |
1391 info.v0[y2d] = ( info.oy * info.lh * negYFac ) / img->height(); |
1398 info.v1[x2d] = info.v0[x2d] + info.lw; |
1392 info.v1[x2d] = info.v0[x2d] + info.lw; |
1399 info.v1[y2d] = info.v0[y2d] + info.lh; |
1393 info.v1[y2d] = info.v0[y2d] + info.lh; |
1400 info.fname = dlg.fpath (); |
|
1401 |
1394 |
1402 // Set alpha of all pixels to 0.5 |
1395 // Set alpha of all pixels to 0.5 |
1403 for (long i = 0; i < img->width (); ++i) |
1396 for( long i = 0; i < img->width(); ++i ) |
1404 for (long j = 0; j < img->height (); ++j) { |
1397 for( long j = 0; j < img->height(); ++j ) |
1405 uint32 pixel = img->pixel (i, j); |
1398 { |
1406 img->setPixel (i, j, 0x80000000 | (pixel & 0x00FFFFFF)); |
1399 uint32 pixel = img->pixel( i, j ); |
|
1400 img->setPixel( i, j, 0x80000000 | ( pixel & 0x00FFFFFF )); |
1407 } |
1401 } |
1408 |
1402 |
1409 updateOverlayObjects(); |
1403 updateOverlayObjects(); |
|
1404 return true; |
1410 } |
1405 } |
1411 |
1406 |
1412 void GLRenderer::clearOverlay () { |
1407 void GLRenderer::clearOverlay () { |
1413 if (camera () == Free) |
1408 if (camera () == Free) |
1414 return; |
1409 return; |