Sort magic tools by ..._get_order() value, when possible
Tools in n_pt_persp plugin provide orders. (More coming!)
This commit is contained in:
parent
f7972d04a7
commit
ff9eff4e60
3 changed files with 31 additions and 5 deletions
|
|
@ -17,9 +17,10 @@ https://tuxpaint.org/
|
||||||
or "novice".
|
or "novice".
|
||||||
- Plugins' "init()" functions are sent a new `complexity_level`
|
- Plugins' "init()" functions are sent a new `complexity_level`
|
||||||
argument.
|
argument.
|
||||||
+ WIP Magic tools can provide a value that allows them to be
|
+ Magic tools can provide a value that allows them to be
|
||||||
sorted and grouped together (rather than always relying on the
|
sorted and grouped together (rather than always relying on the
|
||||||
localized name of the tool).
|
localized name of the tool).
|
||||||
|
- WIP Updated many magic tools to take advantage of this.
|
||||||
+ Note: `TP_MAGIC_API_VERSION` bumped to 0x00000009.
|
+ Note: `TP_MAGIC_API_VERSION` bumped to 0x00000009.
|
||||||
Bill Kendrick <bill@newbreedsoftware.com>
|
Bill Kendrick <bill@newbreedsoftware.com>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
by Bill Kendrick <bill@newbreedsoftware.com>
|
by Bill Kendrick <bill@newbreedsoftware.com>
|
||||||
|
|
||||||
December 12, 2023 - January 14, 2024
|
December 12, 2023 - January 16, 2024
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -70,6 +70,7 @@ enum
|
||||||
NUM_TOOLS
|
NUM_TOOLS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
char * tool_debug_names[NUM_TOOLS] = {
|
char * tool_debug_names[NUM_TOOLS] = {
|
||||||
/* 1-point perspective */
|
/* 1-point perspective */
|
||||||
|
|
@ -306,6 +307,7 @@ int n_pt_persp_get_tool_count(magic_api * api);
|
||||||
SDL_Surface *n_pt_persp_get_icon(magic_api * api, int which);
|
SDL_Surface *n_pt_persp_get_icon(magic_api * api, int which);
|
||||||
char *n_pt_persp_get_name(magic_api * api, int which);
|
char *n_pt_persp_get_name(magic_api * api, int which);
|
||||||
int n_pt_persp_get_group(magic_api * api, int which);
|
int n_pt_persp_get_group(magic_api * api, int which);
|
||||||
|
int n_pt_persp_get_order(int which);
|
||||||
char *n_pt_persp_get_description(magic_api * api, int which, int mode);
|
char *n_pt_persp_get_description(magic_api * api, int which, int mode);
|
||||||
int n_pt_persp_requires_colors(magic_api * api, int which);
|
int n_pt_persp_requires_colors(magic_api * api, int which);
|
||||||
int n_pt_persp_modes(magic_api * api, int which);
|
int n_pt_persp_modes(magic_api * api, int which);
|
||||||
|
|
@ -501,6 +503,11 @@ int n_pt_persp_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
|
||||||
return (MAGIC_TYPE_PROJECTIONS);
|
return (MAGIC_TYPE_PROJECTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int n_pt_persp_get_order(int which) {
|
||||||
|
/* Use the order they appear in the TOOL... enum */
|
||||||
|
return which;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
char *n_pt_persp_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
char *n_pt_persp_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
(See COPYING.txt)
|
(See COPYING.txt)
|
||||||
|
|
||||||
June 14, 2002 - January 13, 2024
|
June 14, 2002 - January 16, 2024
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
@ -1552,6 +1552,7 @@ typedef struct magic_funcs_s
|
||||||
{
|
{
|
||||||
int (*get_tool_count)(magic_api *);
|
int (*get_tool_count)(magic_api *);
|
||||||
int (*get_group)(magic_api *, int);
|
int (*get_group)(magic_api *, int);
|
||||||
|
int (*get_order)(int);
|
||||||
char *(*get_name)(magic_api *, int);
|
char *(*get_name)(magic_api *, int);
|
||||||
SDL_Surface *(*get_icon)(magic_api *, int);
|
SDL_Surface *(*get_icon)(magic_api *, int);
|
||||||
char *(*get_description)(magic_api *, int, int);
|
char *(*get_description)(magic_api *, int, int);
|
||||||
|
|
@ -1574,7 +1575,7 @@ typedef struct magic_funcs_s
|
||||||
|
|
||||||
typedef struct magic_s
|
typedef struct magic_s
|
||||||
{
|
{
|
||||||
int place;
|
int place; /* System-wide or local to the user? */
|
||||||
int handle_idx; /* Index to magic funcs for each magic tool (shared objs may report more than 1 tool) */
|
int handle_idx; /* Index to magic funcs for each magic tool (shared objs may report more than 1 tool) */
|
||||||
int idx; /* Index to magic tools within shared objects (shared objs may report more than 1 tool) */
|
int idx; /* Index to magic tools within shared objects (shared objs may report more than 1 tool) */
|
||||||
int mode; /* Current mode (paint or fullscreen) */
|
int mode; /* Current mode (paint or fullscreen) */
|
||||||
|
|
@ -1584,6 +1585,7 @@ typedef struct magic_s
|
||||||
int default_size[MAX_MODES]; /* Magic tool's default size setting */
|
int default_size[MAX_MODES]; /* Magic tool's default size setting */
|
||||||
int size[MAX_MODES]; /* Magic tool's size setting */
|
int size[MAX_MODES]; /* Magic tool's size setting */
|
||||||
int group; /* Which group of magic tools this lives in */
|
int group; /* Which group of magic tools this lives in */
|
||||||
|
int order; /* Order within the group of magic tools (for sorting; falls back to name) */
|
||||||
char *name; /* Name of magic tool */
|
char *name; /* Name of magic tool */
|
||||||
char *tip[MAX_MODES]; /* Description of magic tool, in each possible mode */
|
char *tip[MAX_MODES]; /* Description of magic tool, in each possible mode */
|
||||||
SDL_Surface *img_icon;
|
SDL_Surface *img_icon;
|
||||||
|
|
@ -21485,6 +21487,9 @@ static void load_magic_plugins(void)
|
||||||
safe_snprintf(funcname, sizeof(funcname), "%s_%s", objname, "get_group");
|
safe_snprintf(funcname, sizeof(funcname), "%s_%s", objname, "get_group");
|
||||||
magic_funcs[num_plugin_files].get_group = SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
|
magic_funcs[num_plugin_files].get_group = SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
|
||||||
|
|
||||||
|
safe_snprintf(funcname, sizeof(funcname), "%s_%s", objname, "get_order");
|
||||||
|
magic_funcs[num_plugin_files].get_order = SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
|
||||||
|
|
||||||
safe_snprintf(funcname, sizeof(funcname), "%s_%s", objname, "get_name");
|
safe_snprintf(funcname, sizeof(funcname), "%s_%s", objname, "get_name");
|
||||||
magic_funcs[num_plugin_files].get_name = SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
|
magic_funcs[num_plugin_files].get_name = SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
|
||||||
|
|
||||||
|
|
@ -21541,6 +21546,7 @@ static void load_magic_plugins(void)
|
||||||
//EP added (intptr_t) to avoid warning on x64 on all lines below
|
//EP added (intptr_t) to avoid warning on x64 on all lines below
|
||||||
DEBUG_PRINTF("get_tool_count = 0x%x\n", (int)(intptr_t) magic_funcs[num_plugin_files].get_tool_count);
|
DEBUG_PRINTF("get_tool_count = 0x%x\n", (int)(intptr_t) magic_funcs[num_plugin_files].get_tool_count);
|
||||||
DEBUG_PRINTF("get_group = 0x%x\n", (int)(intptr_t) magic_funcs[num_plugin_files].get_group);
|
DEBUG_PRINTF("get_group = 0x%x\n", (int)(intptr_t) magic_funcs[num_plugin_files].get_group);
|
||||||
|
DEBUG_PRINTF("get_order = 0x%x\n", (int)(intptr_t) magic_funcs[num_plugin_files].get_order);
|
||||||
DEBUG_PRINTF("get_name = 0x%x\n", (int)(intptr_t) magic_funcs[num_plugin_files].get_name);
|
DEBUG_PRINTF("get_name = 0x%x\n", (int)(intptr_t) magic_funcs[num_plugin_files].get_name);
|
||||||
DEBUG_PRINTF("get_icon = 0x%x\n", (int)(intptr_t) magic_funcs[num_plugin_files].get_icon);
|
DEBUG_PRINTF("get_icon = 0x%x\n", (int)(intptr_t) magic_funcs[num_plugin_files].get_icon);
|
||||||
DEBUG_PRINTF("get_description = 0x%x\n", (int)(intptr_t) magic_funcs[num_plugin_files].get_description);
|
DEBUG_PRINTF("get_description = 0x%x\n", (int)(intptr_t) magic_funcs[num_plugin_files].get_description);
|
||||||
|
|
@ -21571,6 +21577,11 @@ static void load_magic_plugins(void)
|
||||||
fprintf(stderr, "Error: plugin %s is missing get_group\n", fname);
|
fprintf(stderr, "Error: plugin %s is missing get_group\n", fname);
|
||||||
err = 1;
|
err = 1;
|
||||||
}
|
}
|
||||||
|
if (magic_funcs[num_plugin_files].get_order == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error: plugin %s is missing get_order\n", fname);
|
||||||
|
err = 1;
|
||||||
|
}
|
||||||
if (magic_funcs[num_plugin_files].get_name == NULL)
|
if (magic_funcs[num_plugin_files].get_name == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error: plugin %s is missing get_name\n", fname);
|
fprintf(stderr, "Error: plugin %s is missing get_name\n", fname);
|
||||||
|
|
@ -21705,6 +21716,7 @@ static void load_magic_plugins(void)
|
||||||
magics[group][idx].handle_idx = num_plugin_files;
|
magics[group][idx].handle_idx = num_plugin_files;
|
||||||
magics[group][idx].group = group;
|
magics[group][idx].group = group;
|
||||||
magics[group][idx].name = magic_funcs[num_plugin_files].get_name(magic_api_struct, i);
|
magics[group][idx].name = magic_funcs[num_plugin_files].get_name(magic_api_struct, i);
|
||||||
|
magics[group][idx].order = magic_funcs[num_plugin_files].get_order(i);
|
||||||
|
|
||||||
magics[group][idx].avail_modes = magic_funcs[num_plugin_files].modes(magic_api_struct, i);
|
magics[group][idx].avail_modes = magic_funcs[num_plugin_files].modes(magic_api_struct, i);
|
||||||
|
|
||||||
|
|
@ -21858,7 +21870,13 @@ static int magic_sort(const void *a, const void *b)
|
||||||
magic_t *am = (magic_t *) a;
|
magic_t *am = (magic_t *) a;
|
||||||
magic_t *bm = (magic_t *) b;
|
magic_t *bm = (magic_t *) b;
|
||||||
|
|
||||||
return (strcoll(gettext(am->name), gettext(bm->name)));
|
if (am->order != bm->order) {
|
||||||
|
/* Different 'order's, use them */
|
||||||
|
return (am->order - bm->order);
|
||||||
|
} else {
|
||||||
|
/* Same 'order', use the (localized) name */
|
||||||
|
return (strcoll(gettext(am->name), gettext(bm->name)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue