4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
32 #include "DNA_text_types.h"
33 #include "DNA_object_types.h"
34 #include "DNA_space_types.h"
35 #include "DNA_scene_types.h"
36 #include "DNA_screen_types.h"
38 #include "MEM_guardedalloc.h"
40 #include "BLI_blenlib.h"
41 #include "BLI_arithb.h"
44 #include "BKE_colortools.h"
45 #include "BKE_global.h"
46 #include "BKE_screen.h"
48 #include "ED_space_api.h"
49 #include "ED_screen.h"
56 #include "UI_interface.h"
57 #include "UI_resources.h"
58 #include "UI_view2d.h"
60 #include "ED_markers.h"
62 #include "text_intern.h" // own include
64 /* ******************** default callbacks for text space ***************** */
66 static SpaceLink *text_new(void)
71 stext= MEM_callocN(sizeof(SpaceText), "inittext");
72 stext->spacetype= SPACE_TEXT;
76 ar= MEM_callocN(sizeof(ARegion), "header for text");
78 BLI_addtail(&stext->regionbase, ar);
79 ar->regiontype= RGN_TYPE_HEADER;
80 ar->alignment= RGN_ALIGN_BOTTOM;
81 UI_view2d_header_default(&ar->v2d);
84 ar= MEM_callocN(sizeof(ARegion), "main area for text");
86 BLI_addtail(&stext->regionbase, ar);
87 ar->regiontype= RGN_TYPE_WINDOW;
89 /* channel list region XXX */
92 return (SpaceLink *)stext;
95 /* not spacelink itself */
96 static void text_free(SpaceLink *sl)
98 SpaceText *stext= (SpaceText*) sl;
104 /* spacetype; init callback */
105 static void text_init(struct wmWindowManager *wm, ScrArea *sa)
110 static SpaceLink *text_duplicate(SpaceLink *sl)
112 SpaceText *stextn= MEM_dupallocN(sl);
114 /* clear or remove stuff from old */
116 return (SpaceLink *)stextn;
121 /* add handlers, stuff you only do once or on area/region changes */
122 static void text_main_area_init(wmWindowManager *wm, ARegion *ar)
126 UI_view2d_size_update(&ar->v2d, ar->winx, ar->winy);
129 keymap= WM_keymap_listbase(wm, "Text", SPACE_TEXT, 0); /* XXX weak? */
130 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
133 static void text_main_area_draw(const bContext *C, ARegion *ar)
135 /* draw entirely, view changes should be handled here */
136 // SpaceText *stext= C->area->spacedata.first;
137 View2D *v2d= &ar->v2d;
140 /* clear and setup matrix */
141 UI_GetThemeColor3fv(TH_BACK, col);
142 glClearColor(col[0], col[1], col[2], 0.0);
143 glClear(GL_COLOR_BUFFER_BIT);
145 UI_view2d_view_ortho(C, v2d);
150 /* reset view matrix */
151 UI_view2d_view_restore(C);
156 void text_operatortypes(void)
161 void text_keymap(struct wmWindowManager *wm)
166 /* add handlers, stuff you only do once or on area/region changes */
167 static void text_header_area_init(wmWindowManager *wm, ARegion *ar)
169 UI_view2d_size_update(&ar->v2d, ar->winx, ar->winy);
172 static void text_header_area_draw(const bContext *C, ARegion *ar)
177 if(ED_screen_area_active(C))
178 UI_GetThemeColor3fv(TH_HEADER, col);
180 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
182 glClearColor(col[0], col[1], col[2], 0.0);
183 glClear(GL_COLOR_BUFFER_BIT);
185 /* set view2d view matrix for scrolling (without scrollers) */
186 UI_view2d_view_ortho(C, &ar->v2d);
188 text_header_buttons(C, ar);
190 /* restore view matrix? */
191 UI_view2d_view_restore(C);
194 static void text_main_area_listener(ARegion *ar, wmNotifier *wmn)
196 /* context changes */
199 /* only called once, from space/spacetypes.c */
200 void ED_spacetype_text(void)
202 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype text");
205 st->spaceid= SPACE_TEXT;
210 st->duplicate= text_duplicate;
211 st->operatortypes= text_operatortypes;
212 st->keymap= text_keymap;
214 /* regions: main window */
215 art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
216 art->regionid = RGN_TYPE_WINDOW;
217 art->init= text_main_area_init;
218 art->draw= text_main_area_draw;
219 art->listener= text_main_area_listener;
220 art->keymapflag= ED_KEYMAP_VIEW2D;
222 BLI_addhead(&st->regiontypes, art);
224 /* regions: header */
225 art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
226 art->regionid = RGN_TYPE_HEADER;
227 art->minsizey= HEADERY;
228 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
230 art->init= text_header_area_init;
231 art->draw= text_header_area_draw;
233 BLI_addhead(&st->regiontypes, art);
236 BKE_spacetype_register(st);