Blender V2.61 - r43446
|
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) 2008 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * 00022 * Contributor(s): Blender Foundation 00023 * 00024 * ***** END GPL LICENSE BLOCK ***** 00025 */ 00026 00032 #include <stdlib.h> 00033 #include <math.h> 00034 00035 #include "DNA_scene_types.h" 00036 00037 #include "BLI_blenlib.h" 00038 #include "BLI_utildefines.h" 00039 00040 #include "BKE_context.h" 00041 00042 #include "ED_screen.h" 00043 00044 #include "WM_api.h" 00045 #include "WM_types.h" 00046 00047 #include "time_intern.h" 00048 00049 /* ****************** Start/End Frame Operators *******************************/ 00050 static int time_set_sfra_exec (bContext *C, wmOperator *UNUSED(op)) 00051 { 00052 Scene *scene= CTX_data_scene(C); 00053 int frame; 00054 00055 if (scene == NULL) 00056 return OPERATOR_CANCELLED; 00057 00058 frame= CFRA; 00059 /* if 'end frame' (Preview Range or Actual) is less than 'frame', 00060 * clamp 'frame' to 'end frame' 00061 */ 00062 if (PEFRA < frame) frame= PEFRA; 00063 00064 /* if Preview Range is defined, set the 'start' frame for that */ 00065 if (PRVRANGEON) 00066 scene->r.psfra= frame; 00067 else 00068 scene->r.sfra= frame; 00069 00070 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); 00071 00072 return OPERATOR_FINISHED; 00073 } 00074 00075 static void TIME_OT_start_frame_set (wmOperatorType *ot) 00076 { 00077 /* identifiers */ 00078 ot->name= "Set Start Frame"; 00079 ot->idname= "TIME_OT_start_frame_set"; 00080 ot->description="Set the start frame"; 00081 00082 /* api callbacks */ 00083 ot->exec= time_set_sfra_exec; 00084 ot->poll= ED_operator_timeline_active; 00085 00086 /* flags */ 00087 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 00088 } 00089 00090 00091 static int time_set_efra_exec (bContext *C, wmOperator *UNUSED(op)) 00092 { 00093 Scene *scene= CTX_data_scene(C); 00094 int frame; 00095 00096 if (scene == NULL) 00097 return OPERATOR_CANCELLED; 00098 00099 frame= CFRA; 00100 00101 /* if 'start frame' (Preview Range or Actual) is greater than 'frame', 00102 * clamp 'frame' to 'end frame' 00103 */ 00104 if (PSFRA > frame) frame= PSFRA; 00105 00106 /* if Preview Range is defined, set the 'end' frame for that */ 00107 if (PRVRANGEON) 00108 scene->r.pefra= frame; 00109 else 00110 scene->r.efra= frame; 00111 00112 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); 00113 00114 return OPERATOR_FINISHED; 00115 } 00116 00117 static void TIME_OT_end_frame_set (wmOperatorType *ot) 00118 { 00119 /* identifiers */ 00120 ot->name= "Set End Frame"; 00121 ot->idname= "TIME_OT_end_frame_set"; 00122 ot->description="Set the end frame"; 00123 00124 /* api callbacks */ 00125 ot->exec= time_set_efra_exec; 00126 ot->poll= ED_operator_timeline_active; 00127 00128 /* flags */ 00129 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 00130 } 00131 00132 /* ************************ View All Operator *******************************/ 00133 00134 static int time_view_all_exec (bContext *C, wmOperator *UNUSED(op)) 00135 { 00136 Scene *scene= CTX_data_scene(C); 00137 ARegion *ar= CTX_wm_region(C); 00138 View2D *v2d= (ar) ? &ar->v2d : NULL; 00139 float extra; 00140 00141 if ELEM(NULL, scene, ar) 00142 return OPERATOR_CANCELLED; 00143 00144 /* set extents of view to start/end frames (Preview Range too) */ 00145 v2d->cur.xmin= (float)PSFRA; 00146 v2d->cur.xmax= (float)PEFRA; 00147 00148 /* we need an extra "buffer" factor on either side so that the endpoints are visible */ 00149 extra= 0.01f * (v2d->cur.xmax - v2d->cur.xmin); 00150 v2d->cur.xmin -= extra; 00151 v2d->cur.xmax += extra; 00152 00153 /* this only affects this TimeLine instance, so just force redraw of this region */ 00154 ED_region_tag_redraw(ar); 00155 00156 return OPERATOR_FINISHED; 00157 } 00158 00159 static void TIME_OT_view_all (wmOperatorType *ot) 00160 { 00161 /* identifiers */ 00162 ot->name= "View All"; 00163 ot->idname= "TIME_OT_view_all"; 00164 ot->description= "Show the entire playable frame range"; 00165 00166 /* api callbacks */ 00167 ot->exec= time_view_all_exec; 00168 ot->poll= ED_operator_timeline_active; 00169 00170 /* flags */ 00171 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 00172 } 00173 00174 /* ************************** registration **********************************/ 00175 00176 void time_operatortypes(void) 00177 { 00178 WM_operatortype_append(TIME_OT_start_frame_set); 00179 WM_operatortype_append(TIME_OT_end_frame_set); 00180 WM_operatortype_append(TIME_OT_view_all); 00181 } 00182 00183 void time_keymap(wmKeyConfig *keyconf) 00184 { 00185 wmKeyMap *keymap= WM_keymap_find(keyconf, "Timeline", SPACE_TIME, 0); 00186 00187 WM_keymap_add_item(keymap, "TIME_OT_start_frame_set", SKEY, KM_PRESS, 0, 0); 00188 WM_keymap_add_item(keymap, "TIME_OT_end_frame_set", EKEY, KM_PRESS, 0, 0); 00189 WM_keymap_add_item(keymap, "TIME_OT_view_all", HOMEKEY, KM_PRESS, 0, 0); 00190 } 00191