apply misc fixes from Markus Fischer and Rambetter
[xonotic/netradiant.git] / radiant / selectedface.cpp
1 /*
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 //-----------------------------------------------------------------------------
23 //
24 // DESCRIPTION:
25 // Quick interface hack for selected face interface
26 // this one really needs more work, but I'm in a hurry with TexTool
27
28 #include "stdafx.h"
29
30 int WINAPI QERApp_GetSelectedFaceCount()
31 {
32   return g_ptrSelectedFaces.GetSize();
33 }
34
35 face_t* WINAPI QERApp_GetSelectedFace(int iface)
36 {
37   if (iface>=g_ptrSelectedFaces.GetSize())
38   {
39     Sys_FPrintf (SYS_ERR, "QERApp_GetFace: selected faces count exceeded\n");
40     return NULL;
41   }
42   return reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(iface));
43 }
44
45 brush_t* WINAPI QERApp_GetSelectedFaceBrush(int iface)
46 {
47   if (iface>=g_ptrSelectedFaceBrushes.GetSize())
48   {
49     Sys_FPrintf (SYS_ERR, "QERApp_GetFace: selected faces count exceeded\n");
50     return NULL;
51   }
52   return reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(iface));
53 }
54
55 // NOTE: we expect pWinding to have MAX_POINTS_ON_WINDING points ready for writing
56 int WINAPI QERApp_GetFaceInfo(int iface, _QERFaceData *pFaceData, winding_t *pWinding)
57 {
58   size_t size;
59
60   if (iface>=g_ptrSelectedFaces.GetSize())
61   {
62     Sys_FPrintf (SYS_ERR, "QERApp_GetFaceInfo: selected faces count exceeded\n");
63     return 0;
64   }
65   if (!g_qeglobals.m_bBrushPrimitMode)
66   {
67     Sys_Printf("Warning: unexpected QERApp_GetFaceInfo out of brush primitive mode\n");
68     return 0;
69   }
70   face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(iface));
71   strcpy( pFaceData->m_TextureName, selFace->texdef.GetName() );
72   VectorCopy( selFace->planepts[0], pFaceData->m_v1 );
73   VectorCopy( selFace->planepts[1], pFaceData->m_v2 );
74   VectorCopy( selFace->planepts[2], pFaceData->m_v3 );
75   pFaceData->m_bBPrimit = true;
76   memcpy( &pFaceData->brushprimit_texdef, &selFace->brushprimit_texdef, sizeof(brushprimit_texdef_t) );
77   size = (size_t)((winding_t *)0)->points[selFace->face_winding->numpoints];
78   memcpy( pWinding, selFace->face_winding, size );
79   return 1;
80 }
81
82 int WINAPI QERApp_SetFaceInfo(int iface, _QERFaceData *pFaceData)
83 {
84   if (iface>=g_ptrSelectedFaces.GetSize())
85   {
86     Sys_FPrintf (SYS_ERR, "QERApp_SetFaceInfo: selected faces count exceeded\n");
87     return 0;
88   }
89   if (!g_qeglobals.m_bBrushPrimitMode)
90   {
91     Sys_Printf("Warning: unexpected QERApp_SetFaceInfo out of brush primitive mode\n");
92     return 0;
93   }
94   face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(iface));
95   brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(iface));
96   //strcpy( selected_face->texdef.name, pFaceData->m_TextureName );
97   selFace->texdef.SetName(pFaceData->m_TextureName);
98   VectorCopy( pFaceData->m_v1, selFace->planepts[0] );
99   VectorCopy( pFaceData->m_v2, selFace->planepts[1] );
100   VectorCopy( pFaceData->m_v3, selFace->planepts[2] );
101   memcpy( &selFace->brushprimit_texdef, &pFaceData->brushprimit_texdef, sizeof(brushprimit_texdef_t) );
102   Brush_Build( selBrush );
103   Sys_UpdateWindows(W_ALL);
104   return 1;
105 }
106
107 int WINAPI QERApp_ISelectedFace_GetTextureNumber(int iface)
108 {
109   if (iface>=g_ptrSelectedFaces.GetSize())
110   {
111     Sys_FPrintf (SYS_ERR, "QERApp_ISelectedFace_GetTextureNumber: selected faces count exceeded\n");
112     return 0;
113   }
114   face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(iface));
115   return selFace->d_texture->texture_number;
116 }
117
118 void WINAPI QERApp_GetTextureSize (int iface, int Size[2])
119 {
120   if (iface>=g_ptrSelectedFaces.GetSize())
121   {
122     Sys_FPrintf (SYS_ERR, "QERApp_GetTextureSize: selected faces count exceeded\n");
123     return;
124   }
125   face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(iface));
126   Size[0] = selFace->d_texture->width;
127   Size[1] = selFace->d_texture->height;
128 }