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_anim.c
Matt Ebb cf9b728c6a Color Picker work:
Restored the old Eyedropper tool from the 2.4 colour picker. Now it's an operator, 
working nicely using rna properties (fixes #19475 and some todo items)

This ended up being a bit more work than expected, it involved converting the 
colour picker to use RNA properties directly, rather than temporary values. This has 
several advantages, including being able to type in RGB values greater than 1, 
however there are still some redraw issues with sliders.

Also removed the alternate color pickers after this time spent testing, the current one 
should be sufficient, or alternatives to the wheel can possibly become preferences 
in the current design.

Converting the picker to RNA also made it very trivial to make a cool new 
ColorWheel template, which can be embedded in UI layouts. I've enabled it already 
in texture/vertex paint brush properties and the sequence editor color correction:
http://mke3.net/blender/devel/2.5/colorwheels.jpg
2010-01-07 09:55:11 +00:00

229 lines
5.2 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_anim_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BKE_animsys.h"
#include "BKE_context.h"
#include "BKE_fcurve.h"
#include "RNA_access.h"
#include "RNA_types.h"
#include "ED_keyframing.h"
#include "UI_interface.h"
#include "WM_api.h"
#include "WM_types.h"
#include "interface_intern.h"
static FCurve *ui_but_get_fcurve(uiBut *but, bAction **action, int *driven)
{
FCurve *fcu= NULL;
*driven= 0;
/* there must be some RNA-pointer + property combo for this button */
if(but->rnaprop && but->rnapoin.id.data &&
RNA_property_animateable(&but->rnapoin, but->rnaprop))
{
AnimData *adt= BKE_animdata_from_id(but->rnapoin.id.data);
char *path;
if(adt) {
if((adt->action && adt->action->curves.first) || (adt->drivers.first)) {
/* XXX this function call can become a performance bottleneck */
path= RNA_path_from_ID_to_property(&but->rnapoin, but->rnaprop);
if(path) {
/* animation takes priority over drivers */
if(adt->action && adt->action->curves.first)
fcu= list_find_fcurve(&adt->action->curves, path, but->rnaindex);
/* if not animated, check if driven */
if(!fcu && (adt->drivers.first)) {
fcu= list_find_fcurve(&adt->drivers, path, but->rnaindex);
if(fcu)
*driven= 1;
}
if(fcu && action)
*action= adt->action;
MEM_freeN(path);
}
}
}
}
return fcu;
}
void ui_but_anim_flag(uiBut *but, float cfra)
{
FCurve *fcu;
int driven;
but->flag &= ~(UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN);
fcu= ui_but_get_fcurve(but, NULL, &driven);
if(fcu) {
if(!driven) {
but->flag |= UI_BUT_ANIMATED;
if(fcurve_frame_has_keyframe(fcu, cfra, 0))
but->flag |= UI_BUT_ANIMATED_KEY;
}
else {
but->flag |= UI_BUT_DRIVEN;
}
}
}
int ui_but_anim_expression_get(uiBut *but, char *str, int maxlen)
{
FCurve *fcu;
ChannelDriver *driver;
int driven;
fcu= ui_but_get_fcurve(but, NULL, &driven);
if(fcu && driven) {
driver= fcu->driver;
if(driver && driver->type == DRIVER_TYPE_PYTHON) {
BLI_strncpy(str, driver->expression, maxlen);
return 1;
}
}
return 0;
}
int ui_but_anim_expression_set(uiBut *but, const char *str)
{
FCurve *fcu;
ChannelDriver *driver;
int driven;
fcu= ui_but_get_fcurve(but, NULL, &driven);
if(fcu && driven) {
driver= fcu->driver;
if(driver && driver->type == DRIVER_TYPE_PYTHON) {
BLI_strncpy(driver->expression, str, sizeof(driver->expression));
return 1;
}
}
return 0;
}
void ui_but_anim_autokey(uiBut *but, Scene *scene, float cfra)
{
ID *id;
bAction *action;
FCurve *fcu;
int driven;
fcu= ui_but_get_fcurve(but, &action, &driven);
if(fcu && !driven) {
id= but->rnapoin.id.data;
// TODO: this should probably respect the keyingset only option for anim
if(autokeyframe_cfra_can_key(scene, id)) {
short flag = ANIM_get_keyframing_flags(scene, 1);
fcu->flag &= ~FCURVE_SELECTED;
insert_keyframe(id, action, ((fcu->grp)?(fcu->grp->name):(NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
}
}
}
void uiAnimContextProperty(const bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index)
{
ARegion *ar= CTX_wm_region(C);
uiBlock *block;
uiBut *but;
memset(ptr, 0, sizeof(*ptr));
*prop= NULL;
*index= 0;
if(ar) {
for(block=ar->uiblocks.first; block; block=block->next) {
for(but=block->buttons.first; but; but= but->next) {
if((but->active || but->flag & UI_BUT_LAST_ACTIVE) && but->rnapoin.id.data) {
*ptr= but->rnapoin;
*prop= but->rnaprop;
*index= but->rnaindex;
return;
}
}
}
}
}
void ui_but_anim_insert_keyframe(bContext *C)
{
/* this operator calls uiAnimContextProperty above */
WM_operator_name_call(C, "ANIM_OT_keyframe_insert_button", WM_OP_INVOKE_DEFAULT, NULL);
}
void ui_but_anim_delete_keyframe(bContext *C)
{
/* this operator calls uiAnimContextProperty above */
WM_operator_name_call(C, "ANIM_OT_keyframe_delete_button", WM_OP_INVOKE_DEFAULT, NULL);
}
void ui_but_anim_add_driver(bContext *C)
{
/* this operator calls uiAnimContextProperty above */
WM_operator_name_call(C, "ANIM_OT_driver_button_add", WM_OP_INVOKE_DEFAULT, NULL);
}
void ui_but_anim_remove_driver(bContext *C)
{
/* this operator calls uiAnimContextProperty above */
WM_operator_name_call(C, "ANIM_OT_driver_button_remove", WM_OP_INVOKE_DEFAULT, NULL);
}
void ui_but_anim_copy_driver(bContext *C)
{
/* this operator calls uiAnimContextProperty above */
WM_operator_name_call(C, "ANIM_OT_copy_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
}
void ui_but_anim_paste_driver(bContext *C)
{
/* this operator calls uiAnimContextProperty above */
WM_operator_name_call(C, "ANIM_OT_paste_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
}
void ui_but_anim_add_keyingset(bContext *C)
{
/* this operator calls uiAnimContextProperty above */
WM_operator_name_call(C, "ANIM_OT_keyingset_button_add", WM_OP_INVOKE_DEFAULT, NULL);
}
void ui_but_anim_remove_keyingset(bContext *C)
{
/* this operator calls uiAnimContextProperty above */
WM_operator_name_call(C, "ANIM_OT_keyingset_button_remove", WM_OP_INVOKE_DEFAULT, NULL);
}