From 602d41be7094bdb9bb33664635a69d64c640fea0 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 9 Sep 2016 13:14:38 -0400 Subject: [PATCH] mouse button release events --- 4coder_API.html | 6 +++--- 4coder_default_bindings.cpp | 5 +++++ 4coder_keycodes.h | 4 ++++ 4coder_types.h | 8 +++----- 4ed.cpp | 27 +++++++++++++++++---------- 4ed_metagen.cpp | 2 ++ TODO.txt | 6 +++--- 7 files changed, 37 insertions(+), 21 deletions(-) diff --git a/4coder_API.html b/4coder_API.html index 5683fe6b..b3777aba 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -151,9 +151,9 @@ a character ignoring the state of caps lock, and an array of all the modifiers that were pressed at the time of the event.

Fields
keycode
This field is the raw keycode which is always non-zero in valid key events.

character
This field is the keycode after translation to a character, this is 0 if there is no translation.

character_no_caps_lock
This field is like the field character, except that the state of caps lock is ignored in the translation.

modifiers
This field is an array indicating the state of modifiers at the time of the key press. The array is indexed using the values of Key_Modifier. A 1 indicates that the corresponding - modifier was held, and a 0 indicates that it was not held.


§3.4.27: Mouse_State

struct Mouse_State {
char l;
char r;
char press_l;
char press_r;
char release_l;
char release_r;
char wheel;
char out_of_window;
int32_t x;
int32_t y;
};
Description
Mouse_State describes an entire mouse state complete with the position, -left and right button states, the wheel state, and whether or not the -mouse if in the window.

Fields
l
This field indicates that the left button is held.

r
This field indicates that the right button is held.

press_l
This field indicates that the left button was pressed this frame.

press_r
This field indicates that the right button was pressed this frame.

release_l
This field indicates that the left button was released this frame.

release_r
This field indicates that the right button was released this frame.

wheel
This field is 0 when the wheel has not moved, it is 1 for a downward motion and -1 for an upward motion.

out_of_window
This field indicates that the mouse is outside of the window.

x
This field contains the x position of the mouse relative to the window where the left side is 0.

y
This field contains the y position of the mouse relative to the window where the top side is 0.


§3.4.28: Range

union Range {
struct {
int32_t min;
int32_t max;
};
struct {
int32_t start;
int32_t end;
};
};
Description
Range describes an integer range typically used for ranges within a buffer. + modifier was held, and a 0 indicates that it was not held.


§3.4.27: Mouse_State

struct Mouse_State {
char l;
char r;
char press_l;
char press_r;
char release_l;
char release_r;
char wheel;
char out_of_window;
int32_t x;
int32_t y;
};
Description
Mouse_State describes an entire mouse state complete with the +position, left and right button states, the wheel state, and whether +or not the mouse if in the window.

Fields
l
This field indicates that the left button is held.

r
This field indicates that the right button is held.

press_l
This field indicates that the left button was pressed this frame.

press_r
This field indicates that the right button was pressed this frame.

release_l
This field indicates that the left button was released this frame.

release_r
This field indicates that the right button was released this frame.

wheel
This field is 0 when the wheel has not moved, it is 1 for a downward motion and -1 for an upward motion.

out_of_window
This field indicates that the mouse is outside of the window.

x
This field contains the x position of the mouse relative to the window where the left side is 0.

y
This field contains the y position of the mouse relative to the window where the top side is 0.


§3.4.28: Range

union Range {
struct {
int32_t min;
int32_t max;
};
struct {
int32_t start;
int32_t end;
};
};
Description
Range describes an integer range typically used for ranges within a buffer. Ranges tend are usually not passed as a Range struct into the API, but this struct is used to return ranges.

