Add GFX2_Log() function
This commit is contained in:
		
							parent
							
								
									221515e663
								
							
						
					
					
						commit
						7fb77f85f1
					
				@ -640,7 +640,8 @@ OBJS = main.o init.o graph.o $(APIOBJ) misc.o special.o \
 | 
			
		||||
       transform.o pversion.o factory.o $(PLATFORMOBJ) \
 | 
			
		||||
       fileformats.o miscfileformats.o libraw2crtc.o \
 | 
			
		||||
       brush_ops.o buttons_effects.o layers.o \
 | 
			
		||||
       oldies.o tiles.o colorred.o unicode.o gfx2surface.o
 | 
			
		||||
       oldies.o tiles.o colorred.o unicode.o gfx2surface.o \
 | 
			
		||||
       gfx2log.o
 | 
			
		||||
ifndef NORECOIL
 | 
			
		||||
OBJS += loadrecoil.o recoil.o
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
@ -79,6 +79,7 @@
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "gfx2log.h"
 | 
			
		||||
#include "errors.h"
 | 
			
		||||
#include "global.h"
 | 
			
		||||
#include "loadsave.h"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										67
									
								
								src/gfx2log.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								src/gfx2log.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,67 @@
 | 
			
		||||
/* vim:expandtab:ts=2 sw=2:
 | 
			
		||||
*/
 | 
			
		||||
/*  Grafx2 - The Ultimate 256-color bitmap paint program
 | 
			
		||||
 | 
			
		||||
    Copyright 2018 Thomas Bernard
 | 
			
		||||
    Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
 | 
			
		||||
 | 
			
		||||
    Grafx2 is free software; you can redistribute it and/or
 | 
			
		||||
    modify it under the terms of the GNU General Public License
 | 
			
		||||
    as published by the Free Software Foundation; version 2
 | 
			
		||||
    of the License.
 | 
			
		||||
 | 
			
		||||
    Grafx2 is distributed in the hope that it will be useful,
 | 
			
		||||
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
    GNU General Public License for more details.
 | 
			
		||||
 | 
			
		||||
    You should have received a copy of the GNU General Public License
 | 
			
		||||
    along with Grafx2; if not, see <http://www.gnu.org/licenses/>
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
#if defined(USE_SDL2)
 | 
			
		||||
#include <SDL.h>
 | 
			
		||||
#endif
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include "gfx2log.h"
 | 
			
		||||
 | 
			
		||||
GFX2_Log_priority_T GFX2_verbosity_level = GFX2_INFO;
 | 
			
		||||
 | 
			
		||||
extern void GFX2_Log(GFX2_Log_priority_T priority, const char * fmt, ...)
 | 
			
		||||
{
 | 
			
		||||
  va_list ap;
 | 
			
		||||
 | 
			
		||||
  va_start(ap, fmt);
 | 
			
		||||
  GFX2_LogV(priority, fmt, ap);
 | 
			
		||||
  va_end(ap);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern void GFX2_LogV(GFX2_Log_priority_T priority, const char * fmt, va_list ap)
 | 
			
		||||
{
 | 
			
		||||
  if ((unsigned)GFX2_verbosity_level < (unsigned)priority)
 | 
			
		||||
    return;
 | 
			
		||||
#if defined(USE_SDL2)
 | 
			
		||||
  {
 | 
			
		||||
    int sdl_priority;
 | 
			
		||||
    switch(priority)
 | 
			
		||||
    {
 | 
			
		||||
      case GFX2_ERROR:
 | 
			
		||||
        sdl_priority = SDL_LOG_PRIORITY_ERROR;
 | 
			
		||||
        break;
 | 
			
		||||
      case GFX2_WARNING:
 | 
			
		||||
        sdl_priority = SDL_LOG_PRIORITY_WARN;
 | 
			
		||||
        break;
 | 
			
		||||
      case GFX2_INFO:
 | 
			
		||||
        sdl_priority = SDL_LOG_PRIORITY_INFO;
 | 
			
		||||
        break;
 | 
			
		||||
      case GFX2_DEBUG:
 | 
			
		||||
        sdl_priority = SDL_LOG_PRIORITY_DEBUG;
 | 
			
		||||
        break;
 | 
			
		||||
      default:
 | 
			
		||||
        sdl_priority = SDL_LOG_PRIORITY_CRITICAL; // unknown
 | 
			
		||||
    }
 | 
			
		||||
    SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, sdl_priority, fmt, ap);
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
  vfprintf((unsigned)priority >= GFX2_INFO ? stdout : stderr, fmt, ap);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										39
									
								
								src/gfx2log.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/gfx2log.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,39 @@
 | 
			
		||||
/* vim:expandtab:ts=2 sw=2:
 | 
			
		||||
*/
 | 
			
		||||
