Blender V2.61 - r43446

clip_toolbar.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2011 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  *
00022  * Contributor(s): Blender Foundation,
00023  *                 Sergey Sharybin
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00032 #include <string.h>
00033 
00034 #include "DNA_windowmanager_types.h"
00035 
00036 #include "MEM_guardedalloc.h"
00037 
00038 #include "BLI_blenlib.h"
00039 #include "BLI_utildefines.h"
00040 
00041 #include "BKE_context.h"
00042 #include "BKE_screen.h"
00043 
00044 #include "ED_screen.h"
00045 #include "ED_util.h"
00046 
00047 #include "WM_types.h"
00048 #include "WM_api.h"
00049 
00050 #include "UI_interface.h"
00051 #include "UI_resources.h"
00052 
00053 #include "clip_intern.h" /* own include */
00054 
00055 /* ************************ header area region *********************** */
00056 
00057 /************************** properties ******************************/
00058 
00059 static ARegion *clip_has_properties_region(ScrArea *sa)
00060 {
00061     ARegion *ar, *arnew;
00062 
00063     ar= BKE_area_find_region_type(sa, RGN_TYPE_UI);
00064     if(ar)
00065         return ar;
00066 
00067     /* add subdiv level; after header */
00068     ar= BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
00069 
00070     /* is error! */
00071     if(ar==NULL)
00072         return NULL;
00073 
00074     arnew= MEM_callocN(sizeof(ARegion), "clip properties region");
00075 
00076     BLI_insertlinkafter(&sa->regionbase, ar, arnew);
00077     arnew->regiontype= RGN_TYPE_UI;
00078     arnew->alignment= RGN_ALIGN_RIGHT;
00079 
00080     arnew->flag= RGN_FLAG_HIDDEN;
00081 
00082     return arnew;
00083 }
00084 
00085 static int properties_poll(bContext *C)
00086 {
00087     return (CTX_wm_space_clip(C) != NULL);
00088 }
00089 
00090 static int properties_exec(bContext *C, wmOperator *UNUSED(op))
00091 {
00092     ScrArea *sa= CTX_wm_area(C);
00093     ARegion *ar= clip_has_properties_region(sa);
00094 
00095     if(ar)
00096         ED_region_toggle_hidden(C, ar);
00097 
00098     return OPERATOR_FINISHED;
00099 }
00100 
00101 void CLIP_OT_properties(wmOperatorType *ot)
00102 {
00103     /* identifiers */
00104     ot->name= "Properties";
00105     ot->description= "Toggle clip properties panel";
00106     ot->idname= "CLIP_OT_properties";
00107 
00108     /* api callbacks */
00109     ot->exec= properties_exec;
00110     ot->poll= properties_poll;
00111 }
00112 
00113 /************************** tools ******************************/
00114 
00115 static ARegion *clip_has_tools_region(ScrArea *sa)
00116 {
00117     ARegion *ar, *artool=NULL, *arprops=NULL, *arhead;
00118 
00119     for(ar= sa->regionbase.first; ar; ar= ar->next) {
00120         if(ar->regiontype==RGN_TYPE_TOOLS)
00121             artool= ar;
00122         if(ar->regiontype==RGN_TYPE_TOOL_PROPS)
00123             arprops= ar;
00124     }
00125 
00126     /* tool region hide/unhide also hides props */
00127     if(arprops && artool)
00128         return artool;
00129 
00130     if(artool==NULL) {
00131         /* add subdiv level; after header */
00132         arhead= BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
00133 
00134         /* is error! */
00135         if(arhead==NULL)
00136             return NULL;
00137 
00138         artool= MEM_callocN(sizeof(ARegion), "clip tools region");
00139 
00140         BLI_insertlinkafter(&sa->regionbase, arhead, artool);
00141         artool->regiontype= RGN_TYPE_TOOLS;
00142         artool->alignment= RGN_ALIGN_LEFT;
00143 
00144         artool->flag= RGN_FLAG_HIDDEN;
00145     }
00146 
00147     if(arprops==NULL) {
00148         /* add extra subdivided region for tool properties */
00149         arprops= MEM_callocN(sizeof(ARegion), "tool props for clip");
00150 
00151         BLI_insertlinkafter(&sa->regionbase, artool, arprops);
00152         arprops->regiontype= RGN_TYPE_TOOL_PROPS;
00153         arprops->alignment= RGN_ALIGN_BOTTOM|RGN_SPLIT_PREV;
00154     }
00155 
00156     return artool;
00157 }
00158 
00159 static int tools_poll(bContext *C)
00160 {
00161     return (CTX_wm_space_clip(C) != NULL);
00162 }
00163 
00164 static int tools_exec(bContext *C, wmOperator *UNUSED(op))
00165 {
00166     ScrArea *sa= CTX_wm_area(C);
00167     ARegion *ar= clip_has_tools_region(sa);
00168 
00169     if(ar)
00170         ED_region_toggle_hidden(C, ar);
00171 
00172     return OPERATOR_FINISHED;
00173 }
00174 
00175 void CLIP_OT_tools(wmOperatorType *ot)
00176 {
00177     /* identifiers */
00178     ot->name= "Tools";
00179     ot->description= "Toggle clip tools panel";
00180     ot->idname= "CLIP_OT_tools";
00181 
00182     /* api callbacks */
00183     ot->exec= tools_exec;
00184     ot->poll= tools_poll;
00185 }
00186 
00187 /************************** redo panel ******************************/
00188 
00189 static void clip_panel_operator_redo_buts(const bContext *C, Panel *pa, wmOperator *op)
00190 {
00191     uiLayoutOperatorButs(C, pa->layout, op, NULL, 'V', 0);
00192 }
00193 
00194 static void clip_panel_operator_redo_header(const bContext *C, Panel *pa)
00195 {
00196     wmOperator *op= WM_operator_last_redo(C);
00197 
00198     if(op) BLI_strncpy(pa->drawname, op->type->name, sizeof(pa->drawname));
00199     else BLI_strncpy(pa->drawname, "Operator", sizeof(pa->drawname));
00200 }
00201 
00202 static void clip_panel_operator_redo_operator(const bContext *C, Panel *pa, wmOperator *op)
00203 {
00204     if(op->type->flag & OPTYPE_MACRO) {
00205         for(op= op->macro.first; op; op= op->next) {
00206             uiItemL(pa->layout, op->type->name, ICON_NONE);
00207             clip_panel_operator_redo_operator(C, pa, op);
00208         }
00209     }
00210     else {
00211         clip_panel_operator_redo_buts(C, pa, op);
00212     }
00213 }
00214 
00215 /* TODO de-duplicate redo panel functions - campbell */
00216 static void clip_panel_operator_redo(const bContext *C, Panel *pa)
00217 {
00218     wmOperator *op= WM_operator_last_redo(C);
00219     uiBlock *block;
00220 
00221     if(op==NULL)
00222         return;
00223     if(WM_operator_poll((bContext*)C, op->type) == 0)
00224         return;
00225 
00226     block= uiLayoutGetBlock(pa->layout);
00227 
00228     if (!WM_operator_check_ui_enabled(C, op->type->name))
00229         uiLayoutSetEnabled(pa->layout, 0);
00230 
00231     /* note, blockfunc is a default but->func, use Handle func to allow button callbacks too */
00232     uiBlockSetHandleFunc(block, ED_undo_operator_repeat_cb_evt, op);
00233 
00234     clip_panel_operator_redo_operator(C, pa, op);
00235 }
00236 
00237 void ED_clip_tool_props_register(ARegionType *art)
00238 {
00239     PanelType *pt;
00240 
00241     pt= MEM_callocN(sizeof(PanelType), "spacetype clip panel last operator");
00242     strcpy(pt->idname, "CLIP_PT_last_operator");
00243     strcpy(pt->label, "Operator");
00244     pt->draw_header= clip_panel_operator_redo_header;
00245     pt->draw= clip_panel_operator_redo;
00246     BLI_addtail(&art->paneltypes, pt);
00247 }