-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;
- }
-}
-
-void Textool_Validate(){
- // validate current situation into the main view
- g_pManager->Commit();
- // for a brush face we have an aditionnal step
- if ( !g_bPatch ) {
- // tell Radiant to update (will also send update windows messages )
- g_SelectedFaceTable.m_pfnSetFaceInfo( 0, &g_SelectedFaceData );
- }
- else
- {
- // ask to rebuild the patch display data
- g_pPatch->bDirty = true;
- // send a repaint to the camera window as well
- g_FuncTable.m_pfnSysUpdateWindows( W_CAMERA );
- }
- // we'll need to update after that as well:
- g_bTexViewReady = false;
- // send a repaint message
- g_pToolWnd->Redraw();
-}
-
-void Textool_Cancel(){
- if ( !g_bPatch ) {
- // tell Radiant to update (will also send update windows messages )
- g_SelectedFaceTable.m_pfnSetFaceInfo( 0, &g_CancelFaceData );
- }
- else
- {
- *g_pPatch = g_CancelPatch;
- g_pPatch->bDirty = true;
- g_FuncTable.m_pfnSysUpdateWindows( W_CAMERA );
- }
- // do not call destroy, decref it
- g_pToolWnd->DecRef();
- g_pToolWnd = NULL;
-}
-
-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 bool CanProcess(){
- if ( !g_bTexViewReady && !g_bClosing ) {
- InitTexView( g_pToolWnd );
-
- if ( !g_bTexViewReady ) {
- g_bClosing = true;
- DoMessageBox( "You must have brush primitives activated in your project settings and\n"
- "have a patch or a single face selected to use the TexTool plugin.\n"
- "See plugins/TexToolHelp for documentation.", "TexTool plugin", MB_ICONERROR | MB_OK );
- // decref, this will destroy
- g_pToolWnd->DecRef();
- g_pToolWnd = NULL;
- return 0;
- }
- else{
- g_bClosing = false;
- }
- }
- else if ( !g_bTexViewReady && g_bClosing ) {
- return 0;
- }
-
- return 1;
+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;
+ }
+}
+
+void Textool_Validate()
+{
+ // validate current situation into the main view
+ g_pManager->Commit();
+ // for a brush face we have an aditionnal step
+ if (!g_bPatch) {
+ // tell Radiant to update (will also send update windows messages )
+ g_SelectedFaceTable.m_pfnSetFaceInfo(0, &g_SelectedFaceData);
+ } else {
+ // ask to rebuild the patch display data
+ g_pPatch->bDirty = true;
+ // send a repaint to the camera window as well
+ g_FuncTable.m_pfnSysUpdateWindows(W_CAMERA);
+ }
+ // we'll need to update after that as well:
+ g_bTexViewReady = false;
+ // send a repaint message
+ g_pToolWnd->Redraw();
+}
+
+void Textool_Cancel()
+{
+ if (!g_bPatch) {
+ // tell Radiant to update (will also send update windows messages )
+ g_SelectedFaceTable.m_pfnSetFaceInfo(0, &g_CancelFaceData);
+ } else {
+ *g_pPatch = g_CancelPatch;
+ g_pPatch->bDirty = true;
+ g_FuncTable.m_pfnSysUpdateWindows(W_CAMERA);
+ }
+ // do not call destroy, decref it
+ g_pToolWnd->DecRef();
+ g_pToolWnd = NULL;
+}
+
+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 bool CanProcess()
+{
+ if (!g_bTexViewReady && !g_bClosing) {
+ InitTexView(g_pToolWnd);
+
+ if (!g_bTexViewReady) {
+ g_bClosing = true;
+ DoMessageBox("You must have brush primitives activated in your project settings and\n"
+ "have a patch or a single face selected to use the TexTool plugin.\n"
+ "See plugins/TexToolHelp for documentation.", "TexTool plugin", MB_ICONERROR | MB_OK);
+ // decref, this will destroy
+ g_pToolWnd->DecRef();
+ g_pToolWnd = NULL;
+ return 0;
+ } else {
+ g_bClosing = false;
+ }
+ } else if (!g_bTexViewReady && g_bClosing) {
+ return 0;
+ }
+
+ return 1;