Welcome to mirror list, hosted at ThFree Co, Russian Federation.

space_stats.c « space_stats « editors « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bc79231d97627ea52baae42f7b4b04c12852cd8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file blender/editors/space_stats/space_stats.c
 *  \ingroup splayers
 */

#include <string.h>

#include "MEM_guardedalloc.h"

#include "BIF_gl.h"

#include "BKE_context.h"
#include "BKE_screen.h"

#include "BLI_listbase.h"
#include "BLI_utildefines.h"

#include "DNA_space_types.h"
#include "DNA_windowmanager_types.h"

#include "ED_screen.h"
#include "ED_space_api.h"

#include "UI_interface.h"
#include "UI_resources.h"
#include "UI_view2d.h"

#include "WM_types.h"


/* ******************** default callbacks for stats editor space ***************** */

static SpaceLink *stats_new(const bContext *UNUSED(C))
{
	ARegion *ar;
	SpaceStats *sstats;

	sstats = MEM_callocN(sizeof(SpaceStats), __func__);
	sstats->spacetype = SPACE_STATS;

	/* header */
	ar = MEM_callocN(sizeof(ARegion), "header for stats editor");

	BLI_addtail(&sstats->regionbase, ar);
	ar->regiontype = RGN_TYPE_HEADER;
	ar->alignment = RGN_ALIGN_BOTTOM;

	/* main region */
	ar = MEM_callocN(sizeof(ARegion), "main region for stats editor");

	BLI_addtail(&sstats->regionbase, ar);
	ar->regiontype = RGN_TYPE_WINDOW;

	return (SpaceLink *)sstats;
}

static SpaceLink *stats_duplicate(SpaceLink *sl)
{
	SpaceStats *sstats = MEM_dupallocN(sl);

	/* clear or remove stuff from old */

	return (SpaceLink *)sstats;
}

/* add handlers, stuff you only do once or on area/region changes */
static void stats_main_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
{
	/* do not use here, the properties changed in userprefs do a system-wide refresh, then scroller jumps back */
	/*    ar->v2d.flag &= ~V2D_IS_INITIALISED; */

	ar->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE;
}

static void stats_main_region_draw(const bContext *C, ARegion *ar)
{
	View2D *v2d = &ar->v2d;
	float size_x = ar->winx;
	float size_y = 0.0f;

	UI_ThemeClearColor(TH_BACK);
	glClear(GL_COLOR_BUFFER_BIT);

	/* update size of tot-rect (extents of data/viewable area) */
	UI_view2d_totRect_set(v2d, size_x, size_y);

	/* reset view matrix */
	UI_view2d_view_restore(C);

	/* scrollers */
	View2DScrollers *scrollers;
	scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
	UI_view2d_scrollers_draw(C, v2d, scrollers);
	UI_view2d_scrollers_free(scrollers);
}

/* add handlers, stuff you only do once or on area/region changes */
static void stats_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
{
	ED_region_header_init(ar);
}

static void stats_header_region_draw(const bContext *C, ARegion *ar)
{
	ED_region_header(C, ar);
}

static void stats_main_region_listener(bScreen *UNUSED(sc), ScrArea *sa, ARegion *UNUSED(ar), wmNotifier *wmn)
{
	switch(wmn->category) {
		case NC_SPACE: {
			if (wmn->data == ND_SPACE_STATS) {
				ED_area_tag_redraw(sa);
			}
			break;
		}
	}
}

/* only called once, from space/spacetypes.c */
void ED_spacetype_stats(void)
{
	SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype stats");
	ARegionType *art;

	st->spaceid = SPACE_STATS;
	strncpy(st->name, "StatsEditor", BKE_ST_MAXNAME);

	st->new = stats_new;
	st->duplicate = stats_duplicate;

	/* regions: main window */
	art = MEM_callocN(sizeof(ARegionType), "stats editor region");
	art->regionid = RGN_TYPE_WINDOW;
	art->init = stats_main_region_init;
	art->draw = stats_main_region_draw;
	art->listener = stats_main_region_listener;
	art->keymapflag = ED_KEYMAP_UI;
	BLI_addhead(&st->regiontypes, art);

	/* regions: header */
	art = MEM_callocN(sizeof(ARegionType), "spacetype stats header");
	art->regionid = RGN_TYPE_HEADER;
	art->prefsizey = HEADERY;
	art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
	art->init = stats_header_region_init;
	art->draw = stats_header_region_draw;
	BLI_addhead(&st->regiontypes, art);

	BKE_spacetype_register(st);
}