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
|
|
|
|
|
|
|
//
|
|
|
|
// 2d background Plugin
|
|
|
|
//
|
|
|
|
// Code by reyalP aka Reed Mideke
|
|
|
|
//
|
2008-06-27 15:09:36 +00:00
|
|
|
// Based on
|
2007-11-04 03:51:54 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
/*
|
|
|
|
Overview
|
|
|
|
========
|
2012-03-17 20:01:54 +00:00
|
|
|
This little plugin allows you to display an image in the background of the
|
|
|
|
gtkradiant XY window.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
Version History
|
|
|
|
===============
|
|
|
|
|
|
|
|
v0.1
|
|
|
|
- Initial version.
|
2012-03-17 20:01:54 +00:00
|
|
|
v0.2
|
|
|
|
- three views, dialog box, toolbar
|
2007-11-04 03:51:54 +00:00
|
|
|
v0.25
|
|
|
|
- tooltips, follow gtkradiant coding conventions
|
|
|
|
|
|
|
|
How ?
|
|
|
|
-----
|
|
|
|
- textures 'n widgets 'n stuff.
|
2012-03-17 20:01:54 +00:00
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
//#include "plugin.h"
|
|
|
|
//TODO we just poke the objects directly
|
|
|
|
#include "bkgrnd2d.h"
|
|
|
|
#include "dialog.h"
|
|
|
|
|
2008-06-27 15:09:36 +00:00
|
|
|
#define CMD_SEP "-"
|
2007-11-04 03:51:54 +00:00
|
|
|
#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
|
2008-06-27 15:09:36 +00:00
|
|
|
static const char *PLUGIN_COMMANDS = CMD_ABOUT ";"
|
2012-03-17 20:01:54 +00:00
|
|
|
CMD_SEP ";"
|
|
|
|
CMD_CONFIG
|
|
|
|
;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
static const char *PLUGIN_ABOUT = "2d window background v0.25\n\n"
|
2012-03-17 20:01:54 +00:00
|
|
|
"By reyalP (hellsownpuppy@yahoo.com)";
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DoBkgrndToggleXY();
|
|
|
|
void DoBkgrndToggleXZ();
|
|
|
|
void DoBkgrndToggleYZ();
|
|
|
|
|
|
|
|
#define NUM_TOOLBAR_BUTTONS 4
|
|
|
|
struct toolbar_button_info_s
|
|
|
|
{
|
2008-09-06 08:35:17 +00:00
|
|
|
const char *image;
|
|
|
|
const char *text;
|
|
|
|
const char *tip;
|
2012-03-17 20:01:54 +00:00
|
|
|
void ( *func )();
|
2007-11-04 03:51:54 +00:00
|
|
|
IToolbarButton::EType type;
|
|
|
|
};
|
|
|
|
|
2008-06-27 15:09:36 +00:00
|
|
|
struct toolbar_button_info_s toolbar_buttons[NUM_TOOLBAR_BUTTONS] =
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
{
|
|
|
|
"bkgrnd2d_xy_toggle.bmp",
|
|
|
|
"xy background",
|
2012-03-17 20:01:54 +00:00
|
|
|
"Toggle xy background image",
|
2007-11-04 03:51:54 +00:00
|
|
|
DoBkgrndToggleXY,
|
|
|
|
IToolbarButton::eToggleButton
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"bkgrnd2d_xz_toggle.bmp",
|
|
|
|
"xz background",
|
2012-03-17 20:01:54 +00:00
|
|
|
"Toggle xz background image",
|
2007-11-04 03:51:54 +00:00
|
|
|
DoBkgrndToggleXZ,
|
|
|
|
IToolbarButton::eToggleButton
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"bkgrnd2d_yz_toggle.bmp",
|
|
|
|
"yz background",
|
2012-03-17 20:01:54 +00:00
|
|
|
"Toggle yz background image",
|
2007-11-04 03:51:54 +00:00
|
|
|
DoBkgrndToggleYZ,
|
|
|
|
IToolbarButton::eToggleButton
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"bkgrnd2d_conf.bmp",
|
|
|
|
"Configure",
|
2012-03-17 20:01:54 +00:00
|
|
|
"Configure background images",
|
2007-11-04 03:51:54 +00:00
|
|
|
ShowBackgroundDialog,
|
|
|
|
IToolbarButton::eButton
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
class Bkgrnd2dButton : public IToolbarButton
|
|
|
|
{
|
|
|
|
public:
|
2012-03-17 20:01:54 +00:00
|
|
|
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;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Bkgrnd2dButton g_bkgrnd2dbuttons[NUM_TOOLBAR_BUTTONS];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
unsigned int ToolbarButtonCount(){
|
|
|
|
return NUM_TOOLBAR_BUTTONS;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
const IToolbarButton* GetToolbarButton( unsigned int index ){
|
|
|
|
g_bkgrnd2dbuttons[index].bi = &toolbar_buttons[index];
|
|
|
|
return &g_bkgrnd2dbuttons[index];
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
extern "C" const char* QERPlug_Init( void *hApp, void* pMainWidget ){
|
|
|
|
g_pMainWidget = pMainWidget;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
InitBackgroundDialog();
|
|
|
|
render.Register();
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
//TODO is it right ? is it wrong ? it works
|
|
|
|
//TODO figure out supported image types
|
2012-03-17 20:01:54 +00:00
|
|
|
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;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
extern "C" const char* QERPlug_GetName(){
|
|
|
|
return (char *) PLUGIN_NAME;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
extern "C" const char* QERPlug_GetCommandList(){
|
|
|
|
return (char *) PLUGIN_COMMANDS;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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();
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO these three suck
|
2012-03-17 20:01:54 +00:00
|
|
|
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 );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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 );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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 );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
// SYNAPSE
|
|
|
|
|
|
|
|
CSynapseServer* g_pSynapseServer = NULL;
|
|
|
|
CSynapseClientBkgrnd2d g_SynapseClient;
|
2008-06-27 15:09:36 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
#if __GNUC__ >= 4
|
|
|
|
#pragma GCC visibility push(default)
|
|
|
|
#endif
|
2012-03-17 20:01:54 +00:00
|
|
|
extern "C" CSynapseClient * SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
#if __GNUC__ >= 4
|
|
|
|
#pragma GCC visibility pop
|
|
|
|
#endif
|
2012-03-17 20:01:54 +00:00
|
|
|
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 );
|
2007-11-04 03:51:54 +00:00
|
|
|
// TODO is this the right way to ask for 'whichever VFS we have loaded' ? Seems to work
|
|
|
|
// for misc filename functions
|
2012-03-17 20:01:54 +00:00
|
|
|
g_SynapseClient.AddAPI( VFS_MAJOR, "*", sizeof( g_FileSystemTable ), SYN_REQUIRE, &g_FileSystemTable );
|
2007-11-04 03:51:54 +00:00
|
|
|
// get worldspawn
|
2012-03-17 20:01:54 +00:00
|
|
|
g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( g_EntityTable ), SYN_REQUIRE, &g_EntityTable );
|
2007-11-04 03:51:54 +00:00
|
|
|
// selected brushes
|
2012-03-17 20:01:54 +00:00
|
|
|
g_SynapseClient.AddAPI( DATA_MAJOR, NULL, sizeof( g_DataTable ), SYN_REQUIRE, &g_DataTable );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return &g_SynapseClient;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "version.h"
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
const char* CSynapseClientBkgrnd2d::GetInfo(){
|
|
|
|
return "2d Background plugin built " __DATE__ " " RADIANT_VERSION;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
const char* CSynapseClientBkgrnd2d::GetName(){
|
|
|
|
return "bkgrnd2d";
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|