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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_image/image_draw.c')
-rw-r--r--source/blender/editors/space_image/image_draw.c141
1 files changed, 135 insertions, 6 deletions
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c
index 4cbe25462af..c49190a97af 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -49,6 +49,7 @@
#include "BLI_threads.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
+#include "BLI_listbase.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
@@ -479,7 +480,7 @@ static void sima_draw_zbuffloat_pixels(Scene *scene, float x1, float y1, int rec
MEM_freeN(rectf);
}
-static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar, Scene *scene, ImBuf *ibuf, float fx, float fy, float zoomx, float zoomy)
+static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar, Scene *scene, ImBuf *ibuf, float fx, float fy, float zoomx, float zoomy, const char *label)
{
int x, y;
@@ -547,6 +548,24 @@ static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar,
if (sima->flag & SI_USE_ALPHA)
GPU_blend(false);
}
+
+ if (label && label[0]) {
+ glEnable(GL_BLEND);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ BLF_size(blf_mono_font, 25 * U.pixelsize, U.dpi);
+
+ int textwidth = BLF_width(blf_mono_font, label, strlen(label)) + 10;
+ float opacity;
+ float stepx = BLI_rcti_size_x(&ar->v2d.mask) / BLI_rctf_size_x(&ar->v2d.cur);
+ if (textwidth < 0.5f*(stepx - 10)) opacity = 1.0f;
+ else if (textwidth < (stepx - 10)) opacity = 2.0f - 2.0f*(textwidth / (stepx - 10));
+ else opacity = 0.0f;
+ BLF_color4ub(blf_mono_font, 220, 220, 220, 150*opacity);
+ BLF_position(blf_mono_font, (int) (x + 10), (int) (y + 10), 0);
+ BLF_draw_ascii(blf_mono_font, label, strlen(label));
+
+ glDisable(GL_BLEND);
+ }
}
/* draw uv edit */
@@ -586,9 +605,13 @@ void draw_image_sample_line(SpaceImage *sima)
immUniformArray4fv("colors", (float *)(float[][4]){{1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, 2);
immUniform1f("dash_width", 2.0f);
+ float co[2][2];
+ add_v2_v2v2(co[0], hist->co[0], hist->draw_offset);
+ add_v2_v2v2(co[1], hist->co[1], hist->draw_offset);
+
immBegin(GPU_PRIM_LINES, 2);
- immVertex2fv(shdr_dashed_pos, hist->co[0]);
- immVertex2fv(shdr_dashed_pos, hist->co[1]);
+ immVertex2fv(shdr_dashed_pos, co[0]);
+ immVertex2fv(shdr_dashed_pos, co[1]);
immEnd();
immUnbindProgram();
@@ -633,6 +656,69 @@ static void draw_image_paint_helpers(const bContext *C, ARegion *ar, Scene *scen
}
}
+static void draw_udim_tile_grid(unsigned int pos_attr, unsigned int color_attr,
+ ARegion *ar, int x, int y,
+ float stepx, float stepy, const float color[3])
+{
+ float x1, y1;
+ UI_view2d_view_to_region_fl(&ar->v2d, x, y, &x1, &y1);
+ int gridpos[5][2] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
+ for(int i = 0; i < 4; i++) {
+ immAttrib3fv(color_attr, color);
+ immVertex2f(pos_attr, x1 + gridpos[i][0]*stepx, y1 + gridpos[i][1]*stepy);
+ immAttrib3fv(color_attr, color);
+ immVertex2f(pos_attr, x1 + gridpos[i+1][0]*stepx, y1 + gridpos[i+1][1]*stepy);
+ }
+}
+
+static void draw_image_tiles(ARegion *ar, SpaceImage *sima, Image *ima)
+{
+ int num_tiles;
+ if (ima) {
+ num_tiles = BLI_listbase_count(&ima->tiles);
+ }
+ else {
+ num_tiles = sima->tile_grid_shape[0] * sima->tile_grid_shape[1];
+ }
+
+ float stepx = BLI_rcti_size_x(&ar->v2d.mask) / BLI_rctf_size_x(&ar->v2d.cur);
+ float stepy = BLI_rcti_size_y(&ar->v2d.mask) / BLI_rctf_size_y(&ar->v2d.cur);
+
+ GPUVertFormat *format = immVertexFormat();
+ unsigned int pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ unsigned color = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ immBegin(GPU_PRIM_LINES, 8*(num_tiles + 1));
+
+ float theme_color[3], selected_color[3];
+ UI_GetThemeColorShade3fv(TH_BACK, 60.0f, theme_color);
+ UI_GetThemeColor3fv(TH_FACE_SELECT, selected_color);
+
+ if (ima) {
+ LISTBASE_FOREACH(ImageTile*, tile, &ima->tiles) {
+ int x = tile->tile_number % 10;
+ int y = tile->tile_number / 10;
+ draw_udim_tile_grid(pos, color, ar, x, y, stepx, stepy, theme_color);
+ }
+ }
+ else {
+ for (int y = 0; y < sima->tile_grid_shape[1]; y++) {
+ for (int x = 0; x < sima->tile_grid_shape[0]; x++) {
+ draw_udim_tile_grid(pos, color, ar, x, y, stepx, stepy, theme_color);
+ }
+ }
+ }
+
+ int cur_x = sima->curtile % 10, cur_y = sima->curtile / 10;
+ draw_udim_tile_grid(pos, color, ar, cur_x, cur_y, stepx, stepy, selected_color);
+
+ immEnd();
+ immUnbindProgram();
+
+ return;
+}
+
/* draw main image region */
void draw_image_main(const bContext *C, ARegion *ar)
@@ -692,14 +778,35 @@ void draw_image_main(const bContext *C, ARegion *ar)
BKE_image_multiview_index(ima, &sima->iuser);
}
- ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ ibuf = ED_space_image_acquire_buffer(sima, &lock, 0);
+
+ int main_w = 0;
+ int main_h = 0;
/* draw the image or grid */
if (ibuf == NULL) {
- ED_region_grid_draw(ar, zoomx, zoomy);
+ if (ima) {
+ LISTBASE_FOREACH(ImageTile*, tile, &ima->tiles) {
+ int x = tile->tile_number % 10;
+ int y = tile->tile_number / 10;
+ ED_region_grid_draw(ar, zoomx, zoomy, x, y);
+ }
+ }
+ else {
+ for (int y = 0; y < sima->tile_grid_shape[1]; y++) {
+ for (int x = 0; x < sima->tile_grid_shape[0]; x++) {
+ ED_region_grid_draw(ar, zoomx, zoomy, x, y);
+ }
+ }
+ }
}
else {
- draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy);
+ main_w = ibuf->x;
+ main_h = ibuf->y;
+
+ char label[64];
+ BKE_image_get_tile_label(ima, 0, label, sizeof(label));
+ draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy, label);
if (sima->flag & SI_DRAW_METADATA) {
int x, y;
@@ -714,6 +821,28 @@ void draw_image_main(const bContext *C, ARegion *ar)
ED_space_image_release_buffer(sima, ibuf, lock);
+ if (ima && ima->source == IMA_SRC_TILED) {
+ LISTBASE_FOREACH(ImageTile*, tile, &ima->tiles) {
+ if (tile->tile_number == 0)
+ continue;
+
+ ibuf = ED_space_image_acquire_buffer(sima, &lock, tile->tile_number);
+ if (ibuf) {
+ int x_pos = tile->tile_number % 10;
+ int y_pos = tile->tile_number / 10;
+ char label[64];
+ BKE_image_get_tile_label(ima, tile, label, sizeof(label));
+
+ float tile_zoomx = (zoomx * main_w) / ibuf->x;
+ float tile_zoomy = (zoomy * main_h) / ibuf->y;
+ draw_image_buffer(C, sima, ar, scene, ibuf, x_pos, y_pos, tile_zoomx, tile_zoomy, label);
+ }
+ ED_space_image_release_buffer(sima, ibuf, lock);
+ }
+ }
+
+ draw_image_tiles(ar, sima, ima);
+
/* paint helpers */
if (show_paint)
draw_image_paint_helpers(C, ar, scene, zoomx, zoomy);