Improvements and fixes to Cycles metadata
[blender.git] / source / blender / editors / space_sequencer / sequencer_buttons.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2009 by Blender Foundation
17  * All rights reserved.
18  */
19
20 /** \file \ingroup spseq
21  */
22
23 #include <string.h>
24 #include <stdio.h>
25
26
27 #include "MEM_guardedalloc.h"
28
29 #include "BLI_utildefines.h"
30 #include "BLI_listbase.h"
31
32 #include "BLT_translation.h"
33
34 #include "BKE_context.h"
35 #include "BKE_global.h"
36 #include "BKE_screen.h"
37
38 #include "ED_screen.h"
39 #include "ED_gpencil.h"
40 #include "ED_sequencer.h"
41
42 #include "WM_api.h"
43 #include "WM_types.h"
44
45 #include "IMB_imbuf_types.h"
46 #include "IMB_imbuf.h"
47
48 #include "sequencer_intern.h"
49
50 /* **************************** buttons ********************************* */
51
52 #if 0
53 static bool sequencer_grease_pencil_panel_poll(const bContext *C, PanelType *UNUSED(pt))
54 {
55         SpaceSeq *sseq = CTX_wm_space_seq(C);
56
57         /* don't show the gpencil if we are not showing the image */
58         return ED_space_sequencer_check_show_imbuf(sseq);
59 }
60 #endif
61
62 static bool metadata_panel_context_poll(const bContext *C, PanelType *UNUSED(pt))
63 {
64         SpaceSeq *space_sequencer = CTX_wm_space_seq(C);
65         if (space_sequencer == NULL) {
66                 return false;
67         }
68         return ED_space_sequencer_check_show_imbuf(space_sequencer);
69 }
70
71 static void metadata_panel_context_draw(const bContext *C, Panel *panel)
72 {
73         /* Image buffer can not be acquired during render, similar to
74          * draw_image_seq(). */
75         if (G.is_rendering) {
76                 return;
77         }
78         struct Main *bmain = CTX_data_main(C);
79         struct Depsgraph *depsgraph = CTX_data_depsgraph(C);
80         struct Scene *scene = CTX_data_scene(C);
81         SpaceSeq *space_sequencer = CTX_wm_space_seq(C);
82         /* NOTE: We can only reliably show metadata for the original (current)
83          * frame when split view is used. */
84         const bool show_split = (
85                 scene->ed &&
86                 (scene->ed->over_flag & SEQ_EDIT_OVERLAY_SHOW) &&
87                 (space_sequencer->mainb == SEQ_DRAW_IMG_IMBUF));
88         if (show_split &&
89             space_sequencer->overlay_type == SEQ_DRAW_OVERLAY_REFERENCE)
90         {
91                 return;
92         }
93         /* NOTE: We disable multiview for drawing, since we don't know what is the
94          * from the panel (is kind of all the views?). */
95         ImBuf *ibuf = sequencer_ibuf_get(bmain, depsgraph, scene, space_sequencer, scene->r.cfra, 0, "");
96         if (ibuf != NULL) {
97                 ED_region_image_metadata_panel_draw(ibuf, panel->layout);
98                 IMB_freeImBuf(ibuf);
99         }
100 }
101
102 void sequencer_buttons_register(ARegionType *art)
103 {
104         PanelType *pt;
105
106 #if 0
107         pt = MEM_callocN(sizeof(PanelType), "spacetype sequencer panel gpencil");
108         strcpy(pt->idname, "SEQUENCER_PT_gpencil");
109         strcpy(pt->label, N_("Grease Pencil"));
110         strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
111         pt->draw_header = ED_gpencil_panel_standard_header;
112         pt->draw = ED_gpencil_panel_standard;
113         pt->poll = sequencer_grease_pencil_panel_poll;
114         BLI_addtail(&art->paneltypes, pt);
115 #endif
116
117         pt = MEM_callocN(sizeof(PanelType), "spacetype sequencer panel metadata");
118         strcpy(pt->idname, "SEQUENCER_PT_metadata");
119         strcpy(pt->label, N_("Metadata"));
120         strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
121         pt->poll = metadata_panel_context_poll;
122         pt->draw = metadata_panel_context_draw;
123         BLI_addtail(&art->paneltypes, pt);
124 }
125
126 /* **************** operator to open/close properties view ************* */
127
128 static int sequencer_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op))
129 {
130         ScrArea *sa = CTX_wm_area(C);
131         ARegion *ar = sequencer_has_buttons_region(sa);
132
133         if (ar)
134                 ED_region_toggle_hidden(C, ar);
135
136         return OPERATOR_FINISHED;
137 }
138
139 void SEQUENCER_OT_properties(wmOperatorType *ot)
140 {
141         ot->name = "Properties";
142         ot->idname = "SEQUENCER_OT_properties";
143         ot->description = "Toggle the properties region visibility";
144
145         ot->exec = sequencer_properties_toggle_exec;
146         ot->poll = ED_operator_sequencer_active;
147
148         /* flags */
149         ot->flag = 0;
150 }