This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/editors/interface/interface_templates.c

3118 lines
99 KiB
C
Raw Normal View History

/*
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
* ***** 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,
2010-02-12 13:34:04 +00:00
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
*
* Contributor(s): Blender Foundation 2009.
*
* ***** END GPL LICENSE BLOCK *****
*/
2011-02-27 20:29:51 +00:00
/** \file blender/editors/interface/interface_templates.c
* \ingroup edinterface
*/
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
#include "MEM_guardedalloc.h"
#include "DNA_anim_types.h"
#include "DNA_dynamicpaint_types.h"
#include "DNA_key_types.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "DNA_userdef_types.h"
#include "BLI_utildefines.h"
#include "BLI_string.h"
#include "BLI_ghash.h"
2012-08-20 23:06:17 +00:00
#include "BLI_rect.h"
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
#include "BLF_translation.h"
#include "BKE_animsys.h"
#include "BKE_colortools.h"
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
#include "BKE_context.h"
#include "BKE_dynamicpaint.h"
#include "BKE_global.h"
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_material.h"
#include "BKE_texture.h"
#include "BKE_report.h"
#include "BKE_displist.h"
#include "BKE_sca.h"
#include "BKE_scene.h"
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
#include "ED_screen.h"
#include "ED_object.h"
Sorry, three commits in one, became difficult to untangle.. Editors Modules * render/ module added in editors, moved the preview render code there and also shading related operators. * physics/ module made more consistent with other modules. renaming files, making a single physics_ops.c for operators and keymaps. Also move all particle related operators here now. * space_buttons/ now should have only operators relevant to the buttons specificially. Updates & Notifiers * Material/Texture/World/Lamp can now be passed to DAG_id_flush_update, which will go back to a callback in editors. Eventually these should be in the depsgraph itself, but for now this gives a unified call for doing updates. * GLSL materials are now refreshed on changes. There's still various cases missing, * Preview icons now hook into this system, solving various update cases that were missed before. * Also fixes issue in my last commit, where some preview would not render, problem is avoided in the new system. Icon Rendering * On systems with support for non-power of two textures, an OpenGL texture is now used instead of glDrawPixels. This avoids problems with icons get clipped on region borders. On my Linux desktop, this gives an 1.1x speedup, and on my Mac laptop a 2.3x speedup overall in redrawing the full window, with the default setup. The glDrawPixels implementation on Mac seems to have a lot of overhread. * Preview icons are now drawn using proper premul alpha, and never faded so you can see them clearly. * Also tried to fix issue with texture node preview rendering, globals can't be used with threads reliably.
2009-09-29 19:12:12 +00:00
#include "ED_render.h"
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
#include "RNA_access.h"
#include "RNA_enum_types.h"
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
#include "WM_api.h"
#include "WM_types.h"
#include "UI_interface.h"
#include "interface_intern.h"
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
#include "BLF_api.h"
#include "BLF_translation.h"
void UI_template_fix_linking(void)
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
{
}
/********************** Header Template *************************/
void uiTemplateHeader(uiLayout *layout, bContext *C, int menus)
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
{
uiBlock *block;
2012-03-30 01:51:25 +00:00
block = uiLayoutAbsoluteBlock(layout);
if (menus) ED_area_header_standardbuttons(C, block, 0);
else ED_area_header_switchbutton(C, block, 0);
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
}
/********************** Search Callbacks *************************/
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
typedef struct TemplateID {
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
PointerRNA ptr;
PropertyRNA *prop;
ListBase *idlb;
int prv_rows, prv_cols;
int preview;
} TemplateID;
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
/* Search browse menu, assign */
static void id_search_call_cb(bContext *C, void *arg_template, void *item)
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
{
2012-03-30 01:51:25 +00:00
TemplateID *template = (TemplateID *)arg_template;
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
/* ID */
if (item) {
PointerRNA idptr;
RNA_id_pointer_create(item, &idptr);
RNA_property_pointer_set(&template->ptr, template->prop, idptr);
RNA_property_update(C, &template->ptr, template->prop);
}
}
/* ID Search browse menu, do the search */
static void id_search_cb(const bContext *C, void *arg_template, const char *str, uiSearchItems *items)
{
2012-03-30 01:51:25 +00:00
TemplateID *template = (TemplateID *)arg_template;
ListBase *lb = template->idlb;
ID *id, *id_from = template->ptr.id.data;
int iconid;
2012-03-30 01:51:25 +00:00
int flag = RNA_property_flag(template->prop);
/* ID listbase */
2012-03-30 01:51:25 +00:00
for (id = lb->first; id; id = id->next) {
if (!((flag & PROP_ID_SELF_CHECK) && id == id_from)) {
/* use filter */
2012-03-30 01:51:25 +00:00
if (RNA_property_type(template->prop) == PROP_POINTER) {
PointerRNA ptr;
RNA_id_pointer_create(id, &ptr);
2012-03-30 01:51:25 +00:00
if (RNA_property_pointer_poll(&template->ptr, template->prop, &ptr) == 0)
continue;
}
/* hide dot-datablocks, but only if filter does not force it visible */
if (U.uiflag & USER_HIDE_DOT)
2012-03-30 01:51:25 +00:00
if ((id->name[2] == '.') && (str[0] != '.'))
continue;
2012-03-30 01:51:25 +00:00
if (BLI_strcasestr(id->name + 2, str)) {
char name_ui[MAX_ID_NAME];
name_uiprefix_id(name_ui, id);
2012-03-30 01:51:25 +00:00
iconid = ui_id_icon_get((bContext *)C, id, template->preview);
if (!uiSearchItemAdd(items, name_ui, id, iconid))
break;
}
}
}
}
/* ID Search browse menu, open */
static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem)
{
static char search[256];
static TemplateID template;
PointerRNA idptr;
2012-03-30 01:51:25 +00:00
wmWindow *win = CTX_wm_window(C);
uiBlock *block;
uiBut *but;
/* clear initial search string, then all items show */
2012-03-30 01:51:25 +00:00
search[0] = 0;
/* arg_litem is malloced, can be freed by parent button */
2012-03-30 01:51:25 +00:00
template = *((TemplateID *)arg_litem);
/* get active id for showing first item */
2012-03-30 01:51:25 +00:00
idptr = RNA_property_pointer_get(&template.ptr, template.prop);
2012-03-30 01:51:25 +00:00
block = uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW | UI_BLOCK_SEARCH_MENU);
/* preview thumbnails */
if (template.prv_rows > 0 && template.prv_cols > 0) {
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
int w = 4 * U.widget_unit * template.prv_cols;
int h = 4 * U.widget_unit * template.prv_rows + U.widget_unit;
/* fake button, it holds space for search items */
uiDefBut(block, LABEL, 0, "", 10, 15, w, h, NULL, 0, 0, 0, 0, NULL);
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, w, UI_UNIT_Y,
template.prv_rows, template.prv_cols, "");
uiButSetSearchFunc(but, id_search_cb, &template, id_search_call_cb, idptr.data);
}
/* list view */
else {
const int searchbox_width = uiSearchBoxWidth();
const int searchbox_height = uiSearchBoxHeight();
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
/* fake button, it holds space for search items */
uiDefBut(block, LABEL, 0, "", 10, 15, searchbox_width, searchbox_height, NULL, 0, 0, 0, 0, NULL);
but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, searchbox_width, UI_UNIT_Y - 1, 0, 0, "");
uiButSetSearchFunc(but, id_search_cb, &template, id_search_call_cb, idptr.data);
}
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
uiBoundsBlock(block, 0.3f * U.widget_unit);
uiBlockSetDirection(block, UI_DOWN);
uiEndBlock(C, block);
/* give search-field focus */
uiButSetFocusOnEnter(win, but);
/* this type of search menu requires undo */
but->flag |= UI_BUT_UNDO;
return block;
}
/************************ ID Template ***************************/
/* This is for browsing and editing the ID-blocks used */
/* for new/open operators */
void uiIDContextProperty(bContext *C, PointerRNA *ptr, PropertyRNA **prop)
{
TemplateID *template;
2012-03-30 01:51:25 +00:00
ARegion *ar = CTX_wm_region(C);
uiBlock *block;
uiBut *but;
memset(ptr, 0, sizeof(*ptr));
2012-03-30 01:51:25 +00:00
*prop = NULL;
if (!ar)
return;
2012-03-30 01:51:25 +00:00
for (block = ar->uiblocks.first; block; block = block->next) {
for (but = block->buttons.first; but; but = but->next) {
/* find the button before the active one */
2012-03-30 01:51:25 +00:00
if ((but->flag & (UI_BUT_LAST_ACTIVE | UI_ACTIVE))) {
if (but->func_argN) {
2012-03-30 01:51:25 +00:00
template = but->func_argN;
*ptr = template->ptr;
*prop = template->prop;
return;
}
}
}
}
}
static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
{
2012-03-30 01:51:25 +00:00
TemplateID *template = (TemplateID *)arg_litem;
PointerRNA idptr = RNA_property_pointer_get(&template->ptr, template->prop);
ID *id = idptr.data;
int event = GET_INT_FROM_POINTER(arg_event);
2012-03-30 01:51:25 +00:00
switch (event) {
case UI_ID_BROWSE:
case UI_ID_PIN:
RNA_warning("warning, id event %d shouldnt come here", event);
break;
case UI_ID_OPEN:
case UI_ID_ADD_NEW:
/* these call uiIDContextProperty */
break;
case UI_ID_DELETE:
memset(&idptr, 0, sizeof(idptr));
RNA_property_pointer_set(&template->ptr, template->prop, idptr);
RNA_property_update(C, &template->ptr, template->prop);
if (id && CTX_wm_window(C)->eventstate->shift) /* useful hidden functionality, */
2012-03-30 01:51:25 +00:00
id->us = 0;
break;
case UI_ID_FAKE_USER:
if (id) {
if (id->flag & LIB_FAKEUSER) id_us_plus(id);
else id_us_min(id);
}
else return;
break;
case UI_ID_LOCAL:
if (id) {
if (id_make_local(id, 0)) {
/* reassign to get get proper updates/notifiers */
2012-03-30 01:51:25 +00:00
idptr = RNA_property_pointer_get(&template->ptr, template->prop);
RNA_property_pointer_set(&template->ptr, template->prop, idptr);
RNA_property_update(C, &template->ptr, template->prop);
}
}
break;
case UI_ID_ALONE:
if (id) {
2012-03-30 01:51:25 +00:00
const int do_scene_obj = (GS(id->name) == ID_OB) &&
(template->ptr.type == &RNA_SceneObjects);
/* make copy */
if (do_scene_obj) {
2012-03-30 01:51:25 +00:00
Scene *scene = CTX_data_scene(C);
ED_object_single_user(scene, (struct Object *)id);
2012-03-30 01:51:25 +00:00
WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
}
else {
if (id) {
id_single_user(C, id, &template->ptr, template->prop);
}
}
}
break;
#if 0
case UI_ID_AUTO_NAME:
break;
#endif
}
}
static const char *template_id_browse_tip(StructRNA *type)
{
if (type) {
2012-03-30 01:51:25 +00:00
switch (RNA_type_to_ID_code(type)) {
case ID_SCE: return N_("Browse Scene to be linked");
case ID_OB: return N_("Browse Object to be linked");
case ID_ME: return N_("Browse Mesh Data to be linked");
case ID_CU: return N_("Browse Curve Data to be linked");
case ID_MB: return N_("Browse Metaball Data to be linked");
case ID_MA: return N_("Browse Material to be linked");
case ID_TE: return N_("Browse Texture to be linked");
case ID_IM: return N_("Browse Image to be linked");
case ID_LT: return N_("Browse Lattice Data to be linked");
case ID_LA: return N_("Browse Lamp Data to be linked");
case ID_CA: return N_("Browse Camera Data to be linked");
case ID_WO: return N_("Browse World Settings to be linked");
case ID_SCR: return N_("Choose Screen lay-out");
case ID_TXT: return N_("Browse Text to be linked");
case ID_SPK: return N_("Browse Speaker Data to be linked");
case ID_SO: return N_("Browse Sound to be linked");
case ID_AR: return N_("Browse Armature data to be linked");
case ID_AC: return N_("Browse Action to be linked");
case ID_NT: return N_("Browse Node Tree to be linked");
case ID_BR: return N_("Browse Brush to be linked");
case ID_PA: return N_("Browse Particle System to be linked");
case ID_GD: return N_("Browse Grease Pencil Data to be linked");
}
}
return N_("Browse ID data to be linked");
}
/* Return a type-based i18n context, needed e.g. by "New" button.
* In most languages, this adjective takes different form based on gender of type name...
*/
static const char *template_id_context(StructRNA *type)
{
if (type) {
switch (RNA_type_to_ID_code(type)) {
case ID_SCE: return BLF_I18NCONTEXT_ID_SCENE;
case ID_OB: return BLF_I18NCONTEXT_ID_OBJECT;
case ID_ME: return BLF_I18NCONTEXT_ID_MESH;
case ID_CU: return BLF_I18NCONTEXT_ID_CURVE;
case ID_MB: return BLF_I18NCONTEXT_ID_METABALL;
case ID_MA: return BLF_I18NCONTEXT_ID_MATERIAL;
case ID_TE: return BLF_I18NCONTEXT_ID_TEXTURE;
case ID_IM: return BLF_I18NCONTEXT_ID_IMAGE;
case ID_LT: return BLF_I18NCONTEXT_ID_LATTICE;
case ID_LA: return BLF_I18NCONTEXT_ID_LAMP;
case ID_CA: return BLF_I18NCONTEXT_ID_CAMERA;
case ID_WO: return BLF_I18NCONTEXT_ID_WORLD;
case ID_SCR: return BLF_I18NCONTEXT_ID_SCREEN;
case ID_TXT: return BLF_I18NCONTEXT_ID_TEXT;
case ID_SPK: return BLF_I18NCONTEXT_ID_SPEAKER;
case ID_SO: return BLF_I18NCONTEXT_ID_SOUND;
case ID_AR: return BLF_I18NCONTEXT_ID_ARMATURE;
case ID_AC: return BLF_I18NCONTEXT_ID_ACTION;
case ID_NT: return BLF_I18NCONTEXT_ID_NODETREE;
case ID_BR: return BLF_I18NCONTEXT_ID_BRUSH;
case ID_PA: return BLF_I18NCONTEXT_ID_PARTICLESETTINGS;
case ID_GD: return BLF_I18NCONTEXT_ID_GPENCIL;
}
}
return BLF_I18NCONTEXT_DEFAULT;
}
static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, StructRNA *type, short idcode, int flag,
const char *newop, const char *openop, const char *unlinkop)
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
{
uiBut *but;
uiBlock *block;
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
PointerRNA idptr;
// ListBase *lb; // UNUSED
ID *id, *idfrom;
2012-03-30 01:51:25 +00:00
int editable = RNA_property_editable(&template->ptr, template->prop);
const char *i18n_ctxt = template_id_context(type);
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
2012-03-30 01:51:25 +00:00
idptr = RNA_property_pointer_get(&template->ptr, template->prop);
id = idptr.data;
idfrom = template->ptr.id.data;
2012-05-27 19:40:36 +00:00
// lb = template->idlb;
2012-03-30 01:51:25 +00:00
block = uiLayoutGetBlock(layout);
uiBlockBeginAlign(block);
if (idptr.type)
2012-03-30 01:51:25 +00:00
type = idptr.type;
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
if (flag & UI_ID_PREVIEWS) {
2012-10-05 07:17:45 +00:00
template->preview = TRUE;
2012-03-30 01:51:25 +00:00
but = uiDefBlockButN(block, id_search_menu, MEM_dupallocN(template), "", 0, 0, UI_UNIT_X * 6, UI_UNIT_Y * 6,
TIP_(template_id_browse_tip(type)));
if (type) {
2012-03-30 01:51:25 +00:00
but->icon = RNA_struct_ui_icon(type);
if (id) but->icon = ui_id_icon_get(C, id, 1);
2012-03-30 01:51:25 +00:00
uiButSetFlag(but, UI_HAS_ICON | UI_ICON_PREVIEW);
}
if ((idfrom && idfrom->lib) || !editable)
uiButSetFlag(but, UI_BUT_DISABLED);
uiLayoutRow(layout, TRUE);
}
else if (flag & UI_ID_BROWSE) {
2012-03-30 01:51:25 +00:00
but = uiDefBlockButN(block, id_search_menu, MEM_dupallocN(template), "", 0, 0, UI_UNIT_X * 1.6, UI_UNIT_Y,
TIP_(template_id_browse_tip(type)));
uiButSetDrawFlag(but, UI_BUT_DRAW_ENUM_ARROWS);
if (type) {
2012-03-30 01:51:25 +00:00
but->icon = RNA_struct_ui_icon(type);
Drag and drop 2.5 integration! Finally, slashdot regulars can use Blender too now! :) ** Drag works as follows: - drag-able items are defined by the standard interface ui toolkit - each button can get this feature, via uiButSetDragXXX(but, ...). There are calls to define drag-able images, ID blocks, RNA paths, file paths, and so on. By default you drag an icon, exceptionally an ImBuf - Drag items are registered centrally in the WM, it allows more drag items simultaneous too, but not implemented ** Drop works as follows: - On mouse release, and if drag items exist in the WM, it converts the mouse event to an EVT_DROP type. This event then gets the full drag info as customdata - drop regions are defined with WM_dropbox_add(), similar to keymaps you can make a "drop map" this way, which become 'drop map handlers' in the queues. - next to that the UI kit handles some common button types (like accepting ID or names) to be catching a drop event too. - Every "drop box" has two callbacks: - poll() = check if the event drag data is relevant for this box - copy() = fill in custom properties in the dropbox to initialize an operator - The dropbox handler then calls its standard Operator with its dropbox properties. ** Currently implemented Drag items: - ID icons in browse buttons - ID icons in context menu of properties region - ID icons in outliner and rna viewer - FileBrowser icons - FileBrowser preview images Drag-able icons are subtly visualized by making them brighter a bit on mouse-over. In case the icon is a button or UI element too (most cases), the drag-able feature will make the item react to mouse-release instead of mouse-press. Drop options: - UI buttons: ID and text buttons (paste name) - View3d: Object ID drop copies object - View3d: Material ID drop assigns to object under cursor - View3d: Image ID drop assigns to object UV texture under cursor - Sequencer: Path drop will add either Image or Movie strip - Image window: Path drop will open image ** Drag and drop Notes: - Dropping into another Blender window (from same application) works too. I've added code that passes on mousemoves and clicks to other windows, without activating them though. This does make using multi-window Blender a bit friendler. - Dropping a file path to an image, is not the same as dropping an Image ID... keep this in mind. Sequencer for example wants paths to be dropped, textures in 3d window wants an Image ID. - Although drop boxes could be defined via Python, I suggest they're part of the UI and editor design (= how we want an editor to work), and not default offered configurable like keymaps. - At the moment only one item can be dragged at a time. This is for several reasons.... For one, Blender doesn't have a well defined uniform way to define "what is selected" (files, outliner items, etc). Secondly there's potential conflicts on what todo when you drop mixed drag sets on spots. All undefined stuff... nice for later. - Example to bypass the above: a collection of images that form a strip, should be represented in filewindow as a single sequence anyway. This then will fit well and gets handled neatly by design. - Another option to check is to allow multiple options per drop... it could show the operator as a sort of menu, allowing arrow or scrollwheel to choose. For time being I'd prefer to try to design a singular drop though, just offer only one drop action per data type on given spots. - What does work already, but a tad slow, is to use a function that detects an object (type) under cursor, so a drag item's option can be further refined (like drop object on object = parent). (disabled) ** More notes - Added saving for Region layouts (like split points for toolbar) - Label buttons now handle mouse over - File list: added full path entry for drop feature. - Filesel bugfix: wm_operator_exec() got called there and fully handled, while WM event code tried same. Added new OPERATOR_HANDLED flag for this. Maybe python needs it too? - Cocoa: added window move event, so multi-win setups work OK (didnt save). - Interface_handlers.c: removed win->active - Severe area copy bug: area handlers were not set to NULL - Filesel bugfix: next/prev folder list was not copied on area copies ** Leftover todos - Cocoa windows seem to hang on cases still... needs check - Cocoa 'draw overlap' swap doesn't work - Cocoa window loses focus permanently on using Spotlight (for these reasons, makefile building has Carbon as default atm) - ListView templates in UI cannot become dragged yet, needs review... it consists of two overlapping UI elements, preventing handling icon clicks. - There's already Ghost library code to handle dropping from OS into Blender window. I've noticed this code is unfinished for Macs, but seems to be complete for Windows. Needs test... currently, an external drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
/* default dragging of icon for id browse buttons */
uiButSetDragID(but, id);
2012-03-30 01:51:25 +00:00
uiButSetFlag(but, UI_HAS_ICON | UI_ICON_LEFT);
}
if ((idfrom && idfrom->lib) || !editable)
uiButSetFlag(but, UI_BUT_DISABLED);
}
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
/* text button with name */
if (id) {
char name[UI_MAX_NAME_STR];
2012-03-30 01:51:25 +00:00
const short user_alert = (id->us <= 0);
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
//text_idbutton(id, name);
2012-03-30 01:51:25 +00:00
name[0] = '\0';
but = uiDefButR(block, TEX, 0, name, 0, 0, UI_UNIT_X * 6, UI_UNIT_Y,
&idptr, "name", -1, 0, 0, -1, -1, RNA_struct_ui_description(type));
uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_RENAME));
if (user_alert) uiButSetFlag(but, UI_BUT_REDALERT);
if (id->lib) {
if (id->flag & LIB_INDIRECT) {
but = uiDefIconBut(block, BUT, 0, ICON_LIBRARY_DATA_INDIRECT, 0, 0, UI_UNIT_X, UI_UNIT_Y,
NULL, 0, 0, 0, 0, TIP_("Indirect library datablock, cannot change"));
uiButSetFlag(but, UI_BUT_DISABLED);
}
else {
but = uiDefIconBut(block, BUT, 0, ICON_LIBRARY_DATA_DIRECT, 0, 0, UI_UNIT_X, UI_UNIT_Y,
NULL, 0, 0, 0, 0, TIP_("Direct linked library datablock, click to make local"));
if (!id_make_local(id, 1 /* test */) || (idfrom && idfrom->lib))
uiButSetFlag(but, UI_BUT_DISABLED);
}
uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_LOCAL));
}
if (id->us > 1) {
char numstr[32];
BLI_snprintf(numstr, sizeof(numstr), "%d", id->us);
but = uiDefBut(block, BUT, 0, numstr, 0, 0, UI_UNIT_X + ((id->us < 10) ? 0 : 10), UI_UNIT_Y,
NULL, 0, 0, 0, 0,
2012-03-30 01:51:25 +00:00
TIP_("Display number of users of this data (click to make a single-user copy)"));
uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ALONE));
if (/* test only */
(id_copy(id, NULL, 1) == FALSE) ||
(idfrom && idfrom->lib) ||
(editable == FALSE) ||
/* object in editmode - don't change data */
(idfrom && GS(idfrom->name) == ID_OB && (((Object *)idfrom)->mode & OB_MODE_EDIT)))
{
uiButSetFlag(but, UI_BUT_DISABLED);
}
}
if (user_alert) uiButSetFlag(but, UI_BUT_REDALERT);
if (id->lib == NULL && !(ELEM5(GS(id->name), ID_GR, ID_SCE, ID_SCR, ID_TXT, ID_OB))) {
uiDefButR(block, TOG, 0, "F", 0, 0, UI_UNIT_X, UI_UNIT_Y, &idptr, "use_fake_user", -1, 0, 0, -1, -1, NULL);
}
}
if (flag & UI_ID_ADD_NEW) {
2012-03-30 01:51:25 +00:00
int w = id ? UI_UNIT_X : (flag & UI_ID_OPEN) ? UI_UNIT_X * 3 : UI_UNIT_X * 6;
/* i18n markup, does nothing! */
BLF_I18N_MSGID_MULTI_CTXT("New", BLF_I18NCONTEXT_DEFAULT,
BLF_I18NCONTEXT_ID_SCENE,
BLF_I18NCONTEXT_ID_OBJECT,
BLF_I18NCONTEXT_ID_MESH,
BLF_I18NCONTEXT_ID_CURVE,
BLF_I18NCONTEXT_ID_METABALL,
BLF_I18NCONTEXT_ID_MATERIAL,
BLF_I18NCONTEXT_ID_TEXTURE,
BLF_I18NCONTEXT_ID_IMAGE,
BLF_I18NCONTEXT_ID_LATTICE,
BLF_I18NCONTEXT_ID_LAMP,
BLF_I18NCONTEXT_ID_CAMERA,
BLF_I18NCONTEXT_ID_WORLD,
BLF_I18NCONTEXT_ID_SCREEN,
BLF_I18NCONTEXT_ID_TEXT);
BLF_I18N_MSGID_MULTI_CTXT("New", BLF_I18NCONTEXT_ID_SPEAKER,
BLF_I18NCONTEXT_ID_SOUND,
BLF_I18NCONTEXT_ID_ARMATURE,
BLF_I18NCONTEXT_ID_ACTION,
BLF_I18NCONTEXT_ID_NODETREE,
BLF_I18NCONTEXT_ID_BRUSH,
BLF_I18NCONTEXT_ID_PARTICLESETTINGS,
BLF_I18NCONTEXT_ID_GPENCIL);
if (newop) {
but = uiDefIconTextButO(block, BUT, newop, WM_OP_INVOKE_DEFAULT, ICON_ZOOMIN,
(id) ? "" : CTX_IFACE_(i18n_ctxt, "New"), 0, 0, w, UI_UNIT_Y, NULL);
uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
}
else {
but = uiDefIconTextBut(block, BUT, 0, ICON_ZOOMIN, (id) ? "" : CTX_IFACE_(i18n_ctxt, "New"),
0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
}
if ((idfrom && idfrom->lib) || !editable)
uiButSetFlag(but, UI_BUT_DISABLED);
}
if (flag & UI_ID_OPEN) {
2012-03-30 01:51:25 +00:00
int w = id ? UI_UNIT_X : (flag & UI_ID_ADD_NEW) ? UI_UNIT_X * 3 : UI_UNIT_X * 6;
if (openop) {
but = uiDefIconTextButO(block, BUT, openop, WM_OP_INVOKE_DEFAULT, ICON_FILESEL, (id) ? "" : IFACE_("Open"),
0, 0, w, UI_UNIT_Y, NULL);
uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_OPEN));
}
else {
but = uiDefIconTextBut(block, BUT, 0, ICON_FILESEL, (id) ? "" : IFACE_("Open"), 0, 0, w, UI_UNIT_Y,
NULL, 0, 0, 0, 0, NULL);
uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_OPEN));
}
if ((idfrom && idfrom->lib) || !editable)
uiButSetFlag(but, UI_BUT_DISABLED);
}
/* delete button */
2012-03-30 01:51:25 +00:00
if (id && (flag & UI_ID_DELETE) && (RNA_property_flag(template->prop) & PROP_NEVER_UNLINK) == 0) {
if (unlinkop) {
but = uiDefIconButO(block, BUT, unlinkop, WM_OP_INVOKE_REGION_WIN, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
/* so we can access the template from operators, font unlinking needs this */
uiButSetNFunc(but, NULL, MEM_dupallocN(template), NULL);
}
else {
but = uiDefIconBut(block, BUT, 0, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0,
TIP_("Unlink datablock "
"(Shift + Click to set users to zero, data will then not be saved)"));
uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_DELETE));
if (RNA_property_flag(template->prop) & PROP_NEVER_NULL)
uiButSetFlag(but, UI_BUT_DISABLED);
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
}
if ((idfrom && idfrom->lib) || !editable)
uiButSetFlag(but, UI_BUT_DISABLED);
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
}
if (idcode == ID_TE)
uiTemplateTextureShow(layout, C, &template->ptr, template->prop);
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
uiBlockEndAlign(block);
}
static void ui_template_id(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop,
const char *openop, const char *unlinkop, int flag, int prv_rows, int prv_cols)
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
{
TemplateID *template;
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
PropertyRNA *prop;
StructRNA *type;
short idcode;
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
2012-03-30 01:51:25 +00:00
prop = RNA_struct_find_property(ptr, propname);
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
if (!prop || RNA_property_type(prop) != PROP_POINTER) {
RNA_warning("pointer property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
return;
}
2012-03-30 01:51:25 +00:00
template = MEM_callocN(sizeof(TemplateID), "TemplateID");
template->ptr = *ptr;
template->prop = prop;
template->prv_rows = prv_rows;
template->prv_cols = prv_cols;
if (newop)
flag |= UI_ID_ADD_NEW;
if (openop)
flag |= UI_ID_OPEN;
2012-03-30 01:51:25 +00:00
type = RNA_property_pointer_type(ptr, prop);
idcode = RNA_type_to_ID_code(type);
template->idlb = which_libbase(CTX_data_main(C), idcode);
/* create UI elements for this template
* - template_ID makes a copy of the template data and assigns it to the relevant buttons
*/
if (template->idlb) {
uiLayoutRow(layout, TRUE);
template_ID(C, layout, template, type, idcode, flag, newop, openop, unlinkop);
}
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
MEM_freeN(template);
}
void uiTemplateID(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop,
const char *openop, const char *unlinkop)
{
ui_template_id(layout, C, ptr, propname, newop, openop, unlinkop,
UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE, 0, 0);
}
void uiTemplateIDBrowse(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop,
const char *openop, const char *unlinkop)
{
2012-03-30 01:51:25 +00:00
ui_template_id(layout, C, ptr, propname, newop, openop, unlinkop, UI_ID_BROWSE | UI_ID_RENAME, 0, 0);
}
void uiTemplateIDPreview(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop,
const char *openop, const char *unlinkop, int rows, int cols)
{
ui_template_id(layout, C, ptr, propname, newop, openop, unlinkop,
UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE | UI_ID_PREVIEWS, rows, cols);
UI: Layout Engine * Buttons are now created first, and after that the layout is computed. This means the layout engine now works at button level, and makes it easier to write templates. Otherwise you had to store all info and create the buttons later. * Added interface_templates.c as a separate file to put templates in. These can contain regular buttons, and can be put in a Free layout, which means you can specify manual coordinates, but still get nested correct inside other layouts. * API was changed to allow better nesting. Previously items were added in the last added layout specifier, i.e. one level up in the layout hierarchy. This doesn't work well in always, so now when creating things like rows or columns it always returns a layout which you have to add the items in. All py scripts were updated to follow this. * Computing the layout now goes in two passes, first estimating the required width/height of all nested layouts, and then in the second pass using the results of that to decide on the actual locations. * Enum and array buttons now follow the direction of the layout, i.e. they are vertical or horizontal depending if they are in a column or row. * Color properties now get a color picker, and only get the additional RGB sliders with Expand=True. * File/directory string properties now get a button next to them for opening the file browse, though this is not implemented yet. * Layout items can now be aligned, set align=True when creating a column, row, etc. * Buttons now get a minimum width of one icon (avoids squashing icon buttons). * Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
}
/************************ ID Chooser Template ***************************/
/* This is for selecting the type of ID-block to use, and then from the relevant type choosing the block to use
*
* - propname: property identifier for property that ID-pointer gets stored to
* - proptypename: property identifier for property used to determine the type of ID-pointer that can be used
*/
void uiTemplateAnyID(uiLayout *layout, PointerRNA *ptr, const char *propname, const char *proptypename,
const char *text)
{
PropertyRNA *propID, *propType;
uiLayout *row;
/* get properties... */
2012-03-30 01:51:25 +00:00
propID = RNA_struct_find_property(ptr, propname);
propType = RNA_struct_find_property(ptr, proptypename);
if (!propID || RNA_property_type(propID) != PROP_POINTER) {
RNA_warning("pointer property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
return;
}
if (!propType || RNA_property_type(propType) != PROP_ENUM) {
RNA_warning("pointer-type property not found: %s.%s", RNA_struct_identifier(ptr->type), proptypename);
return;
}
/* Start drawing UI Elements using standard defines */
row = uiLayoutRow(layout, TRUE);
/* Label - either use the provided text, or will become "ID-Block:" */
if (text) {
if (text[0])
uiItemL(row, text, ICON_NONE);
}
else
uiItemL(row, "ID-Block:", ICON_NONE);
/* ID-Type Selector - just have a menu of icons */
/* FIXME: the icon-only setting doesn't work when we supply a blank name */
uiItemFullR(row, ptr, propType, 0, 0, UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
/* ID-Block Selector - just use pointer widget... */
uiItemFullR(row, ptr, propID, 0, 0, 0, "", ICON_NONE);
}
/********************* RNA Path Builder Template ********************/
/* ---------- */
/* This is creating/editing RNA-Paths
*
* - ptr: struct which holds the path property
* - propname: property identifier for property that path gets stored to
* - root_ptr: struct that path gets built from
*/
void uiTemplatePathBuilder(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *UNUSED(root_ptr),
const char *text)
{
PropertyRNA *propPath;
uiLayout *row;
/* check that properties are valid */
2012-03-30 01:51:25 +00:00
propPath = RNA_struct_find_property(ptr, propname);
if (!propPath || RNA_property_type(propPath) != PROP_STRING) {
RNA_warning("path property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
return;
}
/* Start drawing UI Elements using standard defines */
row = uiLayoutRow(layout, TRUE);
/* Path (existing string) Widget */
uiItemR(row, ptr, propname, 0, text, ICON_RNA);
/* TODO: attach something to this to make allow searching of nested properties to 'build' the path */
}
/************************ Modifier Template *************************/
#define ERROR_LIBDATA_MESSAGE "Can't edit external libdata"
#include <string.h>
#include "DNA_object_force.h"
#include "BKE_depsgraph.h"
#include "BKE_modifier.h"
#include "BKE_particle.h"
#include "ED_util.h"
#include "BLI_math.h"
#include "BLI_listbase.h"
#include "ED_object.h"
static void modifiers_setOnCage(bContext *C, void *ob_v, void *md_v)
{
Scene *scene = CTX_data_scene(C);
Object *ob = ob_v;
2012-03-30 01:51:25 +00:00
ModifierData *md = md_v;
int i, cageIndex = modifiers_getCageIndex(scene, ob, NULL, 0);
/* undo button operation */
md->mode ^= eModifierMode_OnCage;
2012-03-30 01:51:25 +00:00
for (i = 0, md = ob->modifiers.first; md; ++i, md = md->next) {
if (md == md_v) {
if (i >= cageIndex)
md->mode ^= eModifierMode_OnCage;
break;
}
}
2012-03-30 01:51:25 +00:00
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
static void modifiers_convertToReal(bContext *C, void *ob_v, void *md_v)
{
Object *ob = ob_v;
ModifierData *md = md_v;
ModifierData *nmd = modifier_new(md->type);
modifier_copyData(md, nmd);
nmd->mode &= ~eModifierMode_Virtual;
BLI_addhead(&ob->modifiers, nmd);
modifier_unique_name(&ob->modifiers, nmd);
ob->partype = PAROBJECT;
2012-03-30 01:51:25 +00:00
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
ED_undo_push(C, "Modifier convert to real");
}
static int modifier_can_delete(ModifierData *md)
{
/* fluid particle modifier can't be deleted here */
if (md->type == eModifierType_ParticleSystem)
if (((ParticleSystemModifierData *)md)->psys->part->type == PART_FLUID)
return 0;
return 1;
}
/* Check whether Modifier is a simulation or not, this is used for switching to the physics/particles context tab */
static int modifier_is_simulation(ModifierData *md)
{
/* Physic Tab */
if (ELEM7(md->type, eModifierType_Cloth, eModifierType_Collision, eModifierType_Fluidsim, eModifierType_Smoke,
2012-03-30 01:51:25 +00:00
eModifierType_Softbody, eModifierType_Surface, eModifierType_DynamicPaint))
{
return 1;
}
/* Particle Tab */
else if (md->type == eModifierType_ParticleSystem) {
return 2;
}
else {
return 0;
}
}
static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob,
ModifierData *md, int index, int cageIndex, int lastCageIndex)
{
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
PointerRNA ptr;
uiBut *but;
uiBlock *block;
uiLayout *box, *column, *row;
2012-03-30 01:51:25 +00:00
uiLayout *result = NULL;
int isVirtual = (md->mode & eModifierMode_Virtual);
char str[128];
/* create RNA pointer */
RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr);
column = uiLayoutColumn(layout, TRUE);
uiLayoutSetContextPointer(column, "modifier", &ptr);
/* rounded header ------------------------------------------------------------------- */
2012-03-30 01:51:25 +00:00
box = uiLayoutBox(column);
if (isVirtual) {
row = uiLayoutRow(box, FALSE);
uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_EXPAND);
2012-03-30 01:51:25 +00:00
block = uiLayoutGetBlock(row);
/* VIRTUAL MODIFIER */
/* XXX this is not used now, since these cannot be accessed via RNA */
BLI_snprintf(str, sizeof(str), "%s parent deform", md->name);
uiDefBut(block, LABEL, 0, str, 0, 0, 185, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Modifier name");
but = uiDefBut(block, BUT, 0, IFACE_("Make Real"), 0, 0, 80, 16, NULL, 0.0, 0.0, 0.0, 0.0,
2012-03-30 01:51:25 +00:00
TIP_("Convert virtual modifier to a real modifier"));
uiButSetFunc(but, modifiers_convertToReal, ob, md);
}
else {
/* REAL MODIFIER */
row = uiLayoutRow(box, FALSE);
block = uiLayoutGetBlock(row);
uiBlockSetEmboss(block, UI_EMBOSSN);
/* Open/Close ................................. */
uiItemR(row, &ptr, "show_expanded", 0, "", ICON_NONE);
/* modifier-type icon */
uiItemL(row, "", RNA_struct_ui_icon(ptr.type));
uiBlockSetEmboss(block, UI_EMBOSS);
/* modifier name */
uiItemR(row, &ptr, "name", 0, "", ICON_NONE);
/* mode enabling buttons */
uiBlockBeginAlign(block);
/* Softbody not allowed in this situation, enforce! */
if (((md->type != eModifierType_Softbody && md->type != eModifierType_Collision) || !(ob->pd && ob->pd->deflect)) &&
(md->type != eModifierType_Surface) )
{
uiItemR(row, &ptr, "show_render", 0, "", ICON_NONE);
uiItemR(row, &ptr, "show_viewport", 0, "", ICON_NONE);
if (mti->flags & eModifierTypeFlag_SupportsEditmode)
uiItemR(row, &ptr, "show_in_editmode", 0, "", ICON_NONE);
}
2012-03-30 01:51:25 +00:00
if (ob->type == OB_MESH) {
if (modifier_couldBeCage(scene, md) && (index <= lastCageIndex)) {
/* -- convert to rna ? */
but = uiDefIconButBitI(block, TOG, eModifierMode_OnCage, 0, ICON_MESH_DATA, 0, 0,
UI_UNIT_X - 2, UI_UNIT_Y, &md->mode, 0.0, 0.0, 0.0, 0.0,
TIP_("Apply modifier to editing cage during Edit mode"));
if (index < cageIndex)
uiButSetFlag(but, UI_BUT_DISABLED);
uiButSetFunc(but, modifiers_setOnCage, ob, md);
}
else {
uiBlockEndAlign(block);
/* place holder button */
uiBlockSetEmboss(block, UI_EMBOSSN);
but = uiDefIconBut(block, BUT, 0, ICON_NONE, 0, 0, UI_UNIT_X - 2, UI_UNIT_Y,
NULL, 0.0, 0.0, 0.0, 0.0, NULL);
uiButSetFlag(but, UI_BUT_DISABLED);
uiBlockSetEmboss(block, UI_EMBOSS);
}
} /* tessellation point for curve-typed objects */
else if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
2012-03-18 07:38:51 +00:00
/* some modifiers could work with pre-tessellated curves only */
if (ELEM3(md->type, eModifierType_Hook, eModifierType_Softbody, eModifierType_MeshDeform)) {
2012-03-18 07:38:51 +00:00
/* add disabled pre-tessellated button, so users could have
* message for this modifiers */
but = uiDefIconButBitI(block, TOG, eModifierMode_ApplyOnSpline, 0, ICON_SURFACE_DATA, 0, 0,
UI_UNIT_X - 2, UI_UNIT_Y, &md->mode, 0.0, 0.0, 0.0, 0.0,
2012-03-30 01:51:25 +00:00
TIP_("This modifier could be applied on splines' points only"));
uiButSetFlag(but, UI_BUT_DISABLED);
}
else if (mti->type != eModifierTypeType_Constructive) {
/* constructive modifiers tessellates curve before applying */
uiItemR(row, &ptr, "use_apply_on_spline", 0, "", ICON_NONE);
}
}
uiBlockEndAlign(block);
/* Up/Down + Delete ........................... */
uiBlockBeginAlign(block);
uiItemO(row, "", ICON_TRIA_UP, "OBJECT_OT_modifier_move_up");
uiItemO(row, "", ICON_TRIA_DOWN, "OBJECT_OT_modifier_move_down");
uiBlockEndAlign(block);
uiBlockSetEmboss(block, UI_EMBOSSN);
/* When Modifier is a simulation, show button to switch to context rather than the delete button. */
if (modifier_can_delete(md) && !modifier_is_simulation(md))
uiItemO(row, "", ICON_X, "OBJECT_OT_modifier_remove");
if (modifier_is_simulation(md) == 1)
uiItemStringO(row, "", ICON_BUTS, "WM_OT_properties_context_change", "context", "PHYSICS");
else if (modifier_is_simulation(md) == 2)
uiItemStringO(row, "", ICON_BUTS, "WM_OT_properties_context_change", "context", "PARTICLES");
uiBlockSetEmboss(block, UI_EMBOSS);
}
/* modifier settings (under the header) --------------------------------------------------- */
if (!isVirtual && (md->mode & eModifierMode_Expanded)) {
/* apply/convert/copy */
2012-03-30 01:51:25 +00:00
box = uiLayoutBox(column);
row = uiLayoutRow(box, FALSE);
if (!ELEM(md->type, eModifierType_Collision, eModifierType_Surface)) {
/* only here obdata, the rest of modifiers is ob level */
uiBlockSetButLock(block, BKE_object_obdata_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2012-03-30 01:51:25 +00:00
if (md->type == eModifierType_ParticleSystem) {
ParticleSystem *psys = ((ParticleSystemModifierData *)md)->psys;
if (!(ob->mode & OB_MODE_PARTICLE_EDIT) && psys->pathcache) {
if (ELEM(psys->part->ren_as, PART_DRAW_GR, PART_DRAW_OB))
uiItemO(row, "Convert", ICON_NONE, "OBJECT_OT_duplicates_make_real");
else if (psys->part->ren_as == PART_DRAW_PATH)
uiItemO(row, "Convert", ICON_NONE, "OBJECT_OT_modifier_convert");
}
}
else {
uiLayoutSetOperatorContext(row, WM_OP_INVOKE_DEFAULT);
uiItemEnumO(row, "OBJECT_OT_modifier_apply", IFACE_("Apply"), 0, "apply_as", MODIFIER_APPLY_DATA);
if (modifier_isSameTopology(md) && !modifier_isNonGeometrical(md)) {
uiItemEnumO(row, "OBJECT_OT_modifier_apply", IFACE_("Apply as Shape Key"), 0,
"apply_as", MODIFIER_APPLY_SHAPE);
}
}
uiBlockClearButLock(block);
uiBlockSetButLock(block, ob && ob->id.lib, ERROR_LIBDATA_MESSAGE);
if (!ELEM5(md->type, eModifierType_Fluidsim, eModifierType_Softbody, eModifierType_ParticleSystem,
eModifierType_Cloth, eModifierType_Smoke))
{
uiItemO(row, IFACE_("Copy"), ICON_NONE, "OBJECT_OT_modifier_copy");
}
}
/* result is the layout block inside the box, that we return so that modifier settings can be drawn */
result = uiLayoutColumn(box, FALSE);
2012-03-30 01:51:25 +00:00
block = uiLayoutAbsoluteBlock(box);
}
/* error messages */
if (md->error) {
box = uiLayoutBox(column);
row = uiLayoutRow(box, FALSE);
uiItemL(row, md->error, ICON_ERROR);
}
return result;
}
uiLayout *uiTemplateModifier(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
Scene *scene = CTX_data_scene(C);
Object *ob;
ModifierData *md, *vmd;
int i, lastCageIndex, cageIndex;
/* verify we have valid data */
if (!RNA_struct_is_a(ptr->type, &RNA_Modifier)) {
RNA_warning("Expected modifier on object");
return NULL;
}
2012-03-30 01:51:25 +00:00
ob = ptr->id.data;
md = ptr->data;
if (!ob || !(GS(ob->id.name) == ID_OB)) {
RNA_warning("Expected modifier on object");
return NULL;
}
uiBlockSetButLock(uiLayoutGetBlock(layout), (ob && ob->id.lib), ERROR_LIBDATA_MESSAGE);
/* find modifier and draw it */
cageIndex = modifiers_getCageIndex(scene, ob, &lastCageIndex, 0);
/* XXX virtual modifiers are not accesible for python */
vmd = modifiers_getVirtualModifierList(ob);
2012-03-30 01:51:25 +00:00
for (i = 0; vmd; i++, vmd = vmd->next) {
if (md == vmd)
return draw_modifier(layout, scene, ob, md, i, cageIndex, lastCageIndex);
else if (vmd->mode & eModifierMode_Virtual)
i--;
}
return NULL;
}
/************************ Constraint Template *************************/
#include "DNA_constraint_types.h"
#include "BKE_action.h"
#include "BKE_constraint.h"
2012-03-30 01:51:25 +00:00
#define B_CONSTRAINT_TEST 5
// #define B_CONSTRAINT_CHANGETARGET 6
static void do_constraint_panels(bContext *C, void *ob_pt, int event)
{
2012-03-30 01:51:25 +00:00
Object *ob = (Object *)ob_pt;
switch (event) {
case B_CONSTRAINT_TEST:
break; /* no handling */
#if 0 /* UNUSED */
2012-03-30 01:51:25 +00:00
case B_CONSTRAINT_CHANGETARGET:
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
if (ob->pose) ob->pose->flag |= POSE_RECALC; /* checks & sorts pose channels */
2012-03-30 01:51:25 +00:00
DAG_scene_sort(bmain, scene);
break;
}
#endif
2012-03-30 01:51:25 +00:00
default:
break;
}
/* note: RNA updates now call this, commenting else it gets called twice.
* if there are problems because of this, then rna needs changed update functions.
*
* object_test_constraints(ob);
* if (ob->pose) BKE_pose_update_constraint_flags(ob->pose); */
2012-03-30 01:51:25 +00:00
if (ob->type == OB_ARMATURE) DAG_id_tag_update(&ob->id, OB_RECALC_DATA | OB_RECALC_OB);
else DAG_id_tag_update(&ob->id, OB_RECALC_OB);
2012-03-30 01:51:25 +00:00
WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT, ob);
}
static void constraint_active_func(bContext *UNUSED(C), void *ob_v, void *con_v)
{
ED_object_constraint_set_active(ob_v, con_v);
}
/* draw panel showing settings for a constraint */
static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
{
bPoseChannel *pchan = BKE_pose_channel_active(ob);
bConstraintTypeInfo *cti;
uiBlock *block;
2012-03-30 01:51:25 +00:00
uiLayout *result = NULL, *col, *box, *row;
PointerRNA ptr;
char typestr[32];
2012-03-30 01:51:25 +00:00
short proxy_protected, xco = 0, yco = 0;
// int rb_col; // UNUSED
/* get constraint typeinfo */
2012-03-30 01:51:25 +00:00
cti = constraint_get_typeinfo(con);
if (cti == NULL) {
/* exception for 'Null' constraint - it doesn't have constraint typeinfo! */
BLI_strncpy(typestr, (con->type == CONSTRAINT_TYPE_NULL) ? "Null" : "Unknown", sizeof(typestr));
}
else
BLI_strncpy(typestr, cti->name, sizeof(typestr));
/* determine whether constraint is proxy protected or not */
if (proxylocked_constraints_owner(ob, pchan))
2012-03-30 01:51:25 +00:00
proxy_protected = (con->flag & CONSTRAINT_PROXY_LOCAL) == 0;
else
2012-03-30 01:51:25 +00:00
proxy_protected = 0;
/* unless button has own callback, it adds this callback to button */
2012-03-30 01:51:25 +00:00
block = uiLayoutGetBlock(layout);
uiBlockSetHandleFunc(block, do_constraint_panels, ob);
uiBlockSetFunc(block, constraint_active_func, ob, con);
RNA_pointer_create(&ob->id, &RNA_Constraint, con, &ptr);
col = uiLayoutColumn(layout, TRUE);
uiLayoutSetContextPointer(col, "constraint", &ptr);
2012-03-30 01:51:25 +00:00
box = uiLayoutBox(col);
row = uiLayoutRow(box, FALSE);
2012-03-30 01:51:25 +00:00
block = uiLayoutGetBlock(box);
/* Draw constraint header */
/* open/close */
uiBlockSetEmboss(block, UI_EMBOSSN);
uiItemR(row, &ptr, "show_expanded", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
uiBlockSetEmboss(block, UI_EMBOSS);
/* name */
2012-03-30 01:51:25 +00:00
uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, xco + 10, yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
if (con->flag & CONSTRAINT_DISABLE)
2012-09-04 18:47:08 +00:00
uiLayoutSetRedAlert(row, TRUE);
if (proxy_protected == 0) {
uiItemR(row, &ptr, "name", 0, "", ICON_NONE);
}
else
uiItemL(row, con->name, ICON_NONE);
2012-09-04 18:47:08 +00:00
uiLayoutSetRedAlert(row, FALSE);
/* proxy-protected constraints cannot be edited, so hide up/down + close buttons */
if (proxy_protected) {
uiBlockSetEmboss(block, UI_EMBOSSN);
/* draw a ghost icon (for proxy) and also a lock beside it, to show that constraint is "proxy locked" */
uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_GHOST, xco + 244, yco, 19, 19,
NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Proxy Protected"));
uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_LOCKED, xco + 262, yco, 19, 19,
NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Proxy Protected"));
uiBlockSetEmboss(block, UI_EMBOSS);
}
else {
short prev_proxylock, show_upbut, show_downbut;
/* Up/Down buttons:
* Proxy-constraints are not allowed to occur after local (non-proxy) constraints
* as that poses problems when restoring them, so disable the "up" button where
* it may cause this situation.
*
* Up/Down buttons should only be shown (or not grayed - todo) if they serve some purpose.
*/
if (proxylocked_constraints_owner(ob, pchan)) {
if (con->prev) {
2012-03-30 01:51:25 +00:00
prev_proxylock = (con->prev->flag & CONSTRAINT_PROXY_LOCAL) ? 0 : 1;
}
else
2012-03-30 01:51:25 +00:00
prev_proxylock = 0;
}
else
2012-03-30 01:51:25 +00:00
prev_proxylock = 0;
2012-03-30 01:51:25 +00:00
show_upbut = ((prev_proxylock == 0) && (con->prev));
show_downbut = (con->next) ? 1 : 0;
/* enabled */
uiBlockSetEmboss(block, UI_EMBOSSN);
uiItemR(row, &ptr, "mute", 0, "",
(con->flag & CONSTRAINT_OFF) ? ICON_RESTRICT_VIEW_ON : ICON_RESTRICT_VIEW_OFF);
uiBlockSetEmboss(block, UI_EMBOSS);
uiLayoutSetOperatorContext(row, WM_OP_INVOKE_DEFAULT);
/* up/down */
if (show_upbut || show_downbut) {
uiBlockBeginAlign(block);
if (show_upbut)
uiItemO(row, "", ICON_TRIA_UP, "CONSTRAINT_OT_move_up");
if (show_downbut)
uiItemO(row, "", ICON_TRIA_DOWN, "CONSTRAINT_OT_move_down");
uiBlockEndAlign(block);
}
/* Close 'button' - emboss calls here disable drawing of 'button' behind X */
uiBlockSetEmboss(block, UI_EMBOSSN);
uiItemO(row, "", ICON_X, "CONSTRAINT_OT_delete");
uiBlockSetEmboss(block, UI_EMBOSS);
}
/* Set but-locks for protected settings (magic numbers are used here!) */
if (proxy_protected)
uiBlockSetButLock(block, 1, "Cannot edit Proxy-Protected Constraint");
/* Draw constraint data */
if ((con->flag & CONSTRAINT_EXPAND) == 0) {
(yco) -= 21;
}
else {
2012-03-30 01:51:25 +00:00
box = uiLayoutBox(col);
block = uiLayoutAbsoluteBlock(box);
result = box;
}
/* clear any locks set up for proxies/lib-linking */
uiBlockClearButLock(block);
return result;
}
uiLayout *uiTemplateConstraint(uiLayout *layout, PointerRNA *ptr)
{
Object *ob;
bConstraint *con;
/* verify we have valid data */
if (!RNA_struct_is_a(ptr->type, &RNA_Constraint)) {
RNA_warning("Expected constraint on object");
return NULL;
}
2012-03-30 01:51:25 +00:00
ob = ptr->id.data;
con = ptr->data;
if (!ob || !(GS(ob->id.name) == ID_OB)) {
RNA_warning("Expected constraint on object");
return NULL;
}
uiBlockSetButLock(uiLayoutGetBlock(layout), (ob && ob->id.lib), ERROR_LIBDATA_MESSAGE);
/* hrms, the temporal constraint should not draw! */
2012-03-30 01:51:25 +00:00
if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
bKinematicConstraint *data = con->data;
if (data->flag & CONSTRAINT_IK_TEMP)
return NULL;
}
return draw_constraint(layout, ob, con);
}
/************************* Preview Template ***************************/
#include "DNA_lamp_types.h"
#include "DNA_material_types.h"
#include "DNA_world_types.h"
#define B_MATPRV 1
static void do_preview_buttons(bContext *C, void *arg, int event)
{
2012-03-30 01:51:25 +00:00
switch (event) {
case B_MATPRV:
2012-03-30 01:51:25 +00:00
WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING, arg);
break;
}
}
void uiTemplatePreview(uiLayout *layout, ID *id, int show_buttons, ID *parent, MTex *slot)
{
uiLayout *row, *col;
uiBlock *block;
2012-03-30 01:51:25 +00:00
Material *ma = NULL;
Tex *tex = (Tex *)id;
ID *pid, *pparent;
2012-03-30 01:51:25 +00:00
short *pr_texture = NULL;
PointerRNA material_ptr;
PointerRNA texture_ptr;
if (id && !ELEM4(GS(id->name), ID_MA, ID_TE, ID_WO, ID_LA)) {
RNA_warning("Expected ID of type material, texture, lamp or world");
return;
}
/* decide what to render */
2012-03-30 01:51:25 +00:00
pid = id;
pparent = NULL;
if (id && (GS(id->name) == ID_TE)) {
if (parent && (GS(parent->name) == ID_MA))
2012-03-30 01:51:25 +00:00
pr_texture = &((Material *)parent)->pr_texture;
else if (parent && (GS(parent->name) == ID_WO))
2012-03-30 01:51:25 +00:00
pr_texture = &((World *)parent)->pr_texture;
else if (parent && (GS(parent->name) == ID_LA))
2012-03-30 01:51:25 +00:00
pr_texture = &((Lamp *)parent)->pr_texture;
if (pr_texture) {
if (*pr_texture == TEX_PR_OTHER)
2012-03-30 01:51:25 +00:00
pid = parent;
else if (*pr_texture == TEX_PR_BOTH)
2012-03-30 01:51:25 +00:00
pparent = parent;
}
}
/* layout */
2012-03-30 01:51:25 +00:00
block = uiLayoutGetBlock(layout);
row = uiLayoutRow(layout, FALSE);
col = uiLayoutColumn(row, FALSE);
2012-09-04 18:47:08 +00:00
uiLayoutSetKeepAspect(col, TRUE);
/* add preview */
2012-03-30 01:51:25 +00:00
uiDefBut(block, BUT_EXTRA, 0, "", 0, 0, UI_UNIT_X * 6, UI_UNIT_Y * 6, pid, 0.0, 0.0, 0, 0, "");
uiBlockSetDrawExtraFunc(block, ED_preview_draw, pparent, slot);
uiBlockSetHandleFunc(block, do_preview_buttons, NULL);
/* add buttons */
if (pid && show_buttons) {
if (GS(pid->name) == ID_MA || (pparent && GS(pparent->name) == ID_MA)) {
2012-03-30 01:51:25 +00:00
if (GS(pid->name) == ID_MA) ma = (Material *)pid;
else ma = (Material *)pparent;
/* Create RNA Pointer */
RNA_pointer_create(&ma->id, &RNA_Material, ma, &material_ptr);
col = uiLayoutColumn(row, TRUE);
uiLayoutSetScaleX(col, 1.5);
uiItemR(col, &material_ptr, "preview_render_type", UI_ITEM_R_EXPAND, "", ICON_NONE);
}
if (pr_texture) {
/* Create RNA Pointer */
RNA_pointer_create(id, &RNA_Texture, tex, &texture_ptr);
uiLayoutRow(layout, TRUE);
uiDefButS(block, ROW, B_MATPRV, IFACE_("Texture"), 0, 0, UI_UNIT_X * 10, UI_UNIT_Y,
pr_texture, 10, TEX_PR_TEXTURE, 0, 0, "");
if (GS(parent->name) == ID_MA) {
uiDefButS(block, ROW, B_MATPRV, IFACE_("Material"), 0, 0, UI_UNIT_X * 10, UI_UNIT_Y,
pr_texture, 10, TEX_PR_OTHER, 0, 0, "");
}
else if (GS(parent->name) == ID_LA) {
uiDefButS(block, ROW, B_MATPRV, IFACE_("Lamp"), 0, 0, UI_UNIT_X * 10, UI_UNIT_Y,
pr_texture, 10, TEX_PR_OTHER, 0, 0, "");
}
else if (GS(parent->name) == ID_WO) {
uiDefButS(block, ROW, B_MATPRV, IFACE_("World"), 0, 0, UI_UNIT_X * 10, UI_UNIT_Y,
pr_texture, 10, TEX_PR_OTHER, 0, 0, "");
}
uiDefButS(block, ROW, B_MATPRV, IFACE_("Both"), 0, 0, UI_UNIT_X * 10, UI_UNIT_Y,
pr_texture, 10, TEX_PR_BOTH, 0, 0, "");
/* Alpha button for texture preview */
2012-03-30 01:51:25 +00:00
if (*pr_texture != TEX_PR_OTHER) {
row = uiLayoutRow(layout, FALSE);
uiItemR(row, &texture_ptr, "use_preview_alpha", 0, NULL, ICON_NONE);
}
}
}
}
/********************** ColorRamp Template **************************/
typedef struct RNAUpdateCb {
PointerRNA ptr;
PropertyRNA *prop;
} RNAUpdateCb;
static void rna_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg))
{
2012-03-30 01:51:25 +00:00
RNAUpdateCb *cb = (RNAUpdateCb *)arg_cb;
/* we call update here on the pointer property, this way the
* owner of the curve mapping can still define it's own update
* and notifier, even if the CurveMapping struct is shared. */
RNA_property_update(C, &cb->ptr, cb->prop);
}
static void colorband_add_cb(bContext *C, void *cb_v, void *coba_v)
{
2012-03-30 01:51:25 +00:00
ColorBand *coba = coba_v;
float pos = 0.5f;
if (coba->tot > 1) {
2012-03-30 01:51:25 +00:00
if (coba->cur > 0) pos = (coba->data[coba->cur - 1].pos + coba->data[coba->cur].pos) * 0.5f;
else pos = (coba->data[coba->cur + 1].pos + coba->data[coba->cur].pos) * 0.5f;
}
if (colorband_element_add(coba, pos)) {
rna_update_cb(C, cb_v, NULL);
ED_undo_push(C, "Add colorband");
}
}
static void colorband_del_cb(bContext *C, void *cb_v, void *coba_v)
{
2012-03-30 01:51:25 +00:00
ColorBand *coba = coba_v;
if (colorband_element_remove(coba, coba->cur)) {
ED_undo_push(C, "Delete colorband");
rna_update_cb(C, cb_v, NULL);
}
}
static void colorband_flip_cb(bContext *C, void *cb_v, void *coba_v)
{
CBData data_tmp[MAXCOLORBAND];
2012-03-30 01:51:25 +00:00
ColorBand *coba = coba_v;
int a;
2012-03-30 01:51:25 +00:00
for (a = 0; a < coba->tot; a++) {
data_tmp[a] = coba->data[coba->tot - (a + 1)];
}
2012-03-30 01:51:25 +00:00
for (a = 0; a < coba->tot; a++) {
data_tmp[a].pos = 1.0f - data_tmp[a].pos;
2012-03-30 01:51:25 +00:00
coba->data[a] = data_tmp[a];
}
/* may as well flip the cur*/
2012-03-30 01:51:25 +00:00
coba->cur = coba->tot - (coba->cur + 1);
ED_undo_push(C, "Flip colorband");
rna_update_cb(C, cb_v, NULL);
}
static void colorband_update_cb(bContext *UNUSED(C), void *bt_v, void *coba_v)
{
2012-03-30 01:51:25 +00:00
uiBut *bt = bt_v;
ColorBand *coba = coba_v;
/* sneaky update here, we need to sort the colorband points to be in order,
* however the RNA pointer then is wrong, so we update it */
colorband_update_sort(coba);
bt->rnapoin.data = coba->data + coba->cur;
}
/* offset aligns from bottom, standard width 300, height 115 */
static void colorband_buttons_large(uiLayout *layout, uiBlock *block, ColorBand *coba,
int xoffs, int yoffs, RNAUpdateCb *cb)
{
uiBut *bt;
uiLayout *row;
2012-03-30 01:51:25 +00:00
const int line1_y = yoffs + 65 + UI_UNIT_Y + 2; /* 2 for some space between the buttons */
const int line2_y = yoffs + 65;
2012-03-30 01:51:25 +00:00
if (coba == NULL) return;
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
2012-03-30 01:51:25 +00:00
bt = uiDefBut(block, BUT, 0, IFACE_("Add"), 0 + xoffs, line1_y, 40, UI_UNIT_Y, NULL, 0, 0, 0, 0,
TIP_("Add a new color stop to the colorband"));
uiButSetNFunc(bt, colorband_add_cb, MEM_dupallocN(cb), coba);
2012-03-30 01:51:25 +00:00
bt = uiDefBut(block, BUT, 0, IFACE_("Delete"), 45 + xoffs, line1_y, 45, UI_UNIT_Y, NULL, 0, 0, 0, 0,
TIP_("Delete the active position"));
uiButSetNFunc(bt, colorband_del_cb, MEM_dupallocN(cb), coba);
/* XXX, todo for later - convert to operator - campbell */
bt = uiDefBut(block, BUT, 0, "F", 95 + xoffs, line1_y, 20, UI_UNIT_Y,
NULL, 0, 0, 0, 0, TIP_("Flip colorband"));
uiButSetNFunc(bt, colorband_flip_cb, MEM_dupallocN(cb), coba);
uiDefButS(block, NUM, 0, "", 120 + xoffs, line1_y, 80, UI_UNIT_Y, &coba->cur, 0.0, (float)(MAX2(0, coba->tot - 1)),
0, 0, TIP_("Choose active color stop"));
bt = uiDefButS(block, MENU, 0, IFACE_("Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4"),
210 + xoffs, line1_y, 90, UI_UNIT_Y, &coba->ipotype, 0.0, 0.0, 0, 0,
TIP_("Set interpolation between color stops"));
uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
uiBlockEndAlign(block);
2012-03-30 01:51:25 +00:00
bt = uiDefBut(block, BUT_COLORBAND, 0, "", xoffs, line2_y, 300, UI_UNIT_Y, coba, 0, 0, 0, 0, "");
uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
if (coba->tot) {
2012-03-30 01:51:25 +00:00
CBData *cbd = coba->data + coba->cur;
/* better to use rna so we can animate them */
PointerRNA ptr;
RNA_pointer_create(cb->ptr.id.data, &RNA_ColorRampElement, cbd, &ptr);
row = uiLayoutRow(layout, FALSE);
uiItemR(row, &ptr, "position", 0, "Pos", ICON_NONE);
2012-03-30 01:51:25 +00:00
bt = block->buttons.last;
uiButSetFunc(bt, colorband_update_cb, bt, coba);
uiItemR(row, &ptr, "color", 0, "", ICON_NONE);
}
}
static void colorband_buttons_small(uiLayout *layout, uiBlock *block, ColorBand *coba, rctf *butr, RNAUpdateCb *cb)
{
uiBut *bt;
float unit = BLI_rctf_size_x(butr) / 14.0f;
2012-03-30 01:51:25 +00:00
float xs = butr->xmin;
uiBlockBeginAlign(block);
2012-03-30 01:51:25 +00:00
bt = uiDefBut(block, BUT, 0, IFACE_("Add"), xs, butr->ymin + UI_UNIT_Y, 2.0f * unit, UI_UNIT_Y, NULL, 0, 0, 0, 0,
TIP_("Add a new color stop to the colorband"));
uiButSetNFunc(bt, colorband_add_cb, MEM_dupallocN(cb), coba);
bt = uiDefBut(block, BUT, 0, IFACE_("Delete"), xs + 2.0f * unit, butr->ymin + UI_UNIT_Y, 1.5f * unit, UI_UNIT_Y,
NULL, 0, 0, 0, 0, TIP_("Delete the active position"));
uiButSetNFunc(bt, colorband_del_cb, MEM_dupallocN(cb), coba);
bt = uiDefBut(block, BUT, 0, "F", xs + 3.5f * unit, butr->ymin + UI_UNIT_Y, 0.5f * unit, UI_UNIT_Y,
NULL, 0, 0, 0, 0, TIP_("Flip the color ramp"));
uiButSetNFunc(bt, colorband_flip_cb, MEM_dupallocN(cb), coba);
uiBlockEndAlign(block);
if (coba->tot) {
2012-03-30 01:51:25 +00:00
CBData *cbd = coba->data + coba->cur;
PointerRNA ptr;
RNA_pointer_create(cb->ptr.id.data, &RNA_ColorRampElement, cbd, &ptr);
uiItemR(layout, &ptr, "color", 0, "", ICON_NONE);
}
bt = uiDefButS(block, MENU, 0, IFACE_("Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4"),
xs + 10.0f * unit, butr->ymin + UI_UNIT_Y, unit * 4, UI_UNIT_Y, &coba->ipotype, 0.0, 0.0, 0, 0,
2012-03-30 01:51:25 +00:00
TIP_("Set interpolation between color stops"));
uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
bt = uiDefBut(block, BUT_COLORBAND, 0, "", xs, butr->ymin, BLI_rctf_size_x(butr), UI_UNIT_Y, coba, 0, 0, 0, 0, "");
uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
uiBlockEndAlign(block);
}
static void colorband_buttons_layout(uiLayout *layout, uiBlock *block, ColorBand *coba, rctf *butr,
int small, RNAUpdateCb *cb)
{
if (small)
colorband_buttons_small(layout, block, coba, butr, cb);
else
colorband_buttons_large(layout, block, coba, 0, 0, cb);
}
void uiTemplateColorRamp(uiLayout *layout, PointerRNA *ptr, const char *propname, int expand)
{
2012-03-30 01:51:25 +00:00
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
PointerRNA cptr;
RNAUpdateCb *cb;
uiBlock *block;
rctf rect;
if (!prop || RNA_property_type(prop) != PROP_POINTER)
return;
2012-03-30 01:51:25 +00:00
cptr = RNA_property_pointer_get(ptr, prop);
if (!cptr.data || !RNA_struct_is_a(cptr.type, &RNA_ColorRamp))
return;
2012-03-30 01:51:25 +00:00
cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
cb->ptr = *ptr;
cb->prop = prop;
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
rect.xmin = 0; rect.xmax = 10.0f * UI_UNIT_X;
rect.ymin = 0; rect.ymax = 19.5f * UI_UNIT_X;
2012-03-30 01:51:25 +00:00
block = uiLayoutAbsoluteBlock(layout);
colorband_buttons_layout(layout, block, cptr.data, &rect, !expand, cb);
MEM_freeN(cb);
}
/********************* Histogram Template ************************/
void uiTemplateHistogram(uiLayout *layout, PointerRNA *ptr, const char *propname)
{
2012-03-30 01:51:25 +00:00
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
PointerRNA cptr;
RNAUpdateCb *cb;
uiBlock *block;
uiBut *bt;
Histogram *hist;
rctf rect;
if (!prop || RNA_property_type(prop) != PROP_POINTER)
return;
2012-03-30 01:51:25 +00:00
cptr = RNA_property_pointer_get(ptr, prop);
if (!cptr.data || !RNA_struct_is_a(cptr.type, &RNA_Histogram))
return;
2012-03-30 01:51:25 +00:00
cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
cb->ptr = *ptr;
cb->prop = prop;
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
rect.xmin = 0; rect.xmax = 10.0f * UI_UNIT_X;
rect.ymin = 0; rect.ymax = 9.5f * UI_UNIT_Y;
2012-03-30 01:51:25 +00:00
block = uiLayoutAbsoluteBlock(layout);
//colorband_buttons_layout(layout, block, cptr.data, &rect, !expand, cb);
hist = (Histogram *)cptr.data;
2012-03-30 01:51:25 +00:00
hist->height = (hist->height <= UI_UNIT_Y) ? UI_UNIT_Y : hist->height;
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
bt = uiDefBut(block, HISTOGRAM, 0, "", rect.xmin, rect.ymin, BLI_rctf_size_x(&rect), UI_DPI_FAC * hist->height,
hist, 0, 0, 0, 0, "");
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
MEM_freeN(cb);
}
/********************* Waveform Template ************************/
void uiTemplateWaveform(uiLayout *layout, PointerRNA *ptr, const char *propname)
{
2012-03-30 01:51:25 +00:00
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
PointerRNA cptr;
RNAUpdateCb *cb;
uiBlock *block;
uiBut *bt;
Scopes *scopes;
rctf rect;
if (!prop || RNA_property_type(prop) != PROP_POINTER)
return;
2012-03-30 01:51:25 +00:00
cptr = RNA_property_pointer_get(ptr, prop);
if (!cptr.data || !RNA_struct_is_a(cptr.type, &RNA_Scopes))
return;
scopes = (Scopes *)cptr.data;
2012-03-30 01:51:25 +00:00
cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
cb->ptr = *ptr;
cb->prop = prop;
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
rect.xmin = 0; rect.xmax = 10.0f * UI_UNIT_X;
rect.ymin = 0; rect.ymax = 9.5f * UI_UNIT_Y;
2012-03-30 01:51:25 +00:00
block = uiLayoutAbsoluteBlock(layout);
2012-03-30 01:51:25 +00:00
scopes->wavefrm_height = (scopes->wavefrm_height <= UI_UNIT_Y) ? UI_UNIT_Y : scopes->wavefrm_height;
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
bt = uiDefBut(block, WAVEFORM, 0, "", rect.xmin, rect.ymin, BLI_rctf_size_x(&rect), UI_DPI_FAC * scopes->wavefrm_height,
scopes, 0, 0, 0, 0, "");
2012-08-19 10:41:27 +00:00
(void)bt; /* UNUSED */
MEM_freeN(cb);
}
/********************* Vectorscope Template ************************/
void uiTemplateVectorscope(uiLayout *layout, PointerRNA *ptr, const char *propname)
{
2012-03-30 01:51:25 +00:00
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
PointerRNA cptr;
RNAUpdateCb *cb;
uiBlock *block;
uiBut *bt;
Scopes *scopes;
rctf rect;
if (!prop || RNA_property_type(prop) != PROP_POINTER)
return;
2012-03-30 01:51:25 +00:00
cptr = RNA_property_pointer_get(ptr, prop);
if (!cptr.data || !RNA_struct_is_a(cptr.type, &RNA_Scopes))
return;
scopes = (Scopes *)cptr.data;
2012-03-30 01:51:25 +00:00
cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
cb->ptr = *ptr;
cb->prop = prop;
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
rect.xmin = 0; rect.xmax = 10.0f * UI_UNIT_X;
rect.ymin = 0; rect.ymax = 9.5f * UI_UNIT_Y;
2012-03-30 01:51:25 +00:00
block = uiLayoutAbsoluteBlock(layout);
2012-03-30 01:51:25 +00:00
scopes->vecscope_height = (scopes->vecscope_height <= UI_UNIT_Y) ? UI_UNIT_Y : scopes->vecscope_height;
bt = uiDefBut(block, VECTORSCOPE, 0, "", rect.xmin, rect.ymin, BLI_rctf_size_x(&rect),
UI_DPI_FAC * scopes->vecscope_height, scopes, 0, 0, 0, 0, "");
uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
MEM_freeN(cb);
}
/********************* CurveMapping Template ************************/
static void curvemap_buttons_zoom_in(bContext *C, void *cumap_v, void *UNUSED(arg))
{
CurveMapping *cumap = cumap_v;
float d;
/* we allow 20 times zoom */
if (BLI_rctf_size_x(&cumap->curr) > 0.04f * BLI_rctf_size_x(&cumap->clipr)) {
d = 0.1154f * BLI_rctf_size_x(&cumap->curr);
2012-03-30 01:51:25 +00:00
cumap->curr.xmin += d;
cumap->curr.xmax -= d;
d = 0.1154f * BLI_rctf_size_y(&cumap->curr);
2012-03-30 01:51:25 +00:00
cumap->curr.ymin += d;
cumap->curr.ymax -= d;
}
ED_region_tag_redraw(CTX_wm_region(C));
}
static void curvemap_buttons_zoom_out(bContext *C, void *cumap_v, void *UNUSED(unused))
{
CurveMapping *cumap = cumap_v;
float d, d1;
2012-03-18 07:38:51 +00:00
/* we allow 20 times zoom, but don't view outside clip */
if (BLI_rctf_size_x(&cumap->curr) < 20.0f * BLI_rctf_size_x(&cumap->clipr)) {
d = d1 = 0.15f * BLI_rctf_size_x(&cumap->curr);
if (cumap->flag & CUMA_DO_CLIP)
2012-03-30 01:51:25 +00:00
if (cumap->curr.xmin - d < cumap->clipr.xmin)
d1 = cumap->curr.xmin - cumap->clipr.xmin;
cumap->curr.xmin -= d1;
2012-03-30 01:51:25 +00:00
d1 = d;
if (cumap->flag & CUMA_DO_CLIP)
2012-03-30 01:51:25 +00:00
if (cumap->curr.xmax + d > cumap->clipr.xmax)
d1 = -cumap->curr.xmax + cumap->clipr.xmax;
cumap->curr.xmax += d1;
d = d1 = 0.15f * BLI_rctf_size_y(&cumap->curr);
if (cumap->flag & CUMA_DO_CLIP)
2012-03-30 01:51:25 +00:00
if (cumap->curr.ymin - d < cumap->clipr.ymin)
d1 = cumap->curr.ymin - cumap->clipr.ymin;
cumap->curr.ymin -= d1;
2012-03-30 01:51:25 +00:00
d1 = d;
if (cumap->flag & CUMA_DO_CLIP)
2012-03-30 01:51:25 +00:00
if (cumap->curr.ymax + d > cumap->clipr.ymax)
d1 = -cumap->curr.ymax + cumap->clipr.ymax;
cumap->curr.ymax += d1;
}
ED_region_tag_redraw(CTX_wm_region(C));
}
static void curvemap_buttons_setclip(bContext *UNUSED(C), void *cumap_v, void *UNUSED(arg))
{
CurveMapping *cumap = cumap_v;
curvemapping_changed(cumap, FALSE);
}
static void curvemap_buttons_delete(bContext *C, void *cb_v, void *cumap_v)
{
CurveMapping *cumap = cumap_v;
2012-03-30 01:51:25 +00:00
curvemap_remove(cumap->cm + cumap->cur, SELECT);
curvemapping_changed(cumap, FALSE);
rna_update_cb(C, cb_v, NULL);
}
/* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
static uiBlock *curvemap_clipping_func(bContext *C, ARegion *ar, void *cumap_v)
{
CurveMapping *cumap = cumap_v;
uiBlock *block;
uiBut *bt;
2012-03-30 01:51:25 +00:00
float width = 8 * UI_UNIT_X;
block = uiBeginBlock(C, ar, __func__, UI_EMBOSS);
/* use this for a fake extra empy space around the buttons */
2012-03-30 01:51:25 +00:00
uiDefBut(block, LABEL, 0, "", -4, 16, width + 8, 6 * UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
2012-03-30 01:51:25 +00:00
bt = uiDefButBitI(block, TOG, CUMA_DO_CLIP, 1, "Use Clipping",
0, 5 * UI_UNIT_Y, width, UI_UNIT_Y, &cumap->flag, 0.0, 0.0, 10, 0, "");
uiButSetFunc(bt, curvemap_buttons_setclip, cumap, NULL);
uiBlockBeginAlign(block);
uiDefButF(block, NUM, 0, IFACE_("Min X "), 0, 4 * UI_UNIT_Y, width, UI_UNIT_Y,
&cumap->clipr.xmin, -100.0, cumap->clipr.xmax, 10, 0, "");
uiDefButF(block, NUM, 0, IFACE_("Min Y "), 0, 3 * UI_UNIT_Y, width, UI_UNIT_Y,
&cumap->clipr.ymin, -100.0, cumap->clipr.ymax, 10, 0, "");
uiDefButF(block, NUM, 0, IFACE_("Max X "), 0, 2 * UI_UNIT_Y, width, UI_UNIT_Y,
&cumap->clipr.xmax, cumap->clipr.xmin, 100.0, 10, 0, "");
uiDefButF(block, NUM, 0, IFACE_("Max Y "), 0, UI_UNIT_Y, width, UI_UNIT_Y,
&cumap->clipr.ymax, cumap->clipr.ymin, 100.0, 10, 0, "");
uiBlockSetDirection(block, UI_RIGHT);
uiEndBlock(C, block);
return block;
}
static void curvemap_tools_dofunc(bContext *C, void *cumap_v, int event)
{
CurveMapping *cumap = cumap_v;
2012-03-30 01:51:25 +00:00
CurveMap *cuma = cumap->cm + cumap->cur;
2012-03-30 01:51:25 +00:00
switch (event) {
case 0: /* reset */
2012-03-30 01:51:25 +00:00
curvemap_reset(cuma, &cumap->clipr, cumap->preset, CURVEMAP_SLOPE_POSITIVE);
curvemapping_changed(cumap, FALSE);
break;
case 1:
2012-03-30 01:51:25 +00:00
cumap->curr = cumap->clipr;
break;
2012-03-30 01:51:25 +00:00
case 2: /* set vector */
curvemap_sethandle(cuma, 1);
curvemapping_changed(cumap, FALSE);
break;
case 3: /* set auto */
curvemap_sethandle(cuma, 0);
curvemapping_changed(cumap, FALSE);
break;
case 4: /* extend horiz */
cuma->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
curvemapping_changed(cumap, FALSE);
break;
case 5: /* extend extrapolate */
cuma->flag |= CUMA_EXTEND_EXTRAPOLATE;
curvemapping_changed(cumap, FALSE);
break;
}
ED_region_tag_redraw(CTX_wm_region(C));
}
static uiBlock *curvemap_tools_func(bContext *C, ARegion *ar, void *cumap_v)
{
uiBlock *block;
2012-03-30 01:51:25 +00:00
short yco = 0, menuwidth = 10 * UI_UNIT_X;
2012-03-30 01:51:25 +00:00
block = uiBeginBlock(C, ar, __func__, UI_EMBOSS);
uiBlockSetButmFunc(block, curvemap_tools_dofunc, cumap_v);
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Reset View"), 0, yco -= UI_UNIT_Y,
menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 1, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Vector Handle"), 0, yco -= UI_UNIT_Y,
menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 2, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Auto Handle"), 0, yco -= UI_UNIT_Y,
menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 3, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Extend Horizontal"), 0, yco -= UI_UNIT_Y,
menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 4, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Extend Extrapolated"), 0, yco -= UI_UNIT_Y,
menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 5, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Reset Curve"), 0, yco -= UI_UNIT_Y,
menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
uiBlockSetDirection(block, UI_RIGHT);
uiTextBoundsBlock(block, 50);
uiEndBlock(C, block);
return block;
}
static uiBlock *curvemap_brush_tools_func(bContext *C, ARegion *ar, void *cumap_v)
{
uiBlock *block;
2012-03-30 01:51:25 +00:00
short yco = 0, menuwidth = 10 * UI_UNIT_X;
2012-03-30 01:51:25 +00:00
block = uiBeginBlock(C, ar, __func__, UI_EMBOSS);
uiBlockSetButmFunc(block, curvemap_tools_dofunc, cumap_v);
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Reset View"), 0, yco -= UI_UNIT_Y,
menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 1, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Vector Handle"), 0, yco -= UI_UNIT_Y,
menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 2, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Auto Handle"), 0, yco -= UI_UNIT_Y,
menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 3, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Reset Curve"), 0, yco -= UI_UNIT_Y,
menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
uiBlockSetDirection(block, UI_RIGHT);
uiTextBoundsBlock(block, 50);
uiEndBlock(C, block);
return block;
}
static void curvemap_buttons_redraw(bContext *C, void *UNUSED(arg1), void *UNUSED(arg2))
{
ED_region_tag_redraw(CTX_wm_region(C));
}
static void curvemap_buttons_update(bContext *C, void *arg1_v, void *cumap_v)
{
CurveMapping *cumap = cumap_v;
curvemapping_changed(cumap, TRUE);
rna_update_cb(C, arg1_v, NULL);
}
static void curvemap_buttons_reset(bContext *C, void *cb_v, void *cumap_v)
{
CurveMapping *cumap = cumap_v;
int a;
cumap->preset = CURVE_PRESET_LINE;
2012-03-30 01:51:25 +00:00
for (a = 0; a < CM_TOT; a++)
curvemap_reset(cumap->cm + a, &cumap->clipr, cumap->preset, CURVEMAP_SLOPE_POSITIVE);
2012-03-30 01:51:25 +00:00
cumap->black[0] = cumap->black[1] = cumap->black[2] = 0.0f;
cumap->white[0] = cumap->white[1] = cumap->white[2] = 1.0f;
curvemapping_set_black_white(cumap, NULL, NULL);
curvemapping_changed(cumap, FALSE);
rna_update_cb(C, cb_v, NULL);
}
/* still unsure how this call evolves... we use labeltype for defining what curve-channels to show */
static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labeltype, int levels,
int brush, RNAUpdateCb *cb)
{
2012-03-30 01:51:25 +00:00
CurveMapping *cumap = ptr->data;
CurveMap *cm = &cumap->cm[cumap->cur];
CurveMapPoint *cmp = NULL;
uiLayout *row, *sub, *split;
uiBlock *block;
uiBut *bt;
2012-03-30 01:51:25 +00:00
float dx = UI_UNIT_X;
int icon, size;
int bg = -1, i;
2012-03-30 01:51:25 +00:00
block = uiLayoutGetBlock(layout);
/* curve chooser */
row = uiLayoutRow(layout, FALSE);
2012-03-30 01:51:25 +00:00
if (labeltype == 'v') {
/* vector */
sub = uiLayoutRow(row, TRUE);
uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_LEFT);
if (cumap->cm[0].curve) {
2012-03-30 01:51:25 +00:00
bt = uiDefButI(block, ROW, 0, "X", 0, 0, dx, dx, &cumap->cur, 0.0, 0.0, 0.0, 0.0, "");
uiButSetFunc(bt, curvemap_buttons_redraw, NULL, NULL);
}
if (cumap->cm[1].curve) {
2012-03-30 01:51:25 +00:00
bt = uiDefButI(block, ROW, 0, "Y", 0, 0, dx, dx, &cumap->cur, 0.0, 1.0, 0.0, 0.0, "");
uiButSetFunc(bt, curvemap_buttons_redraw, NULL, NULL);
}
if (cumap->cm[2].curve) {
2012-03-30 01:51:25 +00:00
bt = uiDefButI(block, ROW, 0, "Z", 0, 0, dx, dx, &cumap->cur, 0.0, 2.0, 0.0, 0.0, "");
uiButSetFunc(bt, curvemap_buttons_redraw, NULL, NULL);
}
}
2012-03-30 01:51:25 +00:00
else if (labeltype == 'c') {
/* color */
sub = uiLayoutRow(row, TRUE);
uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_LEFT);
if (cumap->cm[3].curve) {
2012-03-30 01:51:25 +00:00
bt = uiDefButI(block, ROW, 0, "C", 0, 0, dx, dx, &cumap->cur, 0.0, 3.0, 0.0, 0.0, "");
uiButSetFunc(bt, curvemap_buttons_redraw, NULL, NULL);
}
if (cumap->cm[0].curve) {
2012-03-30 01:51:25 +00:00
bt = uiDefButI(block, ROW, 0, "R", 0, 0, dx, dx, &cumap->cur, 0.0, 0.0, 0.0, 0.0, "");
uiButSetFunc(bt, curvemap_buttons_redraw, NULL, NULL);
}
if (cumap->cm[1].curve) {
2012-03-30 01:51:25 +00:00
bt = uiDefButI(block, ROW, 0, "G", 0, 0, dx, dx, &cumap->cur, 0.0, 1.0, 0.0, 0.0, "");
uiButSetFunc(bt, curvemap_buttons_redraw, NULL, NULL);
}
if (cumap->cm[2].curve) {
2012-03-30 01:51:25 +00:00
bt = uiDefButI(block, ROW, 0, "B", 0, 0, dx, dx, &cumap->cur, 0.0, 2.0, 0.0, 0.0, "");
uiButSetFunc(bt, curvemap_buttons_redraw, NULL, NULL);
}
}
else if (labeltype == 'h') {
/* HSV */
sub = uiLayoutRow(row, TRUE);
uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_LEFT);
if (cumap->cm[0].curve) {
2012-03-30 01:51:25 +00:00
bt = uiDefButI(block, ROW, 0, "H", 0, 0, dx, dx, &cumap->cur, 0.0, 0.0, 0.0, 0.0, "");
uiButSetFunc(bt, curvemap_buttons_redraw, NULL, NULL);
}
if (cumap->cm[1].curve) {
2012-03-30 01:51:25 +00:00
bt = uiDefButI(block, ROW, 0, "S", 0, 0, dx, dx, &cumap->cur, 0.0, 1.0, 0.0, 0.0, "");
uiButSetFunc(bt, curvemap_buttons_redraw, NULL, NULL);
}
if (cumap->cm[2].curve) {
2012-03-30 01:51:25 +00:00
bt = uiDefButI(block, ROW, 0, "V", 0, 0, dx, dx, &cumap->cur, 0.0, 2.0, 0.0, 0.0, "");
uiButSetFunc(bt, curvemap_buttons_redraw, NULL, NULL);
}
}
else
uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT);
2012-03-30 01:51:25 +00:00
if (labeltype == 'h')
bg = UI_GRAD_H;
/* operation buttons */
sub = uiLayoutRow(row, TRUE);
uiBlockSetEmboss(block, UI_EMBOSSN);
2012-03-30 01:51:25 +00:00
bt = uiDefIconBut(block, BUT, 0, ICON_ZOOMIN, 0, 0, dx, dx, NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Zoom in"));
uiButSetFunc(bt, curvemap_buttons_zoom_in, cumap, NULL);
2012-03-30 01:51:25 +00:00
bt = uiDefIconBut(block, BUT, 0, ICON_ZOOMOUT, 0, 0, dx, dx, NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Zoom out"));
uiButSetFunc(bt, curvemap_buttons_zoom_out, cumap, NULL);
if (brush)
2012-03-30 01:51:25 +00:00
bt = uiDefIconBlockBut(block, curvemap_brush_tools_func, cumap, 0, ICON_MODIFIER, 0, 0, dx, dx, TIP_("Tools"));
else
2012-03-30 01:51:25 +00:00
bt = uiDefIconBlockBut(block, curvemap_tools_func, cumap, 0, ICON_MODIFIER, 0, 0, dx, dx, TIP_("Tools"));
uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
icon = (cumap->flag & CUMA_DO_CLIP) ? ICON_CLIPUV_HLT : ICON_CLIPUV_DEHLT;
2012-03-30 01:51:25 +00:00
bt = uiDefIconBlockBut(block, curvemap_clipping_func, cumap, 0, icon, 0, 0, dx, dx, TIP_("Clipping Options"));
uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
2012-03-30 01:51:25 +00:00
bt = uiDefIconBut(block, BUT, 0, ICON_X, 0, 0, dx, dx, NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Delete points"));
uiButSetNFunc(bt, curvemap_buttons_delete, MEM_dupallocN(cb), cumap);
uiBlockSetEmboss(block, UI_EMBOSS);
uiBlockSetNFunc(block, rna_update_cb, MEM_dupallocN(cb), NULL);
/* curve itself */
2012-03-30 01:51:25 +00:00
size = uiLayoutGetWidth(layout);
row = uiLayoutRow(layout, FALSE);
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
uiDefBut(block, BUT_CURVE, 0, "", 0, 0, size, MIN2(size, 10.0f * UI_UNIT_X), cumap, 0.0f, 1.0f, bg, 0, "");
/* sliders for selected point */
for (i = 0; i < cm->totpoint; i++) {
if (cm->curve[i].flag & CUMA_SELECT) {
cmp = &cm->curve[i];
break;
}
}
if (cmp) {
const float range_clamp[2] = {0.0f, 1.0f};
const float range_unclamp[2] = {-1000.0f, 1000.0f}; /* arbitrary limits here */
const float *range = (cumap->flag & CUMA_DO_CLIP) ? range_clamp : range_unclamp;
2012-09-04 18:47:08 +00:00
uiLayoutRow(layout, TRUE);
uiBlockSetNFunc(block, curvemap_buttons_update, MEM_dupallocN(cb), cumap);
bt = uiDefButF(block, NUM, 0, "X", 0, 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y,
&cmp->x, range[0], range[1], 1, 5, "");
bt = uiDefButF(block, NUM, 0, "Y", 0, 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y,
&cmp->y, range[0], range[1], 1, 5, "");
}
/* black/white levels */
if (levels) {
split = uiLayoutSplit(layout, 0.0f, FALSE);
uiItemR(uiLayoutColumn(split, FALSE), ptr, "black_level", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
uiItemR(uiLayoutColumn(split, FALSE), ptr, "white_level", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
uiLayoutRow(layout, FALSE);
2012-03-30 01:51:25 +00:00
bt = uiDefBut(block, BUT, 0, IFACE_("Reset"), 0, 0, UI_UNIT_X * 10, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0,
TIP_("Reset Black/White point and curves"));
uiButSetNFunc(bt, curvemap_buttons_reset, MEM_dupallocN(cb), cumap);
}
uiBlockSetNFunc(block, NULL, NULL, NULL);
}
void uiTemplateCurveMapping(uiLayout *layout, PointerRNA *ptr, const char *propname, int type, int levels, int brush)
{
RNAUpdateCb *cb;
2012-03-30 01:51:25 +00:00
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
PointerRNA cptr;
if (!prop) {
RNA_warning("curve property not found: %s.%s",
RNA_struct_identifier(ptr->type), propname);
return;
}
if (RNA_property_type(prop) != PROP_POINTER) {
RNA_warning("curve is not a pointer: %s.%s",
RNA_struct_identifier(ptr->type), propname);
return;
}
2012-03-30 01:51:25 +00:00
cptr = RNA_property_pointer_get(ptr, prop);
if (!cptr.data || !RNA_struct_is_a(cptr.type, &RNA_CurveMapping))
return;
2012-03-30 01:51:25 +00:00
cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
cb->ptr = *ptr;
cb->prop = prop;
curvemap_buttons_layout(layout, &cptr, type, levels, brush, cb);
MEM_freeN(cb);
}
/********************* ColorPicker Template ************************/
#define WHEEL_SIZE (5 * U.widget_unit)
/* This template now follows User Preference for type - name is not correct anymore... */
void uiTemplateColorPicker(uiLayout *layout, PointerRNA *ptr, const char *propname, int value_slider,
int lock, int lock_luminosity, int cubic)
{
2012-03-30 01:51:25 +00:00
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
uiBlock *block = uiLayoutGetBlock(layout);
uiLayout *col, *row;
uiBut *but = NULL;
float softmin, softmax, step, precision;
if (!prop) {
RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
return;
}
RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision);
col = uiLayoutColumn(layout, TRUE);
row = uiLayoutRow(col, TRUE);
switch (U.color_picker_type) {
case USER_CP_CIRCLE:
but = uiDefButR_prop(block, HSVCIRCLE, 0, "", 0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, prop,
-1, 0.0, 0.0, 0, 0, "");
break;
case USER_CP_SQUARE_SV:
but = uiDefButR_prop(block, HSVCUBE, 0, "", 0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, prop,
-1, 0.0, 0.0, UI_GRAD_SV, 0, "");
break;
case USER_CP_SQUARE_HS:
but = uiDefButR_prop(block, HSVCUBE, 0, "", 0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, prop,
-1, 0.0, 0.0, UI_GRAD_HS, 0, "");
break;
case USER_CP_SQUARE_HV:
but = uiDefButR_prop(block, HSVCUBE, 0, "", 0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, prop,
-1, 0.0, 0.0, UI_GRAD_HV, 0, "");
break;
}
if (lock) {
but->flag |= UI_BUT_COLOR_LOCK;
}
if (lock_luminosity) {
float color[4]; /* in case of alpha */
but->flag |= UI_BUT_VEC_SIZE_LOCK;
RNA_property_float_get_array(ptr, prop, color);
2012-03-30 01:51:25 +00:00
but->a2 = len_v3(color);
}
if (cubic)
but->flag |= UI_BUT_COLOR_CUBIC;
if (value_slider) {
switch (U.color_picker_type) {
case USER_CP_CIRCLE:
uiItemS(row);
uiDefButR_prop(block, HSVCUBE, 0, "", WHEEL_SIZE + 6, 0, 14, WHEEL_SIZE, ptr, prop,
-1, softmin, softmax, UI_GRAD_V_ALT, 0, "");
break;
case USER_CP_SQUARE_SV:
uiItemS(col);
uiDefButR_prop(block, HSVCUBE, 0, "", 0, 4, WHEEL_SIZE, 18, ptr, prop,
-1, softmin, softmax, UI_GRAD_SV + 3, 0, "");
break;
case USER_CP_SQUARE_HS:
uiItemS(col);
uiDefButR_prop(block, HSVCUBE, 0, "", 0, 4, WHEEL_SIZE, 18, ptr, prop,
-1, softmin, softmax, UI_GRAD_HS + 3, 0, "");
break;
case USER_CP_SQUARE_HV:
uiItemS(col);
uiDefButR_prop(block, HSVCUBE, 0, "", 0, 4, WHEEL_SIZE, 18, ptr, prop,
-1, softmin, softmax, UI_GRAD_HV + 3, 0, "");
break;
}
}
}
/********************* Layer Buttons Template ************************/
static void handle_layer_buttons(bContext *C, void *arg1, void *arg2)
{
uiBut *but = arg1;
int cur = GET_INT_FROM_POINTER(arg2);
2012-03-30 01:51:25 +00:00
wmWindow *win = CTX_wm_window(C);
int i, tot, shift = win->eventstate->shift;
if (!shift) {
2012-03-30 01:51:25 +00:00
tot = RNA_property_array_length(&but->rnapoin, but->rnaprop);
/* Normally clicking only selects one layer */
RNA_property_boolean_set_index(&but->rnapoin, but->rnaprop, cur, TRUE);
for (i = 0; i < tot; ++i) {
if (i != cur)
RNA_property_boolean_set_index(&but->rnapoin, but->rnaprop, i, FALSE);
}
}
/* view3d layer change should update depsgraph (invisible object changed maybe) */
/* see view3d_header.c */
}
/* TODO:
* - for now, grouping of layers is determined by dividing up the length of
* the array of layer bitflags */
void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, const char *propname,
2012-03-30 01:51:25 +00:00
PointerRNA *used_ptr, const char *used_propname, int active_layer)
{
uiLayout *uRow, *uCol;
2012-03-30 01:51:25 +00:00
PropertyRNA *prop, *used_prop = NULL;
int groups, cols, layers;
int group, col, layer, row;
int cols_per_group = 5;
2012-03-30 01:51:25 +00:00
prop = RNA_struct_find_property(ptr, propname);
if (!prop) {
RNA_warning("layers property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
return;
}
/* the number of layers determines the way we group them
* - we want 2 rows only (for now)
* - the number of columns (cols) is the total number of buttons per row
* the 'remainder' is added to this, as it will be ok to have first row slightly wider if need be
* - for now, only split into groups if group will have at least 5 items
*/
2012-03-30 01:51:25 +00:00
layers = RNA_property_array_length(ptr, prop);
cols = (layers / 2) + (layers % 2);
groups = ((cols / 2) < cols_per_group) ? (1) : (cols / cols_per_group);
if (used_ptr && used_propname) {
2012-03-30 01:51:25 +00:00
used_prop = RNA_struct_find_property(used_ptr, used_propname);
if (!used_prop) {
RNA_warning("used layers property not found: %s.%s", RNA_struct_identifier(ptr->type), used_propname);
return;
}
if (RNA_property_array_length(used_ptr, used_prop) < layers)
used_prop = NULL;
}
/* layers are laid out going across rows, with the columns being divided into groups */
2012-03-30 01:51:25 +00:00
for (group = 0; group < groups; group++) {
uCol = uiLayoutColumn(layout, TRUE);
2012-03-30 01:51:25 +00:00
for (row = 0; row < 2; row++) {
uiBlock *block;
uiBut *but;
uRow = uiLayoutRow(uCol, TRUE);
2012-03-30 01:51:25 +00:00
block = uiLayoutGetBlock(uRow);
layer = groups * cols_per_group * row + cols_per_group * group;
/* add layers as toggle buts */
2012-03-30 01:51:25 +00:00
for (col = 0; (col < cols_per_group) && (layer < layers); col++, layer++) {
int icon = 0;
int butlay = 1 << layer;
if (active_layer & butlay)
icon = ICON_LAYER_ACTIVE;
else if (used_prop && RNA_property_boolean_get_index(used_ptr, used_prop, layer))
icon = ICON_LAYER_USED;
2012-03-30 01:51:25 +00:00
but = uiDefAutoButR(block, ptr, prop, layer, "", icon, 0, 0, UI_UNIT_X / 2, UI_UNIT_Y / 2);
uiButSetFunc(but, handle_layer_buttons, but, SET_INT_IN_POINTER(layer));
2012-03-30 01:51:25 +00:00
but->type = TOG;
}
}
}
}
void uiTemplateGameStates(uiLayout *layout, PointerRNA *ptr, const char *propname,
PointerRNA *used_ptr, const char *used_propname, int active_state)
{
uiLayout *uRow, *uCol;
PropertyRNA *prop, *used_prop = NULL;
int groups, cols, states;
int group, col, state, row;
int cols_per_group = 5;
Object *ob = (Object *)ptr->id.data;
prop = RNA_struct_find_property(ptr, propname);
if (!prop) {
RNA_warning("states property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
return;
}
/* the number of states determines the way we group them
* - we want 2 rows only (for now)
* - the number of columns (cols) is the total number of buttons per row
* the 'remainder' is added to this, as it will be ok to have first row slightly wider if need be
* - for now, only split into groups if group will have at least 5 items
*/
states = RNA_property_array_length(ptr, prop);
cols = (states / 2) + (states % 2);
groups = ((cols / 2) < cols_per_group) ? (1) : (cols / cols_per_group);
if (used_ptr && used_propname) {
used_prop = RNA_struct_find_property(used_ptr, used_propname);
if (!used_prop) {
RNA_warning("used layers property not found: %s.%s", RNA_struct_identifier(ptr->type), used_propname);
return;
}
if (RNA_property_array_length(used_ptr, used_prop) < states)
used_prop = NULL;
}
/* layers are laid out going across rows, with the columns being divided into groups */
for (group = 0; group < groups; group++) {
uCol = uiLayoutColumn(layout, TRUE);
for (row = 0; row < 2; row++) {
uiBlock *block;
uiBut *but;
uRow = uiLayoutRow(uCol, TRUE);
block = uiLayoutGetBlock(uRow);
state = groups * cols_per_group * row + cols_per_group * group;
/* add layers as toggle buts */
for (col = 0; (col < cols_per_group) && (state < states); col++, state++) {
int icon = 0;
int butlay = 1 << state;
if (active_state & butlay)
icon = ICON_LAYER_ACTIVE;
else if (used_prop && RNA_property_boolean_get_index(used_ptr, used_prop, state))
icon = ICON_LAYER_USED;
but = uiDefIconButR_prop(block, ICONTOG, 0, icon, 0, 0, UI_UNIT_X / 2, UI_UNIT_Y / 2, ptr, prop,
state, 0, 0, -1, -1, sca_state_name_get(ob, state));
uiButSetFunc(but, handle_layer_buttons, but, SET_INT_IN_POINTER(state));
but->type = TOG;
}
}
}
}
/************************* List Template **************************/
static int list_item_icon_get(bContext *C, PointerRNA *itemptr, int rnaicon, int big)
{
2012-03-30 01:51:25 +00:00
ID *id = NULL;
int icon;
if (!itemptr->data)
return rnaicon;
/* try ID, material or texture slot */
if (RNA_struct_is_ID(itemptr->type)) {
2012-03-30 01:51:25 +00:00
id = itemptr->id.data;
}
else if (RNA_struct_is_a(itemptr->type, &RNA_MaterialSlot)) {
2012-03-30 01:51:25 +00:00
id = RNA_pointer_get(itemptr, "material").data;
}
else if (RNA_struct_is_a(itemptr->type, &RNA_TextureSlot)) {
2012-03-30 01:51:25 +00:00
id = RNA_pointer_get(itemptr, "texture").data;
}
else if (RNA_struct_is_a(itemptr->type, &RNA_DynamicPaintSurface)) {
2012-03-30 01:51:25 +00:00
DynamicPaintSurface *surface = (DynamicPaintSurface *)itemptr->data;
if (surface->format == MOD_DPAINT_SURFACE_F_PTEX) return ICON_TEXTURE_SHADED;
else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) return ICON_OUTLINER_DATA_MESH;
else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) return ICON_FILE_IMAGE;
}
/* get icon from ID */
if (id) {
2012-03-30 01:51:25 +00:00
icon = ui_id_icon_get(C, id, big);
if (icon)
return icon;
}
return rnaicon;
}
static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i,
int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop, const char *prop_list_id)
{
2012-03-30 01:51:25 +00:00
uiBlock *block = uiLayoutGetBlock(layout);
uiBut *but;
uiLayout *split, *overlap, *sub, *row;
char *namebuf;
const char *name;
int icon;
2012-03-30 01:51:25 +00:00
overlap = uiLayoutOverlap(layout);
/* list item behind label & other buttons */
sub = uiLayoutRow(overlap, FALSE);
but = uiDefButR_prop(block, LISTROW, 0, "", 0, 0, UI_UNIT_X * 10, UI_UNIT_Y, activeptr, activeprop,
0, 0, i, 0, 0, "");
uiButSetFlag(but, UI_BUT_NO_TOOLTIP);
sub = uiLayoutRow(overlap, FALSE);
/* retrieve icon and name */
2012-03-30 01:51:25 +00:00
icon = list_item_icon_get(C, itemptr, rnaicon, 0);
if (icon == ICON_NONE || icon == ICON_DOT)
2012-03-30 01:51:25 +00:00
icon = 0;
2012-03-30 01:51:25 +00:00
namebuf = RNA_struct_name_get_alloc(itemptr, NULL, 0, NULL);
name = (namebuf) ? namebuf : "";
/* hardcoded types */
if (itemptr->type == &RNA_MeshTexturePolyLayer || itemptr->type == &RNA_MeshLoopColorLayer) {
uiItemL(sub, name, icon);
uiBlockSetEmboss(block, UI_EMBOSSN);
uiDefIconButR(block, TOG, 0, ICON_SCENE, 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "active_render",
0, 0, 0, 0, 0, NULL);
uiBlockSetEmboss(block, UI_EMBOSS);
}
else if (RNA_struct_is_a(itemptr->type, &RNA_MaterialTextureSlot)) {
uiItemL(sub, name, icon);
uiBlockSetEmboss(block, UI_EMBOSS);
uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, ptr, "use_textures", i, 0, 0, 0, 0, NULL);
}
else if (RNA_struct_is_a(itemptr->type, &RNA_SceneRenderLayer)) {
uiItemL(sub, name, icon);
uiBlockSetEmboss(block, UI_EMBOSS);
uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "use", 0, 0, 0, 0, 0, NULL);
}
else if (RNA_struct_is_a(itemptr->type, &RNA_MaterialSlot)) {
/* provision to draw active node name */
Material *ma, *manode;
2012-03-30 01:51:25 +00:00
Scene *scene = CTX_data_scene(C);
Object *ob = (Object *)ptr->id.data;
int index = (Material **)itemptr->data - ob->mat;
/* default item with material base name */
uiItemL(sub, name, icon);
2012-03-30 01:51:25 +00:00
ma = give_current_material(ob, index + 1);
if (ma && !BKE_scene_use_new_shading_nodes(scene)) {
2012-03-30 01:51:25 +00:00
manode = give_node_material(ma);
if (manode) {
char str[MAX_ID_NAME + 12];
BLI_snprintf(str, sizeof(str), IFACE_("Node %s"), manode->id.name + 2);
uiItemL(sub, str, ui_id_icon_get(C, &manode->id, 1));
}
else if (ma->use_nodes) {
uiItemL(sub, IFACE_("Node <none>"), ICON_NONE);
}
}
}
else if (itemptr->type == &RNA_ShapeKey) {
2012-03-30 01:51:25 +00:00
Object *ob = (Object *)activeptr->data;
Key *key = (Key *)itemptr->id.data;
KeyBlock *kb = (KeyBlock *)itemptr->data;
split = uiLayoutSplit(sub, 0.66f, FALSE);
uiItemL(split, name, icon);
uiBlockSetEmboss(block, UI_EMBOSSN);
row = uiLayoutRow(split, TRUE);
if (i == 0 || (key->type != KEY_RELATIVE)) uiItemL(row, "", ICON_NONE);
else uiItemR(row, itemptr, "value", 0, "", ICON_NONE);
2012-09-04 18:47:08 +00:00
uiItemR(row, itemptr, "mute", 0, "", ICON_NONE);
if ((kb->flag & KEYBLOCK_MUTE) ||
(ob->mode == OB_MODE_EDIT && !((ob->shapeflag & OB_SHAPE_EDIT_MODE) && ob->type == OB_MESH)))
{
uiLayoutSetActive(row, FALSE);
}
uiBlockSetEmboss(block, UI_EMBOSS);
}
else if (itemptr->type == &RNA_VertexGroup) {
2012-03-30 01:51:25 +00:00
bDeformGroup *dg = (bDeformGroup *)itemptr->data;
uiItemL(sub, name, icon);
/* RNA does not allow nice lock icons, use lower level buttons */
#if 0
uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "lock_weight", 0, 0, 0, 0, 0, NULL);
#else
uiBlockSetEmboss(block, UI_EMBOSSN);
uiDefIconButBitC(block, TOG, DG_LOCK_WEIGHT, 0, (dg->flag & DG_LOCK_WEIGHT) ? ICON_LOCKED : ICON_UNLOCKED,
0, 0, UI_UNIT_X, UI_UNIT_Y, &dg->flag, 0, 0, 0, 0,
TIP_("Maintain relative weights while painting"));
uiBlockSetEmboss(block, UI_EMBOSS);
#endif
}
else if (itemptr->type == &RNA_KeyingSetPath) {
2012-03-30 01:51:25 +00:00
KS_Path *ksp = (KS_Path *)itemptr->data;
/* icon needs to be the type of ID which is currently active */
RNA_enum_icon_from_value(id_type_items, ksp->idtype, &icon);
/* nothing else special to do... */
uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */
}
else if (itemptr->type == &RNA_DynamicPaintSurface) {
char name_final[96];
const char *enum_name;
PropertyRNA *prop = RNA_struct_find_property(itemptr, "surface_type");
2012-03-30 01:51:25 +00:00
DynamicPaintSurface *surface = (DynamicPaintSurface *)itemptr->data;
RNA_property_enum_name(C, itemptr, prop, RNA_property_enum_get(itemptr, prop), &enum_name);
2012-03-30 01:51:25 +00:00
BLI_snprintf(name_final, sizeof(name_final), "%s (%s)", name, enum_name);
uiItemL(sub, name_final, icon);
if (dynamicPaint_surfaceHasColorPreview(surface)) {
uiBlockSetEmboss(block, UI_EMBOSSN);
uiDefIconButR(block, OPTION, 0,
(surface->flags & MOD_DPAINT_PREVIEW) ? ICON_RESTRICT_VIEW_OFF : ICON_RESTRICT_VIEW_ON,
2012-03-30 01:51:25 +00:00
0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "show_preview", 0, 0, 0, 0, 0, NULL);
uiBlockSetEmboss(block, UI_EMBOSS);
}
uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "is_active", i, 0, 0, 0, 0, NULL);
}
else if (itemptr->type == &RNA_MovieTrackingObject) {
2012-03-30 01:51:25 +00:00
MovieTrackingObject *tracking_object = (MovieTrackingObject *)itemptr->data;
split = uiLayoutSplit(sub, 0.75f, FALSE);
2012-03-30 01:51:25 +00:00
if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
uiItemL(split, name, ICON_CAMERA_DATA);
}
else {
uiItemL(split, name, ICON_OBJECT_DATA);
}
}
else if (itemptr->type == &RNA_MaskLayer) {
split = uiLayoutRow(sub, FALSE);
uiItemL(split, name, icon);
uiBlockSetEmboss(block, UI_EMBOSSN);
row = uiLayoutRow(split, TRUE);
uiItemR(row, itemptr, "alpha", 0, "", ICON_NONE);
2012-09-04 18:47:08 +00:00
uiItemR(row, itemptr, "hide", 0, "", ICON_NONE);
uiItemR(row, itemptr, "hide_select", 0, "", ICON_NONE);
uiItemR(row, itemptr, "hide_render", 0, "", ICON_NONE);
uiBlockSetEmboss(block, UI_EMBOSS);
}
2011-10-28 17:00:53 +00:00
/* There is a last chance to display custom controls (in addition to the name/label):
* If the given item property group features a string property named as prop_list,
* this tries to add controls for all properties of the item listed in that string property.
* (colon-separated names).
*
* This is especially useful for python. E.g., if you list a collection of this property
* group:
*
* class TestPropertyGroup(bpy.types.PropertyGroup):
* bool = BoolProperty(default=False)
* integer = IntProperty()
* string = StringProperty()
*
* # A string of all identifiers (colon-separated) which property's controls should be
* # displayed in a template_list.
* template_list_controls = StringProperty(default="integer:bool:string", options={"HIDDEN"})
*
* ... you'll get a numfield for the integer prop, a check box for the bool prop, and a textfield
* for the string prop, after the name of each item of the collection.
*/
else if (prop_list_id) {
row = uiLayoutRow(sub, TRUE);
uiItemL(row, name, icon);
/* XXX: Check, as sometimes we get an itemptr looking like
* {id = {data = 0x0}, type = 0x0, data = 0x0}
* which would obviously produce a sigsev... */
if (itemptr->type) {
/* If the special property is set for the item, and it is a collection... */
2012-03-30 01:51:25 +00:00
PropertyRNA *prop_list = RNA_struct_find_property(itemptr, prop_list_id);
if (prop_list && RNA_property_type(prop_list) == PROP_STRING) {
int prop_names_len;
char *prop_names = RNA_property_string_get_alloc(itemptr, prop_list, NULL, 0, &prop_names_len);
2012-03-30 01:51:25 +00:00
char *prop_names_end = prop_names + prop_names_len;
char *id = prop_names;
char *id_next;
while (id < prop_names_end) {
2012-03-30 01:51:25 +00:00
if ((id_next = strchr(id, ':'))) *id_next++ = '\0';
else id_next = prop_names_end;
2012-09-04 18:47:08 +00:00
uiItemR(row, itemptr, id, 0, NULL, ICON_NONE);
2012-03-30 01:51:25 +00:00
id = id_next;
}
MEM_freeN(prop_names);
}
}
}
else
2012-03-30 01:51:25 +00:00
uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */
/* free name */
if (namebuf) {
MEM_freeN(namebuf);
}
}
void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *activeptr,
const char *activepropname, const char *prop_list, int rows, int maxrows, int listtype)
{
2012-03-30 01:51:25 +00:00
PropertyRNA *prop = NULL, *activeprop;
PropertyType type, activetype;
StructRNA *ptype;
uiLayout *box, *row, *col;
uiBlock *block;
uiBut *but;
Panel *pa;
const char *name;
char numstr[32];
2012-03-30 01:51:25 +00:00
int rnaicon = 0, icon = 0, i = 0, activei = 0, len = 0, items, found, min, max;
/* validate arguments */
2012-03-30 01:51:25 +00:00
block = uiLayoutGetBlock(layout);
pa = block->panel;
if (!pa) {
RNA_warning("Only works inside a panel");
return;
}
if (!activeptr->data)
return;
if (ptr->data) {
2012-03-30 01:51:25 +00:00
prop = RNA_struct_find_property(ptr, propname);
if (!prop) {
RNA_warning("Property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
return;
}
}
2012-03-30 01:51:25 +00:00
activeprop = RNA_struct_find_property(activeptr, activepropname);
if (!activeprop) {
RNA_warning("Property not found: %s.%s", RNA_struct_identifier(ptr->type), activepropname);
return;
}
if (prop) {
2012-03-30 01:51:25 +00:00
type = RNA_property_type(prop);
if (type != PROP_COLLECTION) {
RNA_warning("uiExpected collection property");
return;
}
}
2012-03-30 01:51:25 +00:00
activetype = RNA_property_type(activeprop);
if (activetype != PROP_INT) {
RNA_warning("Expected integer property");
return;
}
/* get icon */
if (ptr->data && prop) {
2012-03-30 01:51:25 +00:00
ptype = RNA_property_pointer_type(ptr, prop);
rnaicon = RNA_struct_ui_icon(ptype);
}
/* get active data */
2012-03-30 01:51:25 +00:00
activei = RNA_property_int_get(activeptr, activeprop);
if (listtype == 'i') {
2012-03-30 01:51:25 +00:00
box = uiLayoutListBox(layout, ptr, prop, activeptr, activeprop);
col = uiLayoutColumn(box, TRUE);
row = uiLayoutRow(col, FALSE);
if (ptr->data && prop) {
/* create list items */
RNA_PROP_BEGIN (ptr, itemptr, prop)
{
/* create button */
if (!(i % 9))
row = uiLayoutRow(col, FALSE);
2012-03-30 01:51:25 +00:00
icon = list_item_icon_get(C, &itemptr, rnaicon, 1);
but = uiDefIconButR_prop(block, LISTROW, 0, icon, 0, 0, UI_UNIT_X * 10, UI_UNIT_Y, activeptr,
activeprop, 0, 0, i, 0, 0, "");
uiButSetFlag(but, UI_BUT_NO_TOOLTIP);
Drag and drop 2.5 integration! Finally, slashdot regulars can use Blender too now! :) ** Drag works as follows: - drag-able items are defined by the standard interface ui toolkit - each button can get this feature, via uiButSetDragXXX(but, ...). There are calls to define drag-able images, ID blocks, RNA paths, file paths, and so on. By default you drag an icon, exceptionally an ImBuf - Drag items are registered centrally in the WM, it allows more drag items simultaneous too, but not implemented ** Drop works as follows: - On mouse release, and if drag items exist in the WM, it converts the mouse event to an EVT_DROP type. This event then gets the full drag info as customdata - drop regions are defined with WM_dropbox_add(), similar to keymaps you can make a "drop map" this way, which become 'drop map handlers' in the queues. - next to that the UI kit handles some common button types (like accepting ID or names) to be catching a drop event too. - Every "drop box" has two callbacks: - poll() = check if the event drag data is relevant for this box - copy() = fill in custom properties in the dropbox to initialize an operator - The dropbox handler then calls its standard Operator with its dropbox properties. ** Currently implemented Drag items: - ID icons in browse buttons - ID icons in context menu of properties region - ID icons in outliner and rna viewer - FileBrowser icons - FileBrowser preview images Drag-able icons are subtly visualized by making them brighter a bit on mouse-over. In case the icon is a button or UI element too (most cases), the drag-able feature will make the item react to mouse-release instead of mouse-press. Drop options: - UI buttons: ID and text buttons (paste name) - View3d: Object ID drop copies object - View3d: Material ID drop assigns to object under cursor - View3d: Image ID drop assigns to object UV texture under cursor - Sequencer: Path drop will add either Image or Movie strip - Image window: Path drop will open image ** Drag and drop Notes: - Dropping into another Blender window (from same application) works too. I've added code that passes on mousemoves and clicks to other windows, without activating them though. This does make using multi-window Blender a bit friendler. - Dropping a file path to an image, is not the same as dropping an Image ID... keep this in mind. Sequencer for example wants paths to be dropped, textures in 3d window wants an Image ID. - Although drop boxes could be defined via Python, I suggest they're part of the UI and editor design (= how we want an editor to work), and not default offered configurable like keymaps. - At the moment only one item can be dragged at a time. This is for several reasons.... For one, Blender doesn't have a well defined uniform way to define "what is selected" (files, outliner items, etc). Secondly there's potential conflicts on what todo when you drop mixed drag sets on spots. All undefined stuff... nice for later. - Example to bypass the above: a collection of images that form a strip, should be represented in filewindow as a single sequence anyway. This then will fit well and gets handled neatly by design. - Another option to check is to allow multiple options per drop... it could show the operator as a sort of menu, allowing arrow or scrollwheel to choose. For time being I'd prefer to try to design a singular drop though, just offer only one drop action per data type on given spots. - What does work already, but a tad slow, is to use a function that detects an object (type) under cursor, so a drag item's option can be further refined (like drop object on object = parent). (disabled) ** More notes - Added saving for Region layouts (like split points for toolbar) - Label buttons now handle mouse over - File list: added full path entry for drop feature. - Filesel bugfix: wm_operator_exec() got called there and fully handled, while WM event code tried same. Added new OPERATOR_HANDLED flag for this. Maybe python needs it too? - Cocoa: added window move event, so multi-win setups work OK (didnt save). - Interface_handlers.c: removed win->active - Severe area copy bug: area handlers were not set to NULL - Filesel bugfix: next/prev folder list was not copied on area copies ** Leftover todos - Cocoa windows seem to hang on cases still... needs check - Cocoa 'draw overlap' swap doesn't work - Cocoa window loses focus permanently on using Spotlight (for these reasons, makefile building has Carbon as default atm) - ListView templates in UI cannot become dragged yet, needs review... it consists of two overlapping UI elements, preventing handling icon clicks. - There's already Ghost library code to handle dropping from OS into Blender window. I've noticed this code is unfinished for Macs, but seems to be complete for Windows. Needs test... currently, an external drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
i++;
}
RNA_PROP_END;
}
}
else if (listtype == 'c') {
/* compact layout */
row = uiLayoutRow(layout, TRUE);
if (ptr->data && prop) {
/* create list items */
RNA_PROP_BEGIN (ptr, itemptr, prop)
{
2012-03-30 01:51:25 +00:00
found = (activei == i);
if (found) {
/* create button */
2012-03-30 01:51:25 +00:00
name = RNA_struct_name_get_alloc(&itemptr, NULL, 0, NULL);
icon = list_item_icon_get(C, &itemptr, rnaicon, 0);
uiItemL(row, (name) ? name : "", icon);
if (name) {
MEM_freeN((void *)name);
}
}
i++;
}
RNA_PROP_END;
}
/* if not found, add in dummy button */
if (i == 0)
uiItemL(row, "", ICON_NONE);
/* next/prev button */
BLI_snprintf(numstr, sizeof(numstr), "%d :", i);
but = uiDefIconTextButR_prop(block, NUM, 0, 0, numstr, 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, activeptr,
activeprop, 0, 0, 0, 0, 0, "");
if (i == 0)
uiButSetFlag(but, UI_BUT_DISABLED);
}
else {
/* default rows */
if (rows == 0)
2012-03-30 01:51:25 +00:00
rows = 5;
if (maxrows == 0)
maxrows = 5;
if (pa->list_grip_size != 0)
2012-03-30 01:51:25 +00:00
rows = pa->list_grip_size;
/* layout */
2012-03-30 01:51:25 +00:00
box = uiLayoutListBox(layout, ptr, prop, activeptr, activeprop);
row = uiLayoutRow(box, FALSE);
col = uiLayoutColumn(row, TRUE);
/* init numbers */
RNA_property_int_range(activeptr, activeprop, &min, &max);
if (prop)
2012-03-30 01:51:25 +00:00
len = RNA_property_collection_length(ptr, prop);
items = CLAMPIS(len, rows, MAX2(rows, maxrows));
/* if list length changes and active is out of view, scroll to it */
if (pa->list_last_len != len)
2012-03-30 01:51:25 +00:00
if ((activei < pa->list_scroll || activei >= pa->list_scroll + items))
pa->list_scroll = activei;
2012-03-30 01:51:25 +00:00
pa->list_scroll = MIN2(pa->list_scroll, len - items);
pa->list_scroll = MAX2(pa->list_scroll, 0);
pa->list_size = items;
pa->list_last_len = len;
if (ptr->data && prop) {
/* create list items */
RNA_PROP_BEGIN (ptr, itemptr, prop)
{
2012-03-30 01:51:25 +00:00
if (i >= pa->list_scroll && i < pa->list_scroll + items)
list_item_row(C, col, ptr, &itemptr, i, rnaicon, activeptr, activeprop, prop_list);
i++;
}
RNA_PROP_END;
}
/* add dummy buttons to fill space */
2012-03-30 01:51:25 +00:00
while (i < pa->list_scroll + items) {
if (i >= pa->list_scroll)
uiItemL(col, "", ICON_NONE);
i++;
}
/* add scrollbar */
if (len > items) {
col = uiLayoutColumn(row, FALSE);
uiDefButI(block, SCROLL, 0, "", 0, 0, UI_UNIT_X * 0.75, UI_UNIT_Y * items, &pa->list_scroll,
0, len - items, items, 0, "");
}
}
}
/************************* Operator Search Template **************************/
static void operator_call_cb(bContext *C, void *UNUSED(arg1), void *arg2)
{
2012-03-30 01:51:25 +00:00
wmOperatorType *ot = arg2;
if (ot)
WM_operator_name_call(C, ot->idname, WM_OP_INVOKE_DEFAULT, NULL);
}
static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char *str, uiSearchItems *items)
{
2012-03-30 01:51:25 +00:00
GHashIterator *iter = WM_operatortype_iter();
2012-03-30 01:51:25 +00:00
for (; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) {
wmOperatorType *ot = BLI_ghashIterator_getValue(iter);
if ((ot->flag & OPTYPE_INTERNAL) && (G.debug & G_DEBUG_WM) == 0)
continue;
if (BLI_strcasestr(ot->name, str)) {
2012-03-30 01:51:25 +00:00
if (WM_operator_poll((bContext *)C, ot)) {
char name[256];
2012-03-30 01:51:25 +00:00
int len = strlen(ot->name);
/* display name for menu, can hold hotkey */
BLI_strncpy(name, ot->name, sizeof(name));
/* check for hotkey */
2012-03-30 01:51:25 +00:00
if (len < sizeof(name) - 6) {
if (WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, TRUE,
2012-03-30 01:51:25 +00:00
&name[len + 1], sizeof(name) - len - 1))
{
2012-03-30 01:51:25 +00:00
name[len] = '|';
}
}
2012-03-30 01:51:25 +00:00
if (0 == uiSearchItemAdd(items, name, ot, 0))
break;
}
}
}
BLI_ghashIterator_free(iter);
}
void uiOperatorSearch_But(uiBut *but)
{
uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL);
}
void uiTemplateOperatorSearch(uiLayout *layout)
{
uiBlock *block;
uiBut *but;
2012-03-30 01:51:25 +00:00
static char search[256] = "";
2012-03-30 01:51:25 +00:00
block = uiLayoutGetBlock(layout);
uiBlockSetCurLayout(block, layout);
2012-03-30 01:51:25 +00:00
but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 0, 0, UI_UNIT_X * 6, UI_UNIT_Y, 0, 0, "");
uiOperatorSearch_But(but);
}
/************************* Running Jobs Template **************************/
2012-03-30 01:51:25 +00:00
#define B_STOPRENDER 1
#define B_STOPCAST 2
#define B_STOPANIM 3
#define B_STOPCOMPO 4
#define B_STOPSEQ 5
#define B_STOPCLIP 6
#define B_STOPOTHER 7
static void do_running_jobs(bContext *C, void *UNUSED(arg), int event)
{
2012-03-30 01:51:25 +00:00
switch (event) {
case B_STOPRENDER:
G.is_break = TRUE;
break;
case B_STOPCAST:
WM_jobs_stop(CTX_wm_manager(C), CTX_wm_screen(C), NULL);
break;
case B_STOPANIM:
WM_operator_name_call(C, "SCREEN_OT_animation_play", WM_OP_INVOKE_SCREEN, NULL);
break;
case B_STOPCOMPO:
WM_jobs_stop(CTX_wm_manager(C), CTX_data_scene(C), NULL);
break;
case B_STOPSEQ:
WM_jobs_stop(CTX_wm_manager(C), CTX_wm_area(C), NULL);
break;
Camera tracking integration =========================== Commiting camera tracking integration gsoc project into trunk. This commit includes: - Bundled version of libmv library (with some changes against official repo, re-sync with libmv repo a bit later) - New datatype ID called MovieClip which is optimized to work with movie clips (both of movie files and image sequences) and doing camera/motion tracking operations. - New editor called Clip Editor which is currently used for motion/tracking stuff only, but which can be easily extended to work with masks too. This editor supports: * Loading movie files/image sequences * Build proxies with different size for loaded movie clip, also supports building undistorted proxies to increase speed of playback in undistorted mode. * Manual lens distortion mode calibration using grid and grease pencil * Supervised 2D tracking using two different algorithms KLT and SAD. * Basic algorithm for feature detection * Camera motion solving. scene orientation - New constraints to "link" scene objects with solved motions from clip: * Follow Track (make object follow 2D motion of track with given name or parent object to reconstructed 3D position of track) * Camera Solver to make camera moving in the same way as reconstructed camera This commit NOT includes changes from tomato branch: - New nodes (they'll be commited as separated patch) - Automatic image offset guessing for image input node and image editor (need to do more tests and gather more feedback) - Code cleanup in libmv-capi. It's not so critical cleanup, just increasing readability and understanadability of code. Better to make this chaneg when Keir will finish his current patch. More details about this project can be found on this page: http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2011 Further development of small features would be done in trunk, bigger/experimental features would first be implemented in tomato branch.
2011-11-07 12:55:18 +00:00
case B_STOPCLIP:
WM_jobs_stop(CTX_wm_manager(C), CTX_wm_area(C), NULL);
break;
case B_STOPOTHER:
G.is_break = TRUE;
break;
}
}
void uiTemplateRunningJobs(uiLayout *layout, bContext *C)
{
2012-03-30 01:51:25 +00:00
bScreen *screen = CTX_wm_screen(C);
wmWindowManager *wm = CTX_wm_manager(C);
ScrArea *sa = CTX_wm_area(C);
uiBlock *block;
2012-03-30 01:51:25 +00:00
void *owner = NULL;
int handle_event;
2012-03-30 01:51:25 +00:00
block = uiLayoutGetBlock(layout);
uiBlockSetCurLayout(block, layout);
uiBlockSetHandleFunc(block, do_running_jobs, NULL);
if (sa->spacetype == SPACE_SEQ) {
if (WM_jobs_test(wm, sa, WM_JOB_TYPE_ANY))
owner = sa;
handle_event = B_STOPSEQ;
}
2012-03-30 01:51:25 +00:00
else if (sa->spacetype == SPACE_CLIP) {
if (WM_jobs_test(wm, sa, WM_JOB_TYPE_ANY))
2012-03-30 01:51:25 +00:00
owner = sa;
handle_event = B_STOPCLIP;
}
else {
Scene *scene;
/* another scene can be rendering too, for example via compositor */
for (scene = CTX_data_main(C)->scene.first; scene; scene = scene->id.next) {
if (WM_jobs_test(wm, scene, WM_JOB_TYPE_RENDER)) {
handle_event = B_STOPRENDER;
break;
}
else if (WM_jobs_test(wm, scene, WM_JOB_TYPE_COMPOSITE)) {
handle_event = B_STOPCOMPO;
break;
}
else if (WM_jobs_test(wm, scene, WM_JOB_TYPE_ANY)) {
handle_event = B_STOPOTHER;
break;
}
}
owner = scene;
}
if (owner) {
uiLayout *ui_abs;
ui_abs = uiLayoutAbsolute(layout, FALSE);
2012-08-19 10:41:27 +00:00
(void)ui_abs; /* UNUSED */
uiDefIconBut(block, BUT, handle_event, ICON_PANEL_CLOSE, 0, UI_UNIT_Y * 0.1, UI_UNIT_X * 0.8, UI_UNIT_Y * 0.8,
NULL, 0.0f, 0.0f, 0, 0, TIP_("Stop this job"));
uiDefBut(block, PROGRESSBAR, 0, WM_jobs_name(wm, owner),
2012-03-30 01:51:25 +00:00
UI_UNIT_X, 0, 100, UI_UNIT_Y, NULL, 0.0f, 0.0f, WM_jobs_progress(wm, owner), 0, TIP_("Progress"));
uiLayoutRow(layout, FALSE);
}
if (WM_jobs_test(wm, screen, WM_JOB_TYPE_SCREENCAST))
uiDefIconTextBut(block, BUT, B_STOPCAST, ICON_CANCEL, IFACE_("Capture"), 0, 0, 85, UI_UNIT_Y,
NULL, 0.0f, 0.0f, 0, 0, TIP_("Stop screencast"));
if (screen->animtimer)
uiDefIconTextBut(block, BUT, B_STOPANIM, ICON_CANCEL, IFACE_("Anim Player"), 0, 0, 100, UI_UNIT_Y,
NULL, 0.0f, 0.0f, 0, 0, TIP_("Stop animation playback"));
}
/************************* Reports for Last Operator Template **************************/
void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
{
ReportList *reports = CTX_wm_reports(C);
2012-03-30 01:51:25 +00:00
Report *report = BKE_reports_last_displayable(reports);
ReportTimerInfo *rti;
uiLayout *ui_abs;
uiBlock *block;
uiBut *but;
2012-03-30 01:51:25 +00:00
uiStyle *style = UI_GetStyle();
int width;
2012-03-30 01:51:25 +00:00
int icon = 0;
/* if the report display has timed out, don't show */
if (!reports->reporttimer) return;
2012-03-30 01:51:25 +00:00
rti = (ReportTimerInfo *)reports->reporttimer->customdata;
2012-03-30 01:51:25 +00:00
if (!rti || rti->widthfac == 0.0f || !report) return;
ui_abs = uiLayoutAbsolute(layout, FALSE);
2012-03-30 01:51:25 +00:00
block = uiLayoutGetBlock(ui_abs);
width = BLF_width(style->widget.uifont_id, report->message);
width = min_ii((int)(rti->widthfac * width), width);
width = max_ii(width, 10);
/* make a box around the report to make it stand out */
uiBlockBeginAlign(block);
2012-03-30 01:51:25 +00:00
but = uiDefBut(block, ROUNDBOX, 0, "", 0, 0, UI_UNIT_X + 10, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
/* set the report's bg color in but->col - ROUNDBOX feature */
rgb_float_to_uchar(but->col, rti->col);
2012-03-30 01:51:25 +00:00
but->col[3] = 255;
but = uiDefBut(block, ROUNDBOX, 0, "", UI_UNIT_X + 10, 0, UI_UNIT_X + width, UI_UNIT_Y,
NULL, 0.0f, 0.0f, 0, 0, "");
but->col[0] = but->col[1] = but->col[2] = FTOCHAR(rti->grayscale);
2012-03-30 01:51:25 +00:00
but->col[3] = 255;
uiBlockEndAlign(block);
/* icon and report message on top */
if (report->type & RPT_ERROR_ALL)
icon = ICON_ERROR;
else if (report->type & RPT_WARNING_ALL)
icon = ICON_ERROR;
else if (report->type & RPT_INFO_ALL)
icon = ICON_INFO;
/* XXX: temporary operator to dump all reports to a text block, but only if more than 1 report
* to be shown instead of icon when appropriate...
*/
uiBlockSetEmboss(block, UI_EMBOSSN);
if (reports->list.first != reports->list.last)
uiDefIconButO(block, BUT, "UI_OT_reports_to_textblock", WM_OP_INVOKE_REGION_WIN, icon, 2, 0, UI_UNIT_X,
UI_UNIT_Y, TIP_("Click to see the remaining reports in text block: 'Recent Reports'"));
else
uiDefIconBut(block, LABEL, 0, icon, 2, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
uiBlockSetEmboss(block, UI_EMBOSS);
uiDefBut(block, LABEL, 0, report->message, UI_UNIT_X + 10, 0, UI_UNIT_X + width, UI_UNIT_Y,
NULL, 0.0f, 0.0f, 0, 0, "");
}
/********************************* Keymap *************************************/
static void keymap_item_modified(bContext *UNUSED(C), void *kmi_p, void *UNUSED(unused))
{
2012-03-30 01:51:25 +00:00
wmKeyMapItem *kmi = (wmKeyMapItem *)kmi_p;
WM_keyconfig_update_tag(NULL, kmi);
}
static void template_keymap_item_properties(uiLayout *layout, const char *title, PointerRNA *ptr)
{
uiLayout *flow;
uiItemS(layout);
if (title)
uiItemL(layout, title, ICON_NONE);
flow = uiLayoutColumnFlow(layout, 2, FALSE);
RNA_STRUCT_BEGIN (ptr, prop)
{
2012-03-30 01:51:25 +00:00
int flag = RNA_property_flag(prop);
if (flag & PROP_HIDDEN)
continue;
/* recurse for nested properties */
if (RNA_property_type(prop) == PROP_POINTER) {
2012-03-30 01:51:25 +00:00
PointerRNA propptr = RNA_property_pointer_get(ptr, prop);
const char *name = RNA_property_ui_name(prop);
if (propptr.data && RNA_struct_is_a(propptr.type, &RNA_OperatorProperties)) {
template_keymap_item_properties(layout, name, &propptr);
continue;
}
}
/* add property */
uiItemR(flow, ptr, RNA_property_identifier(prop), 0, NULL, ICON_NONE);
}
RNA_STRUCT_END;
}
void uiTemplateKeymapItemProperties(uiLayout *layout, PointerRNA *ptr)
{
2012-03-30 01:51:25 +00:00
PointerRNA propptr = RNA_pointer_get(ptr, "properties");
if (propptr.data) {
2012-03-30 01:51:25 +00:00
uiBut *but = uiLayoutGetBlock(layout)->buttons.last;
template_keymap_item_properties(layout, NULL, &propptr);
/* attach callbacks to compensate for missing properties update,
* we don't know which keymap (item) is being modified there */
2012-03-30 01:51:25 +00:00
for (; but; but = but->next)
uiButSetFunc(but, keymap_item_modified, ptr->data, NULL);
}
}
Color Management, Stage 2: Switch color pipeline to use OpenColorIO Replace old color pipeline which was supporting linear/sRGB color spaces only with OpenColorIO-based pipeline. This introduces two configurable color spaces: - Input color space for images and movie clips. This space is used to convert images/movies from color space in which file is saved to Blender's linear space (for float images, byte images are not internally converted, only input space is stored for such images and used later). This setting could be found in image/clip data block settings. - Display color space which defines space in which particular display is working. This settings could be found in scene's Color Management panel. When render result is being displayed on the screen, apart from converting image to display space, some additional conversions could happen. This conversions are: - View, which defines tone curve applying before display transformation. These are different ways to view the image on the same display device. For example it could be used to emulate film view on sRGB display. - Exposure affects on image exposure before tone map is applied. - Gamma is post-display gamma correction, could be used to match particular display gamma. - RGB curves are user-defined curves which are applying before display transformation, could be used for different purposes. All this settings by default are only applying on render result and does not affect on other images. If some particular image needs to be affected by this transformation, "View as Render" setting of image data block should be set to truth. Movie clips are always affected by all display transformations. This commit also introduces configurable color space in which sequencer is working. This setting could be found in scene's Color Management panel and it should be used if such stuff as grading needs to be done in color space different from sRGB (i.e. when Film view on sRGB display is use, using VD16 space as sequencer's internal space would make grading working in space which is close to the space using for display). Some technical notes: - Image buffer's float buffer is now always in linear space, even if it was created from 16bit byte images. - Space of byte buffer is stored in image buffer's rect_colorspace property. - Profile of image buffer was removed since it's not longer meaningful. - OpenGL and GLSL is supposed to always work in sRGB space. It is possible to support other spaces, but it's quite large project which isn't so much important. - Legacy Color Management option disabled is emulated by using None display. It could have some regressions, but there's no clear way to avoid them. - If OpenColorIO is disabled on build time, it should make blender behaving in the same way as previous release with color management enabled. More details could be found at this page (more details would be added soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management -- Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO integration and to Brecht van Lommel for some further development and code/ usecase review!
2012-09-15 10:05:07 +00:00
/********************************* Color management *************************************/
void uiTemplateColorspaceSettings(uiLayout *layout, PointerRNA *ptr, const char *propname)
{
PropertyRNA *prop;
PointerRNA colorspace_settings_ptr;
prop = RNA_struct_find_property(ptr, propname);
if (!prop) {
printf("%s: property not found: %s.%s\n",
__func__, RNA_struct_identifier(ptr->type), propname);
return;
}
colorspace_settings_ptr = RNA_property_pointer_get(ptr, prop);
uiItemL(layout, "Color Space:", ICON_NONE);
uiItemR(layout, &colorspace_settings_ptr, "name", 0, "", ICON_NONE);
}
void uiTemplateColormanagedViewSettings(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr, const char *propname)
{
PropertyRNA *prop;
PointerRNA view_transform_ptr;
uiLayout *col, *row;
ColorManagedViewSettings *view_settings;
prop = RNA_struct_find_property(ptr, propname);
if (!prop) {
printf("%s: property not found: %s.%s\n",
__func__, RNA_struct_identifier(ptr->type), propname);
return;
}
view_transform_ptr = RNA_property_pointer_get(ptr, prop);
view_settings = view_transform_ptr.data;
col = uiLayoutColumn(layout, FALSE);
row = uiLayoutRow(col, FALSE);
uiItemR(row, &view_transform_ptr, "view_transform", UI_ITEM_R_EXPAND, IFACE_("View"), ICON_NONE);
col = uiLayoutColumn(layout, FALSE);
uiItemR(col, &view_transform_ptr, "exposure", 0, NULL, ICON_NONE);
uiItemR(col, &view_transform_ptr, "gamma", 0, NULL, ICON_NONE);
col = uiLayoutColumn(layout, FALSE);
uiItemR(col, &view_transform_ptr, "use_curve_mapping", 0, NULL, ICON_NONE);
if (view_settings->flag & COLORMANAGE_VIEW_USE_CURVES)
uiTemplateCurveMapping(col, &view_transform_ptr, "curve_mapping", 'c', TRUE, 0);
}