File diff suppressed because it is too large
Load Diff
+58
-8
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "inter.h"
|
#include "inter.h"
|
||||||
#include "inter-bold.h"
|
#include "inter-bold.h"
|
||||||
|
#include "font-awesome-solid.h"
|
||||||
|
|
||||||
extern bool should_exit;
|
extern bool should_exit;
|
||||||
extern bool show_demo_window;
|
extern bool show_demo_window;
|
||||||
@@ -23,6 +24,7 @@ static int current_day;
|
|||||||
//fonts
|
//fonts
|
||||||
static ImFont *inter_regular;
|
static ImFont *inter_regular;
|
||||||
static ImFont *inter_bold;
|
static ImFont *inter_bold;
|
||||||
|
static ImFont *font_awesome;
|
||||||
|
|
||||||
char *open_file_dialog();
|
char *open_file_dialog();
|
||||||
char *save_file_dialog();
|
char *save_file_dialog();
|
||||||
@@ -89,12 +91,20 @@ const char *get_localized_string(Localized_String localized_string) {
|
|||||||
return localized_strings_storage[L_ENGLISH][localized_string];
|
return localized_strings_storage[L_ENGLISH][localized_string];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Localized_String month_names[] = { LS_JANUARY, LS_FEBRUARY, LS_MARCH, LS_APRIL, LS_MAY, LS_JUNE, LS_JULY, LS_AUGUST, LS_SEPTEMBER, LS_OCTOBER, LS_NOVEMBER, LS_DECEMBER };
|
||||||
|
|
||||||
|
static char *save_file_path = NULL;
|
||||||
|
static const char *wiki_url = "https://gitea.ammerhai.com/Ammerhai/work-calendar/wiki";
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
hydro_init();
|
hydro_init();
|
||||||
ImGuiIO &io = ImGui::GetIO();
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
inter_regular = io.Fonts->AddFontFromMemoryCompressedTTF(inter_compressed_data, inter_compressed_size);
|
inter_regular = io.Fonts->AddFontFromMemoryCompressedTTF(inter_compressed_data, inter_compressed_size);
|
||||||
inter_bold = io.Fonts->AddFontFromMemoryCompressedTTF(inter_bold_compressed_data, inter_bold_compressed_size);
|
inter_bold = io.Fonts->AddFontFromMemoryCompressedTTF(inter_bold_compressed_data, inter_bold_compressed_size);
|
||||||
|
font_awesome = io.Fonts->AddFontFromMemoryCompressedTTF(font_awesome_solid_compressed_data, font_awesome_solid_compressed_size, 16.0f);
|
||||||
|
|
||||||
year = get_current_year();
|
year = get_current_year();
|
||||||
|
save_file_path = (char *)calloc(1, 1);
|
||||||
|
|
||||||
ImGuiSettingsHandler settings_handler = {};
|
ImGuiSettingsHandler settings_handler = {};
|
||||||
settings_handler.TypeName = "Calendar";
|
settings_handler.TypeName = "Calendar";
|
||||||
@@ -117,11 +127,6 @@ void init() {
|
|||||||
ImGui::AddSettingsHandler(&settings_handler);
|
ImGui::AddSettingsHandler(&settings_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *save_file_path = NULL;
|
|
||||||
static const char *wiki_url = "https://gitea.ammerhai.com/Ammerhai/work-calendar/wiki";
|
|
||||||
|
|
||||||
static Localized_String month_names[] = { LS_JANUARY, LS_FEBRUARY, LS_MARCH, LS_APRIL, LS_MAY, LS_JUNE, LS_JULY, LS_AUGUST, LS_SEPTEMBER, LS_OCTOBER, LS_NOVEMBER, LS_DECEMBER };
|
|
||||||
|
|
||||||
typedef struct Category {
|
typedef struct Category {
|
||||||
bool editing;
|
bool editing;
|
||||||
ImColor color;
|
ImColor color;
|
||||||
@@ -156,6 +161,10 @@ static ImVec4 table_hover_color = ImVec4(0.0f, 0.3f, 0.6f, 0.2f);
|
|||||||
static char plaintext_buffer[2 * 1024 * 1024] = {};
|
static char plaintext_buffer[2 * 1024 * 1024] = {};
|
||||||
static char encrypted_buffer[hydro_secretbox_HEADERBYTES + sizeof(plaintext_buffer)];
|
static char encrypted_buffer[hydro_secretbox_HEADERBYTES + sizeof(plaintext_buffer)];
|
||||||
|
|
||||||
|
static bool unsaved_changes;
|
||||||
|
static bool last_frame_unsaved_changes;
|
||||||
|
static char *category_name_before_editing = NULL;
|
||||||
|
|
||||||
void save(){
|
void save(){
|
||||||
if (!save_file_path) return;
|
if (!save_file_path) return;
|
||||||
|
|
||||||
@@ -197,10 +206,11 @@ void save(){
|
|||||||
|
|
||||||
set_window_title(title);
|
set_window_title(title);
|
||||||
free(title);
|
free(title);
|
||||||
|
|
||||||
|
unsaved_changes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void load(){
|
void load(){
|
||||||
|
|
||||||
FILE *save_file = fopen(save_file_path, "rb");
|
FILE *save_file = fopen(save_file_path, "rb");
|
||||||
size_t num_bytes = fread(encrypted_buffer, 1, sizeof(encrypted_buffer), save_file);
|
size_t num_bytes = fread(encrypted_buffer, 1, sizeof(encrypted_buffer), save_file);
|
||||||
fclose (save_file);
|
fclose (save_file);
|
||||||
@@ -251,11 +261,26 @@ void load(){
|
|||||||
|
|
||||||
set_window_title(title);
|
set_window_title(title);
|
||||||
free(title);
|
free(title);
|
||||||
|
|
||||||
|
unsaved_changes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void per_frame(){
|
void per_frame(){
|
||||||
current_language = selected_language;
|
current_language = selected_language;
|
||||||
|
|
||||||
|
if(last_frame_unsaved_changes != unsaved_changes) {
|
||||||
|
char *title = (char *)calloc(1, strlen("Work Calendar - ") + strlen(save_file_path) + 2);
|
||||||
|
memcpy(title, "Work Calendar - ", strlen("Work Calendar - "));
|
||||||
|
memcpy(title + strlen(title), save_file_path, strlen(save_file_path));
|
||||||
|
if(unsaved_changes)
|
||||||
|
memcpy(title + strlen(title), "*", 1);
|
||||||
|
|
||||||
|
set_window_title(title);
|
||||||
|
free(title);
|
||||||
|
|
||||||
|
last_frame_unsaved_changes = unsaved_changes;
|
||||||
|
}
|
||||||
|
|
||||||
ImGuiStyle &style = ImGui::GetStyle();
|
ImGuiStyle &style = ImGui::GetStyle();
|
||||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||||
|
|
||||||
@@ -349,6 +374,7 @@ void per_frame(){
|
|||||||
ImGui::EndMainMenuBar();
|
ImGui::EndMainMenuBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save calendar file with password modal dialogue
|
||||||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||||
if (ImGui::BeginPopupModal(get_localized_string(LS_TITLE_ENTER_PASSWORD), NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
|
if (ImGui::BeginPopupModal(get_localized_string(LS_TITLE_ENTER_PASSWORD), NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
|
||||||
@@ -389,6 +415,7 @@ void per_frame(){
|
|||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// open calendar file with password modal dialogue
|
||||||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||||
if (ImGui::BeginPopupModal(get_localized_string(LS_TITLE_OPEN_PASSWORD), NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
|
if (ImGui::BeginPopupModal(get_localized_string(LS_TITLE_OPEN_PASSWORD), NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
|
||||||
@@ -421,6 +448,7 @@ void per_frame(){
|
|||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// close application modal dialogue
|
||||||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||||
if (ImGui::BeginPopupModal(get_localized_string(LS_CLOSE), NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize)) {
|
if (ImGui::BeginPopupModal(get_localized_string(LS_CLOSE), NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||||
ImGui::Text("%s", get_localized_string(LS_QUESTION_DO_YOU_REALLY_WANT_TO_QUIT));
|
ImGui::Text("%s", get_localized_string(LS_QUESTION_DO_YOU_REALLY_WANT_TO_QUIT));
|
||||||
@@ -595,6 +623,7 @@ void per_frame(){
|
|||||||
|
|
||||||
//apply selected color to field
|
//apply selected color to field
|
||||||
if (selected_category != -1 && ImGui::IsItemClicked()) {
|
if (selected_category != -1 && ImGui::IsItemClicked()) {
|
||||||
|
unsaved_changes = true;
|
||||||
for (int i = 0; i < num_categorized_days; i++) {
|
for (int i = 0; i < num_categorized_days; i++) {
|
||||||
if (categorized_days[i].year != year) continue;
|
if (categorized_days[i].year != year) continue;
|
||||||
if (categorized_days[i].month != month) continue;
|
if (categorized_days[i].month != month) continue;
|
||||||
@@ -673,6 +702,10 @@ void per_frame(){
|
|||||||
if (category.editing) {
|
if (category.editing) {
|
||||||
ImGui::SetNextItemWidth(-1);
|
ImGui::SetNextItemWidth(-1);
|
||||||
if (ImGui::InputText("##name", category.name, IM_ARRAYSIZE(category.name), ImGuiInputTextFlags_EnterReturnsTrue)) {
|
if (ImGui::InputText("##name", category.name, IM_ARRAYSIZE(category.name), ImGuiInputTextFlags_EnterReturnsTrue)) {
|
||||||
|
if (strcmp(category_name_before_editing, category.name) != 0) {
|
||||||
|
unsaved_changes = true;
|
||||||
|
}
|
||||||
|
free(category_name_before_editing);
|
||||||
category.editing = false;
|
category.editing = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -680,11 +713,23 @@ void per_frame(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImGui::TableSetColumnIndex(2);
|
ImGui::TableSetColumnIndex(2);
|
||||||
if (ImGui::Button("e"))
|
ImGui::PushFont(font_awesome);
|
||||||
|
if (ImGui::Button("\uf304")) {
|
||||||
|
if(!category.editing) {
|
||||||
|
category_name_before_editing = _strdup(category.name);
|
||||||
|
} else {
|
||||||
|
if (strcmp(category_name_before_editing, category.name) != 0) {
|
||||||
|
unsaved_changes = true;
|
||||||
|
}
|
||||||
|
free(category_name_before_editing);
|
||||||
|
}
|
||||||
category.editing = !category.editing;
|
category.editing = !category.editing;
|
||||||
|
}
|
||||||
|
ImGui::PopFont();
|
||||||
|
|
||||||
ImGui::TableSetColumnIndex(3);
|
ImGui::TableSetColumnIndex(3);
|
||||||
if (ImGui::Button("d")) {
|
ImGui::PushFont(font_awesome);
|
||||||
|
if (ImGui::Button("\uf1f8")) {
|
||||||
for (size_t j = 0; j < num_categorized_days; j++) {
|
for (size_t j = 0; j < num_categorized_days; j++) {
|
||||||
// Remove categorized days that have the to be deleted category
|
// Remove categorized days that have the to be deleted category
|
||||||
if (categorized_days[j].category == i) {
|
if (categorized_days[j].category == i) {
|
||||||
@@ -698,17 +743,22 @@ void per_frame(){
|
|||||||
// Remove the category
|
// Remove the category
|
||||||
for (size_t j = i; j < num_categories - 1; j++) categories[j] = categories[j + 1];
|
for (size_t j = i; j < num_categories - 1; j++) categories[j] = categories[j + 1];
|
||||||
num_categories--;
|
num_categories--;
|
||||||
|
unsaved_changes = true;
|
||||||
}
|
}
|
||||||
|
ImGui::PopFont();
|
||||||
|
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
ImGui::TableSetColumnIndex(0);
|
ImGui::TableSetColumnIndex(0);
|
||||||
|
ImGui::PushFont(font_awesome);
|
||||||
if (ImGui::Button("+")) {
|
if (ImGui::Button("+")) {
|
||||||
categories[num_categories] = {};
|
categories[num_categories] = {};
|
||||||
num_categories++;
|
num_categories++;
|
||||||
|
unsaved_changes = true;
|
||||||
}
|
}
|
||||||
|
ImGui::PopFont();
|
||||||
|
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user