Throughout the API ranges are thought of in the form [min,max

Fields
min
This is the smaller value in the range, it is also the 'start'.

max
This is the larger value in the range, it is also the 'end'.

start
This is the start of the range, it is also the 'min'.

end
This is the end of the range, it is also the 'max'.


§3.4.29: File_Info

struct File_Info {
char * filename;
int32_t filename_len;
int32_t folder;
};
Description
File_Info describes the name and type of a file.

Fields
filename
This field is a null terminated string specifying the name of the file.

filename_len
This field specifies the length of the filename string not counting the null terminator.

folder
This field indicates that the description is for a folder not a file.

See Also
File_List

§3.4.30: File_List

struct File_List {
void * block;
File_Info * infos;
int32_t count;
int32_t block_size;
};
Description
File_List is a list of File_Info structs.

Fields
block
This field is for inernal use.

infos
This field is an array of File_Info structs.

count
This field specifies the number of struts in the info array.

block_size
This field is for internal use.


§3.4.31: Buffer_Identifier

struct Buffer_Identifier {
char * name;
int32_t name_len;
int32_t id;
};
Description
Buffer_Identifier acts as a loosely typed description of a buffer that diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index e636e35d..c92be080 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -342,6 +342,11 @@ default_keys(Bind_Helper *context){ bind(context, key_mouse_left, MDFR_NONE, click_set_cursor); bind(context, key_mouse_right, MDFR_NONE, click_set_mark); + // NOTE(allen|a4.0.11): You can now bind left and right mouse + // button releases. Modifiers do work so control+click shift+click + // etc can now have special meanings. + bind(context, key_mouse_left_release, MDFR_NONE, click_set_mark); + bind(context, key_left, MDFR_NONE, move_left); bind(context, key_right, MDFR_NONE, move_right); bind(context, key_del, MDFR_NONE, delete_char); diff --git a/4coder_keycodes.h b/4coder_keycodes.h index ef638bec..741c0071 100644 --- a/4coder_keycodes.h +++ b/4coder_keycodes.h @@ -13,6 +13,8 @@ key_page_down = 13, key_esc = 14, key_mouse_left = 15, key_mouse_right = 16, +key_mouse_left_release = 17, +key_mouse_right_release = 18, key_f1 = 127, key_f2 = 128, key_f3 = 129, @@ -48,6 +50,8 @@ case key_page_down: result = "page_down"; *size = sizeof("page_down")-1; break; case key_esc: result = "esc"; *size = sizeof("esc")-1; break; case key_mouse_left: result = "mouse_left"; *size = sizeof("mouse_left")-1; break; case key_mouse_right: result = "mouse_right"; *size = sizeof("mouse_right")-1; break; +case key_mouse_left_release: result = "mouse_left_release"; *size = sizeof("mouse_left_release")-1; break; +case key_mouse_right_release: result = "mouse_right_release"; *size = sizeof("mouse_right_release")-1; break; case key_f1: result = "f1"; *size = sizeof("f1")-1; break; case key_f2: result = "f2"; *size = sizeof("f2")-1; break; case key_f3: result = "f3"; *size = sizeof("f3")-1; break; diff --git a/4coder_types.h b/4coder_types.h index 42d6d8e4..4eb4426b 100644 --- a/4coder_types.h +++ b/4coder_types.h @@ -366,11 +366,9 @@ struct Key_Event_Data{ char modifiers[MDFR_INDEX_COUNT]; }; -/* DOC( -Mouse_State describes an entire mouse state complete with the position, -left and right button states, the wheel state, and whether or not the -mouse if in the window. -) */ +/* DOC(Mouse_State describes an entire mouse state complete with the +position, left and right button states, the wheel state, and whether +or not the mouse if in the window.) */ struct Mouse_State{ /* DOC(This field indicates that the left button is held.) */ char l; diff --git a/4ed.cpp b/4ed.cpp index ab513d7a..f0613e18 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -1783,10 +1783,7 @@ App_Step_Sig(app_step){ } Key_Event_Data mouse_event = {0}; - if (input->mouse.press_l || - input->mouse.press_r){ - memcpy(mouse_event.modifiers, input->keys.modifiers, sizeof(input->keys.modifiers)); - } + memcpy(mouse_event.modifiers, input->keys.modifiers, sizeof(input->keys.modifiers)); if (input->mouse.press_l){ mouse_event.keycode = key_mouse_left; @@ -1798,6 +1795,16 @@ App_Step_Sig(app_step){ key_summary.keys[key_summary.count++] = mouse_event; } + if (input->mouse.release_l){ + mouse_event.keycode = key_mouse_left_release; + key_summary.keys[key_summary.count++] = mouse_event; + } + + if (input->mouse.release_r){ + mouse_event.keycode = key_mouse_right_release; + key_summary.keys[key_summary.count++] = mouse_event; + } + input->mouse.wheel = -input->mouse.wheel; } @@ -2436,8 +2443,7 @@ App_Step_Sig(app_step){ if (record->consumed && record->consumer[0] != 0){ Debug_Input_Event *event = debug->input_events; for (i32 i = 0; i < count; ++i, ++event){ - if (event->key == key_mouse_left && - event->consumer[0] == 0){ + if (event->key == key_mouse_left && event->consumer[0] == 0){ memcpy(event->consumer, record->consumer, sizeof(record->consumer)); } } @@ -2447,8 +2453,7 @@ App_Step_Sig(app_step){ if (record->consumed && record->consumer[0] != 0){ Debug_Input_Event *event = debug->input_events; for (i32 i = 0; i < count; ++i, ++event){ - if (event->key == key_mouse_right && - event->consumer[0] == 0){ + if (event->key == key_mouse_right && event->consumer[0] == 0){ memcpy(event->consumer, record->consumer, sizeof(record->consumer)); } } @@ -2458,8 +2463,7 @@ App_Step_Sig(app_step){ if (record->consumed && record->consumer[0] != 0){ Debug_Input_Event *event = debug->input_events; for (i32 i = 0; i < count; ++i, ++event){ - if (event->key == key_esc && - event->consumer[0] == 0){ + if (event->key == key_esc && event->consumer[0] == 0){ memcpy(event->consumer, record->consumer, sizeof(record->consumer)); } } @@ -2491,6 +2495,9 @@ App_Step_Sig(app_step){ " and fullscreen can be toggled with .\n" " (This sometimes causes artifacts on the Windows task bar)\n" "- to exit\n" + "-hook on exit for the customization system\n" + "-tokens now exposed in customization system\n" + "-mouse release events in customization system\n" "\n" "New in alpha 4.0.10:\n" "- list all locations of a string across all open buffers\n" diff --git a/4ed_metagen.cpp b/4ed_metagen.cpp index 5835fb83..cabe3c5d 100644 --- a/4ed_metagen.cpp +++ b/4ed_metagen.cpp @@ -89,6 +89,8 @@ char *keys_that_need_codes[] = { "mouse_left", "mouse_right", + "mouse_left_release", + "mouse_right_release", "f1", "f2", diff --git a/TODO.txt b/TODO.txt index 353051e0..a3974db2 100644 --- a/TODO.txt +++ b/TODO.txt @@ -73,6 +73,7 @@ ; [X] problem with end of line comments ; [X] paths with parens in them ; [X] killing compilation panel changes active panel +; [X] make panel resizing not whacky with child panels ; ; [] indication on failure to save ; [] history is broken, revist the entire system @@ -86,8 +87,6 @@ ; BEFORE I SHIP ; -; [X] make panel resizing not whacky with child panels -; [X] case insensitive interactive switch buffer ; [X] tokens in the custom API ; [X] token seeking on custom side ; [X] auto indent on the custom side @@ -96,7 +95,6 @@ ; [] clean up and comment the auto indent code to allow for customizations ; [] more built in options for auto indenting ; [] expose dirty flags -; [] mouse down/up distinction ; [] occasionally missing the (!) mark on files on windows ; [] scroll down on compilation buffer durring compilation ; [] why are command line files not loading any more? @@ -143,6 +141,8 @@ ; [X] new file ; [X] hook on exit ; [X] file out of sync +; [X] mouse down/up distinction +; [X] case insensitive interactive switch buffer ; ; [] binary buffers