2016-12-01 16:43:57 +01:00
|
|
|
/*
|
|
|
|
* ***** 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/screen/screen_draw.c
|
|
|
|
* \ingroup edscr
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
2018-08-23 22:29:29 +02:00
|
|
|
#include "GPU_batch_presets.h"
|
2018-12-02 13:11:47 +11:00
|
|
|
#include "GPU_extensions.h"
|
2016-12-01 16:43:57 +01:00
|
|
|
#include "GPU_framebuffer.h"
|
|
|
|
#include "GPU_immediate.h"
|
2017-03-21 16:08:14 -04:00
|
|
|
#include "GPU_matrix.h"
|
2018-06-27 19:07:23 -06:00
|
|
|
#include "GPU_state.h"
|
2016-12-01 16:43:57 +01:00
|
|
|
|
2018-04-22 18:56:06 +02:00
|
|
|
#include "BLI_math.h"
|
2018-08-23 22:29:29 +02:00
|
|
|
#include "BLI_rect.h"
|
2018-04-22 18:56:06 +02:00
|
|
|
|
2016-12-01 16:43:57 +01:00
|
|
|
#include "WM_api.h"
|
2016-12-08 23:02:29 +01:00
|
|
|
#include "WM_types.h"
|
2016-12-01 16:43:57 +01:00
|
|
|
|
2018-04-22 18:56:06 +02:00
|
|
|
#include "UI_interface.h"
|
2018-04-22 22:55:05 +02:00
|
|
|
#include "UI_resources.h"
|
2018-04-22 18:56:06 +02:00
|
|
|
|
2016-12-08 23:02:29 +01:00
|
|
|
#include "screen_intern.h"
|
|
|
|
|
|
|
|
/**
|
2017-02-22 14:05:56 +01:00
|
|
|
* Draw horizontal shape visualizing future joining (left as well right direction of future joining).
|
2016-12-08 23:02:29 +01:00
|
|
|
*/
|
2017-02-22 14:05:56 +01:00
|
|
|
static void draw_horizontal_join_shape(ScrArea *sa, char dir, unsigned int pos)
|
2016-12-08 23:02:29 +01:00
|
|
|
{
|
2018-06-30 01:56:07 +02:00
|
|
|
const float width = screen_geom_area_width(sa) - 1;
|
|
|
|
const float height = screen_geom_area_height(sa) - 1;
|
2016-12-08 23:02:29 +01:00
|
|
|
vec2f points[10];
|
|
|
|
short i;
|
|
|
|
float w, h;
|
|
|
|
|
|
|
|
if (height < width) {
|
|
|
|
h = height / 8;
|
|
|
|
w = height / 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
h = width / 8;
|
|
|
|
w = width / 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
points[0].x = sa->v1->vec.x;
|
|
|
|
points[0].y = sa->v1->vec.y + height / 2;
|
|
|
|
|
|
|
|
points[1].x = sa->v1->vec.x;
|
|
|
|
points[1].y = sa->v1->vec.y;
|
|
|
|
|
|
|
|
points[2].x = sa->v4->vec.x - w;
|
|
|
|
points[2].y = sa->v4->vec.y;
|
|
|
|
|
|
|
|
points[3].x = sa->v4->vec.x - w;
|
|
|
|
points[3].y = sa->v4->vec.y + height / 2 - 2 * h;
|
|
|
|
|
|
|
|
points[4].x = sa->v4->vec.x - 2 * w;
|
|
|
|
points[4].y = sa->v4->vec.y + height / 2;
|
|
|
|
|
|
|
|
points[5].x = sa->v4->vec.x - w;
|
|
|
|
points[5].y = sa->v4->vec.y + height / 2 + 2 * h;
|
|
|
|
|
|
|
|
points[6].x = sa->v3->vec.x - w;
|
|
|
|
points[6].y = sa->v3->vec.y;
|
|
|
|
|
|
|
|
points[7].x = sa->v2->vec.x;
|
|
|
|
points[7].y = sa->v2->vec.y;
|
|
|
|
|
|
|
|
points[8].x = sa->v4->vec.x;
|
|
|
|
points[8].y = sa->v4->vec.y + height / 2 - h;
|
|
|
|
|
|
|
|
points[9].x = sa->v4->vec.x;
|
|
|
|
points[9].y = sa->v4->vec.y + height / 2 + h;
|
|
|
|
|
|
|
|
if (dir == 'l') {
|
|
|
|
/* when direction is left, then we flip direction of arrow */
|
|
|
|
float cx = sa->v1->vec.x + width;
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
points[i].x -= cx;
|
|
|
|
points[i].x = -points[i].x;
|
|
|
|
points[i].x += sa->v1->vec.x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
immBegin(GPU_PRIM_TRI_FAN, 5);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
|
|
|
for (i = 0; i < 5; i++) {
|
2017-02-22 14:05:56 +01:00
|
|
|
immVertex2f(pos, points[i].x, points[i].y);
|
2017-02-23 00:27:35 -03:00
|
|
|
}
|
|
|
|
|
2017-02-22 14:05:56 +01:00
|
|
|
immEnd();
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
immBegin(GPU_PRIM_TRI_FAN, 5);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
|
|
|
for (i = 4; i < 8; i++) {
|
2017-02-22 14:05:56 +01:00
|
|
|
immVertex2f(pos, points[i].x, points[i].y);
|
2017-02-23 00:27:35 -03:00
|
|
|
}
|
|
|
|
|
2017-02-22 14:05:56 +01:00
|
|
|
immVertex2f(pos, points[0].x, points[0].y);
|
|
|
|
immEnd();
|
2016-12-08 23:02:29 +01:00
|
|
|
|
2017-02-22 14:05:56 +01:00
|
|
|
immRectf(pos, points[2].x, points[2].y, points[8].x, points[8].y);
|
|
|
|
immRectf(pos, points[6].x, points[6].y, points[9].x, points[9].y);
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw vertical shape visualizing future joining (up/down direction).
|
|
|
|
*/
|
2017-02-22 14:05:56 +01:00
|
|
|
static void draw_vertical_join_shape(ScrArea *sa, char dir, unsigned int pos)
|
2016-12-08 23:02:29 +01:00
|
|
|
{
|
2018-06-30 01:56:07 +02:00
|
|
|
const float width = screen_geom_area_width(sa) - 1;
|
|
|
|
const float height = screen_geom_area_height(sa) - 1;
|
2016-12-08 23:02:29 +01:00
|
|
|
vec2f points[10];
|
|
|
|
short i;
|
|
|
|
float w, h;
|
|
|
|
|
|
|
|
if (height < width) {
|
|
|
|
h = height / 4;
|
|
|
|
w = height / 8;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
h = width / 4;
|
|
|
|
w = width / 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
points[0].x = sa->v1->vec.x + width / 2;
|
|
|
|
points[0].y = sa->v3->vec.y;
|
|
|
|
|
|
|
|
points[1].x = sa->v2->vec.x;
|
|
|
|
points[1].y = sa->v2->vec.y;
|
|
|
|
|
|
|
|
points[2].x = sa->v1->vec.x;
|
|
|
|
points[2].y = sa->v1->vec.y + h;
|
|
|
|
|
|
|
|
points[3].x = sa->v1->vec.x + width / 2 - 2 * w;
|
|
|
|
points[3].y = sa->v1->vec.y + h;
|
|
|
|
|
|
|
|
points[4].x = sa->v1->vec.x + width / 2;
|
|
|
|
points[4].y = sa->v1->vec.y + 2 * h;
|
|
|
|
|
|
|
|
points[5].x = sa->v1->vec.x + width / 2 + 2 * w;
|
|
|
|
points[5].y = sa->v1->vec.y + h;
|
|
|
|
|
|
|
|
points[6].x = sa->v4->vec.x;
|
|
|
|
points[6].y = sa->v4->vec.y + h;
|
|
|
|
|
|
|
|
points[7].x = sa->v3->vec.x;
|
|
|
|
points[7].y = sa->v3->vec.y;
|
|
|
|
|
|
|
|
points[8].x = sa->v1->vec.x + width / 2 - w;
|
|
|
|
points[8].y = sa->v1->vec.y;
|
|
|
|
|
|
|
|
points[9].x = sa->v1->vec.x + width / 2 + w;
|
|
|
|
points[9].y = sa->v1->vec.y;
|
|
|
|
|
|
|
|
if (dir == 'u') {
|
|
|
|
/* when direction is up, then we flip direction of arrow */
|
|
|
|
float cy = sa->v1->vec.y + height;
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
points[i].y -= cy;
|
|
|
|
points[i].y = -points[i].y;
|
|
|
|
points[i].y += sa->v1->vec.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
immBegin(GPU_PRIM_TRI_FAN, 5);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
|
|
|
for (i = 0; i < 5; i++) {
|
2017-02-22 14:05:56 +01:00
|
|
|
immVertex2f(pos, points[i].x, points[i].y);
|
2017-02-23 00:27:35 -03:00
|
|
|
}
|
|
|
|
|
2017-02-22 14:05:56 +01:00
|
|
|
immEnd();
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
immBegin(GPU_PRIM_TRI_FAN, 5);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
|
|
|
for (i = 4; i < 8; i++) {
|
2017-02-22 14:05:56 +01:00
|
|
|
immVertex2f(pos, points[i].x, points[i].y);
|
2017-02-23 00:27:35 -03:00
|
|
|
}
|
|
|
|
|
2017-02-22 14:05:56 +01:00
|
|
|
immVertex2f(pos, points[0].x, points[0].y);
|
|
|
|
immEnd();
|
2016-12-08 23:02:29 +01:00
|
|
|
|
2017-02-22 14:05:56 +01:00
|
|
|
immRectf(pos, points[2].x, points[2].y, points[8].x, points[8].y);
|
|
|
|
immRectf(pos, points[6].x, points[6].y, points[9].x, points[9].y);
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw join shape due to direction of joining.
|
|
|
|
*/
|
2017-02-22 14:05:56 +01:00
|
|
|
static void draw_join_shape(ScrArea *sa, char dir, unsigned int pos)
|
2016-12-08 23:02:29 +01:00
|
|
|
{
|
2017-02-23 00:27:35 -03:00
|
|
|
if (dir == 'u' || dir == 'd') {
|
2017-02-22 14:05:56 +01:00
|
|
|
draw_vertical_join_shape(sa, dir, pos);
|
2017-02-23 00:27:35 -03:00
|
|
|
}
|
|
|
|
else {
|
2017-02-22 14:05:56 +01:00
|
|
|
draw_horizontal_join_shape(sa, dir, pos);
|
2017-02-23 00:27:35 -03:00
|
|
|
}
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
|
|
|
|
2018-12-01 19:49:31 +01:00
|
|
|
#define CORNER_RESOLUTION 3
|
2018-08-23 22:29:29 +02:00
|
|
|
|
|
|
|
static void do_vert_pair(GPUVertBuf *vbo, uint pos, uint *vidx, int corner, int i)
|
|
|
|
{
|
|
|
|
float inter[2], exter[2];
|
2018-08-23 23:02:38 +02:00
|
|
|
inter[0] = cosf(corner * M_PI_2 + (i * M_PI_2 / (CORNER_RESOLUTION - 1.0f)));
|
|
|
|
inter[1] = sinf(corner * M_PI_2 + (i * M_PI_2 / (CORNER_RESOLUTION - 1.0f)));
|
2018-08-23 22:29:29 +02:00
|
|
|
|
|
|
|
/* Snap point to edge */
|
|
|
|
float div = 1.0f / max_ff(fabsf(inter[0]), fabsf(inter[1]));
|
|
|
|
mul_v2_v2fl(exter, inter, div);
|
|
|
|
exter[0] = roundf(exter[0]);
|
|
|
|
exter[1] = roundf(exter[1]);
|
|
|
|
|
|
|
|
if (i == 0 || i == (CORNER_RESOLUTION - 1)) {
|
|
|
|
copy_v2_v2(inter, exter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Line width is 20% of the entire corner size. */
|
2018-12-01 19:49:31 +01:00
|
|
|
const float line_width = 0.2f; /* Keep in sync with shader */
|
2018-08-23 22:29:29 +02:00
|
|
|
mul_v2_fl(inter, 1.0f - line_width);
|
|
|
|
mul_v2_fl(exter, 1.0f + line_width);
|
|
|
|
|
|
|
|
switch (corner) {
|
|
|
|
case 0:
|
|
|
|
add_v2_v2(inter, (float[2]){-1.0f, -1.0f});
|
|
|
|
add_v2_v2(exter, (float[2]){-1.0f, -1.0f});
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
add_v2_v2(inter, (float[2]){1.0f, -1.0f});
|
|
|
|
add_v2_v2(exter, (float[2]){1.0f, -1.0f});
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
add_v2_v2(inter, (float[2]){1.0f, 1.0f});
|
|
|
|
add_v2_v2(exter, (float[2]){1.0f, 1.0f});
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
add_v2_v2(inter, (float[2]){-1.0f, 1.0f});
|
|
|
|
add_v2_v2(exter, (float[2]){-1.0f, 1.0f});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPU_vertbuf_attr_set(vbo, pos, (*vidx)++, inter);
|
|
|
|
GPU_vertbuf_attr_set(vbo, pos, (*vidx)++, exter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GPUBatch *batch_screen_edges_get(int *corner_len)
|
|
|
|
{
|
|
|
|
static GPUBatch *screen_edges_batch = NULL;
|
|
|
|
|
|
|
|
if (screen_edges_batch == NULL) {
|
|
|
|
GPUVertFormat format = {0};
|
|
|
|
uint pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
|
|
|
|
|
|
|
GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
|
2018-12-01 19:49:31 +01:00
|
|
|
GPU_vertbuf_data_alloc(vbo, CORNER_RESOLUTION * 2 * 4 + 2);
|
2018-08-23 22:29:29 +02:00
|
|
|
|
|
|
|
uint vidx = 0;
|
2018-12-01 19:49:31 +01:00
|
|
|
for (int corner = 0; corner < 4; ++corner) {
|
|
|
|
for (int c = 0; c < CORNER_RESOLUTION; ++c) {
|
|
|
|
do_vert_pair(vbo, pos, &vidx, corner, c);
|
2018-08-23 22:29:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* close the loop */
|
|
|
|
do_vert_pair(vbo, pos, &vidx, 0, 0);
|
|
|
|
|
|
|
|
screen_edges_batch = GPU_batch_create_ex(GPU_PRIM_TRI_STRIP, vbo, NULL, GPU_BATCH_OWNS_VBO);
|
|
|
|
gpu_batch_presets_register(screen_edges_batch);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (corner_len) {
|
|
|
|
*corner_len = CORNER_RESOLUTION * 2;
|
|
|
|
}
|
|
|
|
return screen_edges_batch;
|
|
|
|
}
|
|
|
|
|
2018-04-22 18:56:06 +02:00
|
|
|
#undef CORNER_RESOLUTION
|
|
|
|
|
2016-12-08 23:02:29 +01:00
|
|
|
/**
|
|
|
|
* Draw screen area darker with arrow (visualization of future joining).
|
|
|
|
*/
|
2017-02-22 14:05:56 +01:00
|
|
|
static void scrarea_draw_shape_dark(ScrArea *sa, char dir, unsigned int pos)
|
2016-12-08 23:02:29 +01:00
|
|
|
{
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
|
2017-02-22 14:05:56 +01:00
|
|
|
immUniformColor4ub(0, 0, 0, 50);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2017-02-22 14:05:56 +01:00
|
|
|
draw_join_shape(sa, dir, pos);
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw screen area ligher with arrow shape ("eraser" of previous dark shape).
|
|
|
|
*/
|
2017-02-22 14:05:56 +01:00
|
|
|
static void scrarea_draw_shape_light(ScrArea *sa, char UNUSED(dir), unsigned int pos)
|
2016-12-08 23:02:29 +01:00
|
|
|
{
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_blend_set_func(GPU_DST_COLOR, GPU_SRC_ALPHA);
|
2016-12-08 23:02:29 +01:00
|
|
|
/* value 181 was hardly computed: 181~105 */
|
2017-02-22 14:05:56 +01:00
|
|
|
immUniformColor4ub(255, 255, 255, 50);
|
2016-12-08 23:02:29 +01:00
|
|
|
/* draw_join_shape(sa, dir); */
|
2017-02-23 00:27:35 -03:00
|
|
|
|
|
|
|
immRectf(pos, sa->v1->vec.x, sa->v1->vec.y, sa->v3->vec.x, sa->v3->vec.y);
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
|
|
|
|
2018-08-23 22:29:29 +02:00
|
|
|
static void drawscredge_area_draw(int sizex, int sizey, short x1, short y1, short x2, short y2, float edge_thickness)
|
2016-12-08 23:02:29 +01:00
|
|
|
{
|
2018-08-23 22:29:29 +02:00
|
|
|
rctf rect;
|
|
|
|
BLI_rctf_init(&rect, (float)x1, (float)x2, (float)y1, (float)y2);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2016-12-08 23:02:29 +01:00
|
|
|
/* right border area */
|
2018-08-23 22:29:29 +02:00
|
|
|
if (x2 >= sizex - 1) {
|
|
|
|
rect.xmax += edge_thickness * 0.5f;
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* left border area */
|
2018-08-23 22:29:29 +02:00
|
|
|
if (x1 <= 0) { /* otherwise it draws the emboss of window over */
|
|
|
|
rect.xmin -= edge_thickness * 0.5f;
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* top border area */
|
2018-08-23 22:29:29 +02:00
|
|
|
if (y2 >= sizey - 1) {
|
|
|
|
rect.ymax += edge_thickness * 0.5f;
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* bottom border area */
|
2018-08-23 22:29:29 +02:00
|
|
|
if (y1 <= 0) {
|
|
|
|
rect.ymin -= edge_thickness * 0.5f;
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-08-23 22:29:29 +02:00
|
|
|
GPUBatch *batch = batch_screen_edges_get(NULL);
|
|
|
|
GPU_batch_uniform_4fv(batch, "rect", (float *)&rect);
|
|
|
|
GPU_batch_draw(batch);
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Screen edges drawing.
|
|
|
|
*/
|
2018-08-23 22:29:29 +02:00
|
|
|
static void drawscredge_area(ScrArea *sa, int sizex, int sizey, float edge_thickness)
|
2016-12-08 23:02:29 +01:00
|
|
|
{
|
|
|
|
short x1 = sa->v1->vec.x;
|
|
|
|
short y1 = sa->v1->vec.y;
|
|
|
|
short x2 = sa->v3->vec.x;
|
|
|
|
short y2 = sa->v3->vec.y;
|
|
|
|
|
2018-08-23 22:29:29 +02:00
|
|
|
drawscredge_area_draw(sizex, sizey, x1, y1, x2, y2, edge_thickness);
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-21 18:22:39 -02:00
|
|
|
* Only for edge lines between areas.
|
2016-12-08 23:02:29 +01:00
|
|
|
*/
|
2018-01-19 17:31:10 +11:00
|
|
|
void ED_screen_draw_edges(wmWindow *win)
|
2016-12-08 23:02:29 +01:00
|
|
|
{
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
bScreen *screen = WM_window_get_active_screen(win);
|
2018-11-22 12:32:54 +11:00
|
|
|
screen->do_draw = false;
|
|
|
|
|
|
|
|
if (screen->state == SCREENFULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-08 23:02:29 +01:00
|
|
|
const int winsize_x = WM_window_pixels_x(win);
|
|
|
|
const int winsize_y = WM_window_pixels_y(win);
|
2018-08-23 22:29:29 +02:00
|
|
|
float col[4], corner_scale, edge_thickness;
|
|
|
|
int verts_per_corner = 0;
|
2016-12-08 23:02:29 +01:00
|
|
|
|
|
|
|
ScrArea *sa;
|
|
|
|
|
2018-08-23 23:02:38 +02:00
|
|
|
rcti scissor_rect;
|
|
|
|
BLI_rcti_init_minmax(&scissor_rect);
|
|
|
|
for (sa = screen->areabase.first; sa; sa = sa->next) {
|
|
|
|
BLI_rcti_do_minmax_v(&scissor_rect, (int[2]){sa->v1->vec.x, sa->v1->vec.y});
|
|
|
|
BLI_rcti_do_minmax_v(&scissor_rect, (int[2]){sa->v3->vec.x, sa->v3->vec.y});
|
|
|
|
}
|
|
|
|
|
2018-12-02 03:49:26 +01:00
|
|
|
if (GPU_type_matches(GPU_DEVICE_INTEL_UHD, GPU_OS_UNIX, GPU_DRIVER_ANY)) {
|
2018-12-02 01:57:22 +01:00
|
|
|
/* For some reason, on linux + Intel UHD Graphics 620 the driver
|
|
|
|
* hangs if we don't flush before this. (See T57455) */
|
2018-12-05 04:23:45 +01:00
|
|
|
GPU_flush();
|
2018-12-02 01:57:22 +01:00
|
|
|
}
|
|
|
|
|
2018-08-23 23:02:38 +02:00
|
|
|
GPU_scissor(scissor_rect.xmin,
|
|
|
|
scissor_rect.ymin,
|
|
|
|
BLI_rcti_size_x(&scissor_rect) + 1,
|
|
|
|
BLI_rcti_size_y(&scissor_rect) + 1);
|
|
|
|
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
|
2018-08-23 22:29:29 +02:00
|
|
|
UI_GetThemeColor4fv(TH_EDITOR_OUTLINE, col);
|
2018-12-01 19:49:31 +01:00
|
|
|
col[3] = 1.0f;
|
2018-08-23 22:29:29 +02:00
|
|
|
corner_scale = U.pixelsize * 8.0f;
|
|
|
|
edge_thickness = corner_scale * 0.21f;
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-08-23 22:29:29 +02:00
|
|
|
GPU_blend(true);
|
2016-12-08 23:02:29 +01:00
|
|
|
|
2018-08-23 22:29:29 +02:00
|
|
|
GPUBatch *batch = batch_screen_edges_get(&verts_per_corner);
|
|
|
|
GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_AREA_EDGES);
|
|
|
|
GPU_batch_uniform_1i(batch, "cornerLen", verts_per_corner);
|
|
|
|
GPU_batch_uniform_1f(batch, "scale", corner_scale);
|
|
|
|
GPU_batch_uniform_4fv(batch, "color", col);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
for (sa = screen->areabase.first; sa; sa = sa->next) {
|
2018-08-23 22:29:29 +02:00
|
|
|
drawscredge_area(sa, winsize_x, winsize_y, edge_thickness);
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
|
|
|
|
2018-08-23 22:29:29 +02:00
|
|
|
GPU_blend(false);
|
|
|
|
|
2018-08-23 23:02:38 +02:00
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2018-01-19 17:31:10 +11:00
|
|
|
}
|
|
|
|
|
2018-01-21 18:22:39 -02:00
|
|
|
/**
|
|
|
|
* The blended join arrows.
|
|
|
|
*
|
|
|
|
* \param sa1: Area from which the resultant originates.
|
|
|
|
* \param sa2: Target area that will be replaced.
|
|
|
|
*/
|
2018-01-19 17:31:10 +11:00
|
|
|
void ED_screen_draw_join_shape(ScrArea *sa1, ScrArea *sa2)
|
|
|
|
{
|
2018-07-18 00:12:21 +02:00
|
|
|
uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
2018-01-19 17:31:10 +11:00
|
|
|
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
|
|
|
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_line_width(1);
|
2018-01-19 17:31:10 +11:00
|
|
|
|
2016-12-08 23:02:29 +01:00
|
|
|
/* blended join arrow */
|
2018-01-19 17:31:10 +11:00
|
|
|
int dir = area_getorientation(sa1, sa2);
|
|
|
|
int dira = -1;
|
|
|
|
if (dir != -1) {
|
|
|
|
switch (dir) {
|
|
|
|
case 0: /* W */
|
|
|
|
dir = 'r';
|
|
|
|
dira = 'l';
|
|
|
|
break;
|
|
|
|
case 1: /* N */
|
|
|
|
dir = 'd';
|
|
|
|
dira = 'u';
|
|
|
|
break;
|
|
|
|
case 2: /* E */
|
|
|
|
dir = 'l';
|
|
|
|
dira = 'r';
|
|
|
|
break;
|
|
|
|
case 3: /* S */
|
|
|
|
dir = 'u';
|
|
|
|
dira = 'd';
|
|
|
|
break;
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_blend(true);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2017-02-22 14:05:56 +01:00
|
|
|
scrarea_draw_shape_dark(sa2, dir, pos);
|
|
|
|
scrarea_draw_shape_light(sa1, dira, pos);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_blend(false);
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
|
|
|
|
2018-01-19 17:31:10 +11:00
|
|
|
immUnbindProgram();
|
|
|
|
}
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-01-19 17:31:10 +11:00
|
|
|
void ED_screen_draw_split_preview(ScrArea *sa, const int dir, const float fac)
|
|
|
|
{
|
2018-07-18 00:12:21 +02:00
|
|
|
uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
2018-01-19 17:31:10 +11:00
|
|
|
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
2016-12-08 23:02:29 +01:00
|
|
|
|
2018-01-19 17:31:10 +11:00
|
|
|
/* splitpoint */
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_blend(true);
|
2018-01-19 17:31:10 +11:00
|
|
|
immUniformColor4ub(255, 255, 255, 100);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
immBegin(GPU_PRIM_LINES, 2);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-01-19 17:31:10 +11:00
|
|
|
if (dir == 'h') {
|
|
|
|
const float y = (1 - fac) * sa->totrct.ymin + fac * sa->totrct.ymax;
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-01-19 17:31:10 +11:00
|
|
|
immVertex2f(pos, sa->totrct.xmin, y);
|
|
|
|
immVertex2f(pos, sa->totrct.xmax, y);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-01-19 17:31:10 +11:00
|
|
|
immEnd();
|
|
|
|
|
|
|
|
immUniformColor4ub(0, 0, 0, 100);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
immBegin(GPU_PRIM_LINES, 2);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-01-19 17:31:10 +11:00
|
|
|
immVertex2f(pos, sa->totrct.xmin, y + 1);
|
|
|
|
immVertex2f(pos, sa->totrct.xmax, y + 1);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-01-19 17:31:10 +11:00
|
|
|
immEnd();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_assert(dir == 'v');
|
|
|
|
const float x = (1 - fac) * sa->totrct.xmin + fac * sa->totrct.xmax;
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-01-19 17:31:10 +11:00
|
|
|
immVertex2f(pos, x, sa->totrct.ymin);
|
|
|
|
immVertex2f(pos, x, sa->totrct.ymax);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2017-02-22 14:05:56 +01:00
|
|
|
immEnd();
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-01-19 17:31:10 +11:00
|
|
|
immUniformColor4ub(0, 0, 0, 100);
|
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
immBegin(GPU_PRIM_LINES, 2);
|
2018-01-19 17:31:10 +11:00
|
|
|
|
|
|
|
immVertex2f(pos, x + 1, sa->totrct.ymin);
|
|
|
|
immVertex2f(pos, x + 1, sa->totrct.ymax);
|
|
|
|
|
|
|
|
immEnd();
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
|
|
|
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_blend(false);
|
2017-02-23 00:27:35 -03:00
|
|
|
|
2018-01-19 17:31:10 +11:00
|
|
|
immUnbindProgram();
|
2016-12-08 23:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/* Screen Thumbnail Preview */
|
2016-12-01 16:43:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates a scale factor to squash the preview for \a screen into a rectangle of given size and aspect.
|
|
|
|
*/
|
|
|
|
static void screen_preview_scale_get(
|
|
|
|
const bScreen *screen, float size_x, float size_y,
|
|
|
|
const float asp[2],
|
|
|
|
float r_scale[2])
|
|
|
|
{
|
|
|
|
float max_x = 0, max_y = 0;
|
|
|
|
|
|
|
|
for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
|
|
|
|
max_x = MAX2(max_x, sa->totrct.xmax);
|
|
|
|
max_y = MAX2(max_y, sa->totrct.ymax);
|
|
|
|
}
|
|
|
|
r_scale[0] = (size_x * asp[0]) / max_x;
|
|
|
|
r_scale[1] = (size_y * asp[1]) / max_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void screen_preview_draw_areas(const bScreen *screen, const float scale[2], const float col[4],
|
|
|
|
const float ofs_between_areas)
|
|
|
|
{
|
|
|
|
const float ofs_h = ofs_between_areas * 0.5f;
|
2018-07-18 00:12:21 +02:00
|
|
|
uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
2016-12-01 16:43:57 +01:00
|
|
|
|
|
|
|
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
|
|
|
immUniformColor4fv(col);
|
|
|
|
|
|
|
|
for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
|
2017-03-30 03:01:50 -04:00
|
|
|
rctf rect = {
|
|
|
|
.xmin = sa->totrct.xmin * scale[0] + ofs_h,
|
|
|
|
.xmax = sa->totrct.xmax * scale[0] - ofs_h,
|
|
|
|
.ymin = sa->totrct.ymin * scale[1] + ofs_h,
|
|
|
|
.ymax = sa->totrct.ymax * scale[1] - ofs_h
|
|
|
|
};
|
2016-12-01 16:43:57 +01:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
immBegin(GPU_PRIM_TRI_FAN, 4);
|
2016-12-01 16:43:57 +01:00
|
|
|
immVertex2f(pos, rect.xmin, rect.ymin);
|
|
|
|
immVertex2f(pos, rect.xmax, rect.ymin);
|
|
|
|
immVertex2f(pos, rect.xmax, rect.ymax);
|
|
|
|
immVertex2f(pos, rect.xmin, rect.ymax);
|
|
|
|
immEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
immUnbindProgram();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void screen_preview_draw(const bScreen *screen, int size_x, int size_y)
|
|
|
|
{
|
|
|
|
const float asp[2] = {1.0f, 0.8f}; /* square previews look a bit ugly */
|
|
|
|
/* could use theme color (tui.wcol_menu_item.text), but then we'd need to regenerate all previews when changing */
|
|
|
|
const float col[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
|
|
|
float scale[2];
|
|
|
|
|
|
|
|
wmOrtho2(0.0f, size_x, 0.0f, size_y);
|
|
|
|
/* center */
|
2018-07-15 15:27:15 +02:00
|
|
|
GPU_matrix_push();
|
|
|
|
GPU_matrix_identity_set();
|
|
|
|
GPU_matrix_translate_2f(size_x * (1.0f - asp[0]) * 0.5f, size_y * (1.0f - asp[1]) * 0.5f);
|
2016-12-01 16:43:57 +01:00
|
|
|
|
|
|
|
screen_preview_scale_get(screen, size_x, size_y, asp, scale);
|
|
|
|
screen_preview_draw_areas(screen, scale, col, 1.5f);
|
2017-03-30 03:01:50 -04:00
|
|
|
|
2018-07-15 15:27:15 +02:00
|
|
|
GPU_matrix_pop();
|
2016-12-01 16:43:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the preview for a screen layout in \a screen.
|
|
|
|
*/
|
|
|
|
void ED_screen_preview_render(const bScreen *screen, int size_x, int size_y, unsigned int *r_rect)
|
|
|
|
{
|
|
|
|
char err_out[256] = "unknown";
|
2018-02-13 18:18:04 +01:00
|
|
|
GPUOffScreen *offscreen = GPU_offscreen_create(size_x, size_y, 0, true, false, err_out);
|
2016-12-01 16:43:57 +01:00
|
|
|
|
|
|
|
GPU_offscreen_bind(offscreen, true);
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_clear_color(0.0, 0.0, 0.0, 0.0);
|
|
|
|
GPU_clear(GPU_COLOR_BIT | GPU_DEPTH_BIT);
|
2016-12-01 16:43:57 +01:00
|
|
|
|
|
|
|
screen_preview_draw(screen, size_x, size_y);
|
|
|
|
|
|
|
|
GPU_offscreen_read_pixels(offscreen, GL_UNSIGNED_BYTE, r_rect);
|
|
|
|
GPU_offscreen_unbind(offscreen, true);
|
|
|
|
|
|
|
|
GPU_offscreen_free(offscreen);
|
|
|
|
}
|