// Position and size subwindows.
// Note that the border size applies to each subwindow, not
// including the edges next to the sash.
void wxSashWindow::SizeWindows()
{
int cw, ch;
GetClientSize(&cw, &ch);
if (GetChildren().GetCount() == 1)
{
wxWindow* child = GetChildren().GetFirst()->GetData();
int x = 0;
int y = 0;
int width = cw;
int height = ch;
// Top
if (m_sashes[0].m_show)
{
y = m_borderSize;
height -= m_borderSize;
}
y += m_extraBorderSize;
// Left
if (m_sashes[3].m_show)
{
x = m_borderSize;
width -= m_borderSize;
}
x += m_extraBorderSize;
// Right
if (m_sashes[1].m_show)
{
width -= m_borderSize;
}
width -= 2*m_extraBorderSize;
// Bottom
if (m_sashes[2].m_show)
{
height -= m_borderSize;
}
height -= 2*m_extraBorderSize;
child->SetSize(x, y, width, height);
}
else if (GetChildren().GetCount() > 1)
{
// Perhaps multiple children are themselves sash windows.
// TODO: this doesn't really work because the subwindows sizes/positions
// must be set to leave a gap for the parent's sash (hit-test and decorations).
// Perhaps we can allow for this within LayoutWindow, testing whether the parent
// is a sash window, and if so, allowing some space for the edges.
wxLayoutAlgorithm layout;
layout.LayoutWindow(this);
}
wxClientDC dc(this);
DrawBorders(dc);
DrawSashes(dc);
}
void wxWindow::Refresh(bool eraseBackground, const wxRect *rect)
{
wxRect rectClient; // the same rectangle in client coordinates
wxPoint origin = GetClientAreaOrigin();
wxSize size = GetClientSize();
if ( rect )
{
// the rectangle passed as argument is in client coordinates
rectClient = *rect;
// don't refresh anything beyond the client area (scrollbars for
// example)
if ( rectClient.GetRight() > size.x )
rectClient.SetRight(size.x);
if ( rectClient.GetBottom() > size.y )
rectClient.SetBottom(size.y);
}
else // refresh the entire client area
{
// x,y is already set to 0 by default
rectClient.SetSize(size);
}
// convert refresh rectangle to window coordinates:
wxRect rectWin(rectClient);
rectWin.Offset(origin);
// debugging helper
#ifdef WXDEBUG_REFRESH
static bool s_refreshDebug = false;
if ( s_refreshDebug )
{
wxWindowDC dc(this);
dc.SetBrush(*wxCYAN_BRUSH);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.DrawRectangle(rectWin);
// under Unix we use "--sync" X option for this
#if defined(__WXMSW__) && !defined(__WXMICROWIN__)
::GdiFlush();
::Sleep(200);
#endif // __WXMSW__
}
#endif // WXDEBUG_REFRESH
wxWindowNative::Refresh(eraseBackground, &rectWin);
// Refresh all sub controls if any.
wxWindowList& children = GetChildren();
for ( wxWindowList::iterator i = children.begin(); i != children.end(); ++i )
{
wxWindow *child = *i;
// only refresh subcontrols if they are visible:
if ( child->IsTopLevel() || !child->IsShown() || child->IsFrozen() )
continue;
// ...and when the subcontrols are in the update region:
wxRect childrect(child->GetRect());
childrect.Intersect(rectClient);
if ( childrect.IsEmpty() )
continue;
// refresh the subcontrol now:
childrect.Offset(-child->GetPosition());
// NB: We must call wxWindowNative version because we need to refresh
// the entire control, not just its client area, and this is why we
// don't account for child client area origin here neither. Also
// note that we don't pass eraseBackground to the child, but use
// true instead: this is because we can't be sure that
// eraseBackground=false is safe for children as well and not only
// for the parent.
child->wxWindowNative::Refresh(eraseBackground, &childrect);
}
}
wxRect wxWindow::ScrollNoRefresh(int dx, int dy, const wxRect *rectTotal)
{
wxASSERT_MSG( !dx || !dy, _T("can't be used for diag scrolling") );
// the rect to refresh (which we will calculate)
wxRect rect;
if ( !dx && !dy )
{
// nothing to do
return rect;
}
// calculate the part of the window which we can just redraw in the new
// location
wxSize sizeTotal = rectTotal ? rectTotal->GetSize() : GetClientSize();
wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
sizeTotal.x, sizeTotal.y, dx, dy);
// the initial and end point of the region we move in client coords
wxPoint ptSource, ptDest;
if ( rectTotal )
{
ptSource = rectTotal->GetPosition();
ptDest = rectTotal->GetPosition();
}
// the size of this region
wxSize size;
size.x = sizeTotal.x - abs(dx);
size.y = sizeTotal.y - abs(dy);
if ( size.x <= 0 || size.y <= 0 )
{
// just redraw everything as nothing of the displayed image will stay
wxLogTrace(_T("scroll"), _T("refreshing everything"));
rect = rectTotal ? *rectTotal : wxRect(0, 0, sizeTotal.x, sizeTotal.y);
}
else // move the part which doesn't change to the new location
{
// note that when we scroll the canvas in some direction we move the
// block which doesn't need to be refreshed in the opposite direction
if ( dx < 0 )
{
// scroll to the right, move to the left
ptSource.x -= dx;
}
else
{
// scroll to the left, move to the right
ptDest.x += dx;
}
if ( dy < 0 )
{
// scroll down, move up
ptSource.y -= dy;
}
else
{
// scroll up, move down
ptDest.y += dy;
}
#if wxUSE_CARET
// we need to hide the caret before moving or it will erase itself at
// the wrong (old) location
wxCaret *caret = GetCaret();
if ( caret )
caret->Hide();
#endif // wxUSE_CARET
// do move
wxClientDC dc(this);
wxBitmap bmp(size.x, size.y);
wxMemoryDC dcMem;
dcMem.SelectObject(bmp);
dcMem.Blit(wxPoint(0,0), size, &dc, ptSource
#if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
+ GetClientAreaOrigin()
#endif // broken wxGTK wxDC::Blit
);
dc.Blit(ptDest, size, &dcMem, wxPoint(0,0));
wxLogTrace(_T("scroll"),
_T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
ptSource.x, ptSource.y,
size.x, size.y,
ptDest.x, ptDest.y);
// and now repaint the uncovered area
// FIXME: We repaint the intersection of these rectangles twice - is
// it bad? I don't think so as it is rare to scroll the window
// diagonally anyhow and so adding extra logic to compute
// rectangle intersection is probably not worth the effort
//.........这里部分代码省略.........
void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
{
wxPaintDC( this );
// SwapBuffer requires the window to be shown before calling
if( !IsShownOnScreen() )
{
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnPaint !IsShown" ) );
return;
}
// "Makes the OpenGL state that is represented by the OpenGL rendering
// context context current, i.e. it will be used by all subsequent OpenGL calls.
// This function may only be called when the window is shown on screen"
GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );
// Set the OpenGL viewport according to the client size of this canvas.
// This is done here rather than in a wxSizeEvent handler because our
// OpenGL rendering context (and thus viewport setting) is used with
// multiple canvases: If we updated the viewport in the wxSizeEvent
// handler, changing the size of one canvas causes a viewport setting that
// is wrong when next another canvas is repainted.
wxSize clientSize = GetClientSize();
if( !m_ogl_initialized )
{
m_ogl_initialized = true;
ogl_initialize();
}
if( m_reload_is_needed )
{
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnPaint m_reload_is_needed" ) );
m_reload_is_needed = false;
m_ogl_3dmodel = new C_OGL_3DMODEL( *m_3d_model );
// It convert a model as it was a board, so get the max size dimension of the board
// and compute the conversion scale
m_BiuTo3Dunits = (double)RANGE_SCALE_3D / ((double)m_ogl_3dmodel->GetBBox().GetMaxDimension() * UNITS3D_TO_UNITSPCB);
}
glViewport( 0, 0, clientSize.x, clientSize.y );
m_trackBallCamera.SetCurWindowSize( clientSize );
// clear color and depth buffers
// /////////////////////////////////////////////////////////////////////////
glEnable( GL_DEPTH_TEST );
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
glClearDepth( 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
// Set projection and modelview matrixes
// /////////////////////////////////////////////////////////////////////////
glMatrixMode( GL_PROJECTION );
glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetProjectionMatrix() ) );
glMatrixMode( GL_MODELVIEW );
glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetViewMatrix() ) );
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
// Render Model
if( m_ogl_3dmodel )
{
glPushMatrix();
double modelunit_to_3d_units_factor = m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
glScaled( modelunit_to_3d_units_factor, modelunit_to_3d_units_factor, modelunit_to_3d_units_factor);
// Center model in the render viewport
const SFVEC3F model_center = m_ogl_3dmodel->GetBBox().GetCenter();
glTranslatef( -model_center.x, -model_center.y, -model_center.z );
// !TODO: draw transparent models
m_ogl_3dmodel->Draw_opaque();
m_ogl_3dmodel->Draw_transparent();
//m_ogl_3dmodel->Draw_bboxes();
glPopMatrix();
}
glViewport( 0, 0, clientSize.y / 8 , clientSize.y / 8 ); // YxY squared view port
glClear( GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0f, 1.0f, 0.01f, RANGE_SCALE_3D * 2.0f );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
const glm::mat4 TranslationMatrix = glm::translate( glm::mat4(1.0f), SFVEC3F( 0.0f, 0.0f, -RANGE_SCALE_3D ) );
const glm::mat4 ViewMatrix = TranslationMatrix * m_trackBallCamera.GetRotationMatrix();
//.........这里部分代码省略.........
// Print the canvas contents to a bitmap:
void gateImage::generateImage() {
//WARNING!!! Heavily platform-dependent code ahead! This only works in MS Windows because of the
// DIB Section OpenGL rendering.
wxSize sz = GetClientSize();
// Create a DIB section.
// (The Windows wxBitmap implementation will create a DIB section for a bitmap if you set
// a color depth of 24 or greater.)
wxBitmap theBM( GATEIMAGESIZE, GATEIMAGESIZE, 32 );
// Get a memory hardware device context for writing to the bitmap DIB Section:
wxMemoryDC myDC;
myDC.SelectObject(theBM);
WXHDC theHDC = myDC.GetHDC();
// The basics of setting up OpenGL to render to the bitmap are found at:
// http://www.nullterminator.net/opengl32.html
// http://www.codeguru.com/cpp/g-m/opengl/article.php/c5587/
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
// set the pixel format for the DC
::ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ::ChoosePixelFormat( (HDC) theHDC, &pfd );
::SetPixelFormat( (HDC) theHDC, iFormat, &pfd );
// create and enable the render context (RC)
HGLRC hRC = ::wglCreateContext( (HDC) theHDC );
HGLRC oldhRC = ::wglGetCurrentContext();
HDC oldDC = ::wglGetCurrentDC();
::wglMakeCurrent( (HDC) theHDC, hRC );
// Setup the viewport for rendering:
setViewport();
// Reset the glViewport to the size of the bitmap:
glViewport(0, 0, GATEIMAGESIZE, GATEIMAGESIZE);
// Set the bitmap clear color:
glClearColor (1.0, 1.0, 1.0, 0.0);
glColor3b(0, 0, 0);
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
//TODO: Check if alpha is hardware supported, and
// don't enable it if not!
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
//*********************************
//Edit by Joshua Lansford 4/09/07
//anti-alis ing is nice
//glEnable( GL_LINE_SMOOTH );
//End of edit
// Load the font texture
guiText::loadFont(wxGetApp().appSettings.textFontFile);
// Do the rendering here.
renderMap();
// Flush the OpenGL buffer to make sure the rendering has happened:
glFlush();
// Destroy the OpenGL rendering context, release the memDC, and
// convert the DIB Section into a wxImage to return to the caller:
::wglMakeCurrent( oldDC, oldhRC );
//::wglMakeCurrent( NULL, NULL );
::wglDeleteContext( hRC );
myDC.SelectObject(wxNullBitmap);
gImage = theBM.ConvertToImage();
}
void AudacityProject::OnPaint(wxPaintEvent & event)
{
wxPaintDC dc(this);
int top = 0;
int h = 0;
int i, j;
int toolbartop, toolbarbottom, toolbarheight;
wxRect r;
int width, height;
GetClientSize(&width, &height);
//Deal with the ToolBars
for (i = 0; i < mToolBarArray.GetCount(); i++) {
AColor::Medium(&dc, false);
toolbartop = h;
h += mToolBarArray[i]->GetHeight();
toolbarbottom = h;
toolbarheight = toolbarbottom - toolbartop;
//Adjust a little for Windows (tm)
#ifdef __WXMSW__
h++;
#endif
//Draw a rectangle the space of scrollbar
r.x = width - sbarSpaceWidth;
r.y = toolbartop;
r.width = sbarSpaceWidth;
r.height = toolbarheight;
dc.DrawRectangle(r);
//Draw a rectangle around the "grab-bar"
r.x = 0;
r.y = toolbartop;
r.width = 10;
r.height = toolbarheight;
dc.DrawRectangle(r);
// Draw little bumps to the left of the toolbar to
// make it a "grab-bar".
//adjust min and max so that they aren't too close to the edges
int minbump = (toolbarheight % 2 == 0) ? 3 : 4;
int maxbump =
(toolbarheight % 2 == 0) ? toolbarheight - 3 : toolbarheight - 4;
AColor::Light(&dc, false);
for (j = minbump; j < maxbump; j += 4)
dc.DrawLine(3, toolbartop + j, 6, toolbartop + j);
AColor::Dark(&dc, false);
for (j = minbump + 1; j < maxbump + 1; j += 4)
dc.DrawLine(3, toolbartop + j, 6, toolbartop + j);
//Draw a black line to the right of the grab-bar
dc.SetPen(*wxBLACK_PEN);
dc.DrawLine(9, toolbartop, 9, toolbarbottom);
//Draw some more lines for Windows (tm)
#ifdef __WXMSW__
dc.DrawLine(0, toolbartop, width, toolbartop);
dc.DrawLine(0, toolbartop, 0, toolbarbottom);
#endif
dc.DrawLine(0, toolbarbottom, width, toolbarbottom);
h++;
}
//Now, h is equal to the total height of all the toolbars
top += h;
height -= h;
int sh = GetStatusHeight();
height -= sh;
// Fill in space on sides of scrollbars
dc.SetPen(*wxBLACK_PEN);
dc.DrawLine(width - sbarSpaceWidth, top,
width - sbarSpaceWidth, top + height - sbarSpaceWidth + 1);
dc.DrawLine(0, top + height - sbarSpaceWidth,
width - sbarSpaceWidth, top + height - sbarSpaceWidth);
wxRect f;
f.x = 0;
f.y = top + height - sbarSpaceWidth + 1;
f.width = mTrackPanel->GetLeftOffset() - 2;
f.height = sbarSpaceWidth - 2;
AColor::Medium(&dc, false);
//.........这里部分代码省略.........
请发表评论