Paste in Text tool: fix a graphic overflow.
Palette reduce: use DawnBringer's formula for color likeness git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1837 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
		
							parent
							
								
									db3293060f
								
							
						
					
					
						commit
						775ee56ed0
					
				
							
								
								
									
										13
									
								
								src/input.h
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/input.h
									
									
									
									
									
								
							@ -64,3 +64,16 @@ extern int Snap_axis_origin_Y;
 | 
			
		||||
/// This malloced string is set when a drag-and-drop event
 | 
			
		||||
/// brings a file to Grafx2's window.
 | 
			
		||||
extern char * Drop_file_name;
 | 
			
		||||
 | 
			
		||||
#if defined __HAIKU__
 | 
			
		||||
	#define SHORTCUT_COPY (SDLK_c|MOD_ALT)
 | 
			
		||||
#else
 | 
			
		||||
	#define SHORTCUT_COPY (SDLK_c|MOD_CTRL)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if defined __HAIKU__
 | 
			
		||||
	#define SHORTCUT_PASTE (SDLK_v|MOD_ALT)
 | 
			
		||||
#else
 | 
			
		||||
	#define SHORTCUT_PASTE (SDLK_v|MOD_CTRL)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -559,8 +559,8 @@ void Reduce_palette(short * used_colors,int nb_colors_asked,T_Palette palette,dw
 | 
			
		||||
  int   color_2;                // |  de la palette
 | 
			
		||||
  int   best_color_1=0;
 | 
			
		||||
  int   best_color_2=0;
 | 
			
		||||
  int   difference;
 | 
			
		||||
  int   best_difference;
 | 
			
		||||
  long   difference;
 | 
			
		||||
  long   best_difference;
 | 
			
		||||
  dword used;
 | 
			
		||||
  dword best_used;
 | 
			
		||||
 | 
			
		||||
@ -621,16 +621,19 @@ void Reduce_palette(short * used_colors,int nb_colors_asked,T_Palette palette,dw
 | 
			
		||||
    // une seule couleur qui est la moyenne pondérée de ces 2 couleurs
 | 
			
		||||
    // en fonction de leur utilisation dans l'image.
 | 
			
		||||
 | 
			
		||||
    best_difference =0x7FFF;
 | 
			
		||||
    best_difference =26*255*26*255+55*255*255+19*255*19*255;
 | 
			
		||||
    best_used=0x7FFFFFFF;
 | 
			
		||||
 | 
			
		||||
    for (color_1=0;color_1<(*used_colors);color_1++)
 | 
			
		||||
      for (color_2=color_1+1;color_2<(*used_colors);color_2++)
 | 
			
		||||
        if (color_1!=color_2)
 | 
			
		||||
        {
 | 
			
		||||
          difference =abs((short)palette[color_1].R-palette[color_2].R)+
 | 
			
		||||
                      abs((short)palette[color_1].G-palette[color_2].G)+
 | 
			
		||||
                      abs((short)palette[color_1].B-palette[color_2].B);
 | 
			
		||||
          difference =26*abs((long)palette[color_1].R-palette[color_2].R)*
 | 
			
		||||
                      26*abs((long)palette[color_1].R-palette[color_2].R)+
 | 
			
		||||
                      55*abs((long)palette[color_1].G-palette[color_2].G)*
 | 
			
		||||
                      55*abs((long)palette[color_1].G-palette[color_2].G)+
 | 
			
		||||
                      19*abs((long)palette[color_1].B-palette[color_2].B)*
 | 
			
		||||
                      19*abs((long)palette[color_1].B-palette[color_2].B);
 | 
			
		||||
 | 
			
		||||
          if (difference<=best_difference)
 | 
			
		||||
          {
 | 
			
		||||
@ -2673,11 +2676,11 @@ void Button_Palette(void)
 | 
			
		||||
          // Close (confirm)
 | 
			
		||||
          clicked_button=14;
 | 
			
		||||
        }
 | 
			
		||||
        else if (Key == (SDLK_c|MOD_CTRL)) // Ctrl-C
 | 
			
		||||
        else if (Key == SHORTCUT_COPY)
 | 
			
		||||
        {
 | 
			
		||||
          Set_clipboard_colors(block_end+1-block_start,working_palette + block_start);
 | 
			
		||||
        }
 | 
			
		||||
        else if (Key == (SDLK_v|MOD_CTRL)) // Ctrl-V
 | 
			
		||||
        else if (Key == SHORTCUT_PASTE)
 | 
			
		||||
        {
 | 
			
		||||
          int nb_colors;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -526,23 +526,30 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz
 | 
			
		||||
          input_key=SDLK_RETURN;
 | 
			
		||||
 | 
			
		||||
        // Handle paste request on CTRL+v
 | 
			
		||||
#if defined __HAIKU__
 | 
			
		||||
	#define SHORTCUTKEY MOD_ALT
 | 
			
		||||
#else
 | 
			
		||||
	#define SHORTCUTKEY MOD_CTRL
 | 
			
		||||
#endif
 | 
			
		||||
        if ((Key & SHORTCUTKEY) && ((Key & 0xFFF) == 'v'))
 | 
			
		||||
        if (Key == SHORTCUT_PASTE)
 | 
			
		||||
        {
 | 
			
		||||
          int nb_added;
 | 
			
		||||
          char* data = getClipboard();
 | 
			
		||||
          if (data == NULL) continue; // No clipboard data
 | 
			
		||||
		  Cleanup_string(data, input_type);
 | 
			
		||||
            Cleanup_string(data, input_type);
 | 
			
		||||
          // Insert it at the cursor position
 | 
			
		||||
		  position += Prepend_string(str + position, data, max_size - position);
 | 
			
		||||
          nb_added = Prepend_string(str + position, data, max_size - position);
 | 
			
		||||
          while (nb_added)
 | 
			
		||||
          {
 | 
			
		||||
            size++;
 | 
			
		||||
            if (size<max_size)
 | 
			
		||||
            {
 | 
			
		||||
              position++;
 | 
			
		||||
              if (display_string[position-offset]==RIGHT_TRIANGLE_CHARACTER || position-offset>=visible_size)
 | 
			
		||||
                offset++;
 | 
			
		||||
            }
 | 
			
		||||
            nb_added--;
 | 
			
		||||
          }
 | 
			
		||||
          free(data);
 | 
			
		||||
          goto affichage;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
      } while(input_key==0);
 | 
			
		||||
#undef SHORTCUTKEY
 | 
			
		||||
    }
 | 
			
		||||
    Hide_cursor();
 | 
			
		||||
 | 
			
		||||
@ -639,7 +646,7 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz
 | 
			
		||||
        if (size<max_size)
 | 
			
		||||
        {
 | 
			
		||||
          // Si la touche était autorisée...
 | 
			
		||||
		  byte is_authorized = Valid_character(input_key, input_type);
 | 
			
		||||
          byte is_authorized = Valid_character(input_key, input_type);
 | 
			
		||||
          if (is_authorized == 1 || (is_authorized == 2 && position == 0 && str[position] != '-'))
 | 
			
		||||
          {
 | 
			
		||||
            // ... alors on l'insère ...
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user