diff --git a/src/engine.c b/src/engine.c index 1e2ad64a..2cb62b63 100644 --- a/src/engine.c +++ b/src/engine.c @@ -3145,9 +3145,10 @@ short Window_get_button_shortcut(void) short Window_clicked_button(void) { short Button; + byte old_mouse_k; + old_mouse_k=Mouse_K; Get_input(20); - // Handle clicks if (Mouse_K) { @@ -3174,6 +3175,9 @@ short Window_clicked_button(void) { short clicked_button; T_List_button * list; + static Uint32 time_last_click = 0; + static int last_list_number = -1; + Uint32 time_now; // Check which controls was clicked (by rectangular area) clicked_button = Window_get_clicked_button(); @@ -3186,9 +3190,25 @@ short Window_clicked_button(void) // Click in the textual part of a list. short clicked_line; clicked_line = (((Mouse_Y-Window_pos_Y)/Menu_factor_Y)-list->Entry_button->Pos_Y)>>3; - if (clicked_line == list->Cursor_position || // Same as before - clicked_line >= list->Scroller->Nb_elements) // Below last line + if (clicked_line >= list->Scroller->Nb_elements) // Below last line return 0; + time_now = SDL_GetTicks(); + if (clicked_line == list->Cursor_position) + { + // Double click check + if (old_mouse_k==0 && last_list_number==list->Number && time_now - time_last_click < Config.Double_click_speed) + { + time_last_click = time_now; + // Store the selected value as attribute2 + Window_attribute2=list->List_start + list->Cursor_position; + // Return the control ID of the list. + return list->Number; + } + time_last_click = time_now; + last_list_number=list->Number; + // Already selected : don't activate anything + return 0; + } Hide_cursor(); // Redraw one item as disabled diff --git a/src/factory.c b/src/factory.c index 5a50f759..693c319d 100644 --- a/src/factory.c +++ b/src/factory.c @@ -1632,7 +1632,7 @@ void Button_Brush_Factory(void) T_Special_button* scriptarea; char scriptdir[MAX_PATH_CHARACTERS]; T_Fileselector_item *item; - + int last_selected_item=-1; // Reinitialize the list Free_fileselector_list(&Scripts_selector); strcpy(scriptdir, Data_directory); @@ -1675,6 +1675,12 @@ void Button_Brush_Factory(void) Update_window_area(0, 0, Window_width, Window_height); Display_cursor(); + // Wait for mouse release (needed for example after a double-click + // that navigates to a subdirectory) + while (last_selected_item==-1 && Mouse_K) + { + Get_input(20); + } Reset_quicksearch(); @@ -1701,28 +1707,17 @@ void Button_Brush_Factory(void) switch (clicked_button) { case 4: + if (last_selected_item == scriptlist->List_start + scriptlist->Cursor_position) + { + // Double click + clicked_button=5; + break; + } + last_selected_item = scriptlist->List_start + scriptlist->Cursor_position; Hide_cursor(); Draw_script_information(Get_item_by_index(&Scripts_selector, scriptlist->List_start + scriptlist->Cursor_position)); Display_cursor(); - { - // Test double-click - static long time_click = 0; - static int last_selected_item=-1; - static long time_previous; - - time_previous = time_click; - time_click = SDL_GetTicks(); - if (scriptlist->List_start + scriptlist->Cursor_position == last_selected_item) - { - if (time_click - time_previous < Config.Double_click_speed) - clicked_button=5; - } - else - { - last_selected_item=scriptlist->List_start + scriptlist->Cursor_position; - } - } break; case 6: @@ -1807,7 +1802,7 @@ void Button_Brush_Factory(void) scriptlist->Scroller->Nb_elements=Scripts_selector.Nb_elements; Compute_slider_cursor_length(scriptlist->Scroller); - + last_selected_item = -1; Hide_cursor(); } }