[Bf-blender-cvs] [89c0dc4ebdb] temp-udim-images: Implement basic UDIM grid drawing
Lukas Stockner
noreply at git.blender.org
Sun Jun 10 23:15:01 CEST 2018
Commit: 89c0dc4ebdb8e07865c780664159cc0fb12e0653
Author: Lukas Stockner
Date: Sun Jun 10 23:14:07 2018 +0200
Branches: temp-udim-images
https://developer.blender.org/rB89c0dc4ebdb8e07865c780664159cc0fb12e0653
Implement basic UDIM grid drawing
===================================================================
M source/blender/blenfont/BLF_api.h
M source/blender/blenfont/intern/blf.c
M source/blender/editors/include/ED_screen.h
M source/blender/editors/screen/area.c
M source/blender/editors/space_clip/clip_draw.c
M source/blender/editors/space_image/image_draw.c
===================================================================
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h
index 90c0016d0ed..f7a88ee4a11 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -74,6 +74,7 @@ void BLF_size(int fontid, int size, int dpi);
void BLF_color4ubv(int fontid, const unsigned char rgba[4]);
void BLF_color3ubv(int fontid, const unsigned char rgb[3]);
void BLF_color3ubv_alpha(int fontid, const unsigned char rgb[3], unsigned char alpha);
+void BLF_color4ub(int fontid, unsigned char r, unsigned char g, unsigned char b, unsigned char alpha);
void BLF_color3ub(int fontid, unsigned char r, unsigned char g, unsigned char b);
void BLF_color4f(int fontid, float r, float g, float b, float a);
void BLF_color4fv(int fontid, const float rgba[4]);
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 5dd692d3855..1b397ee70eb 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -513,6 +513,18 @@ void BLF_color3ub(int fontid, unsigned char r, unsigned char g, unsigned char b)
}
}
+void BLF_color4ub(int fontid, unsigned char r, unsigned char g, unsigned char b, unsigned char alpha)
+{
+ FontBLF *font = blf_get(fontid);
+
+ if (font) {
+ font->color[0] = r;
+ font->color[1] = g;
+ font->color[2] = b;
+ font->color[3] = alpha;
+ }
+}
+
void BLF_color4fv(int fontid, const float rgba[4])
{
FontBLF *font = blf_get(fontid);
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index cd1fb1f91d8..397feb07f03 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -91,7 +91,7 @@ void ED_region_visibility_change_update(struct bContext *C, struct ARegion *a
void ED_region_info_draw(struct ARegion *ar, const char *text, float fill_color[4], const bool full_redraw);
void ED_region_info_draw_multiline(ARegion *ar, const char *text_array[], float fill_color[4], const bool full_redraw);
void ED_region_image_metadata_draw(int x, int y, struct ImBuf *ibuf, const rctf *frame, float zoomx, float zoomy);
-void ED_region_grid_draw(struct ARegion *ar, float zoomx, float zoomy);
+void ED_region_grid_draw(struct ARegion *ar, float zoomx, float zoomy, float x0, float y0);
float ED_region_blend_alpha(struct ARegion *ar);
void ED_region_visible_rect(struct ARegion *ar, struct rcti *rect);
bool ED_region_is_overlap(int spacetype, int regiontype);
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index b4d932d3272..c0b9db1c369 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -2561,15 +2561,15 @@ void ED_region_image_metadata_draw(int x, int y, ImBuf *ibuf, const rctf *frame,
gpuPopMatrix();
}
-void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy)
+void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy, float x0, float y0)
{
float gridsize, gridstep = 1.0f / 32.0f;
float fac, blendfac;
int x1, y1, x2, y2;
- /* the image is located inside (0, 0), (1, 1) as set by view2d */
- UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x1, &y1);
- UI_view2d_view_to_region(&ar->v2d, 1.0f, 1.0f, &x2, &y2);
+ /* the image is located inside (x0, y0), (x0+1, y0+1) as set by view2d */
+ UI_view2d_view_to_region(&ar->v2d, x0, y0, &x1, &y1);
+ UI_view2d_view_to_region(&ar->v2d, x0+1.0f, y0+1.0f, &x2, &y2);
Gwn_VertFormat *format = immVertexFormat();
unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c
index 5962bfe33f3..77d71b83a97 100644
--- a/source/blender/editors/space_clip/clip_draw.c
+++ b/source/blender/editors/space_clip/clip_draw.c
@@ -1789,7 +1789,7 @@ void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *ar)
/* if no clip, nothing to do */
if (!clip) {
- ED_region_grid_draw(ar, zoomx, zoomy);
+ ED_region_grid_draw(ar, zoomx, zoomy, 0.0f, 0.0f);
return;
}
@@ -1835,7 +1835,7 @@ void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *ar)
draw_movieclip_muted(ar, width, height, zoomx, zoomy);
}
else {
- ED_region_grid_draw(ar, zoomx, zoomy);
+ ED_region_grid_draw(ar, zoomx, zoomy, 0.0f, 0.0f);
}
if (width && height) {
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c
index c5b9e236030..bd008e4b392 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -632,6 +632,81 @@ static void draw_image_paint_helpers(const bContext *C, ARegion *ar, Scene *scen
}
}
+static bool draw_image_udim_grid(ARegion *ar, SpaceImage *sima, float zoomx, float zoomy, bool draw_tilegrids)
+{
+ Image *ima = ED_space_image(sima);
+
+ int num_col = max_ii(ima->num_tiles, 10);
+ int num_row = 1 + (ima->num_tiles / 10);
+
+ const int xmin = MAX2(floor(ar->v2d.cur.xmin), 0);
+ const int ymin = MAX2(floor(ar->v2d.cur.ymin), 0);
+ const int xmax = MIN2(ceil(ar->v2d.cur.xmax), num_col);
+ const int ymax = MIN2(ceil(ar->v2d.cur.ymax), num_row);
+
+ 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);
+
+ float x1, y1;
+ UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x1, &y1);
+
+ if (draw_tilegrids) {
+ for (int y = ymin; y < ymax; y++) {
+ for (int x = xmin; x < xmax; x++) {
+ ED_region_grid_draw(ar, zoomx, zoomy, x, y);
+ }
+ }
+ }
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ immBegin(GWN_PRIM_LINES, 4 * (xmax - xmin + 1) + 4 * (ymax - ymin + 1));
+ float theme_color[3];
+ UI_GetThemeColorShade3fv(TH_BACK, 20.0f, theme_color);
+
+ for (int x = xmin; x <= xmax; x++) {
+ immAttrib3fv(color, theme_color);
+ immVertex2f(pos, x1 + x*stepx, y1 + ymin*stepy);
+ immAttrib3fv(color, theme_color);
+ immVertex2f(pos, x1 + x*stepx, y1 + ymax*stepy);
+ }
+ for (int y = ymin; y <= ymax; y++) {
+ immAttrib3fv(color, theme_color);
+ immVertex2f(pos, x1 + xmin*stepx, y1 + y*stepy);
+ immAttrib3fv(color, theme_color);
+ immVertex2f(pos, x1 + xmax*stepx, y1 + y*stepy);
+ }
+
+ immEnd();
+ immUnbindProgram();
+
+ 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);
+
+ char id[256];
+ for (int y = ymin; y < ymax; y++) {
+ for (int x = xmin; x < xmax; x++) {
+ BLI_snprintf(id, sizeof(id), "%d", 1001 + y*10 + x);
+ int textwidth = BLF_width(blf_mono_font, id, sizeof(id)) + 10;
+ float opacity;
+ 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) (x1 + x*stepx + 10), (int) (y1 + y*stepy + 10), 0);
+ BLF_draw_ascii(blf_mono_font, id, sizeof(id));
+ }
+ }
+
+ glDisable(GL_BLEND);
+
+ return true;
+}
+
/* draw main image region */
void draw_image_main(const bContext *C, ARegion *ar)
@@ -695,7 +770,12 @@ void draw_image_main(const bContext *C, ARegion *ar)
/* draw the image or grid */
if (ibuf == NULL) {
- ED_region_grid_draw(ar, zoomx, zoomy);
+ if (ima && ima->source == IMA_SRC_UDIM) {
+ draw_image_udim_grid(ar, sima, zoomx, zoomy, true);
+ }
+ else {
+ ED_region_grid_draw(ar, zoomx, zoomy, 0.0f, 0.0f);
+ }
}
else {
draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy);
@@ -726,6 +806,7 @@ void draw_image_main(const bContext *C, ARegion *ar)
ED_space_image_release_buffer(sima, ibuf, lock);
}
sima->iuser.tile = 0;
+ draw_image_udim_grid(ar, sima, zoomx, zoomy, false);
}
/* paint helpers */
More information about the Bf-blender-cvs
mailing list