glzoomlens.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:6k
- /*
- * ===========================================================================
- * PRODUCTION $Log: glzoomlens.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 20:51:14 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.2
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: glzoomlens.cpp,v 1000.1 2004/06/01 20:51:14 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Peter Meric
- *
- * File Description:
- * CGlZoomLens - OpenGL zoom lens
- *
- */
- #include <ncbi_pch.hpp>
- #include <corelib/ncbistd.hpp>
- #include <gui/opengl.h>
- #include <gui/opengl/glzoomlens.hpp>
- BEGIN_NCBI_SCOPE
- CGlZoomLens::CGlZoomLens(bool visible)
- : CGlWidget(visible)
- {
- }
- CGlZoomLens::~CGlZoomLens()
- {
- }
- void CGlZoomLens::SetProperties(struct GlZoomSpec& spec, CGlCamera& zoomcam)
- {
- m_Spec = spec;
- m_ZoomCamera = zoomcam;
- }
- //
- // zoomwidth, zoom_height - dimensions of zoom lens, in pixels
- // zoom_xpos, zoom_ypos - location of zoom lens, in pixels
- // m_Spec.gl_dim.x1, m_Spec.gl_dim.x2 - x coordinates of zoom lens, in GL coordinates
- // m_Spec.gl_dim.y1, m_Spec.gl_dim.y2 - y coordinates of zoom lens, in GL coordinates
- // m_ZoomCamera - projection for zoom window
- //
- void CGlZoomLens::Draw(void)
- {
- if (!IsVisible()) {
- return;
- }
- _TRACE("void CGlZoomLens::Draw() - " << m_Spec.gl_dim.x1 << " to " << m_Spec.gl_dim.x2);
- glPushMatrix();
- glLoadIdentity();
- //
- // draw zoom/magic lens
- //
- //const int w = m_Spec.pixel_dim.width;
- //const int h = m_Spec.pixel_dim.height;
- // calculate a one-pixel offset
- const float x_pixel = (m_Spec.gl_dim.x2 - m_Spec.gl_dim.x1) / m_Spec.pixel_dim.width;
- const float y_pixel = (m_Spec.gl_dim.y1 - m_Spec.gl_dim.y2) / m_Spec.pixel_dim.height;
- // zoom window in pixels
- const int zw = int(m_Spec.pixel_dim.width * m_Spec.xratio + 0.5);
- float zh;
- if ((m_Spec.type & GlZoomSpec::eFullHeight) == GlZoomSpec::eFullHeight) {
- zh = m_Spec.pixel_dim.height;
- }
- else {
- zh = m_Spec.pixel_dim.height * m_Spec.yratio;
- }
- const float zw_2 = zw >> 1;
- const float zh_2 = zh / 2;
- const float zx = m_Spec.pixel_dim.xpos - zw_2;
- const float zy = m_Spec.pixel_dim.ypos - zh_2;
- const int border = 10;
- const float x_delta = x_pixel * border;
- const float y_delta = y_pixel * border;
- const float white[4] = { 1.0f, 1.0f, 1.0f, 0.4f };
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glBegin(GL_QUADS);
- glColor4fv(white);
- const float ymid = (m_Spec.gl_dim.y1 + m_Spec.gl_dim.y2) / 2;
- const float yoffset = y_pixel * zh_2 + y_delta;
- const float y1 = ymid - yoffset;
- const float y2 = ymid + yoffset;
- const float xmid = (m_Spec.gl_dim.x1 + m_Spec.gl_dim.x2) / 2;
- const float xoffset = x_pixel * zw_2 + x_delta;
- const float x1 = xmid - xoffset;
- const float x2 = xmid + xoffset;
- glVertex3f(m_Spec.gl_dim.x1, y1, -1.0f);
- glVertex3f(m_Spec.gl_dim.x1, y2, -1.0f);
- glVertex3f(m_Spec.gl_dim.x2, y2, -1.0f);
- glVertex3f(m_Spec.gl_dim.x2, y1, -1.0f);
- glVertex3f(x1, m_Spec.gl_dim.y1, -1.0f);
- glVertex3f(x1, m_Spec.gl_dim.y2, -1.0f);
- glVertex3f(x2, m_Spec.gl_dim.y2, -1.0f);
- glVertex3f(x2, m_Spec.gl_dim.y1, -1.0f);
- glEnd();
- glDisable(GL_BLEND);
- glEnable(GL_SCISSOR_TEST);
- const int _zx = int(zx + 0.5);
- const int _zy = int(zy + 0.5);
- const int _zw = int(zw + 0.5);
- const int _zh = int(zh + 0.5);
- glViewport(_zx, _zy, _zw, _zh);
- glScissor(_zx, _zy, _zw, _zh);
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- const_cast<CGlCamera&>(m_ZoomCamera).MakeCurrent(true);
- (*m_Spec.DrawFunc)();
- glBegin(GL_LINE_LOOP);
- glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
- glVertex2f(m_Spec.gl_dim.x1, m_Spec.gl_dim.y1);
- glVertex2f(m_Spec.gl_dim.x2, m_Spec.gl_dim.y1);
- glVertex2f(m_Spec.gl_dim.x2, m_Spec.gl_dim.y2);
- glVertex2f(m_Spec.gl_dim.x1, m_Spec.gl_dim.y2);
- glVertex2f(m_Spec.gl_dim.x1 + x_pixel/2, m_Spec.gl_dim.y1 - y_pixel/2);
- glVertex2f(m_Spec.gl_dim.x2 - x_pixel/2, m_Spec.gl_dim.y1 - y_pixel/2);
- glVertex2f(m_Spec.gl_dim.x2 - x_pixel/2, m_Spec.gl_dim.y2 + y_pixel/2);
- glVertex2f(m_Spec.gl_dim.x1 + x_pixel/2, m_Spec.gl_dim.y2 + y_pixel/2);
- glEnd();
- const_cast<CGlCamera&>(m_ZoomCamera).ReleaseCurrent(true);
- glDisable(GL_SCISSOR_TEST);
- }
- void CGlZoomLens::ProcessEvent(CGlEvent& event)
- {
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: glzoomlens.cpp,v $
- * Revision 1000.1 2004/06/01 20:51:14 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.2
- *
- * Revision 1.2 2004/05/21 22:27:45 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.1 2003/10/13 16:37:19 meric
- * Initial version
- *
- * ===========================================================================
- */