Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draw_setup #68

Open
gnysek opened this issue Aug 19, 2024 · 1 comment
Open

draw_setup #68

gnysek opened this issue Aug 19, 2024 · 1 comment
Labels
feature ✨ For feature requests and implementations

Comments

@gnysek
Copy link

gnysek commented Aug 19, 2024

A simple function to set most often used draw functions in one call.
Thanks to omitting arguments possibility in GM and possibility to use built-in functions as argument default value, this allows to skip arguments in middle by using comma, or put closing bracket after last one we need.
By default, it keeps current setting for each of those options.

Order of arguments was set by how often I'm using each of those functions based on my 21 years experience with GameMaker.
My most common cases are:

  • changing color+alpha (drawing transparent shapes as backgrounds for text; changing color and resetting alpha to 1 after such drawing)
  • changing color+font (and sometimes (re)setting alpha, depending what was drawn before; also useful for "inactive" text)
  • changing color+font+alignment
/// @param {Constant.Color} color
/// @param {Real} alpha
/// @param {Asset.GMFont} font
/// @param {Constant.HAlign} halign
/// @param {Constant.VAlign} valign
function draw_setup(color = draw_get_color(), alpha = draw_get_alpha(), font = draw_get_font(), halign = draw_get_halign(), valign = draw_get_valign()) {
    gml_pragma("forceinline");
    draw_set_color(color);
    draw_set_alpha(alpha);
    draw_set_font(font);
    draw_set_halign(halign);
    draw_set_valign(valign);
}

Examples (including examples in which arguments are omitted):

draw_setup(c_blue, 0.5);
draw_setup(c_green,1,fnt_main,fa_center,fa_middle);
draw_setup(c_green,,fnt_main,,fa_middle);
draw_setup(c_green,,,fa_center,fa_middle);

In case when only one param requires change, it's still better to use default GM functions.

This script comes from my personal toolbox, but I decided to share it and discuss if it would be useful after seeing draw_set_color_ext (#42) and draw_set_text_align (#43).

@Alphish
Copy link
Owner

Alphish commented Nov 17, 2024

Hmmm... I'd prefer the other two functions (draw_set_color_ext and draw_set_text_align) over this one.
A large part of that is that draw_setup doesn't really tell you what it does, and also the things it does aren't as tightly related as just color+alpha or text halign+valign on their own.

It's perfectly fine as a personal script, but as a library function I feel its naming is vague and it tries to do too many things at once. If I were to use this regularly, I would likely eventually lean towards for some full-fledged styling system or similar. ^^'

@Alphish Alphish added the feature ✨ For feature requests and implementations label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ✨ For feature requests and implementations
Projects
None yet
Development

No branches or pull requests

2 participants