3 registered members (VoroneTZ, monk12, Quad),
829
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
on_ and file_dialog
#472458
04/28/18 23:53
04/28/18 23:53
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
I have two functions, let's call them 'save' and 'load'. In them I use 'file_dialog' and 'file_dialog_save' in order to save/load a file. To call those functions I use f4 (to call 'save') and f5 (to call 'load'). All is great, but I noticed that after first two calls, in order to call those functions I have to press f4 and f5 twice! Can anyone please explain why? Best regards! Edit: also noticed, that this results to not being able to close game's window by clicking on 'close' X at the upper right corner.. Could this be a memory issue? Pointers and such? Edit2: thx God, this has nothing to do with my map editor in general, here is a small example, that has the same problem:
#include <acknex.h>
#include <default.c>
#include <windows.h>
#include <strio.c>
#define PRAGMA_POINTER
BMAP *temp_bmp = NULL;
void save_level(){
char *map_file = file_dialog_save("Save level", "*.png");
if(map_file == NULL){ return(-1); }
STRING *file_name_str = "";
STRING *path_str = str_create(map_file);
var e_pos = str_stri(path_str, ".png");
if(e_pos == 0){
var length = str_len(path_str);
var n_pos = str_chr(path_str, -length, 92);
str_cut(file_name_str, path_str, n_pos + 1, length);
}
else{
var n_pos = str_chr(path_str, -e_pos, 92);
str_cut(file_name_str, path_str, n_pos + 1, e_pos - 1);
}
str_cat(file_name_str, ".png");
bmap_save(temp_bmp, file_name_str);
}
void load_level(){
char *map_file = file_dialog("Load level", "*.png");
if(map_file == NULL){ return; }
STRING *file_name_str = "";
STRING *path_str = str_create(map_file);
var e_pos = str_stri(path_str, ".png");
if(e_pos == 0){
var length = str_len(path_str);
var n_pos = str_chr(path_str, -length, 92);
str_cut(file_name_str, path_str, n_pos + 1, length);
}
else{
var n_pos = str_chr(path_str, -e_pos, 92);
str_cut(file_name_str, path_str, n_pos + 1, e_pos - 1);
}
str_cat(file_name_str, ".png");
if(!file_exists(file_name_str)){ return; }
temp_bmp = bmap_create(file_name_str);
}
void remove_level(){
if(temp_bmp){ safe_remove(temp_bmp); }
}
void main(){
on_f3 = remove_level;
on_f4 = save_level;
on_f5 = load_level;
fps_max = 60;
warn_level = 6;
level_load("");
wait(3);
temp_bmp = bmap_createblack(256, 64, 32);
bmap_fill(temp_bmp, COLOR_RED, 100);
while(!key_esc){
draw_text("F3 - remove\nF4 - save\nF5 - load", 10, 10, COLOR_WHITE);
if(temp_bmp){
draw_quad(temp_bmp, vector(256, 256, 0), NULL, NULL, NULL, NULL, 100, 0);
}
wait(1);
}
sys_exit("");
}
Last edited by 3run; 04/29/18 01:00.
|
|
|
Re: on_ and file_dialog
[Re: 3run]
#472460
04/29/18 08:24
04/29/18 08:24
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
It's because acknex doesn't recognize the key being released when another window is in focus.
One cheap solution would be to wait until the key is released. Otherwise, using the windows API directly for input should work aswell.
POTATO-MAN saves the day! - Random
|
|
|
Re: on_ and file_dialog
[Re: Kartoffel]
#472462
04/29/18 09:34
04/29/18 09:34
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hi, that happens when you open any new window (file explorer, printf, error, etc) with a pressed key. The engine does not reset its pilot variable (key_... and key_any aswell), so they remain true although the new window is closed. I guess that happens because the key releasing windows event is received by the new window instead of its parent so engines key_... variables manager is never executed for that event. I thought that calling the engines windows callback function with the proper parameters might work but no luck.
// global prototype
UINT CALLBACK myMsgHandler (HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);
// save engines callback function
myMsgHandler = on_message;
// call it on_f5 event
myMsgHandler (hWnd, WM_KEYUP, VK_F5, 0);
Salud! edited________ ups, late...
Last edited by txesmi; 04/29/18 09:44.
|
|
|
Re: on_ and file_dialog
[Re: txesmi]
#472463
04/29/18 09:46
04/29/18 09:46
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Hi guys! Thank you for suggestions! Does it mean that windows API won't help here? Edit: yes, 'key_pressed' shows that f4 and f5 are remaining pressed when file dialog windows get's closed... Edit2: I found this in manual for 'key_pressed' number - scancode of the key to check, 8.30 or -1 for resetting all keys to the nonpressed state. So maybe I need to call 'key_pressed(-1)' to reset all keys, right after the file windows was closed ? Edit3: yes, this helped. Just call 'key_pressed(-1)' right after 'file_dialog' function. As a prove, here is edited example from first post:
#include <acknex.h>
#include <default.c>
#include <windows.h>
#include <strio.c>
#define PRAGMA_POINTER
BMAP *temp_bmp = NULL;
void save_level(){
char *map_file = file_dialog_save("Save level", "*.png");
key_pressed(-1);
if(map_file == NULL){ return(-1); }
STRING *file_name_str = "";
STRING *path_str = str_create(map_file);
var e_pos = str_stri(path_str, ".png");
if(e_pos == 0){
var length = str_len(path_str);
var n_pos = str_chr(path_str, -length, 92);
str_cut(file_name_str, path_str, n_pos + 1, length);
}
else{
var n_pos = str_chr(path_str, -e_pos, 92);
str_cut(file_name_str, path_str, n_pos + 1, e_pos - 1);
}
str_cat(file_name_str, ".png");
bmap_save(temp_bmp, file_name_str);
}
void load_level(){
char *map_file = file_dialog("Load level", "*.png");
key_pressed(-1);
if(map_file == NULL){ return; }
STRING *file_name_str = "";
STRING *path_str = str_create(map_file);
var e_pos = str_stri(path_str, ".png");
if(e_pos == 0){
var length = str_len(path_str);
var n_pos = str_chr(path_str, -length, 92);
str_cut(file_name_str, path_str, n_pos + 1, length);
}
else{
var n_pos = str_chr(path_str, -e_pos, 92);
str_cut(file_name_str, path_str, n_pos + 1, e_pos - 1);
}
str_cat(file_name_str, ".png");
if(!file_exists(file_name_str)){ return; }
temp_bmp = bmap_create(file_name_str);
}
void remove_level(){
if(temp_bmp){ safe_remove(temp_bmp); }
}
void main(){
on_f3 = remove_level;
on_f4 = save_level;
on_f5 = load_level;
fps_max = 60;
warn_level = 6;
level_load("");
wait(3);
temp_bmp = bmap_createblack(256, 64, 32);
bmap_fill(temp_bmp, COLOR_RED, 100);
while(!key_esc){
draw_text("F3 - removenF4 - savenF5 - load", 10, 10, COLOR_WHITE);
DEBUG_VAR(key_pressed(62), 100);
DEBUG_VAR(key_pressed(63), 130);
if(temp_bmp){
draw_quad(temp_bmp, vector(256, 256, 0), NULL, NULL, NULL, NULL, 100, 0);
}
wait(1);
}
sys_exit("");
}
Thank you for clearing things out guys! Without you I wouldn't even understand why this happened. Was thinking about memory/pointers related issues
Last edited by 3run; 04/29/18 09:56.
|
|
|
Re: on_ and file_dialog
[Re: txesmi]
#472465
04/29/18 10:18
04/29/18 10:18
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
you hit the clove! at least once I did ahah, thank you guys! My best regards!
|
|
|
|