From 29ac8a44c6faca8054bcbadc30c0142e1e7f895c Mon Sep 17 00:00:00 2001 From: spog Date: Tue, 21 Feb 2006 21:09:05 +0000 Subject: [PATCH] fixed eol-style git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@22 8a3a26a2-13c4-0310-b231-cf6edde360e5 --- contrib/bkgrnd2d/bkgrnd2d.cpp | 636 ++++++++++++++--------------- contrib/bkgrnd2d/dialog.cpp | 728 +++++++++++++++++----------------- contrib/bkgrnd2d/plugin.cpp | 638 ++++++++++++++--------------- libs/container/stack.cpp | 46 +-- 4 files changed, 1024 insertions(+), 1024 deletions(-) diff --git a/contrib/bkgrnd2d/bkgrnd2d.cpp b/contrib/bkgrnd2d/bkgrnd2d.cpp index 8f96c97..36cf45e 100644 --- a/contrib/bkgrnd2d/bkgrnd2d.cpp +++ b/contrib/bkgrnd2d/bkgrnd2d.cpp @@ -1,318 +1,318 @@ -/* -Copyright (C) 2003 Reed Mideke. - -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 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 -*/ - -// -// bkgrnd2d Plugin -// -// Code by reyalP aka Reed Mideke -// -// Based on various other plugins -// - -#include "bkgrnd2d.h" - -CBackgroundRender render; - -CBackgroundImage backgroundXY(XY),backgroundXZ(XZ),backgroundYZ(YZ); - -CBackgroundRender::CBackgroundRender() -{ - refCount = 1; -} - -CBackgroundRender::~CBackgroundRender() -{ -} - -void CBackgroundRender::Register() -{ - g_QglTable.m_pfnHookGL2DWindow( this ); -} - -void CBackgroundRender::Draw2D( VIEWTYPE vt ) -{ - switch(vt) - { - case XY: - backgroundXY.Render(); - break; - case XZ: - backgroundXZ.Render(); - break; - case YZ: - backgroundYZ.Render(); - break; - } -} - - -CBackgroundImage::CBackgroundImage(VIEWTYPE vt) -{ - 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; - - 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; - } -} - -/* - * 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); - m_tex = NULL; - } -} - -void CBackgroundImage::Render() -{ - if (!m_bActive || !Valid()) - return; - 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_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_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,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_qglEnd(); - g_QglTable.m_pfn_qglBindTexture(GL_TEXTURE_2D, 0); - - g_QglTable.m_pfn_qglPopAttrib(); -} - -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); - - 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; - int i; - 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); - - g_free(image); - - if(!newtex) { - Syn_Printf(MSG_WARN "image to texture failed\n"); - return false; - } - - Cleanup(); - m_tex = newtex; - - g_FuncTable.m_pfnSysUpdateWindows(W_XY); - - return true; -} - -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"); - 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"); - 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"); - return false; - } - - 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"); - 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; - - 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; - 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; - } - // this should mean no selection - if(selected_brushes == selected_brushes->next) { - Sys_Printf (MSG_PREFIX "nothing selected\n"); - - return false; - } - - for (i=0 ; i<3 ; i++) - { - mins[i] = 99999; - maxs[i] = -99999; - } - - 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->origin[i] < mins[i]) - mins[i] = b->owner->origin[i]; - if (b->owner->origin[i] > maxs[i]) - maxs[i] = b->owner->origin[i]; - } - } - else - { - for (i=0 ; i<3 ; i++) - { - if (b->mins[i] < mins[i]) - mins[i] = b->mins[i]; - if (b->maxs[i] > maxs[i]) - maxs[i] = b->maxs[i]; - } - } - } - return true; -} - -bool CBackgroundImage::SetExtentsSel() -{ - vec3_t 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"); - return false; - } - - m_xmin = mins[m_ix]; - m_ymin = mins[m_iy]; - m_xmax = maxs[m_ix]; - m_ymax = maxs[m_iy]; - - g_FuncTable.m_pfnSysUpdateWindows(W_XY); - - return true; -} - +/* +Copyright (C) 2003 Reed Mideke. + +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 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 +*/ + +// +// bkgrnd2d Plugin +// +// Code by reyalP aka Reed Mideke +// +// Based on various other plugins +// + +#include "bkgrnd2d.h" + +CBackgroundRender render; + +CBackgroundImage backgroundXY(XY),backgroundXZ(XZ),backgroundYZ(YZ); + +CBackgroundRender::CBackgroundRender() +{ + refCount = 1; +} + +CBackgroundRender::~CBackgroundRender() +{ +} + +void CBackgroundRender::Register() +{ + g_QglTable.m_pfnHookGL2DWindow( this ); +} + +void CBackgroundRender::Draw2D( VIEWTYPE vt ) +{ + switch(vt) + { + case XY: + backgroundXY.Render(); + break; + case XZ: + backgroundXZ.Render(); + break; + case YZ: + backgroundYZ.Render(); + break; + } +} + + +CBackgroundImage::CBackgroundImage(VIEWTYPE vt) +{ + 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; + + 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; + } +} + +/* + * 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); + m_tex = NULL; + } +} + +void CBackgroundImage::Render() +{ + if (!m_bActive || !Valid()) + return; + 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_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_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,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_qglEnd(); + g_QglTable.m_pfn_qglBindTexture(GL_TEXTURE_2D, 0); + + g_QglTable.m_pfn_qglPopAttrib(); +} + +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); + + 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; + int i; + 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); + + g_free(image); + + if(!newtex) { + Syn_Printf(MSG_WARN "image to texture failed\n"); + return false; + } + + Cleanup(); + m_tex = newtex; + + g_FuncTable.m_pfnSysUpdateWindows(W_XY); + + return true; +} + +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"); + 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"); + 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"); + return false; + } + + 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"); + 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; + + 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; + 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; + } + // this should mean no selection + if(selected_brushes == selected_brushes->next) { + Sys_Printf (MSG_PREFIX "nothing selected\n"); + + return false; + } + + for (i=0 ; i<3 ; i++) + { + mins[i] = 99999; + maxs[i] = -99999; + } + + 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->origin[i] < mins[i]) + mins[i] = b->owner->origin[i]; + if (b->owner->origin[i] > maxs[i]) + maxs[i] = b->owner->origin[i]; + } + } + else + { + for (i=0 ; i<3 ; i++) + { + if (b->mins[i] < mins[i]) + mins[i] = b->mins[i]; + if (b->maxs[i] > maxs[i]) + maxs[i] = b->maxs[i]; + } + } + } + return true; +} + +bool CBackgroundImage::SetExtentsSel() +{ + vec3_t 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"); + return false; + } + + m_xmin = mins[m_ix]; + m_ymin = mins[m_iy]; + m_xmax = maxs[m_ix]; + m_ymax = maxs[m_iy]; + + g_FuncTable.m_pfnSysUpdateWindows(W_XY); + + return true; +} + diff --git a/contrib/bkgrnd2d/dialog.cpp b/contrib/bkgrnd2d/dialog.cpp index 02f39cc..8d9a845 100644 --- a/contrib/bkgrnd2d/dialog.cpp +++ b/contrib/bkgrnd2d/dialog.cpp @@ -1,364 +1,364 @@ -/* -Copyright (C) 2003 Reed Mideke. - -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 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 -*/ - -// -// bkgrnd2d Plugin dialog -// -// Code by reyalP aka Reed Mideke -// -// Based on various other plugins -// - -#include - -#include "bkgrnd2d.h" -#include "dialog.h" - -// spaces to make label nice and big -#define NO_FILE_MSG " (no file loaded) " - -static GtkWidget *pDialogWnd; -static GtkWidget *pNotebook; -static GtkTooltips *pTooltips; - -class CBackgroundDialogPage -{ -private: - GtkWidget *m_pWidget; - GtkWidget *m_pTabLabel; - GtkWidget *m_pFileLabel; - GtkWidget *m_pPosLabel; - VIEWTYPE m_vt; - bool m_bValidFile; - -public: - CBackgroundImage *m_pImage; - CBackgroundDialogPage( VIEWTYPE vt ); - void Append(GtkWidget *notebook); - void Browse(); - void Reload(); - void SetPosLabel(); -// ~BackgroundDialogPage(); -}; - - -// dialog page callbacks -static void browse_callback( GtkWidget *widget, gpointer data ) -{ - ((CBackgroundDialogPage *)data)->Browse(); -} - -static void reload_callback( GtkWidget *widget, gpointer data ) -{ - ((CBackgroundDialogPage *)data)->Reload(); -} - -static void size_sel_callback( GtkWidget *widget, gpointer data ) -{ - CBackgroundDialogPage *pPage = (CBackgroundDialogPage *)data; - if (pPage->m_pImage->SetExtentsSel()) - pPage->SetPosLabel(); -} - -static void size_mm_callback( GtkWidget *widget, gpointer data ) -{ - CBackgroundDialogPage *pPage = (CBackgroundDialogPage *)data; - if(pPage->m_pImage->SetExtentsMM()) - pPage->SetPosLabel(); -} - -static void alpha_adjust_callback( GtkWidget *widget, gpointer data ) -{ - CBackgroundDialogPage *pPage = (CBackgroundDialogPage *)data; - pPage->m_pImage->m_alpha = (float)gtk_range_get_value (GTK_RANGE(widget)); - g_FuncTable.m_pfnSysUpdateWindows(W_XY); -} - -void CBackgroundDialogPage::Reload() -{ - if(m_bValidFile) - m_pImage->Load(gtk_label_get_text(GTK_LABEL(m_pFileLabel))); -} - -void CBackgroundDialogPage::Browse() -{ - char browsedir[PATH_MAX]; - const char *ct; - const char *newfile; - char *t; - - //TODO GetMapName saves the map. eeep! - //also with no map, returns unnamed.map, otherwise returns full path -// Syn_Printf(MSG_PREFIX "GetMapName() %s\n", -// g_FuncTable.m_pfnGetMapName()); - - ct = g_FuncTable.m_pfnReadProjectKey("basepath"); - // TODO shouldn't need this stuff - if(!ct || !strlen(ct)) { - Syn_Printf(MSG_PREFIX "basepath = NULL or empty\n"); - return; - } - Syn_Printf(MSG_PREFIX "basepath: %s\n",ct); - if(strlen(ct) >= PATH_MAX) { - Syn_Printf(MSG_PREFIX "base game dir too long\n"); - return; - } - - strcpy(browsedir,ct); - // make sure we have a trailing / - if(browsedir[strlen(browsedir) - 1] != '/') - strcat(browsedir,"/"); - - //if we dont have a file yet, don't try to use it for default dir - if(m_bValidFile) { - // filename should always be a nice clean unix style relative path - ct = gtk_label_get_text(GTK_LABEL(m_pFileLabel)); - strcat(browsedir,ct); - Syn_Printf(MSG_PREFIX "full path: %s\n",browsedir); - - // lop off the file part - t = browsedir + strlen(browsedir) - 1; - while (t != browsedir && *t != '/') - t--; - *t = 0; - } - Syn_Printf(MSG_PREFIX "browse directory %s\n",browsedir); - -//does NOT need freeing contrary to include/qerplugin.h comments -//TODO bug/patch for comments -//TODO patern gets fucked up sometimes if empty -//http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=915 - newfile = g_FuncTable.m_pfnFileDialog(pDialogWnd,TRUE, - "Load Background Image",browsedir,FILETYPE_KEY); - if(!newfile) { - Syn_Printf(MSG_PREFIX "newfile = NULL\n"); - return; - } - Syn_Printf(MSG_PREFIX "newfile: %s\n",newfile); - newfile = g_FileSystemTable.m_pfnExtractRelativePath(newfile); - - if(!newfile) { - Syn_Printf(MSG_PREFIX "newfile = NULL\n"); - return; - } - Syn_Printf(MSG_PREFIX "newfile: %s\n",newfile); - - if(m_pImage->Load(newfile)) { - m_bValidFile = true; - gtk_label_set_text(GTK_LABEL(m_pFileLabel),newfile); - } -} - -void CBackgroundDialogPage::SetPosLabel() -{ - char s[64]; - // TODO no snprintf ? - sprintf(s, "Size/Position (%d,%d) (%d,%d)",(int)(m_pImage->m_xmin), - (int)(m_pImage->m_ymin),(int)(m_pImage->m_xmax),(int)(m_pImage->m_ymax)); - gtk_label_set_text(GTK_LABEL(m_pPosLabel),s); -} - -CBackgroundDialogPage::CBackgroundDialogPage(VIEWTYPE vt ) -{ - GtkWidget *frame; - GtkWidget *hbox; - GtkWidget *w; - - m_vt = vt; - - m_bValidFile = false; - - switch(m_vt) - { - case XY: - m_pTabLabel = gtk_label_new("X/Y"); - m_pImage = &backgroundXY; - break; - case XZ: - m_pTabLabel = gtk_label_new("X/Z"); - m_pImage = &backgroundXZ; - break; - case YZ: - m_pTabLabel = gtk_label_new("Y/Z"); - m_pImage = &backgroundYZ; - break; - } -// A vbox to hold everything - m_pWidget = gtk_vbox_new(FALSE,0); -// Frame for file row - frame = gtk_frame_new("File"); - gtk_box_pack_start (GTK_BOX (m_pWidget),frame, FALSE, FALSE, 2); - -// hbox for first row - hbox = gtk_hbox_new(FALSE,5); - gtk_container_set_border_width(GTK_CONTAINER (hbox),4); - gtk_container_add (GTK_CONTAINER (frame), hbox); - -// label to display filename - m_pFileLabel = gtk_label_new(NO_FILE_MSG); - gtk_label_set_selectable(GTK_LABEL(m_pFileLabel),TRUE); -//TODO set min size ? done with spaces right now - gtk_box_pack_start (GTK_BOX (hbox),m_pFileLabel, TRUE, TRUE, 5); - - gtk_widget_show (m_pFileLabel); - - w = gtk_button_new_with_label ("Browse..."); - g_signal_connect (G_OBJECT (w), "clicked", G_CALLBACK (browse_callback), - (gpointer)this); - gtk_box_pack_start (GTK_BOX (hbox),w, FALSE, FALSE, 5); - gtk_tooltips_set_tip (pTooltips, w, "Select a file", NULL); - gtk_widget_show (w); - - w = gtk_button_new_with_label ("Reload"); - g_signal_connect (G_OBJECT (w), "clicked", G_CALLBACK (reload_callback), - (gpointer)this); - // TODO disable until we have file - // gtk_widget_set_sensitive(w,FALSE); - gtk_tooltips_set_tip (pTooltips, w, "Reload current file", NULL); - gtk_box_pack_start (GTK_BOX (hbox),w, FALSE, FALSE, 5); - gtk_widget_show (w); - - gtk_widget_show (hbox); - gtk_widget_show (frame); - -// second row (rendering options) - frame = gtk_frame_new("Rendering"); - gtk_box_pack_start (GTK_BOX (m_pWidget),frame, FALSE, FALSE, 2); - - hbox = gtk_hbox_new(FALSE,5); - gtk_container_set_border_width(GTK_CONTAINER (hbox),4); - gtk_container_add (GTK_CONTAINER (frame), hbox); - - w = gtk_label_new("Vertex alpha:"); - gtk_box_pack_start (GTK_BOX (hbox),w, FALSE, FALSE, 5); - gtk_widget_show (w); - - w = gtk_hscale_new_with_range(0.0,1.0,0.01); - gtk_range_set_value(GTK_RANGE(w),0.5); - gtk_scale_set_value_pos(GTK_SCALE(w),GTK_POS_LEFT); - g_signal_connect (G_OBJECT (w), "value-changed", - G_CALLBACK (alpha_adjust_callback), (gpointer)this); - gtk_box_pack_start (GTK_BOX (hbox),w, TRUE, TRUE, 5); - gtk_tooltips_set_tip (pTooltips, w, "Set image transparancy", NULL); - gtk_widget_show (w); - - gtk_widget_show (hbox); - gtk_widget_show (frame); -// Third row (size and position) - frame = gtk_frame_new("Size/Position (undefined)"); - m_pPosLabel = gtk_frame_get_label_widget (GTK_FRAME(frame)); - gtk_box_pack_start ( GTK_BOX (m_pWidget), frame, FALSE, FALSE, 2); - - hbox = gtk_hbox_new(FALSE,5); - gtk_container_add (GTK_CONTAINER (frame), hbox); - gtk_container_set_border_width(GTK_CONTAINER (hbox),4); - - w = gtk_button_new_with_label ("from selection"); - gtk_box_pack_start (GTK_BOX (hbox),w, TRUE, FALSE, 5); - g_signal_connect (G_OBJECT (w), "clicked", G_CALLBACK (size_sel_callback), - (gpointer)this); - gtk_tooltips_set_tip (pTooltips, w, "Set the size of the image to the bounding rectangle of all selected brushes and entities", NULL); - gtk_widget_show (w); - - if(m_vt == XY) { - w = gtk_button_new_with_label ("from map mins/maxs"); - gtk_box_pack_start ( GTK_BOX (hbox),w, TRUE, FALSE, 2); - g_signal_connect (G_OBJECT (w), "clicked", G_CALLBACK (size_mm_callback), - (gpointer)this); - gtk_tooltips_set_tip (pTooltips, w, "Set the size of the image using the mapcoordsmins and mapcoordsmaxs keys of the worldspawn entity", NULL); - gtk_widget_show (w); - } - - gtk_widget_show (hbox); - gtk_widget_show (frame); - - gtk_widget_show ( m_pWidget ); -} - -void CBackgroundDialogPage::Append(GtkWidget *notebook) -{ - gtk_notebook_append_page( GTK_NOTEBOOK(notebook), m_pWidget, m_pTabLabel); -} - -// dialog global callbacks -/* -static gint expose_callback( GtkWidget *widget, gpointer data ) -{ - return FALSE; -} -*/ - -static void response_callback( GtkWidget *widget, gint response, gpointer data ) -{ - if( response == GTK_RESPONSE_CLOSE ) - gtk_widget_hide( pDialogWnd ); -} - -static gint close_callback( GtkWidget *widget, gpointer data ) -{ - gtk_widget_hide( pDialogWnd ); - return TRUE; -} - -void InitBackgroundDialog() -{ - CBackgroundDialogPage *pPage; - - pDialogWnd = gtk_dialog_new_with_buttons ("Background Images", - GTK_WINDOW(g_pMainWidget), - (GtkDialogFlags)(GTK_DIALOG_DESTROY_WITH_PARENT), - // TODO dialog with no buttons - // GTK_STOCK_CLOSE, - // GTK_RESPONSE_CLOSE, - NULL); - gtk_signal_connect( GTK_OBJECT (pDialogWnd), "delete_event", - GTK_SIGNAL_FUNC( close_callback ), NULL ); - gtk_signal_connect( GTK_OBJECT (pDialogWnd), "response", - GTK_SIGNAL_FUNC( response_callback ), NULL ); -// gtk_signal_connect( GTK_OBJECT (pDialogWnd), "expose_event", GTK_SIGNAL_FUNC( ci_expose ), NULL ); - - pTooltips = gtk_tooltips_new(); - - pNotebook = gtk_notebook_new(); - pPage = new CBackgroundDialogPage(XY); - pPage->Append(pNotebook); - pPage = new CBackgroundDialogPage(XZ); - pPage->Append(pNotebook); - pPage = new CBackgroundDialogPage(YZ); - pPage->Append(pNotebook); - - gtk_box_pack_start (GTK_BOX (GTK_DIALOG(pDialogWnd)->vbox), pNotebook, TRUE, TRUE, 0); - - gtk_widget_show ( pNotebook ); - - gtk_widget_realize( pDialogWnd ); -} - -void ShowBackgroundDialog() -{ - gtk_window_present( GTK_WINDOW(pDialogWnd) ); -} - -void ShowBackgroundDialogPG(int page) -{ - gtk_notebook_set_current_page(GTK_NOTEBOOK(pNotebook),page); - ShowBackgroundDialog(); -} - +/* +Copyright (C) 2003 Reed Mideke. + +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 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 +*/ + +// +// bkgrnd2d Plugin dialog +// +// Code by reyalP aka Reed Mideke +// +// Based on various other plugins +// + +#include + +#include "bkgrnd2d.h" +#include "dialog.h" + +// spaces to make label nice and big +#define NO_FILE_MSG " (no file loaded) " + +static GtkWidget *pDialogWnd; +static GtkWidget *pNotebook; +static GtkTooltips *pTooltips; + +class CBackgroundDialogPage +{ +private: + GtkWidget *m_pWidget; + GtkWidget *m_pTabLabel; + GtkWidget *m_pFileLabel; + GtkWidget *m_pPosLabel; + VIEWTYPE m_vt; + bool m_bValidFile; + +public: + CBackgroundImage *m_pImage; + CBackgroundDialogPage( VIEWTYPE vt ); + void Append(GtkWidget *notebook); + void Browse(); + void Reload(); + void SetPosLabel(); +// ~BackgroundDialogPage(); +}; + + +// dialog page callbacks +static void browse_callback( GtkWidget *widget, gpointer data ) +{ + ((CBackgroundDialogPage *)data)->Browse(); +} + +static void reload_callback( GtkWidget *widget, gpointer data ) +{ + ((CBackgroundDialogPage *)data)->Reload(); +} + +static void size_sel_callback( GtkWidget *widget, gpointer data ) +{ + CBackgroundDialogPage *pPage = (CBackgroundDialogPage *)data; + if (pPage->m_pImage->SetExtentsSel()) + pPage->SetPosLabel(); +} + +static void size_mm_callback( GtkWidget *widget, gpointer data ) +{ + CBackgroundDialogPage *pPage = (CBackgroundDialogPage *)data; + if(pPage->m_pImage->SetExtentsMM()) + pPage->SetPosLabel(); +} + +static void alpha_adjust_callback( GtkWidget *widget, gpointer data ) +{ + CBackgroundDialogPage *pPage = (CBackgroundDialogPage *)data; + pPage->m_pImage->m_alpha = (float)gtk_range_get_value (GTK_RANGE(widget)); + g_FuncTable.m_pfnSysUpdateWindows(W_XY); +} + +void CBackgroundDialogPage::Reload() +{ + if(m_bValidFile) + m_pImage->Load(gtk_label_get_text(GTK_LABEL(m_pFileLabel))); +} + +void CBackgroundDialogPage::Browse() +{ + char browsedir[PATH_MAX]; + const char *ct; + const char *newfile; + char *t; + + //TODO GetMapName saves the map. eeep! + //also with no map, returns unnamed.map, otherwise returns full path +// Syn_Printf(MSG_PREFIX "GetMapName() %s\n", +// g_FuncTable.m_pfnGetMapName()); + + ct = g_FuncTable.m_pfnReadProjectKey("basepath"); + // TODO shouldn't need this stuff + if(!ct || !strlen(ct)) { + Syn_Printf(MSG_PREFIX "basepath = NULL or empty\n"); + return; + } + Syn_Printf(MSG_PREFIX "basepath: %s\n",ct); + if(strlen(ct) >= PATH_MAX) { + Syn_Printf(MSG_PREFIX "base game dir too long\n"); + return; + } + + strcpy(browsedir,ct); + // make sure we have a trailing / + if(browsedir[strlen(browsedir) - 1] != '/') + strcat(browsedir,"/"); + + //if we dont have a file yet, don't try to use it for default dir + if(m_bValidFile) { + // filename should always be a nice clean unix style relative path + ct = gtk_label_get_text(GTK_LABEL(m_pFileLabel)); + strcat(browsedir,ct); + Syn_Printf(MSG_PREFIX "full path: %s\n",browsedir); + + // lop off the file part + t = browsedir + strlen(browsedir) - 1; + while (t != browsedir && *t != '/') + t--; + *t = 0; + } + Syn_Printf(MSG_PREFIX "browse directory %s\n",browsedir); + +//does NOT need freeing contrary to include/qerplugin.h comments +//TODO bug/patch for comments +//TODO patern gets fucked up sometimes if empty +//http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=915 + newfile = g_FuncTable.m_pfnFileDialog(pDialogWnd,TRUE, + "Load Background Image",browsedir,FILETYPE_KEY); + if(!newfile) { + Syn_Printf(MSG_PREFIX "newfile = NULL\n"); + return; + } + Syn_Printf(MSG_PREFIX "newfile: %s\n",newfile); + newfile = g_FileSystemTable.m_pfnExtractRelativePath(newfile); + + if(!newfile) { + Syn_Printf(MSG_PREFIX "newfile = NULL\n"); + return; + } + Syn_Printf(MSG_PREFIX "newfile: %s\n",newfile); + + if(m_pImage->Load(newfile)) { + m_bValidFile = true; + gtk_label_set_text(GTK_LABEL(m_pFileLabel),newfile); + } +} + +void CBackgroundDialogPage::SetPosLabel() +{ + char s[64]; + // TODO no snprintf ? + sprintf(s, "Size/Position (%d,%d) (%d,%d)",(int)(m_pImage->m_xmin), + (int)(m_pImage->m_ymin),(int)(m_pImage->m_xmax),(int)(m_pImage->m_ymax)); + gtk_label_set_text(GTK_LABEL(m_pPosLabel),s); +} + +CBackgroundDialogPage::CBackgroundDialogPage(VIEWTYPE vt ) +{ + GtkWidget *frame; + GtkWidget *hbox; + GtkWidget *w; + + m_vt = vt; + + m_bValidFile = false; + + switch(m_vt) + { + case XY: + m_pTabLabel = gtk_label_new("X/Y"); + m_pImage = &backgroundXY; + break; + case XZ: + m_pTabLabel = gtk_label_new("X/Z"); + m_pImage = &backgroundXZ; + break; + case YZ: + m_pTabLabel = gtk_label_new("Y/Z"); + m_pImage = &backgroundYZ; + break; + } +// A vbox to hold everything + m_pWidget = gtk_vbox_new(FALSE,0); +// Frame for file row + frame = gtk_frame_new("File"); + gtk_box_pack_start (GTK_BOX (m_pWidget),frame, FALSE, FALSE, 2); + +// hbox for first row + hbox = gtk_hbox_new(FALSE,5); + gtk_container_set_border_width(GTK_CONTAINER (hbox),4); + gtk_container_add (GTK_CONTAINER (frame), hbox); + +// label to display filename + m_pFileLabel = gtk_label_new(NO_FILE_MSG); + gtk_label_set_selectable(GTK_LABEL(m_pFileLabel),TRUE); +//TODO set min size ? done with spaces right now + gtk_box_pack_start (GTK_BOX (hbox),m_pFileLabel, TRUE, TRUE, 5); + + gtk_widget_show (m_pFileLabel); + + w = gtk_button_new_with_label ("Browse..."); + g_signal_connect (G_OBJECT (w), "clicked", G_CALLBACK (browse_callback), + (gpointer)this); + gtk_box_pack_start (GTK_BOX (hbox),w, FALSE, FALSE, 5); + gtk_tooltips_set_tip (pTooltips, w, "Select a file", NULL); + gtk_widget_show (w); + + w = gtk_button_new_with_label ("Reload"); + g_signal_connect (G_OBJECT (w), "clicked", G_CALLBACK (reload_callback), + (gpointer)this); + // TODO disable until we have file + // gtk_widget_set_sensitive(w,FALSE); + gtk_tooltips_set_tip (pTooltips, w, "Reload current file", NULL); + gtk_box_pack_start (GTK_BOX (hbox),w, FALSE, FALSE, 5); + gtk_widget_show (w); + + gtk_widget_show (hbox); + gtk_widget_show (frame); + +// second row (rendering options) + frame = gtk_frame_new("Rendering"); + gtk_box_pack_start (GTK_BOX (m_pWidget),frame, FALSE, FALSE, 2); + + hbox = gtk_hbox_new(FALSE,5); + gtk_container_set_border_width(GTK_CONTAINER (hbox),4); + gtk_container_add (GTK_CONTAINER (frame), hbox); + + w = gtk_label_new("Vertex alpha:"); + gtk_box_pack_start (GTK_BOX (hbox),w, FALSE, FALSE, 5); + gtk_widget_show (w); + + w = gtk_hscale_new_with_range(0.0,1.0,0.01); + gtk_range_set_value(GTK_RANGE(w),0.5); + gtk_scale_set_value_pos(GTK_SCALE(w),GTK_POS_LEFT); + g_signal_connect (G_OBJECT (w), "value-changed", + G_CALLBACK (alpha_adjust_callback), (gpointer)this); + gtk_box_pack_start (GTK_BOX (hbox),w, TRUE, TRUE, 5); + gtk_tooltips_set_tip (pTooltips, w, "Set image transparancy", NULL); + gtk_widget_show (w); + + gtk_widget_show (hbox); + gtk_widget_show (frame); +// Third row (size and position) + frame = gtk_frame_new("Size/Position (undefined)"); + m_pPosLabel = gtk_frame_get_label_widget (GTK_FRAME(frame)); + gtk_box_pack_start ( GTK_BOX (m_pWidget), frame, FALSE, FALSE, 2); + + hbox = gtk_hbox_new(FALSE,5); + gtk_container_add (GTK_CONTAINER (frame), hbox); + gtk_container_set_border_width(GTK_CONTAINER (hbox),4); + + w = gtk_button_new_with_label ("from selection"); + gtk_box_pack_start (GTK_BOX (hbox),w, TRUE, FALSE, 5); + g_signal_connect (G_OBJECT (w), "clicked", G_CALLBACK (size_sel_callback), + (gpointer)this); + gtk_tooltips_set_tip (pTooltips, w, "Set the size of the image to the bounding rectangle of all selected brushes and entities", NULL); + gtk_widget_show (w); + + if(m_vt == XY) { + w = gtk_button_new_with_label ("from map mins/maxs"); + gtk_box_pack_start ( GTK_BOX (hbox),w, TRUE, FALSE, 2); + g_signal_connect (G_OBJECT (w), "clicked", G_CALLBACK (size_mm_callback), + (gpointer)this); + gtk_tooltips_set_tip (pTooltips, w, "Set the size of the image using the mapcoordsmins and mapcoordsmaxs keys of the worldspawn entity", NULL); + gtk_widget_show (w); + } + + gtk_widget_show (hbox); + gtk_widget_show (frame); + + gtk_widget_show ( m_pWidget ); +} + +void CBackgroundDialogPage::Append(GtkWidget *notebook) +{ + gtk_notebook_append_page( GTK_NOTEBOOK(notebook), m_pWidget, m_pTabLabel); +} + +// dialog global callbacks +/* +static gint expose_callback( GtkWidget *widget, gpointer data ) +{ + return FALSE; +} +*/ + +static void response_callback( GtkWidget *widget, gint response, gpointer data ) +{ + if( response == GTK_RESPONSE_CLOSE ) + gtk_widget_hide( pDialogWnd ); +} + +static gint close_callback( GtkWidget *widget, gpointer data ) +{ + gtk_widget_hide( pDialogWnd ); + return TRUE; +} + +void InitBackgroundDialog() +{ + CBackgroundDialogPage *pPage; + + pDialogWnd = gtk_dialog_new_with_buttons ("Background Images", + GTK_WINDOW(g_pMainWidget), + (GtkDialogFlags)(GTK_DIALOG_DESTROY_WITH_PARENT), + // TODO dialog with no buttons + // GTK_STOCK_CLOSE, + // GTK_RESPONSE_CLOSE, + NULL); + gtk_signal_connect( GTK_OBJECT (pDialogWnd), "delete_event", + GTK_SIGNAL_FUNC( close_callback ), NULL ); + gtk_signal_connect( GTK_OBJECT (pDialogWnd), "response", + GTK_SIGNAL_FUNC( response_callback ), NULL ); +// gtk_signal_connect( GTK_OBJECT (pDialogWnd), "expose_event", GTK_SIGNAL_FUNC( ci_expose ), NULL ); + + pTooltips = gtk_tooltips_new(); + + pNotebook = gtk_notebook_new(); + pPage = new CBackgroundDialogPage(XY); + pPage->Append(pNotebook); + pPage = new CBackgroundDialogPage(XZ); + pPage->Append(pNotebook); + pPage = new CBackgroundDialogPage(YZ); + pPage->Append(pNotebook); + + gtk_box_pack_start (GTK_BOX (GTK_DIALOG(pDialogWnd)->vbox), pNotebook, TRUE, TRUE, 0); + + gtk_widget_show ( pNotebook ); + + gtk_widget_realize( pDialogWnd ); +} + +void ShowBackgroundDialog() +{ + gtk_window_present( GTK_WINDOW(pDialogWnd) ); +} + +void ShowBackgroundDialogPG(int page) +{ + gtk_notebook_set_current_page(GTK_NOTEBOOK(pNotebook),page); + ShowBackgroundDialog(); +} + diff --git a/contrib/bkgrnd2d/plugin.cpp b/contrib/bkgrnd2d/plugin.cpp index ce27430..09e9ed7 100644 --- a/contrib/bkgrnd2d/plugin.cpp +++ b/contrib/bkgrnd2d/plugin.cpp @@ -1,319 +1,319 @@ -/* -Copyright (C) 2003 Reed Mideke. - -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 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 -*/ - -// -// 2d background Plugin -// -// Code by reyalP aka Reed Mideke -// -// Based on -// - -/* - Overview - ======== - This little plugin allows you to display an image in the background of the - gtkradiant XY window. - - Version History - =============== - - v0.1 - - Initial version. - v0.2 - - three views, dialog box, toolbar - v0.25 - - tooltips, follow gtkradiant coding conventions - - Why ? - ----- - http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=88 - - - How ? - ----- - - textures 'n widgets 'n stuff. -*/ - -//#include "plugin.h" -//TODO we just poke the objects directly -#include "bkgrnd2d.h" -#include "dialog.h" - -#define CMD_SEP "-" -#define CMD_CONFIG "Configure..." -#define CMD_ABOUT "About..." -// ============================================================================= -// Globals - -// function tables -_QERFuncTable_1 g_FuncTable; -_QERQglTable g_QglTable; -_QERFileSystemTable g_FileSystemTable; -_QEREntityTable g_EntityTable; -_QERAppDataTable g_DataTable; - -// for the file load dialog -void *g_pMainWidget; - -// ============================================================================= -// plugin implementation - -static const char *PLUGIN_NAME = "2d window background plugin"; - -//backwards for some reason -static const char *PLUGIN_COMMANDS = CMD_ABOUT ";" - CMD_SEP ";" - CMD_CONFIG - ; - -static const char *PLUGIN_ABOUT = "2d window background v0.25\n\n" - "By reyalP (hellsownpuppy@yahoo.com)"; - - - - -void DoBkgrndToggleXY(); -void DoBkgrndToggleXZ(); -void DoBkgrndToggleYZ(); - -#define NUM_TOOLBAR_BUTTONS 4 -struct toolbar_button_info_s -{ - char *image; - char *text; - char *tip; - void (*func)(); - IToolbarButton::EType type; -}; - -struct toolbar_button_info_s toolbar_buttons[NUM_TOOLBAR_BUTTONS] = -{ - { - "bkgrnd2d_xy_toggle.bmp", - "xy background", - "Toggle xy background image", - DoBkgrndToggleXY, - IToolbarButton::eToggleButton - }, - { - "bkgrnd2d_xz_toggle.bmp", - "xz background", - "Toggle xz background image", - DoBkgrndToggleXZ, - IToolbarButton::eToggleButton - }, - { - "bkgrnd2d_yz_toggle.bmp", - "yz background", - "Toggle yz background image", - DoBkgrndToggleYZ, - IToolbarButton::eToggleButton - }, - { - "bkgrnd2d_conf.bmp", - "Configure", - "Configure background images", - ShowBackgroundDialog, - IToolbarButton::eButton - }, -}; - -class Bkgrnd2dButton : public IToolbarButton -{ -public: - const toolbar_button_info_s *bi; - virtual const char* getImage() const - { - return bi->image; - } - virtual const char* getText() const - { - return bi->text; - } - virtual const char* getTooltip() const - { - return bi->tip; - } - virtual void activate() const - { - bi->func(); - return ; - } - virtual EType getType() const - { - return bi->type; - } -}; - -Bkgrnd2dButton g_bkgrnd2dbuttons[NUM_TOOLBAR_BUTTONS]; - -unsigned int ToolbarButtonCount() -{ - return NUM_TOOLBAR_BUTTONS; -} - -const IToolbarButton* GetToolbarButton(unsigned int index) -{ - g_bkgrnd2dbuttons[index].bi = &toolbar_buttons[index]; - return &g_bkgrnd2dbuttons[index]; -} - -extern "C" const char* QERPlug_Init (void *hApp, void* pMainWidget) -{ - g_pMainWidget = pMainWidget; - - InitBackgroundDialog(); - render.Register(); - -//TODO is it right ? is it wrong ? it works -//TODO figure out supported image types - GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("all files", "*.*")); - GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("jpeg files", "*.jpg")); - GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("targa files", "*.tga")); - return (char *) PLUGIN_NAME; -} - -extern "C" const char* QERPlug_GetName () -{ - return (char *) PLUGIN_NAME; -} - -extern "C" const char* QERPlug_GetCommandList () -{ - return (char *) PLUGIN_COMMANDS; -} - -extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush) -{ - Sys_Printf (MSG_PREFIX "Command \"%s\"\n",p); - if(!strcmp(p, CMD_ABOUT)) { - g_FuncTable.m_pfnMessageBox(NULL, PLUGIN_ABOUT, "About", MB_OK, NULL); - } - else if(!strcmp(p,CMD_CONFIG)) { - ShowBackgroundDialog(); - } -} - -//TODO these three suck -void DoBkgrndToggleXY() -{ - Sys_Printf (MSG_PREFIX "DoBkgrndToggleXY\n"); - // always toggle, since the buttons do - backgroundXY.m_bActive = (backgroundXY.m_bActive) ? false:true; - // if we don't have image or extents, and we activated, - // bring up the dialog with the corresponding page - // would be better to hide or grey out button, but we can't - if(backgroundXY.m_bActive && !backgroundXY.Valid()) - ShowBackgroundDialogPG(0); - else - g_FuncTable.m_pfnSysUpdateWindows(W_XY); -} - -void DoBkgrndToggleXZ() -{ - Sys_Printf (MSG_PREFIX "DoBkgrndToggleXZ\n"); - backgroundXZ.m_bActive = (backgroundXZ.m_bActive) ? false:true; - if(backgroundXZ.m_bActive && !backgroundXZ.Valid()) - ShowBackgroundDialogPG(1); - else - g_FuncTable.m_pfnSysUpdateWindows(W_XY); -} - -void DoBkgrndToggleYZ() -{ - Sys_Printf (MSG_PREFIX "DoBkgrndToggleYZ\n"); - backgroundYZ.m_bActive = (backgroundYZ.m_bActive) ? false:true; - if(backgroundYZ.m_bActive && !backgroundYZ.Valid()) - ShowBackgroundDialogPG(2); - else - g_FuncTable.m_pfnSysUpdateWindows(W_XY); -} - -// ============================================================================= -// SYNAPSE - -CSynapseServer* g_pSynapseServer = NULL; -CSynapseClientBkgrnd2d g_SynapseClient; - -extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces (const char *version, CSynapseServer *pServer) -{ - if (strcmp(version, SYNAPSE_VERSION)) - { - Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version); - return NULL; - } - g_pSynapseServer = pServer; - g_pSynapseServer->IncRef(); - Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf()); - - g_SynapseClient.AddAPI(TOOLBAR_MAJOR, BKGRND2D_MINOR, sizeof(_QERPlugToolbarTable)); - g_SynapseClient.AddAPI(PLUGIN_MAJOR, BKGRND2D_MINOR, sizeof( _QERPluginTable ) ); - - g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( g_FuncTable ), SYN_REQUIRE, &g_FuncTable ); - g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( g_QglTable ), SYN_REQUIRE, &g_QglTable ); -// TODO is this the right way to ask for 'whichever VFS we have loaded' ? Seems to work -// for misc filename functions - g_SynapseClient.AddAPI( VFS_MAJOR, "*", sizeof( g_FileSystemTable ), SYN_REQUIRE, &g_FileSystemTable ); -// get worldspawn - g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( g_EntityTable ), SYN_REQUIRE, &g_EntityTable ); -// selected brushes - g_SynapseClient.AddAPI( DATA_MAJOR, NULL, sizeof( g_DataTable ), SYN_REQUIRE, &g_DataTable ); - - return &g_SynapseClient; -} - -bool CSynapseClientBkgrnd2d::RequestAPI(APIDescriptor_t *pAPI) -{ - if (!strcmp(pAPI->major_name, PLUGIN_MAJOR)) - { - _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable); - - pTable->m_pfnQERPlug_Init = QERPlug_Init; - pTable->m_pfnQERPlug_GetName = QERPlug_GetName; - pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList; - pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch; - return true; - } - if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR)) - { - _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable); - - pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount; - pTable->m_pfnGetToolbarButton = &GetToolbarButton; - return true; - } - - Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo()); - return false; -} - -#include "version.h" - -const char* CSynapseClientBkgrnd2d::GetInfo() -{ - return "2d Background plugin built " __DATE__ " " RADIANT_VERSION; -} - -const char* CSynapseClientBkgrnd2d::GetName() -{ - return "bkgrnd2d"; -} - +/* +Copyright (C) 2003 Reed Mideke. + +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 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 +*/ + +// +// 2d background Plugin +// +// Code by reyalP aka Reed Mideke +// +// Based on +// + +/* + Overview + ======== + This little plugin allows you to display an image in the background of the + gtkradiant XY window. + + Version History + =============== + + v0.1 + - Initial version. + v0.2 + - three views, dialog box, toolbar + v0.25 + - tooltips, follow gtkradiant coding conventions + + Why ? + ----- + http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=88 + + + How ? + ----- + - textures 'n widgets 'n stuff. +*/ + +//#include "plugin.h" +//TODO we just poke the objects directly +#include "bkgrnd2d.h" +#include "dialog.h" + +#define CMD_SEP "-" +#define CMD_CONFIG "Configure..." +#define CMD_ABOUT "About..." +// ============================================================================= +// Globals + +// function tables +_QERFuncTable_1 g_FuncTable; +_QERQglTable g_QglTable; +_QERFileSystemTable g_FileSystemTable; +_QEREntityTable g_EntityTable; +_QERAppDataTable g_DataTable; + +// for the file load dialog +void *g_pMainWidget; + +// ============================================================================= +// plugin implementation + +static const char *PLUGIN_NAME = "2d window background plugin"; + +//backwards for some reason +static const char *PLUGIN_COMMANDS = CMD_ABOUT ";" + CMD_SEP ";" + CMD_CONFIG + ; + +static const char *PLUGIN_ABOUT = "2d window background v0.25\n\n" + "By reyalP (hellsownpuppy@yahoo.com)"; + + + + +void DoBkgrndToggleXY(); +void DoBkgrndToggleXZ(); +void DoBkgrndToggleYZ(); + +#define NUM_TOOLBAR_BUTTONS 4 +struct toolbar_button_info_s +{ + char *image; + char *text; + char *tip; + void (*func)(); + IToolbarButton::EType type; +}; + +struct toolbar_button_info_s toolbar_buttons[NUM_TOOLBAR_BUTTONS] = +{ + { + "bkgrnd2d_xy_toggle.bmp", + "xy background", + "Toggle xy background image", + DoBkgrndToggleXY, + IToolbarButton::eToggleButton + }, + { + "bkgrnd2d_xz_toggle.bmp", + "xz background", + "Toggle xz background image", + DoBkgrndToggleXZ, + IToolbarButton::eToggleButton + }, + { + "bkgrnd2d_yz_toggle.bmp", + "yz background", + "Toggle yz background image", + DoBkgrndToggleYZ, + IToolbarButton::eToggleButton + }, + { + "bkgrnd2d_conf.bmp", + "Configure", + "Configure background images", + ShowBackgroundDialog, + IToolbarButton::eButton + }, +}; + +class Bkgrnd2dButton : public IToolbarButton +{ +public: + const toolbar_button_info_s *bi; + virtual const char* getImage() const + { + return bi->image; + } + virtual const char* getText() const + { + return bi->text; + } + virtual const char* getTooltip() const + { + return bi->tip; + } + virtual void activate() const + { + bi->func(); + return ; + } + virtual EType getType() const + { + return bi->type; + } +}; + +Bkgrnd2dButton g_bkgrnd2dbuttons[NUM_TOOLBAR_BUTTONS]; + +unsigned int ToolbarButtonCount() +{ + return NUM_TOOLBAR_BUTTONS; +} + +const IToolbarButton* GetToolbarButton(unsigned int index) +{ + g_bkgrnd2dbuttons[index].bi = &toolbar_buttons[index]; + return &g_bkgrnd2dbuttons[index]; +} + +extern "C" const char* QERPlug_Init (void *hApp, void* pMainWidget) +{ + g_pMainWidget = pMainWidget; + + InitBackgroundDialog(); + render.Register(); + +//TODO is it right ? is it wrong ? it works +//TODO figure out supported image types + GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("all files", "*.*")); + GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("jpeg files", "*.jpg")); + GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("targa files", "*.tga")); + return (char *) PLUGIN_NAME; +} + +extern "C" const char* QERPlug_GetName () +{ + return (char *) PLUGIN_NAME; +} + +extern "C" const char* QERPlug_GetCommandList () +{ + return (char *) PLUGIN_COMMANDS; +} + +extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush) +{ + Sys_Printf (MSG_PREFIX "Command \"%s\"\n",p); + if(!strcmp(p, CMD_ABOUT)) { + g_FuncTable.m_pfnMessageBox(NULL, PLUGIN_ABOUT, "About", MB_OK, NULL); + } + else if(!strcmp(p,CMD_CONFIG)) { + ShowBackgroundDialog(); + } +} + +//TODO these three suck +void DoBkgrndToggleXY() +{ + Sys_Printf (MSG_PREFIX "DoBkgrndToggleXY\n"); + // always toggle, since the buttons do + backgroundXY.m_bActive = (backgroundXY.m_bActive) ? false:true; + // if we don't have image or extents, and we activated, + // bring up the dialog with the corresponding page + // would be better to hide or grey out button, but we can't + if(backgroundXY.m_bActive && !backgroundXY.Valid()) + ShowBackgroundDialogPG(0); + else + g_FuncTable.m_pfnSysUpdateWindows(W_XY); +} + +void DoBkgrndToggleXZ() +{ + Sys_Printf (MSG_PREFIX "DoBkgrndToggleXZ\n"); + backgroundXZ.m_bActive = (backgroundXZ.m_bActive) ? false:true; + if(backgroundXZ.m_bActive && !backgroundXZ.Valid()) + ShowBackgroundDialogPG(1); + else + g_FuncTable.m_pfnSysUpdateWindows(W_XY); +} + +void DoBkgrndToggleYZ() +{ + Sys_Printf (MSG_PREFIX "DoBkgrndToggleYZ\n"); + backgroundYZ.m_bActive = (backgroundYZ.m_bActive) ? false:true; + if(backgroundYZ.m_bActive && !backgroundYZ.Valid()) + ShowBackgroundDialogPG(2); + else + g_FuncTable.m_pfnSysUpdateWindows(W_XY); +} + +// ============================================================================= +// SYNAPSE + +CSynapseServer* g_pSynapseServer = NULL; +CSynapseClientBkgrnd2d g_SynapseClient; + +extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces (const char *version, CSynapseServer *pServer) +{ + if (strcmp(version, SYNAPSE_VERSION)) + { + Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version); + return NULL; + } + g_pSynapseServer = pServer; + g_pSynapseServer->IncRef(); + Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf()); + + g_SynapseClient.AddAPI(TOOLBAR_MAJOR, BKGRND2D_MINOR, sizeof(_QERPlugToolbarTable)); + g_SynapseClient.AddAPI(PLUGIN_MAJOR, BKGRND2D_MINOR, sizeof( _QERPluginTable ) ); + + g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( g_FuncTable ), SYN_REQUIRE, &g_FuncTable ); + g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( g_QglTable ), SYN_REQUIRE, &g_QglTable ); +// TODO is this the right way to ask for 'whichever VFS we have loaded' ? Seems to work +// for misc filename functions + g_SynapseClient.AddAPI( VFS_MAJOR, "*", sizeof( g_FileSystemTable ), SYN_REQUIRE, &g_FileSystemTable ); +// get worldspawn + g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( g_EntityTable ), SYN_REQUIRE, &g_EntityTable ); +// selected brushes + g_SynapseClient.AddAPI( DATA_MAJOR, NULL, sizeof( g_DataTable ), SYN_REQUIRE, &g_DataTable ); + + return &g_SynapseClient; +} + +bool CSynapseClientBkgrnd2d::RequestAPI(APIDescriptor_t *pAPI) +{ + if (!strcmp(pAPI->major_name, PLUGIN_MAJOR)) + { + _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable); + + pTable->m_pfnQERPlug_Init = QERPlug_Init; + pTable->m_pfnQERPlug_GetName = QERPlug_GetName; + pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList; + pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch; + return true; + } + if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR)) + { + _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable); + + pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount; + pTable->m_pfnGetToolbarButton = &GetToolbarButton; + return true; + } + + Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo()); + return false; +} + +#include "version.h" + +const char* CSynapseClientBkgrnd2d::GetInfo() +{ + return "2d Background plugin built " __DATE__ " " RADIANT_VERSION; +} + +const char* CSynapseClientBkgrnd2d::GetName() +{ + return "bkgrnd2d"; +} + diff --git a/libs/container/stack.cpp b/libs/container/stack.cpp index d9f62e1..3a7c7ce 100644 --- a/libs/container/stack.cpp +++ b/libs/container/stack.cpp @@ -1,23 +1,23 @@ -/* -Copyright (C) 2001-2006, William Joseph. -All Rights Reserved. - -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 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 -*/ - -#include "stack.h" - +/* +Copyright (C) 2001-2006, William Joseph. +All Rights Reserved. + +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 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 +*/ + +#include "stack.h" +