Still work on SDL events. Airbrush seems to work. Need to do repeatable buttons.
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1565 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
80b8c4e5a5
commit
951ec2d48a
@ -166,7 +166,8 @@ void Button_Message_initial(void)
|
|||||||
|
|
||||||
Display_cursor();
|
Display_cursor();
|
||||||
|
|
||||||
while(!Mouse_K && !Key) if(!Get_input()) SDL_Delay(20);
|
while(!Mouse_K && !Key)
|
||||||
|
Get_input();
|
||||||
if (Mouse_K)
|
if (Mouse_K)
|
||||||
Wait_end_of_click();
|
Wait_end_of_click();
|
||||||
|
|
||||||
@ -336,8 +337,7 @@ void Button_Select_forecolor(void)
|
|||||||
// Wait loop after initial click
|
// Wait loop after initial click
|
||||||
while(Mouse_K)
|
while(Mouse_K)
|
||||||
{
|
{
|
||||||
if(!Get_input())
|
Get_input();
|
||||||
SDL_Delay(20);
|
|
||||||
|
|
||||||
if (Button_under_mouse()==BUTTON_CHOOSE_COL)
|
if (Button_under_mouse()==BUTTON_CHOOSE_COL)
|
||||||
{
|
{
|
||||||
@ -373,8 +373,7 @@ void Button_Select_backcolor(void)
|
|||||||
// Wait loop after initial click
|
// Wait loop after initial click
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if(!Get_input())
|
Get_input();
|
||||||
SDL_Delay(20);
|
|
||||||
|
|
||||||
if (Button_under_mouse()==BUTTON_CHOOSE_COL)
|
if (Button_under_mouse()==BUTTON_CHOOSE_COL)
|
||||||
break; // This will repeat this button's action
|
break; // This will repeat this button's action
|
||||||
|
|||||||
35
src/engine.c
35
src/engine.c
@ -598,7 +598,7 @@ void Move_separator(void)
|
|||||||
Display_cursor();
|
Display_cursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!Get_input())SDL_Delay(20);
|
Get_input();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Effacer la barre en XOR
|
// Effacer la barre en XOR
|
||||||
@ -1299,21 +1299,7 @@ void Main_handler(void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// No event : we go asleep for a while, but we try to get waked up at constant intervals of time
|
// Removed all SDL_Delay() timing here: relying on Get_input()
|
||||||
// no matter the machine speed or system load. The time is fixed to 10ms (that should be about a cpu slice on most systems)
|
|
||||||
// This allows nice smooth mouse movement.
|
|
||||||
const int delay = 10;
|
|
||||||
|
|
||||||
Uint32 debut;
|
|
||||||
debut = SDL_GetTicks();
|
|
||||||
// Première attente : le complément de "delay" millisecondes
|
|
||||||
SDL_Delay(delay - (debut % delay));
|
|
||||||
// Si ça ne suffit pas, on complète par des attentes successives de "1ms".
|
|
||||||
// (Remarque, Windows arrondit généralement aux 10ms supérieures)
|
|
||||||
while ( SDL_GetTicks()/delay <= debut/delay)
|
|
||||||
{
|
|
||||||
SDL_Delay(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestion de la souris
|
// Gestion de la souris
|
||||||
@ -2272,7 +2258,7 @@ short Wait_click_in_palette(T_Palette_button * button)
|
|||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
while(!Get_input())SDL_Delay(20);
|
Get_input();
|
||||||
|
|
||||||
if (Mouse_K==LEFT_SIDE)
|
if (Mouse_K==LEFT_SIDE)
|
||||||
{
|
{
|
||||||
@ -2353,7 +2339,7 @@ void Get_color_behind_window(byte * color, byte * click)
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if(!Get_input())SDL_Delay(20);
|
Get_input();
|
||||||
|
|
||||||
if ((Mouse_X!=old_x) || (Mouse_Y!=old_y))
|
if ((Mouse_X!=old_x) || (Mouse_Y!=old_y))
|
||||||
{
|
{
|
||||||
@ -2440,7 +2426,10 @@ void Move_window(short dx, short dy)
|
|||||||
old_x=new_x;
|
old_x=new_x;
|
||||||
old_y=new_y;
|
old_y=new_y;
|
||||||
|
|
||||||
while(!Get_input() && new_x==Mouse_X-dx && new_y==Mouse_Y-dy) SDL_Delay(20);
|
do
|
||||||
|
{
|
||||||
|
Get_input();
|
||||||
|
} while(new_x==Mouse_X-dx && new_y==Mouse_Y-dy);
|
||||||
|
|
||||||
new_x=Mouse_X-dx;
|
new_x=Mouse_X-dx;
|
||||||
|
|
||||||
@ -2642,7 +2631,7 @@ T_Dropdown_choice * Dropdown_activate(T_Dropdown_button *button, short off_x, sh
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Attente
|
// Attente
|
||||||
if(!Get_input()) SDL_Delay(20);
|
Get_input();
|
||||||
// Mise à jour du survol
|
// Mise à jour du survol
|
||||||
selected_index=Window_click_in_rectangle(2,2,button->Dropdown_width-2,box_height-1)?
|
selected_index=Window_click_in_rectangle(2,2,button->Dropdown_width-2,box_height-1)?
|
||||||
(((Mouse_Y-Window_pos_Y)/Menu_factor_Y-2)>>3) : -1;
|
(((Mouse_Y-Window_pos_Y)/Menu_factor_Y-2)>>3) : -1;
|
||||||
@ -2713,7 +2702,7 @@ short Window_normal_button_onclick(word x_pos, word y_pos, word width, word heig
|
|||||||
Display_cursor();
|
Display_cursor();
|
||||||
while (Window_click_in_rectangle(x_pos,y_pos,x_pos+width-1,y_pos+height-1))
|
while (Window_click_in_rectangle(x_pos,y_pos,x_pos+width-1,y_pos+height-1))
|
||||||
{
|
{
|
||||||
if(!Get_input()) SDL_Delay(20);
|
Get_input();
|
||||||
if (!Mouse_K)
|
if (!Mouse_K)
|
||||||
{
|
{
|
||||||
Hide_cursor();
|
Hide_cursor();
|
||||||
@ -2727,7 +2716,7 @@ short Window_normal_button_onclick(word x_pos, word y_pos, word width, word heig
|
|||||||
Display_cursor();
|
Display_cursor();
|
||||||
while (!(Window_click_in_rectangle(x_pos,y_pos,x_pos+width-1,y_pos+height-1)))
|
while (!(Window_click_in_rectangle(x_pos,y_pos,x_pos+width-1,y_pos+height-1)))
|
||||||
{
|
{
|
||||||
if(!Get_input()) SDL_Delay(20);
|
Get_input();
|
||||||
if (!Mouse_K)
|
if (!Mouse_K)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2991,7 +2980,7 @@ short Window_clicked_button(void)
|
|||||||
{
|
{
|
||||||
short Button;
|
short Button;
|
||||||
|
|
||||||
if(!Get_input())SDL_Delay(20);
|
Get_input();
|
||||||
|
|
||||||
// Handle clicks
|
// Handle clicks
|
||||||
if (Mouse_K)
|
if (Mouse_K)
|
||||||
|
|||||||
@ -94,7 +94,7 @@ void Redefine_control(word *shortcut, int x_pos, int y_pos)
|
|||||||
Display_cursor();
|
Display_cursor();
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
while(!Get_input())SDL_Delay(20);
|
Get_input();
|
||||||
if (Key==KEY_ESC)
|
if (Key==KEY_ESC)
|
||||||
return;
|
return;
|
||||||
if (Key!=0)
|
if (Key!=0)
|
||||||
|
|||||||
17
src/input.c
17
src/input.c
@ -51,6 +51,8 @@ int Snap_axis = 0;
|
|||||||
int Snap_axis_origin_X;
|
int Snap_axis_origin_X;
|
||||||
int Snap_axis_origin_Y;
|
int Snap_axis_origin_Y;
|
||||||
|
|
||||||
|
volatile int Need_Timer_events;
|
||||||
|
|
||||||
// --
|
// --
|
||||||
|
|
||||||
byte Directional_up;
|
byte Directional_up;
|
||||||
@ -675,6 +677,11 @@ int Get_input(void)
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
int user_feedback_required = 0; // Flag qui indique si on doit arrêter de traiter les évènements ou si on peut enchainer
|
int user_feedback_required = 0; // Flag qui indique si on doit arrêter de traiter les évènements ou si on peut enchainer
|
||||||
|
|
||||||
|
// Commit any pending screen update.
|
||||||
|
// This is done in this function because it's called after reading
|
||||||
|
// some user input.
|
||||||
|
Flush_update();
|
||||||
|
|
||||||
Key_ANSI = 0;
|
Key_ANSI = 0;
|
||||||
Key = 0;
|
Key = 0;
|
||||||
Mouse_moved=0;
|
Mouse_moved=0;
|
||||||
@ -719,6 +726,7 @@ int Get_input(void)
|
|||||||
|
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
Handle_key_release(event.key);
|
Handle_key_release(event.key);
|
||||||
|
user_feedback_required = 1; // new
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Start of Joystik handling
|
// Start of Joystik handling
|
||||||
@ -772,7 +780,7 @@ int Get_input(void)
|
|||||||
user_feedback_required = 1;
|
user_feedback_required = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// DEBUG("Unhandled SDL event number : ",event.type);
|
//DEBUG("Unhandled SDL event number : ",event.type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -839,13 +847,8 @@ int Get_input(void)
|
|||||||
Compute_paintbrush_coordinates();
|
Compute_paintbrush_coordinates();
|
||||||
Display_cursor();
|
Display_cursor();
|
||||||
}
|
}
|
||||||
// Commit any pending screen update.
|
|
||||||
// This is done in this function because it's called after reading
|
|
||||||
// some user input.
|
|
||||||
Flush_update();
|
|
||||||
|
|
||||||
|
|
||||||
return (Mouse_moved!=0) || user_feedback_required;
|
return 1;//(Mouse_moved!=0) || user_feedback_required;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Adjust_mouse_sensitivity(word fullscreen)
|
void Adjust_mouse_sensitivity(word fullscreen)
|
||||||
|
|||||||
@ -59,3 +59,6 @@ extern int Snap_axis;
|
|||||||
extern int Snap_axis_origin_X;
|
extern int Snap_axis_origin_X;
|
||||||
/// For the :Snap_axis mode, sets the origin's point (in image coordinates)
|
/// For the :Snap_axis mode, sets the origin's point (in image coordinates)
|
||||||
extern int Snap_axis_origin_Y;
|
extern int Snap_axis_origin_Y;
|
||||||
|
|
||||||
|
/// Boolean, true if Push_timer_event() should put "ticks" in the SDL queue
|
||||||
|
extern volatile int Need_Timer_events;
|
||||||
|
|||||||
31
src/main.c
31
src/main.c
@ -65,6 +65,7 @@
|
|||||||
#include "brush.h"
|
#include "brush.h"
|
||||||
#include "palette.h"
|
#include "palette.h"
|
||||||
#include "realpath.h"
|
#include "realpath.h"
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
#if defined(__WIN32__)
|
#if defined(__WIN32__)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@ -149,6 +150,12 @@ void Error_function(int error_code, const char *filename, int line_number, const
|
|||||||
temp_palette[index].R=255;
|
temp_palette[index].R=255;
|
||||||
Set_palette(temp_palette);
|
Set_palette(temp_palette);
|
||||||
SDL_Delay(500);
|
SDL_Delay(500);
|
||||||
|
// TODO: Replace the above by a loop where cursor is active:
|
||||||
|
// Need_Timer_events=1
|
||||||
|
// Compute target=now+500
|
||||||
|
// Do
|
||||||
|
// Get_input()
|
||||||
|
// While now<target
|
||||||
Set_palette(Main_palette);
|
Set_palette(Main_palette);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -410,25 +417,23 @@ int Analyze_command_line(int argc, char * argv[], char *main_filename, char *mai
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Uint32 putTimerEvent(Uint32 i, void* p)
|
Uint32 Push_timer_event(Uint32 i, void* p)
|
||||||
{
|
{
|
||||||
|
if (Need_Timer_events)
|
||||||
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_UserEvent userevent;
|
SDL_UserEvent user_event;
|
||||||
|
|
||||||
/* Dans cet exemple, notre fonction de rappel pousse
|
user_event.type = SDL_USEREVENT;
|
||||||
un evenement SDL_USEREVENT dans la file... */
|
user_event.code = 0;
|
||||||
|
user_event.data1 = NULL;
|
||||||
userevent.type = SDL_USEREVENT;
|
user_event.data2 = NULL;
|
||||||
userevent.code = 0;
|
|
||||||
userevent.data1 = NULL;
|
|
||||||
userevent.data2 = NULL;
|
|
||||||
|
|
||||||
event.type = SDL_USEREVENT;
|
event.type = SDL_USEREVENT;
|
||||||
event.user = userevent;
|
event.user = user_event;
|
||||||
|
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,7 +551,7 @@ int Init_program(int argc,char * argv[])
|
|||||||
printf("Couldn't initialize SDL.\n");
|
printf("Couldn't initialize SDL.\n");
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
tid = SDL_AddTimer(10, putTimerEvent, NULL);
|
tid = SDL_AddTimer(10, Push_timer_event, NULL);
|
||||||
|
|
||||||
Joystick = SDL_JoystickOpen(0);
|
Joystick = SDL_JoystickOpen(0);
|
||||||
SDL_EnableKeyRepeat(250, 32);
|
SDL_EnableKeyRepeat(250, 32);
|
||||||
|
|||||||
@ -177,7 +177,8 @@ void Wait_end_of_click(void)
|
|||||||
{
|
{
|
||||||
// On désactive tous les raccourcis clavier
|
// On désactive tous les raccourcis clavier
|
||||||
|
|
||||||
while(Mouse_K) if(!Get_input()) SDL_Delay(20);
|
while(Mouse_K)
|
||||||
|
Get_input();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear_current_image_with_stencil(byte color, byte * stencil)
|
void Clear_current_image_with_stencil(byte color, byte * stencil)
|
||||||
|
|||||||
@ -36,6 +36,7 @@
|
|||||||
#include "sdlscreen.h"
|
#include "sdlscreen.h"
|
||||||
#include "brush.h"
|
#include "brush.h"
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
// PI is NOT part of math.h according to C standards...
|
// PI is NOT part of math.h according to C standards...
|
||||||
#if defined(__GP2X__) || defined(__VBCC__)
|
#if defined(__GP2X__) || defined(__VBCC__)
|
||||||
@ -1908,6 +1909,7 @@ void Airbrush_1_0(void)
|
|||||||
Shade_table=Shade_table_left;
|
Shade_table=Shade_table_left;
|
||||||
|
|
||||||
Airbrush_next_time = SDL_GetTicks()+Airbrush_delay*10;
|
Airbrush_next_time = SDL_GetTicks()+Airbrush_delay*10;
|
||||||
|
Need_Timer_events=1;
|
||||||
Airbrush(LEFT_SIDE);
|
Airbrush(LEFT_SIDE);
|
||||||
|
|
||||||
Operation_push(Paintbrush_X);
|
Operation_push(Paintbrush_X);
|
||||||
@ -1930,6 +1932,7 @@ void Airbrush_2_0(void)
|
|||||||
Backup();
|
Backup();
|
||||||
Shade_table=Shade_table_right;
|
Shade_table=Shade_table_right;
|
||||||
Airbrush_next_time = SDL_GetTicks()+Airbrush_delay*10;
|
Airbrush_next_time = SDL_GetTicks()+Airbrush_delay*10;
|
||||||
|
Need_Timer_events=1;
|
||||||
Airbrush(RIGHT_SIDE);
|
Airbrush(RIGHT_SIDE);
|
||||||
|
|
||||||
Operation_push(Paintbrush_X);
|
Operation_push(Paintbrush_X);
|
||||||
@ -1977,6 +1980,7 @@ void Airbrush_0_2(void)
|
|||||||
//
|
//
|
||||||
{
|
{
|
||||||
Operation_stack_size-=2;
|
Operation_stack_size-=2;
|
||||||
|
Need_Timer_events=0;
|
||||||
End_of_modification();
|
End_of_modification();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -196,7 +196,7 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz
|
|||||||
Display_cursor();
|
Display_cursor();
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if(!Get_input()) SDL_Delay(20);
|
Get_input();
|
||||||
input_key=Key_ANSI;
|
input_key=Key_ANSI;
|
||||||
} while(input_key==0 && Mouse_K == 0);
|
} while(input_key==0 && Mouse_K == 0);
|
||||||
Hide_cursor();
|
Hide_cursor();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user