static void DoPaint () { if (!CanProcess ()) return; if (g_bTexViewReady) { g_2DView.m_rect.bottom = g_pToolWnd->getHeight(); g_2DView.m_rect.right = g_pToolWnd->getWidth(); // set GL_PROJECTION g_2DView.PreparePaint(); // render the objects // the master is not rendered the same way, draw over a unified texture background g_2DView.TextureBackground(g_DrawObjects[0].pObject->getTextureNumber()); if (g_nDrawObjects >= 1) { int i; for (i=1;i<g_nDrawObjects;i++) { // we use a first step to the GL_MODELVIEW for the master object // GL_MODELVIEW will be altered in RenderAuxiliary too g_DrawObjects[0].pObject->PrepareModelView(g_DrawObjects[i].pTopo); g_DrawObjects[i].pObject->RenderAuxiliary(); } } // draw the polygon outline and control points g_DrawObjects[0].pObject->PrepareModelView(NULL); g_DrawObjects[0].pObject->RenderUI(); } }
static gint keypress (GtkWidget* widget, GdkEventKey* event, gpointer data) { unsigned int code = gdk_keyval_to_upper(event->keyval); if (code == GDK_Escape) { gtk_widget_destroy (g_pToolWnd); g_pToolWnd = NULL; return TRUE; } if (CanProcess ()) { if (g_2DView.OnKeyDown (code)) return FALSE; if (code == GDK_Return) { Textool_Validate(); return FALSE; } } return TRUE; }
bool CWindowListener::OnRButtonUp( guint32 nFlags, double x, double y ){ if ( CanProcess() ) { g_2DView.OnRButtonUp( (int)x, (int)y ); return true; } return false; }
static void DoExpose(){ int i,j; g_2DView.PreparePaint(); g_QglTable.m_pfn_qglColor3f( 1, 1, 1 ); // draw the texture background g_QglTable.m_pfn_qglPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); if ( !g_bPatch ) { g_QglTable.m_pfn_qglBindTexture( GL_TEXTURE_2D, g_SelectedFaceTable.m_pfnGetTextureNumber( 0 ) ); } else { g_QglTable.m_pfn_qglBindTexture( GL_TEXTURE_2D, g_pPatch->d_texture->texture_number ); } g_QglTable.m_pfn_qglEnable( GL_TEXTURE_2D ); g_QglTable.m_pfn_qglBegin( GL_QUADS ); g_QglTable.m_pfn_qglTexCoord2f( g_2DView.m_Mins[0], g_2DView.m_Mins[1] ); g_QglTable.m_pfn_qglVertex2f( g_2DView.m_Mins[0], g_2DView.m_Mins[1] ); g_QglTable.m_pfn_qglTexCoord2f( g_2DView.m_Maxs[0], g_2DView.m_Mins[1] ); g_QglTable.m_pfn_qglVertex2f( g_2DView.m_Maxs[0], g_2DView.m_Mins[1] ); g_QglTable.m_pfn_qglTexCoord2f( g_2DView.m_Maxs[0], g_2DView.m_Maxs[1] ); g_QglTable.m_pfn_qglVertex2f( g_2DView.m_Maxs[0], g_2DView.m_Maxs[1] ); g_QglTable.m_pfn_qglTexCoord2f( g_2DView.m_Mins[0], g_2DView.m_Maxs[1] ); g_QglTable.m_pfn_qglVertex2f( g_2DView.m_Mins[0], g_2DView.m_Maxs[1] ); g_QglTable.m_pfn_qglEnd(); g_QglTable.m_pfn_qglDisable( GL_TEXTURE_2D ); if ( !g_bPatch ) { g_QglTable.m_pfn_qglBegin( GL_LINE_LOOP ); for ( i = 0; i < g_NumPoints; i++ ) { g_QglTable.m_pfn_qglVertex2f( g_WorkWinding.data[i][0], g_WorkWinding.data[i][1] ); } g_QglTable.m_pfn_qglEnd(); } else { g_QglTable.m_pfn_qglBegin( GL_LINES ); for ( i = 0; i < g_pPatch->width; i++ ) for ( j = 0; j < g_pPatch->height; j++ ) { if ( i < g_pPatch->width - 1 ) { g_QglTable.m_pfn_qglVertex2f( g_WorkPatch.ctrl[i][j].st[0], g_WorkPatch.ctrl[i][j].st[1] ); g_QglTable.m_pfn_qglVertex2f( g_WorkPatch.ctrl[i + 1][j].st[0], g_WorkPatch.ctrl[i + 1][j].st[1] ); } if ( j < g_pPatch->height - 1 ) { g_QglTable.m_pfn_qglVertex2f( g_WorkPatch.ctrl[i][j].st[0], g_WorkPatch.ctrl[i][j].st[1] ); g_QglTable.m_pfn_qglVertex2f( g_WorkPatch.ctrl[i][j + 1].st[0], g_WorkPatch.ctrl[i][j + 1].st[1] ); } } g_QglTable.m_pfn_qglEnd(); } // let the control points manager render g_pManager->Render(); }
static void motion (GtkWidget *widget, GdkEventMotion *event, gpointer data) { if (CanProcess ()) { if (g_2DView.OnMouseMove (event->x, event->y)) return; if (g_pManager->OnMouseMove (event->x, event->y)) return; } }
bool CWindowListener::OnMouseMove( guint32 nFlags, double x, double y ){ if ( CanProcess() ) { if ( g_2DView.OnMouseMove( (int)x, (int)y ) ) { return true; } g_pManager->OnMouseMove( (int)x, (int)y ); return true; } return false; }
static void button_release( GtkWidget *widget, GdkEventButton *event, gpointer data ){ if ( CanProcess() ) { switch ( event->button ) { case 1: g_pManager->OnLButtonUp( event->x, event->y ); break; case 3: g_2DView.OnRButtonUp( event->x, event->y ); break; } } }
bool CWindowListener::OnKeyPressed( char *s ){ if ( !strcmp( s,"Escape" ) ) { Textool_Cancel(); return TRUE; } if ( CanProcess() ) { if ( g_2DView.OnKeyDown( s ) ) { return TRUE; } if ( !strcmp( s,"Return" ) ) { Textool_Validate(); return TRUE; } } return FALSE; }
// call this one each time we need to re-init //++timo TODO: re-init objects state, g_2DView and g_ControlPointsManager void InitTexView( IWindow* hwndDlg ) { // size of the texture we are working on int TexSize[2]; g_bTexViewReady = false; if (g_SelectedFaceTable.m_pfnGetSelectedFaceCount() != 0) { g_SelectedFaceTable.m_pfnGetFaceInfo( 0, &g_SelectedFaceData, g_pSelectedFaceWinding ); g_bPatch = false; int i; // we have something selected // setup: compute BBox for the winding ( in ST space ) //++timo FIXME: move this in a C2DView member ? used as well for patches g_2DView.m_Mins[0] = +9999.0f; g_2DView.m_Mins[1] = +9999.0f; g_2DView.m_Maxs[0] = -9999.0f; g_2DView.m_Maxs[1] = -9999.0f; for ( i=0; i<g_pSelectedFaceWinding->numpoints; i++ ) { if ( g_pSelectedFaceWinding->points[i][3] < g_2DView.m_Mins[0] ) g_2DView.m_Mins[0] = g_pSelectedFaceWinding->points[i][3]; if ( g_pSelectedFaceWinding->points[i][3] > g_2DView.m_Maxs[0] ) g_2DView.m_Maxs[0] = g_pSelectedFaceWinding->points[i][3]; if ( g_pSelectedFaceWinding->points[i][4] < g_2DView.m_Mins[1] ) g_2DView.m_Mins[1] = g_pSelectedFaceWinding->points[i][4]; if ( g_pSelectedFaceWinding->points[i][4] > g_2DView.m_Maxs[1] ) g_2DView.m_Maxs[1] = g_pSelectedFaceWinding->points[i][4]; } // NOTE: FitView will read and init TexSize FitView( hwndDlg, TexSize ); // now init the work tables g_NumPoints = g_pSelectedFaceWinding->numpoints; for ( i=0; i<g_NumPoints; i++ ) { g_WorkWinding.data[i][0] = g_pSelectedFaceWinding->points[i][3]; g_WorkWinding.data[i][1] = g_pSelectedFaceWinding->points[i][4]; } g_ControlPointsBFace.Init( g_NumPoints, &g_WorkWinding, &g_2DView, TexSize, &g_SelectedFaceData, &g_QglTable ); // init snap-to-grid float fTexStep[2]; fTexStep[0] = 1.0f / float(TexSize[0]); fTexStep[1] = 1.0f / float(TexSize[1]); g_2DView.SetGrid( fTexStep[0], fTexStep[1] ); g_pManager = &g_ControlPointsBFace; // prepare the "Cancel" data memcpy( &g_CancelFaceData, &g_SelectedFaceData, sizeof(_QERFaceData) ); // we are done g_bTexViewReady = true; } else if ( g_SurfaceTable.m_pfnAnyPatchesSelected()) { g_pPatch = g_SurfaceTable.m_pfnGetSelectedPatch(); g_bPatch = true; int i,j; // compute BBox for all patch points g_2DView.m_Mins[0] = +9999.0f; g_2DView.m_Mins[1] = +9999.0f; g_2DView.m_Maxs[0] = -9999.0f; g_2DView.m_Maxs[1] = -9999.0f; for ( i=0; i<g_pPatch->width; i++ ) { for ( j=0; j<g_pPatch->height; j++ ) { if ( g_pPatch->ctrl[i][j].st[0] < g_2DView.m_Mins[0] ) g_2DView.m_Mins[0] = g_pPatch->ctrl[i][j].st[0]; if ( g_pPatch->ctrl[i][j].st[0] > g_2DView.m_Maxs[0] ) g_2DView.m_Maxs[0] = g_pPatch->ctrl[i][j].st[0]; if ( g_pPatch->ctrl[i][j].st[1] < g_2DView.m_Mins[1] ) g_2DView.m_Mins[1] = g_pPatch->ctrl[i][j].st[1]; if ( g_pPatch->ctrl[i][j].st[1] > g_2DView.m_Maxs[1] ) g_2DView.m_Maxs[1] = g_pPatch->ctrl[i][j].st[1]; } } FitView( hwndDlg, TexSize); // init the work tables g_WorkPatch = *g_pPatch; g_ControlPointsPatch.Init( &g_WorkPatch, &g_2DView, &g_QglTable, g_pPatch ); // init snap-to-grid float fTexStep[2]; fTexStep[0] = 1.0f / float(TexSize[0]); fTexStep[1] = 1.0f / float(TexSize[1]); g_2DView.SetGrid( fTexStep[0], fTexStep[1] ); g_pManager = &g_ControlPointsPatch; // prepare the "cancel" data g_CancelPatch = *g_pPatch; // we are done g_bTexViewReady = true; } }