]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/bkgrnd2d/bkgrnd2d.cpp
my own uncrustify run
[xonotic/netradiant.git] / contrib / bkgrnd2d / bkgrnd2d.cpp
index 36cf45e2f24fafa04f52bdb1c75af97c46e0dfd2..b115952550b48e9de09ae19f18477fa0eb6dd7ca 100644 (file)
@@ -1,22 +1,22 @@
 /*
-Copyright (C) 2003 Reed Mideke.
+   Copyright (C) 2003 Reed Mideke.
 
-This file is part of GtkRadiant.
+   This file is part of GtkRadiant.
 
-GtkRadiant is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   GtkRadiant is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-GtkRadiant is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   GtkRadiant is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with GtkRadiant; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-*/
+   You should have received a copy of the GNU General Public License
+   along with GtkRadiant; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
 
 //
 // bkgrnd2d Plugin
@@ -30,25 +30,21 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 CBackgroundRender render;
 
-CBackgroundImage backgroundXY(XY),backgroundXZ(XZ),backgroundYZ(YZ);
+CBackgroundImage backgroundXY( XY ),backgroundXZ( XZ ),backgroundYZ( YZ );
 
-CBackgroundRender::CBackgroundRender()
-{
+CBackgroundRender::CBackgroundRender(){
        refCount = 1;
 }
 
-CBackgroundRender::~CBackgroundRender()
-{
+CBackgroundRender::~CBackgroundRender(){
 }
 
-void CBackgroundRender::Register()
-{
+void CBackgroundRender::Register(){
        g_QglTable.m_pfnHookGL2DWindow( this );
 }
 
-void CBackgroundRender::Draw2D( VIEWTYPE vt )
-{
-       switch(vt)
+void CBackgroundRender::Draw2D( VIEWTYPE vt ){
+       switch ( vt )
        {
        case XY:
                backgroundXY.Render();
@@ -63,8 +59,7 @@ void CBackgroundRender::Draw2D( VIEWTYPE vt )
 }
 
 
-CBackgroundImage::CBackgroundImage(VIEWTYPE vt)
-{
+CBackgroundImage::CBackgroundImage( VIEWTYPE vt ){
        m_tex = NULL;
        m_alpha = 0.5;
 
@@ -76,159 +71,154 @@ CBackgroundImage::CBackgroundImage(VIEWTYPE vt)
 
        m_vt = vt;
 
-       switch(m_vt)
+       switch ( m_vt )
        {
-               case XY:
-                       m_ix = 0;
-                       m_iy = 1;
-                       break;
-               case XZ:
-                       m_ix = 0;
-                       m_iy = 2;
-                       break;
-               case YZ:
-                       m_ix = 1;
-                       m_iy = 2;
-                       break;
+       case XY:
+               m_ix = 0;
+               m_iy = 1;
+               break;
+       case XZ:
+               m_ix = 0;
+               m_iy = 2;
+               break;
+       case YZ:
+               m_ix = 1;
+               m_iy = 2;
+               break;
        }
 }
 
 /*
- * should cleanup, but I don't think we can be sure it happens before our 
+ * should cleanup, but I don't think we can be sure it happens before our
  * interfaces are gone
-CBackgroundImage::~CBackgroundImage()
-{
-}
-*/
-
-void CBackgroundImage::Cleanup()
-{
-       if(m_tex) {
-               g_QglTable.m_pfn_qglDeleteTextures(1,&m_tex->texture_number);
-               g_free(m_tex);
+   CBackgroundImage::~CBackgroundImage()
+   {
+   }
+ */
+
+void CBackgroundImage::Cleanup(){
+       if ( m_tex ) {
+               g_QglTable.m_pfn_qglDeleteTextures( 1,&m_tex->texture_number );
+               g_free( m_tex );
                m_tex = NULL;
        }
 }
 
-void CBackgroundImage::Render()
-{
-       if (!m_bActive || !Valid())
+void CBackgroundImage::Render(){
+       if ( !m_bActive || !Valid() ) {
                return;
-       g_QglTable.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
+       }
+       g_QglTable.m_pfn_qglPushAttrib( GL_ALL_ATTRIB_BITS );
 
-       g_QglTable.m_pfn_qglEnable(GL_TEXTURE_2D);
-       g_QglTable.m_pfn_qglEnable(GL_BLEND);
-       g_QglTable.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-       g_QglTable.m_pfn_qglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-       g_QglTable.m_pfn_qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
-       g_QglTable.m_pfn_qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+       g_QglTable.m_pfn_qglEnable( GL_TEXTURE_2D );
+       g_QglTable.m_pfn_qglEnable( GL_BLEND );
+       g_QglTable.m_pfn_qglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
+       g_QglTable.m_pfn_qglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
+       g_QglTable.m_pfn_qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
+       g_QglTable.m_pfn_qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
 
-       g_QglTable.m_pfn_qglPolygonMode(GL_FRONT,GL_FILL);
+       g_QglTable.m_pfn_qglPolygonMode( GL_FRONT,GL_FILL );
        // TODO, just so we can tell if we end up going the wrong way
        // g_QglTable.m_pfn_qglPolygonMode(GL_BACK,GL_LINE);
        // TODO any other state we should not assume ?
 
-       g_QglTable.m_pfn_qglBindTexture(GL_TEXTURE_2D, m_tex->texture_number);
-       g_QglTable.m_pfn_qglBegin(GL_QUADS);
+       g_QglTable.m_pfn_qglBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
+       g_QglTable.m_pfn_qglBegin( GL_QUADS );
 
-       g_QglTable.m_pfn_qglColor4f(1.0,1.0,1.0,m_alpha);
-       g_QglTable.m_pfn_qglTexCoord2f(0.0,1.0);
-       g_QglTable.m_pfn_qglVertex2f(m_xmin,m_ymin);
+       g_QglTable.m_pfn_qglColor4f( 1.0,1.0,1.0,m_alpha );
+       g_QglTable.m_pfn_qglTexCoord2f( 0.0,1.0 );
+       g_QglTable.m_pfn_qglVertex2f( m_xmin,m_ymin );
 
-       g_QglTable.m_pfn_qglTexCoord2f(1.0,1.0);
-       g_QglTable.m_pfn_qglVertex2f(m_xmax,m_ymin);
+       g_QglTable.m_pfn_qglTexCoord2f( 1.0,1.0 );
+       g_QglTable.m_pfn_qglVertex2f( m_xmax,m_ymin );
 
-       g_QglTable.m_pfn_qglTexCoord2f(1.0,0.0);
-       g_QglTable.m_pfn_qglVertex2f(m_xmax,m_ymax);
+       g_QglTable.m_pfn_qglTexCoord2f( 1.0,0.0 );
+       g_QglTable.m_pfn_qglVertex2f( m_xmax,m_ymax );
 
-       g_QglTable.m_pfn_qglTexCoord2f(0.0,0.0);
-       g_QglTable.m_pfn_qglVertex2f(m_xmin,m_ymax);
+       g_QglTable.m_pfn_qglTexCoord2f( 0.0,0.0 );
+       g_QglTable.m_pfn_qglVertex2f( m_xmin,m_ymax );
 
        g_QglTable.m_pfn_qglEnd();
-       g_QglTable.m_pfn_qglBindTexture(GL_TEXTURE_2D, 0);
+       g_QglTable.m_pfn_qglBindTexture( GL_TEXTURE_2D, 0 );
 
        g_QglTable.m_pfn_qglPopAttrib();
 }
 
-bool CBackgroundImage::Load(const char *filename)
-{
+bool CBackgroundImage::Load( const char *filename ){
        qtexture_t *newtex;
-       
+
        unsigned char *image = NULL; // gets allocated with what ? g_malloc
        int width = 0, height = 0;
 
-       g_FuncTable.m_pfnLoadImage(filename,&image,&width,&height);
+       g_FuncTable.m_pfnLoadImage( filename,&image,&width,&height );
 
-       if(!image) {
-               Syn_Printf(MSG_WARN "load %s failed\n",filename);
+       if ( !image ) {
+               Syn_Printf( MSG_WARN "load %s failed\n",filename );
                return false;
        }
 
 // just in case we want to build for an old version
 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=900
 #ifdef BKGRND2D_JPG_WORKAROUND
-       if ( strlen(filename) > 4 && !strcmp(".jpg",filename + strlen(filename) - 4)) {
-               Syn_Printf(MSG_PREFIX ".jpg workaround, clearing alpha channel\n");
-               int size = width*height*4;
+       if ( strlen( filename ) > 4 && !strcmp( ".jpg",filename + strlen( filename ) - 4 ) ) {
+               Syn_Printf( MSG_PREFIX ".jpg workaround, clearing alpha channel\n" );
+               int size = width * height * 4;
                int i;
-               for (i = 3; i < size; i+=4) {
+               for ( i = 3; i < size; i += 4 ) {
                        image[i] = 255;
                }
        }
 #endif
-       
+
        //TODO bug for stored texture size
        //TODO whose gl context are we in, anyway ?
-       newtex = g_FuncTable.m_pfnLoadTextureRGBA(image,width,height);
+       newtex = g_FuncTable.m_pfnLoadTextureRGBA( image,width,height );
 
-       g_free(image);
+       g_free( image );
 
-       if(!newtex) {
-               Syn_Printf(MSG_WARN "image to texture failed\n");
+       if ( !newtex ) {
+               Syn_Printf( MSG_WARN "image to texture failed\n" );
                return false;
        }
 
        Cleanup();
        m_tex = newtex;
 
-       g_FuncTable.m_pfnSysUpdateWindows(W_XY);
+       g_FuncTable.m_pfnSysUpdateWindows( W_XY );
 
        return true;
 }
 
-bool CBackgroundImage::SetExtentsMM()
-{
+bool CBackgroundImage::SetExtentsMM(){
        entity_s *worldentity;
        const char *val;
        int xmin = 0, ymin = 0, xmax = 0, ymax = 0;
 
-       worldentity = (entity_s *)g_FuncTable.m_pfnGetEntityHandle(0);
-       if(!worldentity) {
-               Syn_Printf(MSG_WARN "SetExtentsMM worldspawn not found\n");
+       worldentity = (entity_s *)g_FuncTable.m_pfnGetEntityHandle( 0 );
+       if ( !worldentity ) {
+               Syn_Printf( MSG_WARN "SetExtentsMM worldspawn not found\n" );
                return false;
        }
        //TODO val is not NULL even if key does not exist
-       val = g_EntityTable.m_pfnValueForKey(worldentity,"mapcoordsmins");
-       if(!val || !val[0]) {
-               Syn_Printf(MSG_WARN "SetExtentsMM mapcoordsmins not found\n");
+       val = g_EntityTable.m_pfnValueForKey( worldentity,"mapcoordsmins" );
+       if ( !val || !val[0] ) {
+               Syn_Printf( MSG_WARN "SetExtentsMM mapcoordsmins not found\n" );
                return false;
        }
 // we could be more robust
 // note contortions due to splashs strange idea of min and max
-       if(sscanf(val, "%d %d",&xmin,&ymax) != 2)
-       {
-               Syn_Printf(MSG_WARN "SetExtentsMM mapcoordsmins malformed\n");
+       if ( sscanf( val, "%d %d",&xmin,&ymax ) != 2 ) {
+               Syn_Printf( MSG_WARN "SetExtentsMM mapcoordsmins malformed\n" );
                return false;
        }
 
-       val = g_EntityTable.m_pfnValueForKey(worldentity,"mapcoordsmaxs");
-       if(!val || !val[0]) {
-               Syn_Printf(MSG_WARN "SetExtentsMM mapcoordsmaxs not found\n");
+       val = g_EntityTable.m_pfnValueForKey( worldentity,"mapcoordsmaxs" );
+       if ( !val || !val[0] ) {
+               Syn_Printf( MSG_WARN "SetExtentsMM mapcoordsmaxs not found\n" );
                return false;
        }
-       if(sscanf(val, "%d %d",&xmax,&ymin) != 2)
-       {
-               Syn_Printf(MSG_WARN "SetExtentsMM mapcoordsmaxs malformed\n");
+       if ( sscanf( val, "%d %d",&xmax,&ymin ) != 2 ) {
+               Syn_Printf( MSG_WARN "SetExtentsMM mapcoordsmaxs malformed\n" );
                return false;
        }
        //might do sanity check before we commit
@@ -237,72 +227,74 @@ bool CBackgroundImage::SetExtentsMM()
        m_xmax = (float)xmax;
        m_ymax = (float)ymax;
 
-       g_FuncTable.m_pfnSysUpdateWindows(W_XY);
+       g_FuncTable.m_pfnSysUpdateWindows( W_XY );
        return true;
 }
 
 // TODO, this should just be exported from core
 // ripped directly from radiant/select.cpp:Select_GetBounds
 //
-static bool get_selection_bounds (vec3_t mins, vec3_t maxs)
-{
-       brush_t *b;
-       int             i;
+static bool get_selection_bounds( vec3_t mins, vec3_t maxs ){
+       brush_t *b;
+       int i;
        brush_t *selected_brushes = g_DataTable.m_pfnSelectedBrushes();
        //TODO should never happen
-       if(!selected_brushes) {
-         Sys_Printf (MSG_PREFIX "selected_brushes = NULL\n"); 
-         return false;
+       if ( !selected_brushes ) {
+               Sys_Printf( MSG_PREFIX "selected_brushes = NULL\n" );
+               return false;
        }
        // this should mean no selection
-       if(selected_brushes == selected_brushes->next) {
-         Sys_Printf (MSG_PREFIX "nothing selected\n"); 
+       if ( selected_brushes == selected_brushes->next ) {
+               Sys_Printf( MSG_PREFIX "nothing selected\n" );
 
-         return false;
+               return false;
        }
 
-       for (i=0 ; i<3 ; i++)
+       for ( i = 0 ; i < 3 ; i++ )
        {
                mins[i] = 99999;
                maxs[i] = -99999;
        }
 
-       for (b=selected_brushes->next ; b != selected_brushes ; b=b->next)
+       for ( b = selected_brushes->next ; b != selected_brushes ; b = b->next )
        {
-               if (b->owner->eclass->fixedsize)
-               {
-                       for (i=0 ; i<3 ; i++)
+               if ( b->owner->eclass->fixedsize ) {
+                       for ( i = 0 ; i < 3 ; i++ )
                        {
-                               if (b->owner->origin[i] < mins[i])
+                               if ( b->owner->origin[i] < mins[i] ) {
                                        mins[i] = b->owner->origin[i];
-                               if (b->owner->origin[i] > maxs[i])
+                               }
+                               if ( b->owner->origin[i] > maxs[i] ) {
                                        maxs[i] = b->owner->origin[i];
+                               }
                        }
                }
                else
                {
-                       for (i=0 ; i<3 ; i++)
+                       for ( i = 0 ; i < 3 ; i++ )
                        {
-                               if (b->mins[i] < mins[i])
+                               if ( b->mins[i] < mins[i] ) {
                                        mins[i] = b->mins[i];
-                               if (b->maxs[i] > maxs[i])
+                               }
+                               if ( b->maxs[i] > maxs[i] ) {
                                        maxs[i] = b->maxs[i];
+                               }
                        }
                }
        }
-  return true;
+       return true;
 }
 
-bool CBackgroundImage::SetExtentsSel()
-{
+bool CBackgroundImage::SetExtentsSel(){
        vec3_t mins,maxs;
 
-       if(!get_selection_bounds(mins,maxs)) 
+       if ( !get_selection_bounds( mins,maxs ) ) {
                return false;
+       }
 
-       if(((int)mins[m_ix] == (int)maxs[m_ix]) ||
-     ((int)mins[m_iy] == (int)maxs[m_iy])) {
-               Syn_Printf(MSG_PREFIX "tiny selection\n");
+       if ( ( (int)mins[m_ix] == (int)maxs[m_ix] ) ||
+                ( (int)mins[m_iy] == (int)maxs[m_iy] ) ) {
+               Syn_Printf( MSG_PREFIX "tiny selection\n" );
                return false;
        }
 
@@ -311,8 +303,7 @@ bool CBackgroundImage::SetExtentsSel()
        m_xmax = maxs[m_ix];
        m_ymax = maxs[m_iy];
 
-       g_FuncTable.m_pfnSysUpdateWindows(W_XY);
+       g_FuncTable.m_pfnSysUpdateWindows( W_XY );
 
-  return true;
+       return true;
 }
-