/*  Grafx2 - The Ultimate 256-color bitmap paint program
 | 
			
		||||
 | 
			
		||||
    Copyright 2018 Thomas Bernard
 | 
			
		||||
    Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
 | 
			
		||||
 | 
			
		||||
    Grafx2 is free software; you can redistribute it and/or
 | 
			
		||||
    modify it under the terms of the GNU General Public License
 | 
			
		||||
    as published by the Free Software Foundation; version 2
 | 
			
		||||
    of the License.
 | 
			
		||||
 | 
			
		||||
    Grafx2 is distributed in the hope that it will be useful,
 | 
			
		||||
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
    GNU General Public License for more details.
 | 
			
		||||
 | 
			
		||||
    You should have received a copy of the GNU General Public License
 | 
			
		||||
    along with Grafx2; if not, see <http://www.gnu.org/licenses/>
 | 
			
		||||
*/
 | 
			
		||||
#ifndef GFX2LOG_H_DEFINED
 | 
			
		||||
#define GFX2LOG_H_DEFINED
 | 
			
		||||
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
  GFX2_ERROR = 0,
 | 
			
		||||
  GFX2_WARNING,
 | 
			
		||||
  GFX2_INFO,
 | 
			
		||||
  GFX2_DEBUG
 | 
			
		||||
} GFX2_Log_priority_T;
 | 
			
		||||
 | 
			
		||||
extern GFX2_Log_priority_T GFX2_verbosity_level;
 | 
			
		||||
 | 
			
		||||
extern void GFX2_Log(GFX2_Log_priority_T priority, const char * fmt, ...);
 | 
			
		||||
 | 
			
		||||
extern void GFX2_LogV(GFX2_Log_priority_T priority, const char * fmt, va_list ap);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										14
									
								
								src/input.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/input.c
									
									
									
									
									
								
							@ -40,6 +40,7 @@
 | 
			
		||||
#include <X11/Xutil.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "gfx2log.h"
 | 
			
		||||
#include "global.h"
 | 
			
		||||
#include "keyboard.h"
 | 
			
		||||
#include "screen.h"
 | 
			
		||||
