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;
83 ar= MEM_callocN(sizeof(ARegion), "main area for text");
85 BLI_addtail(&stext->regionbase, ar);
86 ar->regiontype= RGN_TYPE_WINDOW;
88 /* channel list region XXX */
91 return (SpaceLink *)stext;
94 /* not spacelink itself */
95 static void text_free(SpaceLink *sl)
97 SpaceText *stext= (SpaceText*) sl;
103 /* spacetype; init callback */
104 static void text_init(struct wmWindowManager *wm, ScrArea *sa)
109 static SpaceLink *text_duplicate(SpaceLink *sl)
111 SpaceText *stextn= MEM_dupallocN(sl);
113 /* clear or remove stuff from old */
115 return (SpaceLink *)stextn;
120 /* add handlers, stuff you only do once or on area/region changes */
121 static void text_main_area_init(wmWindowManager *wm, ARegion *ar)
125 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_VIEWCANVAS, ar->winx, ar->winy);
128 keymap= WM_keymap_listbase(wm, "Text", SPACE_TEXT, 0); /* XXX weak? */
129 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
132 static void text_main_area_draw(const bContext *C, ARegion *ar)
134 /* draw entirely, view changes should be handled here */
135 // SpaceText *stext= C->area->spacedata.first;
136 View2D *v2d= &ar->v2d;
139 /* clear and setup matrix */
140 UI_GetThemeColor3fv(TH_BACK, col);
141 glClearColor(col[0], col[1], col[2], 0.0);
142 glClear(GL_COLOR_BUFFER_BIT);
144 UI_view2d_view_ortho(C, v2d);
149 /* reset view matrix */
150 UI_view2d_view_restore(C);
155 static void text_operatortypes(void)
160 static void text_cursor(wmWindow *win, ARegion *ar)
162 if(ar->regiontype==RGN_TYPE_WINDOW)
163 WM_cursor_set(win, BC_TEXTEDITCURSOR);
165 WM_cursor_set(win, CURSOR_STD);
168 static void text_keymap(struct wmWindowManager *wm)
173 /* add handlers, stuff you only do once or on area/region changes */
174 static void text_header_area_init(wmWindowManager *wm, ARegion *ar)
176 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
179 static void text_header_area_draw(const bContext *C, ARegion *ar)
184 if(ED_screen_area_active(C))
185 UI_GetThemeColor3fv(TH_HEADER, col);
187 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
189 glClearColor(col[0], col[1], col[2], 0.0);
190 glClear(GL_COLOR_BUFFER_BIT);
192 /* set view2d view matrix for scrolling (without scrollers) */
193 UI_view2d_view_ortho(C, &ar->v2d);
195 text_header_buttons(C, ar);
197 /* restore view matrix? */
198 UI_view2d_view_restore(C);
201 static void text_main_area_listener(ARegion *ar, wmNotifier *wmn)
203 /* context changes */
206 /* only called once, from space/spacetypes.c */
207 void ED_spacetype_text(void)
209 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype text");
212 st->spaceid= SPACE_TEXT;
217 st->duplicate= text_duplicate;
218 st->operatortypes= text_operatortypes;
219 st->cursor= text_cursor;
220 st->keymap= text_keymap;
222 /* regions: main window */
223 art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
224 art->regionid = RGN_TYPE_WINDOW;
225 art->init= text_main_area_init;
226 art->draw= text_main_area_draw;
227 art->listener= text_main_area_listener;
228 art->keymapflag= ED_KEYMAP_VIEW2D;
230 BLI_addhead(&st->regiontypes, art);
232 /* regions: header */
233 art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
234 art->regionid = RGN_TYPE_HEADER;
235 art->minsizey= HEADERY;
236 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
238 art->init= text_header_area_init;
239 art->draw= text_header_area_draw;
241 BLI_addhead(&st->regiontypes, art);
244 BKE_spacetype_register(st);