Gradients are versatile enough, with so many independently optional * arguments, that it doesn't seem helpful to provide a non-table form with * non-obvious argument order. */ selection.gradient({ type = "radial", x = 3, y = 5, x2 = 10, y2 = 12, * mindist = 4, maxdist = 10, limited = false }); */
| 859 | /* selection.gradient({ type = "radial", x = 3, y = 5, x2 = 10, y2 = 12, |
| 860 | * mindist = 4, maxdist = 10, limited = false }); */ |
| 861 | staticfn int |
| 862 | l_selection_gradient(lua_State *L) |
| 863 | { |
| 864 | int argc = lua_gettop(L); |
| 865 | struct selectionvar *sel = (struct selectionvar *) 0; |
| 866 | /* if x2 and y2 aren't set, the gradient has a single center point of x,y; |
| 867 | * if they are set, the gradient is centered on a (x,y) to (x2,y2) line */ |
| 868 | coordxy x = 0, y = 0, x2 = -1, y2 = -1; |
| 869 | /* points are always added within mindist of the center; the chance for a |
| 870 | * point between mindist and maxdist to be added to the selection starts |
| 871 | * at 100% at mindist and decreases linearly to 0% at maxdist */ |
| 872 | coordxy mindist = 0, maxdist = 0; |
| 873 | long type = 0; |
| 874 | static const char *const gradtypes[] = { |
| 875 | "radial", "square", NULL |
| 876 | }; |
| 877 | static const int gradtypes2i[] = { |
| 878 | SEL_GRADIENT_RADIAL, SEL_GRADIENT_SQUARE, -1 |
| 879 | }; |
| 880 | |
| 881 | if (argc == 1 && lua_type(L, 1) == LUA_TTABLE) { |
| 882 | lcheck_param_table(L); |
| 883 | type = gradtypes2i[get_table_option(L, "type", "radial", gradtypes)]; |
| 884 | x = (coordxy) get_table_int(L, "x"); |
| 885 | y = (coordxy) get_table_int(L, "y"); |
| 886 | x2 = (coordxy) get_table_int_opt(L, "x2", -1); |
| 887 | y2 = (coordxy) get_table_int_opt(L, "y2", -1); |
| 888 | cvt_to_abscoord(&x, &y); |
| 889 | cvt_to_abscoord(&x2, &y2); |
| 890 | /* maxdist is required because there's no obvious default value for |
| 891 | * it, whereas mindist has an obvious default of 0 */ |
| 892 | maxdist = get_table_int(L, "maxdist"); |
| 893 | mindist = get_table_int_opt(L, "mindist", 0); |
| 894 | |
| 895 | lua_pop(L, 1); |
| 896 | (void) l_selection_new(L); |
| 897 | sel = l_selection_check(L, 1); |
| 898 | } else { |
| 899 | nhl_error(L, "selection.gradient requires table argument"); |
| 900 | /* NOTREACHED */ |
| 901 | } |
| 902 | |
| 903 | /* someone might conceivably want to draw a gradient somewhere off-map. So |
| 904 | * the only coordinate that's "illegal" for that is (-1,-1). |
| 905 | * If a level designer really needs to draw a gradient line using that |
| 906 | * coordinate, they can do so by setting regular x and y to -1. */ |
| 907 | if (x2 == -1 && y2 == -1) { |
| 908 | x2 = x; |
| 909 | y2 = y; |
| 910 | } |
| 911 | |
| 912 | selection_do_gradient(sel, x, y, x2, y2, type, mindist, maxdist); |
| 913 | lua_settop(L, 1); |
| 914 | return 1; |
| 915 | } |
| 916 | |
| 917 | DISABLE_WARNING_UNREACHABLE_CODE |
| 918 |
nothing calls this directly
no test coverage detected