Skip to content

Commit

Permalink
gui: Buttons to change stylus's buttons functions
Browse files Browse the repository at this point in the history
For now only the gui part is implemented. The value for the radio
buttons is kept both in the gui and in settings to keep the choice after
reseting the program.
  • Loading branch information
Maciej Wieczór-Retman committed May 29, 2023
1 parent a2a74d6 commit 299c96f
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 1 deletion.
63 changes: 63 additions & 0 deletions src/gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,69 @@ milton_imgui_tick(MiltonInput* input, PlatformState* platform, Milton* milton,
milton->settings->peek_out_increment = (peek_out_percent / 100.0f) * peek_range;
}

#ifdef __linux__
gui->upper_radio = milton->settings->upper_button;
gui->lower_radio = milton->settings->lower_button;
char result[50]; // array to hold the result.


ImGui::Separator();

ImGui::Text(loc(TXT_stylus_upper_button_function));

strcpy(result, loc(TXT_default)); // copy string one into the result.
strcat(result, "##upper");
ImGui::RadioButton(result, &gui->upper_radio, STYLUS_DEFAULT);
ImGui::SameLine();

strcpy(result, loc(TXT_eraser)); // copy string one into the result.
strcat(result, "##upper");
ImGui::RadioButton(result, &gui->upper_radio, STYLUS_ERASER);
ImGui::SameLine();

strcpy(result, loc(TXT_brush)); // copy string one into the result.
strcat(result, "##upper");
ImGui::RadioButton(result, &gui->upper_radio, STYLUS_BRUSH);

strcpy(result, loc(TXT_decrease_brush_size)); // copy string one into the result.
strcat(result, "##upper");
ImGui::RadioButton(result, &gui->upper_radio, STYLUS_DECB);

strcpy(result, loc(TXT_increase_brush_size)); // copy string one into the result.
strcat(result, "##upper");
ImGui::RadioButton(result, &gui->upper_radio, STYLUS_INCB);

milton->settings->upper_button = gui->upper_radio;

ImGui::Separator();

ImGui::Text(loc(TXT_stylus_lower_button_function));

strcpy(result, loc(TXT_default)); // copy string one into the result.
strcat(result, "##lower");
ImGui::RadioButton(result, &gui->lower_radio, STYLUS_DEFAULT);
ImGui::SameLine();

strcpy(result, loc(TXT_eraser)); // copy string one into the result.
strcat(result, "##lower");
ImGui::RadioButton(result, &gui->lower_radio, STYLUS_ERASER);
ImGui::SameLine();

strcpy(result, loc(TXT_brush)); // copy string one into the result.
strcat(result, "##lower");
ImGui::RadioButton(result, &gui->lower_radio, STYLUS_BRUSH);

strcpy(result, loc(TXT_decrease_brush_size)); // copy string one into the result.
strcat(result, "##lower");
ImGui::RadioButton(result, &gui->lower_radio, STYLUS_DECB);

strcpy(result, loc(TXT_increase_brush_size)); // copy string one into the result.
strcat(result, "##lower");
ImGui::RadioButton(result, &gui->lower_radio, STYLUS_INCB);

milton->settings->lower_button = gui->lower_radio;

#endif
ImGui::Separator();

MiltonBindings* bs = &milton->settings->bindings;
Expand Down
5 changes: 5 additions & 0 deletions src/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ struct MiltonGui
MiltonSettings* original_settings;

char scratch_binding_key[Action_COUNT][2];

#ifdef __linux__
int upper_radio;
int lower_radio;
#endif
};

//
Expand Down
3 changes: 3 additions & 0 deletions src/localization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ init_localization()
EN(TXT_size_relative_to_canvas, "Size relative to canvas");
EN(TXT_grid_columns, "Grid Columns");
EN(TXT_grid_rows, "Grid Rows");
EN(TXT_default, "Default");
EN(TXT_stylus_lower_button_function, "Stylus Lower Button Function");
EN(TXT_stylus_upper_button_function, "Stylus Upper Button Function");

EN(TXT_Action_DECREASE_BRUSH_SIZE, "Decrease brush size");
EN(TXT_Action_INCREASE_BRUSH_SIZE, "Increase brush size");
Expand Down
4 changes: 4 additions & 0 deletions src/localization.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ enum Texts
TXT_size_relative_to_canvas,
TXT_grid_columns,
TXT_grid_rows,
TXT_default,
TXT_stylus_lower_button_function,
TXT_stylus_upper_button_function,


// Actions
TXT_Action_FIRST,
Expand Down
23 changes: 22 additions & 1 deletion src/milton.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#define HOVER_FLASH_THRESHOLD_MS 500 // How long does the hidden brush hover show when it has changed size.
#define MODE_STACK_MAX 64

#ifdef __linux__
#define STYLUS_BUTTON_NOT_PRESSED 0
#define STYLUS_BUTTON_PRESSED 1
#endif

struct MiltonGLState
{
GLuint quad_program;
Expand Down Expand Up @@ -98,12 +103,28 @@ enum PrimitiveFSM
Primitive_DONE,
};

#ifdef __linux__
enum MiltonStylusButtonFunction
{
STYLUS_DEFAULT,
STYLUS_ERASER,
STYLUS_BRUSH,
STYLUS_DECB,
STYLUS_INCB,
};
#endif

#pragma pack(push, 1)
struct MiltonSettings
{
v3f background_color;
float peek_out_increment;

#ifdef __linux__
int upper_button;
int lower_button;
#endif

MiltonBindings bindings;
};
#pragma pack(pop)
Expand Down Expand Up @@ -371,4 +392,4 @@ void drag_brush_size_start(Milton* milton, v2i pointer);
void drag_brush_size_stop(Milton* milton);

void drag_zoom_start(Milton* milton, v2i pointer);
void drag_zoom_stop(Milton* milton);
void drag_zoom_stop(Milton* milton);
6 changes: 6 additions & 0 deletions src/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ struct PlatformState
PlatformSpecific* specific;

float ui_scale;

#ifdef __linux__
//Stylus button states
int upper_button;
int lower_button;
#endif
};

typedef enum HistoryDebug
Expand Down
24 changes: 24 additions & 0 deletions src/sdl_milton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,30 @@ sdl_event_loop(Milton* milton, PlatformState* platform)
&& bit_touch
&& !( bit_upper || bit_lower );

#ifdef __linux__
// Save lower and upper button status from the stylus - otherwise it returns
// being pressed all the time
if(bit_lower && platform->lower_button == STYLUS_BUTTON_NOT_PRESSED) {
if(platform->lower_button == STYLUS_BUTTON_NOT_PRESSED) {
platform->lower_button = STYLUS_BUTTON_PRESSED;
}
}

if(!bit_lower && platform->lower_button == STYLUS_BUTTON_PRESSED) {
platform->lower_button = STYLUS_BUTTON_NOT_PRESSED;
}

if(bit_upper) {
if(platform->upper_button == STYLUS_BUTTON_NOT_PRESSED) {
platform->upper_button = STYLUS_BUTTON_PRESSED;
}
}

if(!bit_upper && platform->upper_button == STYLUS_BUTTON_PRESSED) {
platform->upper_button = STYLUS_BUTTON_NOT_PRESSED;
}
#endif

if ( taking_pen_input ) {
platform->is_pointer_down = true;

Expand Down

0 comments on commit 299c96f

Please sign in to comment.