2007-11-04 03:51:54 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// bkgrnd2d Plugin
|
|
|
|
//
|
|
|
|
// Code by reyalP aka Reed Mideke
|
|
|
|
//
|
|
|
|
// Based on various other plugins
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "bkgrnd2d.h"
|
|
|
|
|
|
|
|
CBackgroundRender render;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
CBackgroundImage backgroundXY( XY ),backgroundXZ( XZ ),backgroundYZ( YZ );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
CBackgroundRender::CBackgroundRender(){
|
2007-11-04 03:51:54 +00:00
|
|
|
refCount = 1;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
CBackgroundRender::~CBackgroundRender(){
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void CBackgroundRender::Register(){
|
2007-11-04 03:51:54 +00:00
|
|
|
g_QglTable.m_pfnHookGL2DWindow( this );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void CBackgroundRender::Draw2D( VIEWTYPE vt ){
|
|
|
|
switch ( vt )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
case XY:
|
|
|
|
backgroundXY.Render();
|
|
|
|
break;
|
|
|
|
case XZ:
|
|
|
|
backgroundXZ.Render();
|
|
|
|
break;
|
|
|
|
case YZ:
|
|
|
|
backgroundYZ.Render();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
CBackgroundImage::CBackgroundImage( VIEWTYPE vt ){
|
2007-11-04 03:51:54 +00:00
|
|
|
m_tex = NULL;
|
|
|
|
m_alpha = 0.5;
|
|
|
|
|
|
|
|
// TODO, sensible defaults ? Or not show until we have extents ?
|
|
|
|
m_xmin = m_ymin = 0.0f;
|
|
|
|
m_xmax = m_ymax = 0.0f;
|
|
|
|
|
|
|
|
m_bActive = false;
|
|
|
|
|
|
|
|
m_vt = vt;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
switch ( m_vt )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
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;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-06-27 15:09:36 +00:00
|
|
|
* should cleanup, but I don't think we can be sure it happens before our
|
2007-11-04 03:51:54 +00:00
|
|
|
* interfaces are gone
|
2012-03-17 20:01:54 +00:00
|
|
|
CBackgroundImage::~CBackgroundImage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
void CBackgroundImage::Cleanup(){
|
|
|
|
if ( m_tex ) {
|
|
|
|
g_QglTable.m_pfn_qglDeleteTextures( 1,&m_tex->texture_number );
|
|
|
|
g_free( m_tex );
|
2007-11-04 03:51:54 +00:00
|
|
|
m_tex = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void CBackgroundImage::Render(){
|
|
|
|
if ( !m_bActive || !Valid() ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
g_QglTable.m_pfn_qglPushAttrib( GL_ALL_ATTRIB_BITS );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglPolygonMode( GL_FRONT,GL_FILL );
|
2007-11-04 03:51:54 +00:00
|
|
|
// 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 ?
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
|
|
|
|
g_QglTable.m_pfn_qglBegin( GL_QUADS );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglTexCoord2f( 1.0,1.0 );
|
|
|
|
g_QglTable.m_pfn_qglVertex2f( m_xmax,m_ymin );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglTexCoord2f( 1.0,0.0 );
|
|
|
|
g_QglTable.m_pfn_qglVertex2f( m_xmax,m_ymax );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglTexCoord2f( 0.0,0.0 );
|
|
|
|
g_QglTable.m_pfn_qglVertex2f( m_xmin,m_ymax );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglEnd();
|
2012-03-17 20:01:54 +00:00
|
|
|
g_QglTable.m_pfn_qglBindTexture( GL_TEXTURE_2D, 0 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_QglTable.m_pfn_qglPopAttrib();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool CBackgroundImage::Load( const char *filename ){
|
2007-11-04 03:51:54 +00:00
|
|
|
qtexture_t *newtex;
|
2008-06-27 15:09:36 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
unsigned char *image = NULL; // gets allocated with what ? g_malloc
|
|
|
|
int width = 0, height = 0;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_FuncTable.m_pfnLoadImage( filename,&image,&width,&height );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !image ) {
|
|
|
|
Syn_Printf( MSG_WARN "load %s failed\n",filename );
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// just in case we want to build for an old version
|
|
|
|
#ifdef BKGRND2D_JPG_WORKAROUND
|
2012-03-17 20:01:54 +00:00
|
|
|
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;
|
2007-11-04 03:51:54 +00:00
|
|
|
int i;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 3; i < size; i += 4 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
image[i] = 255;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2008-06-27 15:09:36 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
//TODO bug for stored texture size
|
|
|
|
//TODO whose gl context are we in, anyway ?
|
2012-03-17 20:01:54 +00:00
|
|
|
newtex = g_FuncTable.m_pfnLoadTextureRGBA( image,width,height );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_free( image );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !newtex ) {
|
|
|
|
Syn_Printf( MSG_WARN "image to texture failed\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Cleanup();
|
|
|
|
m_tex = newtex;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_FuncTable.m_pfnSysUpdateWindows( W_XY );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool CBackgroundImage::SetExtentsMM(){
|
2007-11-04 03:51:54 +00:00
|
|
|
entity_s *worldentity;
|
|
|
|
const char *val;
|
|
|
|
int xmin = 0, ymin = 0, xmax = 0, ymax = 0;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
worldentity = (entity_s *)g_FuncTable.m_pfnGetEntityHandle( 0 );
|
|
|
|
if ( !worldentity ) {
|
|
|
|
Syn_Printf( MSG_WARN "SetExtentsMM worldspawn not found\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//TODO val is not NULL even if key does not exist
|
2012-03-17 20:01:54 +00:00
|
|
|
val = g_EntityTable.m_pfnValueForKey( worldentity,"mapcoordsmins" );
|
|
|
|
if ( !val || !val[0] ) {
|
|
|
|
Syn_Printf( MSG_WARN "SetExtentsMM mapcoordsmins not found\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// we could be more robust
|
|
|
|
// note contortions due to splashs strange idea of min and max
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sscanf( val, "%d %d",&xmin,&ymax ) != 2 ) {
|
|
|
|
Syn_Printf( MSG_WARN "SetExtentsMM mapcoordsmins malformed\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
val = g_EntityTable.m_pfnValueForKey( worldentity,"mapcoordsmaxs" );
|
|
|
|
if ( !val || !val[0] ) {
|
|
|
|
Syn_Printf( MSG_WARN "SetExtentsMM mapcoordsmaxs not found\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sscanf( val, "%d %d",&xmax,&ymin ) != 2 ) {
|
|
|
|
Syn_Printf( MSG_WARN "SetExtentsMM mapcoordsmaxs malformed\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//might do sanity check before we commit
|
|
|
|
m_xmin = (float)xmin;
|
|
|
|
m_ymin = (float)ymin;
|
|
|
|
m_xmax = (float)xmax;
|
|
|
|
m_ymax = (float)ymax;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_FuncTable.m_pfnSysUpdateWindows( W_XY );
|
2007-11-04 03:51:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO, this should just be exported from core
|
|
|
|
// ripped directly from radiant/select.cpp:Select_GetBounds
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
static bool get_selection_bounds( vec3_t mins, vec3_t maxs ){
|
|
|
|
brush_t *b;
|
|
|
|
int i;
|
2007-11-04 03:51:54 +00:00
|
|
|
brush_t *selected_brushes = g_DataTable.m_pfnSelectedBrushes();
|
|
|
|
//TODO should never happen
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !selected_brushes ) {
|
|
|
|
Sys_Printf( MSG_PREFIX "selected_brushes = NULL\n" );
|
|
|
|
return false;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
// this should mean no selection
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( selected_brushes == selected_brushes->next ) {
|
|
|
|
Sys_Printf( MSG_PREFIX "nothing selected\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return false;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 3 ; i++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
mins[i] = 99999;
|
|
|
|
maxs[i] = -99999;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( b = selected_brushes->next ; b != selected_brushes ; b = b->next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->owner->eclass->fixedsize ) {
|
|
|
|
for ( i = 0 ; i < 3 ; i++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->owner->origin[i] < mins[i] ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
mins[i] = b->owner->origin[i];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( b->owner->origin[i] > maxs[i] ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
maxs[i] = b->owner->origin[i];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 3 ; i++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->mins[i] < mins[i] ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
mins[i] = b->mins[i];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( b->maxs[i] > maxs[i] ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
maxs[i] = b->maxs[i];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
return true;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool CBackgroundImage::SetExtentsSel(){
|
2007-11-04 03:51:54 +00:00
|
|
|
vec3_t mins,maxs;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !get_selection_bounds( mins,maxs ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( (int)mins[m_ix] == (int)maxs[m_ix] ) ||
|
|
|
|
( (int)mins[m_iy] == (int)maxs[m_iy] ) ) {
|
|
|
|
Syn_Printf( MSG_PREFIX "tiny selection\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_xmin = mins[m_ix];
|
|
|
|
m_ymin = mins[m_iy];
|
|
|
|
m_xmax = maxs[m_ix];
|
|
|
|
m_ymax = maxs[m_iy];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_FuncTable.m_pfnSysUpdateWindows( W_XY );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return true;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|