File diff suppressed because it is too large
Load Diff
+60
-10
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "inter.h"
|
||||
#include "inter-bold.h"
|
||||
#include "font-awesome-solid.h"
|
||||
|
||||
extern bool should_exit;
|
||||
extern bool show_demo_window;
|
||||
@@ -23,6 +24,7 @@ static int current_day;
|
||||
//fonts
|
||||
static ImFont *inter_regular;
|
||||
static ImFont *inter_bold;
|
||||
static ImFont *font_awesome;
|
||||
|
||||
char *open_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];
|
||||
}
|
||||
|
||||
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() {
|
||||
hydro_init();
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
inter_regular = io.Fonts->AddFontFromMemoryCompressedTTF(inter_compressed_data, inter_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();
|
||||
save_file_path = (char *)calloc(1, 1);
|
||||
|
||||
ImGuiSettingsHandler settings_handler = {};
|
||||
settings_handler.TypeName = "Calendar";
|
||||
@@ -117,11 +127,6 @@ void init() {
|
||||
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 {
|
||||
bool editing;
|
||||
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 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(){
|
||||
if (!save_file_path) return;
|
||||
|
||||
@@ -183,7 +192,7 @@ void save(){
|
||||
|
||||
if (hydro_secretbox_encrypt((uint8_t *)encrypted_buffer, plaintext_buffer, offset, 0, HYDROGEN_CONTEXT, derived_key) != 0) {
|
||||
return; //TODO error message
|
||||
}
|
||||
}
|
||||
hydro_memzero(plaintext_buffer, sizeof(plaintext_buffer));
|
||||
|
||||
FILE *save_file = fopen(save_file_path, "wb");
|
||||
@@ -196,11 +205,12 @@ void save(){
|
||||
memcpy(title + strlen("Work Calendar - "), save_file_path, strlen(save_file_path));
|
||||
|
||||
set_window_title(title);
|
||||
free(title);
|
||||
free(title);
|
||||
|
||||
unsaved_changes = false;
|
||||
}
|
||||
|
||||
void load(){
|
||||
|
||||
FILE *save_file = fopen(save_file_path, "rb");
|
||||
size_t num_bytes = fread(encrypted_buffer, 1, sizeof(encrypted_buffer), save_file);
|
||||
fclose (save_file);
|
||||
@@ -251,11 +261,26 @@ void load(){
|
||||
|
||||
set_window_title(title);
|
||||
free(title);
|
||||
|
||||
unsaved_changes = false;
|
||||
}
|
||||
|
||||
void per_frame(){
|
||||
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();
|
||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||
|
||||
@@ -349,6 +374,7 @@ void per_frame(){
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
// save calendar file with password modal dialogue
|
||||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||
if (ImGui::BeginPopupModal(get_localized_string(LS_TITLE_ENTER_PASSWORD), NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
|
||||
@@ -389,6 +415,7 @@ void per_frame(){
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
// open calendar file with password modal dialogue
|
||||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||
if (ImGui::BeginPopupModal(get_localized_string(LS_TITLE_OPEN_PASSWORD), NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
|
||||
@@ -421,6 +448,7 @@ void per_frame(){
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
// close application modal dialogue
|
||||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||
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));
|
||||
@@ -595,6 +623,7 @@ void per_frame(){
|
||||
|
||||
//apply selected color to field
|
||||
if (selected_category != -1 && ImGui::IsItemClicked()) {
|
||||
unsaved_changes = true;
|
||||
for (int i = 0; i < num_categorized_days; i++) {
|
||||
if (categorized_days[i].year != year) continue;
|
||||
if (categorized_days[i].month != month) continue;
|
||||
@@ -673,6 +702,10 @@ void per_frame(){
|
||||
if (category.editing) {
|
||||
ImGui::SetNextItemWidth(-1);
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
@@ -680,11 +713,23 @@ void per_frame(){
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
ImGui::PopFont();
|
||||
|
||||
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++) {
|
||||
// Remove categorized days that have the to be deleted category
|
||||
if (categorized_days[j].category == i) {
|
||||
@@ -698,17 +743,22 @@ void per_frame(){
|
||||
// Remove the category
|
||||
for (size_t j = i; j < num_categories - 1; j++) categories[j] = categories[j + 1];
|
||||
num_categories--;
|
||||
unsaved_changes = true;
|
||||
}
|
||||
ImGui::PopFont();
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
ImGui::PushFont(font_awesome);
|
||||
if (ImGui::Button("+")) {
|
||||
categories[num_categories] = {};
|
||||
num_categories++;
|
||||
unsaved_changes = true;
|
||||
}
|
||||
ImGui::PopFont();
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user