Files
test/source/blender/src/header_script.c

280 lines
7.3 KiB
C
Raw Normal View History

/**
* header_script.c nov-2003
*
* Functions to draw the "Script Window" window header
* and handle user events sent to it.
*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* Contributor(s): Willian P. Germano.
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "BLI_blenlib.h"
#include "BSE_headerbuttons.h"
#include "DNA_ID.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "BIF_interface.h"
#include "BIF_resources.h"
#include "BIF_screen.h"
#include "BIF_space.h"
#include "BIF_toolbox.h"
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_sca.h"
#include "BSE_filesel.h"
#include "BPY_extern.h"
#include "BPY_menus.h"
#include "blendef.h"
#include "mydevice.h"
#include "BLO_sys_types.h" // for intptr_t support
/* ********************** SCRIPT ****************************** */
/* action executed after clicking in Scripts menu */
static void do_scripts_submenus(void *int_arg, int event)
{
int menutype = (intptr_t)int_arg;
BPY_menu_do_python (menutype, event);
//allqueue(REDRAWSCRIPT, 0);
}
static uiBlock *script_scripts_submenus(void *int_menutype)
{
uiBlock *block;
short yco = 20, menuwidth = 120;
BPyMenu *pym;
int i = 0, menutype = (intptr_t)int_menutype;
BPython: - Scripts: fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus. cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu). small updates to help_browser.py script. The above changes are related to this: - Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there. - Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ). - Modules: Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode. NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work). - Bugs fixed: #2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9 Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does. #1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9 Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script"). Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython. - Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
if ((menutype < 0) || (menutype > PYMENU_SCRIPTS_MENU_TOTAL))
return NULL;
block= uiNewBlock(&curarea->uiblocks, "scriptsscriptssubmenus", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
uiBlockSetButmFunc(block, do_scripts_submenus, int_menutype);
for (pym = BPyMenuTable[menutype]; pym; pym = pym->next, i++) {
uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i, pym->tooltip?pym->tooltip:pym->filename);
}
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
uiBlockSetDirection(block, UI_RIGHT);
uiTextBoundsBlock(block, 60);
return block;
}
static void do_script_scriptsmenu(void *arg, int event)
{
ScrArea *sa;
if(curarea->spacetype==SPACE_INFO) {
sa= closest_bigger_area();
areawinset(sa->win);
}
/* these are no defines, easier this way, the codes are in the function below */
switch(event) {
case 0: /* update menus */
if (BPY_path_update()==0) {
error("Invalid scripts dir: check console");
}
break;
}
// allqueue(REDRAWSCRIPT, 0);
}
/* Scripts menu */
static uiBlock *script_scriptsmenu(void *arg_unused)
{
uiBlock *block;
short yco = 0, menuwidth = 120;
int i;
block= uiNewBlock(&curarea->uiblocks, "script_scriptsmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
uiBlockSetButmFunc(block, do_script_scriptsmenu, NULL);
BPython: - Scripts: fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus. cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu). small updates to help_browser.py script. The above changes are related to this: - Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there. - Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ). - Modules: Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode. NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work). - Bugs fixed: #2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9 Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does. #1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9 Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script"). Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython. - Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
for (i = 0; i < PYMENU_SCRIPTS_MENU_TOTAL; i++) {
uiDefIconTextBlockBut(block, script_scripts_submenus, (void *)(intptr_t)i, ICON_RIGHTARROW_THIN, BPyMenu_group_itoa(i), 0, yco-=20, menuwidth, 19, "");
}
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
BPython: - Scripts: fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus. cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu). small updates to help_browser.py script. The above changes are related to this: - Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there. - Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ). - Modules: Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode. NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work). - Bugs fixed: #2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9 Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does. #1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9 Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script"). Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython. - Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Update Menus", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "Use when a scripts folder or its contents are modified");
if(curarea->headertype==HEADERTOP) {
uiBlockSetDirection(block, UI_DOWN);
}
else {
uiBlockSetDirection(block, UI_TOP);
uiBlockFlipOrder(block);
}
uiTextBoundsBlock(block, 50);
return block;
}
void do_script_buttons(unsigned short event)
{
SpaceScript *sc= curarea->spacedata.first;
ID *id, *idtest;
int nr= 1;
Script *script = sc->script;
if (!sc) return;
if (sc->spacetype != SPACE_SCRIPT) return;
switch (event) {
case B_SCRIPTBROWSE:
if (sc->menunr==-2) {
activate_databrowse((ID *)script, ID_SCR, 0, B_SCRIPTBROWSE,
&sc->menunr, do_script_buttons);
break;
}
if(sc->menunr < 0) break;
nr = 1;
id = (ID *)script;
idtest= G.main->script.first;
while(idtest) {
if(nr==sc->menunr) {
break;
}
nr++;
idtest= idtest->next;
}
if(idtest!=id) {
sc->script= (Script *)idtest;
allqueue(REDRAWSCRIPT, 0);
allqueue(REDRAWHEADERS, 0);
}
break;
case B_SCRIPT2PREV:
if(sc->next) {
BLI_remlink(&curarea->spacedata, sc);
BLI_addtail(&curarea->spacedata, sc);
sc = curarea->spacedata.first;
newspace(curarea, sc->spacetype);
}
break;
}
return;
}
void script_buttons(void)
{
uiBlock *block;
SpaceScript *sc= curarea->spacedata.first;
short xco = 8, xmax;
char naam[256];
if (!sc || sc->spacetype != SPACE_SCRIPT) return;
sprintf(naam, "header %d", curarea->headwin);
block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->headwin);
if(area_is_active_area(curarea)) uiBlockSetCol(block, TH_HEADER);
else uiBlockSetCol(block, TH_HEADERDESEL);
curarea->butspacetype= SPACE_SCRIPT;
uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D,
windowtype_pup(), xco,0,XIC+10,YIC, &(curarea->butspacetype), 1.0,
SPACEICONMAX, 0, 0, "Displays Current Window Type. Click for menu"
" of available types.");
xco += XIC+14;
uiBlockSetEmboss(block, UI_EMBOSSN);
if(curarea->flag & HEADER_NO_PULLDOWN) {
uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_RIGHT,
xco,2,XIC,YIC-2,
&(curarea->flag), 0, 0, 0, 0, "Enables display of pulldown menus");
} else {
uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, ICON_DISCLOSURE_TRI_DOWN,
xco,2,XIC,YIC-2,
&(curarea->flag), 0, 0, 0, 0, "Hides pulldown menus");
}
uiBlockSetEmboss(block, UI_EMBOSS);
xco+=XIC;
/* pull down menus */
if((curarea->flag & HEADER_NO_PULLDOWN)==0) {
uiBlockSetEmboss(block, UI_EMBOSSP);
xmax= GetButStringLength("Scripts");
uiDefPulldownBut(block,script_scriptsmenu, NULL, "Scripts", xco, 0, xmax, 20, "");
xco+=xmax;
}
uiBlockSetEmboss(block, UI_EMBOSS);
uiBlockBeginAlign(block);
uiDefIconBut(block, BUT, B_SCRIPT2PREV, ICON_GO_LEFT, xco+=XIC, 0, XIC, YIC,
0, 0, 0, 0, 0, "Returns to previous window");
/* FULL WINDOW */
if(curarea->full)
uiDefIconBut(block, BUT,B_FULL, ICON_SPLITSCREEN, xco+=XIC,0,XIC,YIC, 0, 0,
0, 0, 0, "Returns to multiple views window (CTRL+Up arrow)");
else
uiDefIconBut(block, BUT,B_FULL, ICON_FULLSCREEN, xco+=XIC,0,XIC,YIC, 0, 0,
0, 0, 0, "Makes current window full screen (CTRL+Down arrow)");
uiBlockEndAlign(block);
/* STD SCRIPT BUTTONS */
xco += 2*XIC;
More node goodies! First note; this is a WIP project, some commits might change things that make formerly saved situations not to work identically... like now! ------ New Material integration ------ Until now, the Node system worked on top of the 'current' Material, just like how the Material Layers worked. That's quite confusing in practice, especially to see what Material is a Node, or what is the "base material" Best solution is to completely separate the two. This has been implemented as follows now; - The confusing "Input" node has been removed. - When choosing a Material in Blender, you can define this Material to be either 'normal' (default) or be the root of a Node tree. - If a Material is a Node tree, you have to add Nodes in the tree to see something happen. An empty Node tree doesn't do anything (black). - If a Material is a Node Tree, the 'data browse' menus show it with an 'N' mark before the name. The 'data block' buttons display it with the suffix 'NT' (instead of 'MA'). - In a Node Tree, any Material can be inserted, including itself. Only in that case the Material is being used itself for shading. UI changes: Added a new Panel "Links", which shows: - where the Material is linked to (Object, Mesh, etc) - if the Material is a NodeTree or not - the actual active Material in the Tree The "Node" Panel itself now only shows buttons from the other nodes, when they are active. Further the Material Nodes themselves allow browsing and renaming or adding new Materials now too. Second half of today's work was cleaning up selection when the Nodes overlap... it was possible to drag links from invisible sockets, or click headers for invisible nodes, etc. This because the mouse input code was not checking for visibility yet. Works now even for buttons. :)
2005-12-29 18:08:01 +00:00
xco= std_libbuttons(block, xco, 0, 0, NULL, B_SCRIPTBROWSE, ID_SCRIPT, 0, (ID*)sc->script, 0, &(sc->menunr), 0, 0, 0, 0, 0);
/* always as last */
curarea->headbutlen= xco+2*XIC;
uiDrawBlock(block);
}
/* ********************** SCRIPT ****************************** */