Drag-n-drop file in Grafx2 window is now cleanly prevented while a window is open: The OS's mouse cursor is the 'forbidden' sign. Preparatory work for horizontal slider controls.
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1597 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
		
							parent
							
								
									9e20dd71fd
								
							
						
					
					
						commit
						d78c33855b
					
				
							
								
								
									
										72
									
								
								src/engine.c
									
									
									
									
									
								
							
							
						
						
									
										72
									
								
								src/engine.c
									
									
									
									
									
								
							@ -1592,6 +1592,7 @@ void Open_window(word width,word height, const char * title)
 | 
			
		||||
      // Restore palette
 | 
			
		||||
      Set_palette(Main_palette);
 | 
			
		||||
    }
 | 
			
		||||
    Allow_drag_and_drop(0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Initialisation des listes de boutons de la fenêtre
 | 
			
		||||
@ -1682,6 +1683,7 @@ void Close_window(void)
 | 
			
		||||
    Display_all_screen();
 | 
			
		||||
    Display_menu();
 | 
			
		||||
    Allow_colorcycling=1;
 | 
			
		||||
    Allow_drag_and_drop(1);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Key=0;
 | 
			
		||||
@ -1837,17 +1839,17 @@ void Tag_color_range(byte start,byte end)
 | 
			
		||||
 | 
			
		||||
//------------------ Dessiner un scroller dans une fenêtre -------------------
 | 
			
		||||
 | 
			
		||||
void Compute_slider_cursor_height(T_Scroller_button * button)
 | 
			
		||||
void Compute_slider_cursor_length(T_Scroller_button * button)
 | 
			
		||||
{
 | 
			
		||||
  if (button->Nb_elements>button->Nb_visibles)
 | 
			
		||||
  {
 | 
			
		||||
    button->Cursor_height=(button->Nb_visibles*(button->Height-24))/button->Nb_elements;
 | 
			
		||||
    if (!(button->Cursor_height))
 | 
			
		||||
      button->Cursor_height=1;
 | 
			
		||||
    button->Cursor_length=(button->Nb_visibles*(button->Length-24))/button->Nb_elements;
 | 
			
		||||
    if (!(button->Cursor_length))
 | 
			
		||||
      button->Cursor_length=1;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    button->Cursor_height=button->Height-24;
 | 
			
		||||
    button->Cursor_length=button->Length-24;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1859,28 +1861,28 @@ void Window_draw_slider(T_Scroller_button * button)
 | 
			
		||||
 | 
			
		||||
  Block(Window_pos_X+(button->Pos_X*Menu_factor_X),
 | 
			
		||||
        Window_pos_Y+(slider_position*Menu_factor_Y),
 | 
			
		||||
        11*Menu_factor_X,(button->Height-24)*Menu_factor_Y,MC_Black/*MC_Dark*/);
 | 
			
		||||
        11*Menu_factor_X,(button->Length-24)*Menu_factor_Y,MC_Black/*MC_Dark*/);
 | 
			
		||||
 | 
			
		||||
  if (button->Nb_elements>button->Nb_visibles)
 | 
			
		||||
    slider_position+=Round_div(button->Position*(button->Height-24-button->Cursor_height),button->Nb_elements-button->Nb_visibles);
 | 
			
		||||
    slider_position+=Round_div(button->Position*(button->Length-24-button->Cursor_length),button->Nb_elements-button->Nb_visibles);
 | 
			
		||||
 | 
			
		||||
  Block(Window_pos_X+(button->Pos_X*Menu_factor_X),
 | 
			
		||||
        Window_pos_Y+(slider_position*Menu_factor_Y),
 | 
			
		||||
        11*Menu_factor_X,button->Cursor_height*Menu_factor_Y,MC_OnBlack/*MC_White*/);
 | 
			
		||||
        11*Menu_factor_X,button->Cursor_length*Menu_factor_Y,MC_OnBlack/*MC_White*/);
 | 
			
		||||
 | 
			
		||||
  Update_rect(Window_pos_X+(button->Pos_X*Menu_factor_X),
 | 
			
		||||
        Window_pos_Y+button->Pos_Y*Menu_factor_Y,
 | 
			
		||||
        11*Menu_factor_X,(button->Height)*Menu_factor_Y);
 | 
			
		||||
        11*Menu_factor_X,(button->Length)*Menu_factor_Y);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Window_draw_scroller_bouton(T_Scroller_button * button)
 | 
			
		||||
{
 | 
			
		||||
  Window_display_frame_generic(button->Pos_X-1,button->Pos_Y-1,13,button->Height+2,MC_Black,MC_Black,MC_Dark,MC_Dark,MC_Dark);
 | 
			
		||||
  Window_display_frame_mono(button->Pos_X-1,button->Pos_Y+11,13,button->Height-22,MC_Black);
 | 
			
		||||
  Window_display_frame_generic(button->Pos_X-1,button->Pos_Y-1,13,button->Length+2,MC_Black,MC_Black,MC_Dark,MC_Dark,MC_Dark);
 | 
			
		||||
  Window_display_frame_mono(button->Pos_X-1,button->Pos_Y+11,13,button->Length-22,MC_Black);
 | 
			
		||||
  Window_display_frame_out(button->Pos_X,button->Pos_Y,11,11);
 | 
			
		||||
  Window_display_frame_out(button->Pos_X,button->Pos_Y+button->Height-11,11,11);
 | 
			
		||||
  Window_display_frame_out(button->Pos_X,button->Pos_Y+button->Length-11,11,11);
 | 
			
		||||
  Print_in_window(button->Pos_X+2,button->Pos_Y+2,"\030",MC_Black,MC_Light);
 | 
			
		||||
  Print_in_window(button->Pos_X+2,button->Pos_Y+button->Height-9,"\031",MC_Black,MC_Light);
 | 
			
		||||
  Print_in_window(button->Pos_X+2,button->Pos_Y+button->Length-9,"\031",MC_Black,MC_Light);
 | 
			
		||||
  Window_draw_slider(button);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1996,13 +1998,14 @@ T_Scroller_button * Window_set_scroller_button(word x_pos, word y_pos,
 | 
			
		||||
 | 
			
		||||
  temp=(T_Scroller_button *)malloc(sizeof(T_Scroller_button));
 | 
			
		||||
  temp->Number        =++Window_nb_buttons;
 | 
			
		||||
  temp->Is_horizontal =0;
 | 
			
		||||
  temp->Pos_X         =x_pos;
 | 
			
		||||
  temp->Pos_Y         =y_pos;
 | 
			
		||||
  temp->Height       =height;
 | 
			
		||||
  temp->Length        =height;
 | 
			
		||||
  temp->Nb_elements   =nb_elements;
 | 
			
		||||
  temp->Nb_visibles   =nb_elements_visible;
 | 
			
		||||
  temp->Position      =initial_position;
 | 
			
		||||
  Compute_slider_cursor_height(temp);
 | 
			
		||||
  Compute_slider_cursor_length(temp);
 | 
			
		||||
 | 
			
		||||
  temp->Next=Window_scroller_button_list;
 | 
			
		||||
  Window_scroller_button_list=temp;
 | 
			
		||||
@ -2011,6 +2014,31 @@ T_Scroller_button * Window_set_scroller_button(word x_pos, word y_pos,
 | 
			
		||||
  return temp;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
T_Scroller_button * Window_set_horizontal_scroller_button(word x_pos, word y_pos,
 | 
			
		||||
                                     word width,
 | 
			
		||||
                                     word nb_elements,
 | 
			
		||||
                                     word nb_elements_visible,
 | 
			
		||||
                                     word initial_position)
 | 
			
		||||
{
 | 
			
		||||
  T_Scroller_button * temp;
 | 
			
		||||
 | 
			
		||||
  temp=(T_Scroller_button *)malloc(sizeof(T_Scroller_button));
 | 
			
		||||
  temp->Number        =++Window_nb_buttons;
 | 
			
		||||
  temp->Is_horizontal =1;
 | 
			
		||||
  temp->Pos_X         =x_pos;
 | 
			
		||||
  temp->Pos_Y         =y_pos;
 | 
			
		||||
  temp->Length        =width;
 | 
			
		||||
  temp->Nb_elements   =nb_elements;
 | 
			
		||||
  temp->Nb_visibles   =nb_elements_visible;
 | 
			
		||||
  temp->Position      =initial_position;
 | 
			
		||||
  Compute_slider_cursor_length(temp);
 | 
			
		||||
 | 
			
		||||
  temp->Next=Window_scroller_button_list;
 | 
			
		||||
  Window_scroller_button_list=temp;
 | 
			
		||||
 | 
			
		||||
  Window_draw_scroller_bouton(temp);
 | 
			
		||||
  return temp;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
T_Special_button * Window_set_special_button(word x_pos,word y_pos,word width,word height)
 | 
			
		||||
{
 | 
			
		||||
@ -2874,11 +2902,11 @@ short Window_get_clicked_button(void)
 | 
			
		||||
    
 | 
			
		||||
    // Button Down arrow
 | 
			
		||||
    if ((Input_sticky_control == 0 || Input_sticky_control == (temp3->Number|2048))
 | 
			
		||||
      && Window_click_in_rectangle(temp3->Pos_X,temp3->Pos_Y+temp3->Height-11,temp3->Pos_X+10,temp3->Pos_Y+temp3->Height-1))
 | 
			
		||||
      && Window_click_in_rectangle(temp3->Pos_X,temp3->Pos_Y+temp3->Length-11,temp3->Pos_X+10,temp3->Pos_Y+temp3->Length-1))
 | 
			
		||||
    {
 | 
			
		||||
      Input_sticky_control = temp3->Number | 2048;
 | 
			
		||||
      Hide_cursor();
 | 
			
		||||
      Window_select_normal_button(temp3->Pos_X,temp3->Pos_Y+temp3->Height-11,11,11);
 | 
			
		||||
      Window_select_normal_button(temp3->Pos_X,temp3->Pos_Y+temp3->Length-11,11,11);
 | 
			
		||||
 | 
			
		||||
      if (temp3->Position+temp3->Nb_visibles<temp3->Nb_elements)
 | 
			
		||||
      {
 | 
			
		||||
@ -2895,32 +2923,32 @@ short Window_get_clicked_button(void)
 | 
			
		||||
      Delay_with_active_mouse((Mouse_K==1)? Config.Delay_left_click_on_slider : Config.Delay_right_click_on_slider);
 | 
			
		||||
 | 
			
		||||
      Hide_cursor();
 | 
			
		||||
      Window_unselect_normal_button(temp3->Pos_X,temp3->Pos_Y+temp3->Height-11,11,11);
 | 
			
		||||
      Window_unselect_normal_button(temp3->Pos_X,temp3->Pos_Y+temp3->Length-11,11,11);
 | 
			
		||||
      Display_cursor();
 | 
			
		||||
      
 | 
			
		||||
      return (Window_attribute1)? temp3->Number : 0;
 | 
			
		||||
    }
 | 
			
		||||
    // Middle slider
 | 
			
		||||
    if ((Input_sticky_control == temp3->Number) || (Input_sticky_control==0 &&
 | 
			
		||||
        Window_click_in_rectangle(temp3->Pos_X,temp3->Pos_Y+12,temp3->Pos_X+10,temp3->Pos_Y+temp3->Height-13)))
 | 
			
		||||
        Window_click_in_rectangle(temp3->Pos_X,temp3->Pos_Y+12,temp3->Pos_X+10,temp3->Pos_Y+temp3->Length-13)))
 | 
			
		||||
    {
 | 
			
		||||
      Input_sticky_control = temp3->Number;
 | 
			
		||||
      if (temp3->Nb_elements>temp3->Nb_visibles)
 | 
			
		||||
      {
 | 
			
		||||
        // If there is enough room to make the cursor move:
 | 
			
		||||
 | 
			
		||||
        max_slider_height=(temp3->Height-24);
 | 
			
		||||
        max_slider_height=(temp3->Length-24);
 | 
			
		||||
 | 
			
		||||
        // Window_attribute2 receives the position of the cursor.
 | 
			
		||||
        Window_attribute2 =(Mouse_Y-Window_pos_Y) / Menu_factor_Y;
 | 
			
		||||
        Window_attribute2-=(temp3->Pos_Y+12+((temp3->Cursor_height-1)>>1));
 | 
			
		||||
        Window_attribute2-=(temp3->Pos_Y+12+((temp3->Cursor_length-1)>>1));
 | 
			
		||||
        Window_attribute2*=(temp3->Nb_elements-temp3->Nb_visibles);
 | 
			
		||||
 | 
			
		||||
        if (Window_attribute2<0)
 | 
			
		||||
          Window_attribute2=0;
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
          Window_attribute2 =Round_div(Window_attribute2,max_slider_height-temp3->Cursor_height);
 | 
			
		||||
          Window_attribute2 =Round_div(Window_attribute2,max_slider_height-temp3->Cursor_length);
 | 
			
		||||
          if (Window_attribute2+temp3->Nb_visibles>temp3->Nb_elements)
 | 
			
		||||
            Window_attribute2=temp3->Nb_elements-temp3->Nb_visibles;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -45,7 +45,7 @@ void Window_select_normal_button(word x_pos,word y_pos,word width,word height);
 | 
			
		||||
void Window_unselect_normal_button(word x_pos,word y_pos,word width,word height);
 | 
			
		||||
void Window_draw_palette_bouton(word x_pos,word y_pos);
 | 
			
		||||
 | 
			
		||||
void Compute_slider_cursor_height(T_Scroller_button * button);
 | 
			
		||||
void Compute_slider_cursor_length(T_Scroller_button * button);
 | 
			
		||||
void Window_draw_slider(T_Scroller_button * button);
 | 
			
		||||
void Window_draw_scroller_bouton(T_Scroller_button * button);
 | 
			
		||||
 | 
			
		||||
@ -69,6 +69,10 @@ T_Scroller_button * Window_set_scroller_button(word x_pos, word y_pos,
 | 
			
		||||
  word height, word nb_elements, word nb_elements_visible,
 | 
			
		||||
  word initial_position);
 | 
			
		||||
 | 
			
		||||
T_Scroller_button * Window_set_horizontal_scroller_button(word x_pos, word y_pos,
 | 
			
		||||
  word height, word nb_elements, word nb_elements_visible,
 | 
			
		||||
  word initial_position);
 | 
			
		||||
 | 
			
		||||
T_Special_button * Window_set_special_button(word x_pos, word y_pos, word width,
 | 
			
		||||
  word height);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -77,7 +77,7 @@
 | 
			
		||||
// Returns 0 if all ok, something else if failed
 | 
			
		||||
byte Native_filesel(byte load)
 | 
			
		||||
{
 | 
			
		||||
	load = load;
 | 
			
		||||
	//load = load;
 | 
			
		||||
#ifdef __WIN32__
 | 
			
		||||
  OPENFILENAME ofn;
 | 
			
		||||
  char szFileName[MAX_PATH] = "";
 | 
			
		||||
@ -964,7 +964,7 @@ void Prepare_and_display_filelist(short Position, short offset, T_Scroller_butto
 | 
			
		||||
{
 | 
			
		||||
  button->Nb_elements=Filelist.Nb_elements;
 | 
			
		||||
  button->Position=Position;
 | 
			
		||||
  Compute_slider_cursor_height(button);
 | 
			
		||||
  Compute_slider_cursor_length(button);
 | 
			
		||||
  Window_draw_slider(button);
 | 
			
		||||
  // On efface les anciens noms de fichier:
 | 
			
		||||
  Window_rectangle(8-1,95-1,144+2,80+2,MC_Black);
 | 
			
		||||
 | 
			
		||||
@ -404,7 +404,7 @@ void Scroll_help(T_Scroller_button * scroller)
 | 
			
		||||
{
 | 
			
		||||
  Hide_cursor();
 | 
			
		||||
  scroller->Position=Help_position;
 | 
			
		||||
  Compute_slider_cursor_height(scroller);
 | 
			
		||||
  Compute_slider_cursor_length(scroller);
 | 
			
		||||
  Window_draw_slider(scroller);
 | 
			
		||||
  Display_help();
 | 
			
		||||
  Display_cursor();
 | 
			
		||||
@ -523,7 +523,7 @@ void Window_help(int section, const char *sub_section)
 | 
			
		||||
          nb_lines=Help_section[Current_help_section].Length;
 | 
			
		||||
          scroller->Position=0;
 | 
			
		||||
          scroller->Nb_elements=nb_lines;
 | 
			
		||||
          Compute_slider_cursor_height(scroller);
 | 
			
		||||
          Compute_slider_cursor_length(scroller);
 | 
			
		||||
          Window_draw_slider(scroller);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								src/input.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/input.c
									
									
									
									
									
								
							@ -96,21 +96,6 @@ short Joybutton_left_click=0; // Button number that serves as left click
 | 
			
		||||
short Joybutton_right_click=0; // Button number that serves as right-click
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void AcceptDND(void)
 | 
			
		||||
{
 | 
			
		||||
#ifdef __WIN32__
 | 
			
		||||
	SDL_SysWMinfo wminfo;
 | 
			
		||||
	HWND hwnd;
 | 
			
		||||
	
 | 
			
		||||
	SDL_VERSION(&wminfo.version);
 | 
			
		||||
	SDL_GetWMInfo(&wminfo);
 | 
			
		||||
	hwnd = wminfo.window;
 | 
			
		||||
	DragAcceptFiles(hwnd,TRUE);
 | 
			
		||||
	SDL_EventState (SDL_SYSWMEVENT,SDL_ENABLE );
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Has_shortcut(word function)
 | 
			
		||||
{
 | 
			
		||||
  if (function == 0xFFFF)
 | 
			
		||||
 | 
			
		||||
@ -824,14 +824,7 @@ int Init_program(int argc,char * argv[])
 | 
			
		||||
      }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
  // Color cycling test
 | 
			
		||||
  {
 | 
			
		||||
    SDL_Thread* t = SDL_CreateThread(Color_cycling, NULL);
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  AcceptDND();
 | 
			
		||||
  Allow_drag_and_drop(1);
 | 
			
		||||
 | 
			
		||||
  return(1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -678,7 +678,7 @@ void Set_palette_slider(T_Scroller_button * slider,
 | 
			
		||||
{
 | 
			
		||||
  slider->Nb_elements=nb_elements;
 | 
			
		||||
  slider->Position=position;
 | 
			
		||||
  Compute_slider_cursor_height(slider);
 | 
			
		||||
  Compute_slider_cursor_length(slider);
 | 
			
		||||
  Window_draw_slider(slider);
 | 
			
		||||
  Print_counter(x_pos,NUMERIC_Y,value,MC_Black,MC_Light);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -23,6 +23,14 @@
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <SDL.h>
 | 
			
		||||
#if defined(__WIN32__)
 | 
			
		||||
    #include <windows.h>
 | 
			
		||||
#endif
 | 
			
		||||
// There is no WM on the GP2X...
 | 
			
		||||
#ifndef __GP2X__
 | 
			
		||||
    #include <SDL_syswm.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "global.h"
 | 
			
		||||
#include "sdlscreen.h"
 | 
			
		||||
#include "errors.h"
 | 
			
		||||
@ -270,3 +278,18 @@ void Clear_border(byte color)
 | 
			
		||||
  }  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Activates or desactivates file drag-dropping in program window.
 | 
			
		||||
void Allow_drag_and_drop(int flag)
 | 
			
		||||
{
 | 
			
		||||
  // Inform Windows that we accept drag-n-drop events or not
 | 
			
		||||
  #ifdef __WIN32__
 | 
			
		||||
	SDL_SysWMinfo wminfo;
 | 
			
		||||
	HWND hwnd;
 | 
			
		||||
	
 | 
			
		||||
	SDL_VERSION(&wminfo.version);
 | 
			
		||||
	SDL_GetWMInfo(&wminfo);
 | 
			
		||||
	hwnd = wminfo.window;
 | 
			
		||||
	DragAcceptFiles(hwnd,flag?TRUE:FALSE);
 | 
			
		||||
	SDL_EventState (SDL_SYSWMEVENT,flag?SDL_ENABLE:SDL_DISABLE );
 | 
			
		||||
  #endif
 | 
			
		||||
}
 | 
			
		||||
@ -67,4 +67,7 @@ void Clear_border(byte color);
 | 
			
		||||
  
 | 
			
		||||
extern volatile int Allow_colorcycling;
 | 
			
		||||
 | 
			
		||||
/// Activates or desactivates file drag-dropping in program window.
 | 
			
		||||
void Allow_drag_and_drop(int flag);
 | 
			
		||||
 | 
			
		||||
#endif // SDLSCREEN_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
@ -105,17 +105,18 @@ typedef struct T_Palette_button
 | 
			
		||||
  struct T_Palette_button * Next;///< Pointer to the next palette of current window.
 | 
			
		||||
} T_Palette_button;
 | 
			
		||||
 | 
			
		||||
/// A window control that represents a vertical scrollbar, with a slider, and two arrow buttons.
 | 
			
		||||
/// A window control that represents a scrollbar, with a slider, and two arrow buttons.
 | 
			
		||||
typedef struct T_Scroller_button
 | 
			
		||||
{
 | 
			
		||||
  short Number;                   ///< Unique identifier for all controls
 | 
			
		||||
  byte Is_horizontal;             ///< Boolean: True if slider is horizontal instead of vertical.
 | 
			
		||||
  word Pos_X;                     ///< Coordinate for top of button, relative to the window, before scaling.
 | 
			
		||||
  word Pos_Y;                     ///< Coordinate for left of button, relative to the window, before scaling.
 | 
			
		||||
  word Height;                    ///< Height before scaling.
 | 
			
		||||
  word Length;                    ///< Length before scaling.
 | 
			
		||||
  word Nb_elements;               ///< Number of distinct values it can take.
 | 
			
		||||
  word Nb_visibles;               ///< If this slider is meant to show several elements of a collection, this is their number (otherwise, it's 1).
 | 
			
		||||
  word Position;                  ///< Current position of the slider: which item it's pointing.
 | 
			
		||||
  word Cursor_height;             ///< Vertical dimension of the slider, in pixels before scaling.
 | 
			
		||||
  word Cursor_length;             ///< Dimension of the slider, in pixels before scaling.
 | 
			
		||||
  struct T_Scroller_button * Next;///< Pointer to the next scroller of current window.
 | 
			
		||||
} T_Scroller_button;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user