@ -1264,7 +1265,6 @@ int Get_input(int sleep_time)
 | 
			
		||||
        case KeyPress:
 | 
			
		||||
          {
 | 
			
		||||
            KeySym sym;
 | 
			
		||||
            //printf("key code = %d state=0x%08x\n", event.xkey.keycode, event.xkey.state);
 | 
			
		||||
            // right/left window 40 Mod4Mask
 | 
			
		||||
            // left alt = 8         Mod1Mask
 | 
			
		||||
            // right alt = 80       Mod5Mask
 | 
			
		||||
@ -1279,7 +1279,8 @@ int Get_input(int sleep_time)
 | 
			
		||||
              mod |= MOD_META;
 | 
			
		||||
            //sym = XKeycodeToKeysym(X11_display, event.xkey.keycode, 0);
 | 
			
		||||
            sym = XkbKeycodeToKeysym(X11_display, event.xkey.keycode, 0, 0);
 | 
			
		||||
            //printf("sym = %04lx %s\t\tmod=%04x\n", sym, XKeysymToString(sym), mod);
 | 
			
		||||
            GFX2_Log(GFX2_DEBUG, "key code = %3d state=0x%08x sym = 0x%04lx %s\tmod=%04x\n",
 | 
			
		||||
                     event.xkey.keycode, event.xkey.state, sym, XKeysymToString(sym), mod);
 | 
			
		||||
            Key = mod | (sym & 0x0fff);
 | 
			
		||||
            //sym = XkbKeycodeToKeysym(X11_display, event.xkey.keycode, 0, event.xkey.state);
 | 
			
		||||
            if (((sym & 0xf000) != 0xf000) || IsKeypadKey(sym)) // test for standard key or KeyPad
 | 
			
		||||
@ -1364,7 +1365,7 @@ int Get_input(int sleep_time)
 | 
			
		||||
          user_feedback_required = Move_cursor_with_constraints();
 | 
			
		||||
          break;
 | 
			
		||||
        case Expose:
 | 
			
		||||
          printf("Expose (%d,%d) (%d,%d)\n", event.xexpose.x, event.xexpose.y, event.xexpose.width, event.xexpose.height);
 | 
			
		||||
          GFX2_Log(GFX2_DEBUG, "Expose (%d,%d) (%d,%d)\n", event.xexpose.x, event.xexpose.y, event.xexpose.width, event.xexpose.height);
 | 
			
		||||
          Update_rect(event.xexpose.x, event.xexpose.y,
 | 
			
		||||
                      event.xexpose.width, event.xexpose.height);
 | 
			
		||||
          break;
 | 
			
		||||
@ -1387,7 +1388,7 @@ int Get_input(int sleep_time)
 | 
			
		||||
        case ClientMessage:
 | 
			
		||||
          if (event.xclient.message_type == XInternAtom(X11_display,"WM_PROTOCOLS", False))
 | 
			
		||||
          {
 | 
			
		||||
            if (event.xclient.data.l[0] == XInternAtom(X11_display, "WM_DELETE_WINDOW", False))
 | 
			
		||||
            if ((Atom)event.xclient.data.l[0] == XInternAtom(X11_display, "WM_DELETE_WINDOW", False))
 | 
			
		||||
            {
 | 
			
		||||
              Quit_is_required = 1;
 | 
			
		||||
              user_feedback_required = 1;
 | 
			
		||||
@ -1402,10 +1403,11 @@ int Get_input(int sleep_time)
 | 
			
		||||
            //int list = event.xclient.data.l[1] & 1;
 | 
			
		||||
            xdnd_version = event.xclient.data.l[1] >> 24;
 | 
			
		||||
            xdnd_source = event.xclient.data.l[0];
 | 
			
		||||
            GFX2_Log(GFX2_DEBUG, "XdndEnter version=%d source=%lu\n", xdnd_version, xdnd_source);
 | 
			
		||||
          }
 | 
			
		||||
          else if (event.xclient.message_type == XInternAtom(X11_display, "XdndLeave", False))
 | 
			
		||||
          {
 | 
			
		||||
            //printf("XdndLeave\n");
 | 
			
		||||
            GFX2_Log(GFX2_DEBUG, "XdndLeave\n");
 | 
			
		||||
          }
 | 
			
		||||
          else if (event.xclient.message_type == XInternAtom(X11_display, "XdndPosition", False))
 | 
			
		||||
          {
 | 
			
		||||
@ -1534,7 +1536,7 @@ int Get_input(int sleep_time)
 | 
			
		||||
          }
 | 
			
		||||
          break;
 | 
			
		||||
        default:
 | 
			
		||||
          printf("event.type = %d\n", event.type);
 | 
			
		||||
          GFX2_Log(GFX2_INFO, "X11 event.type = %d not handled\n", event.type);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    // If the cursor was moved since last update,
 | 
			
		||||
 | 
			
		||||
@ -47,6 +47,7 @@
 | 
			
		||||
#include <SDL_endian.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "gfx2log.h"
 | 
			
		||||
#include "buttons.h"
 | 
			
		||||
#include "const.h"
 | 
			
		||||
#include "errors.h"
 | 
			
		||||
@ -624,7 +625,7 @@ void Load_image(T_IO_Context *context)
 | 
			
		||||
 | 
			
		||||
  if (File_error>0)
 | 
			
		||||
  {
 | 
			
		||||
    fprintf(stderr,"Unable to load file %s (error %d)!\n",context->File_name, File_error);
 | 
			
		||||
    GFX2_Log(GFX2_WARNING, "Unable to load file %s (error %d)! format:%s\n", context->File_name, File_error, format->Label);
 | 
			
		||||
    if (context->Type!=CONTEXT_SURFACE)
 | 
			
		||||
      Error(0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -69,6 +69,7 @@
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "gfx2log.h"
 | 
			
		||||
#include "const.h"
 | 
			
		||||
#include "struct.h"
 | 
			
		||||
#include "global.h"
 | 
			
		||||
@ -124,6 +125,7 @@ void Display_syntax(void)
 | 
			
		||||
    "Syntax: grafx2 [<arguments>] [<picture1>] [<picture2>]\n\n"
 | 
			
		||||
    "<arguments> can be:\n"
 | 
			
		||||
    "\t-? -h -H -help     for this help screen\n"
 | 
			
		||||
    "\t-verbose           to increase log verbosity\n"
 | 
			
		||||
    "\t-wide              to emulate a video mode with wide pixels (2x1)\n"
 | 
			
		||||
    "\t-tall              to emulate a video mode with tall pixels (1x2)\n"
 | 
			
		||||
    "\t-double            to emulate a video mode with double pixels (2x2)\n"
 | 
			
		||||
@ -278,7 +280,8 @@ enum CMD_PARAMS
 | 
			
		||||
    CMDPARAM_RGB,
 | 
			
		||||
    CMDPARAM_GAMMA,
 | 
			
		||||
    CMDPARAM_SKIN,
 | 
			
		||||
    CMDPARAM_SIZE
 | 
			
		||||
    CMDPARAM_SIZE,
 | 
			
		||||
    CMDPARAM_VERBOSE,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct {
 | 
			
		||||
@ -302,6 +305,7 @@ struct {
 | 
			
		||||
    {"gamma", CMDPARAM_GAMMA},
 | 
			
		||||
    {"skin", CMDPARAM_SKIN},
 | 
			
		||||
    {"size", CMDPARAM_SIZE},
 | 
			
		||||
    {"verbose", CMDPARAM_VERBOSE},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define ARRAY_SIZE(x) (int)(sizeof(x) / sizeof(x[0]))
 | 
			
		||||
@ -493,6 +497,9 @@ int Analyze_command_line(int argc, char * argv[], char *main_filename, char *mai
 | 
			
		||||
          exit(0);
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
      case CMDPARAM_VERBOSE:
 | 
			
		||||
        GFX2_verbosity_level++;
 | 
			
		||||
        break;
 | 
			
		||||
      default:
 | 
			
		||||
        // Si ce n'est pas un paramètre, c'est le nom du fichier à ouvrir
 | 
			
		||||
        if (file_in_command_line > 1)
 | 
			
		||||
 | 
			
		||||
@ -29,6 +29,7 @@
 | 
			
		||||
#include "screen.h"
 | 
			
		||||
#include "gfx2surface.h"
 | 
			
		||||
#include "loadsave.h"
 | 
			
		||||
#include "gfx2log.h"
 | 
			
		||||
 | 
			
		||||
Display * X11_display = NULL;
 | 
			
		||||
Window X11_window = 0;
 | 
			
		||||
@ -52,7 +53,7 @@ void GFX2_Set_mode(int *width, int *height, int fullscreen)
 | 
			
		||||
    X11_display = XOpenDisplay(NULL);// NULL is equivalent to getenv("DISPLAY")
 | 
			
		||||
  if (X11_display == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    fprintf(stderr, "X11: cannot open display\n");
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "X11: cannot open display\n");
 | 
			
		||||
    exit(1);
 | 
			
		||||
  }
 | 
			
		||||
  s = DefaultScreen(X11_display);
 | 
			
		||||
@ -64,12 +65,12 @@ void GFX2_Set_mode(int *width, int *height, int fullscreen)
 | 
			
		||||
    int i;
 | 
			
		||||
    int count = 0;
 | 
			
		||||
    int * depths = XListDepths(X11_display, s, &count);
 | 
			
		||||
    printf("DefaultDepth = %d, DisplayPlanes = %d\n", DefaultDepth(X11_display, s), DisplayPlanes(X11_display, s));
 | 
			
		||||
    GFX2_Log(GFX2_DEBUG, "DefaultDepth = %d, DisplayPlanes = %d\n", DefaultDepth(X11_display, s), DisplayPlanes(X11_display, s));
 | 
			
		||||
    if (depths != NULL)
 | 
			
		||||
    {
 | 
			
		||||
      for (i = 0; i < count; i++)
 | 
			
		||||
        printf(" %d", depths[i]);
 | 
			
		||||
      printf("\n");
 | 
			
		||||
        GFX2_Log(GFX2_DEBUG, " %d", depths[i]);
 | 
			
		||||
      GFX2_Log(GFX2_DEBUG, "\n");
 | 
			
		||||
      XFree(depths);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@ -184,7 +185,7 @@ void GFX2_Set_mode(int *width, int *height, int fullscreen)
 | 
			
		||||
                             32, 0/**width * 4*/);
 | 
			
		||||
    if(X11_image == NULL)
 | 
			
		||||
    {
 | 
			
		||||
      fprintf(stderr, "XCreateImage failed\n");
 | 
			
		||||
      GFX2_Log(GFX2_ERROR, "XCreateImage failed\n");
 | 
			
		||||
      exit(1);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user