Page MenuHome

create ed_draw.c
ClosedPublic

Authored by Christoph Lendenfeld (ChrisLend) on Oct 22 2020, 3:37 PM.

Details

Summary

Cleanup Phase 1

I had a quick chat with @Julian Eisel (Severin) about where I should add a new generic slider that wil be used in T81785.

The conclusion was that there should be a new file editors/util/ed_draw.c for that into which ED_region_draw_mouse_line_cb and ED_region_image_metadata_draw can be extracted as well.

This patch only creates the file and moves code around

Diff Detail

Repository
rB Blender

Event Timeline

Generally a nice change.
I'm a bit surprised that there's not code sharing between the metadata drawing and the version of it that "stamps" it into the image, BKE_image_stamp_buf(). Maybe add a comment making this relation clear by saying they should be kept in sync.

This revision is now accepted and ready to land.Oct 28 2020, 11:31 AM
Campbell Barton (campbellbarton) requested changes to this revision.Oct 28 2020, 11:33 AM

Generally seems fine, minor change requested.

Note, we could have the metadata drawing in ed_util_imbuf.c, since this function is closely related to imbuf data. - Other opinions?

source/blender/editors/util/ed_draw.c
60
This revision now requires changes to proceed.Oct 28 2020, 11:33 AM
  • added comment to ED_region_image_metadata_draw
  • change comment on top to doxy comment
Sybren A. Stüvel (sybren) requested changes to this revision.Oct 29 2020, 11:22 AM

\name Generic Callbacks for Drawcall API

There is no "Drawcall API" documented anywhere. I realise that this is just a restyling of the pre-existing comment, but still it makes me wonder what is meant by it. If something is named "API", I would expect an interface definition somewhere. In this case there isn't even an ed_draw.h file that exposes this interface. The ED_region_draw_mouse_line_cb() function is declared in source/blender/editors/include/ED_space_api.h; maybe that should move to a different file too?

Talking about ED_space_api.h, that now reads:

/* generic callbacks */
/* ed_util.c */
void ED_region_draw_mouse_line_cb(const struct bContext *C,
                                  struct ARegion *region,
                                  void *arg_info);

The "generic callbacks" comment is very weird, because it doesn't specify what actually accepts this callback function; it doesn't document what the function is for at all. It also doesn't explain why the ED_region_draw_cb_...() functions declared above it are not "generic" and this one is. This is all not strictly part of this patch, but still, now that you've looked at the code, understand what it does, and that it needs to be in a different place, you're the prime candidate to also clarify these functions' declarations.

What is part of this patch is that the comment stating it's implemented in ed_util.c is now incorrect. Personally I'd remove that comment, as you've proven that it's very easy to make it go out of date and it doesn't serve any practical purpose (any IDE worth its salt should make it easy to find the definition from the declaration, and otherwise a quick grep will find it for you).

I'm also not a fan of having one C file that has part of its interface declared in ED_space_api.h and another part in ED_screen.h.

source/blender/editors/util/ed_draw.c
60–62

The goal of this commit is to split off parts of code into its own file. I don't see the need to prepare that file for adding more things that differ in topic.

I think that, if it turns out that more similar code is needed, and that that code should go in this file, that's the moment when sections can be made in a sensible way, because only then you know the context & the different subjects & why they are supposed to go into the same file anyway.

386

Generally files end in a newline.

This revision now requires changes to proceed.Oct 29 2020, 11:22 AM

@Sybren A. Stüvel (sybren) I agree that having declarations in two headers is less than ideal.
But I am not sure how to proceed on this. Both ED_screen.h and ED_space_api.h have some drawing functions declared. But there is probably a good reason for them to be there.

Maybe some confusion arises from the naming. ed_draw.c is in the folder util so maybe it should be called ed_util_draw.c?

And maybe have a header file for utils ed_util.h?

I just realized ED_util.h already exists in editors/include.

We could move the declarations there, I am not sure if that should happen in this patch though.

The declarations should be moved to ED_util.h I think.

  • Moved declarations into ED_util.h

I added in include in all the files that threw an error after that

Unfortunately the patch no longer cleanly applies :/
@Christoph Lendenfeld (ChrisLend) could you take a look and do another rebase?

reapply changes to latest master

This revision was not accepted when it landed; it landed in state Needs Review.Mar 1 2021, 4:23 PM
This revision was automatically updated to reflect the committed changes.