/////////////////////////////////////////////////////////// // // Set the active zoom factor // /////////////////////////////////////////////////////////// void view::setZoomFactor(double zoomFactor, imbxInt32 centerPointX /* =-1 */, imbxInt32 centerPointY /* =-1 */) { // Update the zoom factor /////////////////////////////////////////////////////////// m_zoom = zoomFactor; // If the image hasn't been set, then don't do anything /////////////////////////////////////////////////////////// if(m_originalImage == 0) { return; } // Not automatic zoom /////////////////////////////////////////////////////////// if(m_zoom > 0) { updateImageRect(centerPointX, centerPointY); return; } // Automatic zoom /////////////////////////////////////////////////////////// setScrollSize(1, 1, true); imbxUint32 imageSizeX, imageSizeY; m_originalImage->getSize(&imageSizeX, &imageSizeY); setZoomRect(0, 0, imageSizeX, imageSizeY); }
/////////////////////////////////////////////////////////// // // Zoom to the selected image's area. The rectangle measure // units are in image's pixels // /////////////////////////////////////////////////////////// void view::setZoomRect(imbxInt32 left, imbxInt32 top, imbxInt32 right, imbxInt32 bottom) { if(m_originalImage == 0) { return; } if(left > right) { imbxInt32 temp = left; left = right; right = temp; } if(top > bottom) { imbxInt32 temp = top; top = bottom; bottom = temp; } imbxInt32 centerPointX = (right - left)/2 + left; imbxInt32 centerPointY = (bottom - top)/2 + top; imbxUint32 sizeX, sizeY; getWindowSize(&sizeX, &sizeY); double imageSizeMmX, imageSizeMmY; m_originalImage->getSizeMm(&imageSizeMmX, &imageSizeMmY); imbxUint32 imageSizeX, imageSizeY; m_originalImage->getSize(&imageSizeX, &imageSizeY); imbxUint32 horzDPI, vertDPI; getScreenDPI(&horzDPI, &vertDPI); if(imageSizeMmX == 0) { imageSizeMmX = (double)imageSizeX * 25.4 / (double)horzDPI; } if(imageSizeMmY == 0) { imageSizeMmY = (double)imageSizeY * 25.4 / (double)vertDPI; } double displaySizeMmX = imageSizeMmX * ((double)(right - left) / (double)imageSizeX); double displaySizeMmY = imageSizeMmY * ((double)(bottom - top) / (double)imageSizeY); double horzZoom = 0.95*(sizeX*25.4)/(displaySizeMmX*(double)horzDPI); double vertZoom = 0.95*(sizeY*25.4)/(displaySizeMmY*(double)vertDPI); m_zoom = (horzZoom < vertZoom) ? horzZoom : vertZoom; updateImageRect(centerPointX, centerPointY); }
/////////////////////////////////////////////////////////// // // Zoom in/out. The selected pixel will be centered into the // window // /////////////////////////////////////////////////////////// void view::zoomInOut(bool bZoomIn, imbxInt32 centerPointX /* =-1 */, imbxInt32 centerPointY /* =-1 */) { if(bZoomIn) { m_zoom *= 2; } else { m_zoom /= 2; } updateImageRect(centerPointX, centerPointY); }
//-------------------------------------------------------------- void ofApp::setup(){ //sound image is the large image, image rect acts as it's bounding box which helps it maintain aspect ratio and middle of screen orientation soundImage.load("Volume.jpg"); key.load("key.jpg"); imageRect.setSize(soundImage.getWidth(), soundImage.getHeight()); //loading font for information display stampFont.load("stamped.ttf",7); updateImageRect(); generateStates(); }
//-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ updateImageRect(); }