Skip to content

Commit

Permalink
Added file dragging
Browse files Browse the repository at this point in the history
Made minor changes
  • Loading branch information
otidev committed Dec 23, 2023
1 parent 33ba44b commit c318d17
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
all: compile run

ifdef PUBLISH
ifdef RELEASE
WINDOWS = -mwindows
else
WINDOWS =
Expand Down
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,26 @@ A (kinda) fast Bible that anyone can use.

``=/-`` - Increase/Decrease wrap width

To change Bible versions, type `./bible -v <version>`.
### Versions

Currently, you can select from these versions:
Currently, the program comes with these versions:

* BBE
* KJV
* BSB (Berean Standard Bible)
* BBE (Bible In Basic English)
* KJV (King James Version / Authorized Version)
* AKJV (American KJV)
* UKJV (Updated KJV)
* WEB
* WEB (World English Bible)

***
(find them [here](books/); they are can be used out of the box)

To change Bible versions, drag a compatible file (with the format below) from the file explorer.

In the future, any file with the format:
***
Files with this format:

```xml
<bible lang="<language in Books.json>">
<bible lang="<any language in Books.json>">
<b> <!-- book -->
<c n="<chapterNumber>"> <!-- chapter -->
<v n="<verseNumber>"> <!-- verse -->
Expand All @@ -57,18 +61,18 @@ python text2xml.py <inputTextFile> <outputXMLFile> <(optional; defaults to "en")
and the file must be arranged as such:

```
Genesis\t1\t1\tIn the beginning God created the heavens and the earth.
Genesis\t1\t1\tIn the beginning God created the heavens and the earth.\n
```

*Note*: all `\t` should be replaced with actual tabs.
*Note*: all `\t` should be replaced with actual tabs, and `\n` should be replaced with a newline.

You can find an example [here](books/bsb.txt).

## Images

![Photo featuring John 1](docs/bible.png)
![Photo featuring Genesis 1 16](docs/bible2.png)



More stuff coming soon!

## Thanks
Expand Down
5 changes: 4 additions & 1 deletion src/Window.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ bool WindowIsOpen() {
}
}
break;
case SDL_DROPFILE:
strcpy(globalWindow->droppedFile, globalWindow->event.drop.file);
break;
}
}

Expand Down Expand Up @@ -95,8 +98,8 @@ int InitCores(Window* window, int width, int height) {
}

window->deltaTime = 0;

window->running = true;
for (int i = 0; i < 500; i++) window->droppedFile[i] = 0;
globalWindow = window;
return 0;
}
1 change: 1 addition & 0 deletions src/include/Include.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef struct Window {
bool fullscreen;
bool keys[256], lastKeys[256];
char textInput[500];
char droppedFile[500];
} Window;

typedef struct Waveform {
Expand Down
44 changes: 30 additions & 14 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ void HighlightVerse(Highlight* highlighter, BibleData* data, ezxml_t xmlBible, T
SDL_SetRenderDrawColor(globalWindow->renderer, data->bgColour.r, data->bgColour.g, data->bgColour.b, 0xff);
}

void ChangeBibleVersion(char* filename, BibleData* data, ezxml_t* xmlBible) {
*xmlBible = ezxml_parse_file(filename);
if (!ezxml_attr(*xmlBible, "lang")) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "FATAL ERROR: The file is not a formatted version!", globalWindow->window);
fprintf(stderr, "FATAL ERROR: %s is not a formatted bible version!", filename);
exit(1);
}
snprintf(data->lang, 3, "%s", ezxml_attr(*xmlBible, "lang"));
}

int main(int argc, char** argv) {
Window window;
if (InitCores(&window, 1280, 720)) return 1;
Expand Down Expand Up @@ -178,30 +188,29 @@ int main(int argc, char** argv) {
d.bgImgSrcColour = (SDL_Colour){0x00, 0x00, 0x00, 0xff};
d.bgImgDstColour = (SDL_Colour){0x00, 0x00, 0x00, 0xff};

ezxml_t xmlBible = ezxml_parse_file(bibleVersion);
snprintf(d.lang, 3, "%s", ezxml_attr(xmlBible, "lang"));
free(bibleVersion);

TTF_Font* font = TTF_OpenFont("../fonts/Cardo-Regular.ttf", d.origFontSize);
if (!font) {
fprintf(stderr, "Error: couldn't find font!");
cJSON* jsonBooks = GetRoot("../books/Books.json");
if (!jsonBooks) {
fprintf(stderr, "Error: couldn't find main file!");
return 0;
}

SDL_Surface* surfPtr = IMG_Load("../icons/biblelogo.ico");
SDL_SetWindowIcon(window.window, surfPtr);
SDL_FreeSurface(surfPtr);


cJSON* jsonBooks = GetRoot("../books/Books.json");
if (!jsonBooks) {
fprintf(stderr, "Error: couldn't find main file!");
TTF_Font* font = TTF_OpenFont("../fonts/Cardo-Regular.ttf", d.origFontSize);
if (!font) {
fprintf(stderr, "Error: couldn't find font!");
return 0;
}

LoadBibleIcon(&d, jsonBooks);

Book books[66];
ezxml_t xmlBible = NULL;
ChangeBibleVersion(bibleVersion, &d, &xmlBible);
printf("%s", d.lang);
OpenBook(&books[d.usedBook], font, &d, jsonBooks, xmlBible);
free(bibleVersion);
LoadBibleIcon(&d, jsonBooks);

Highlight highlighter;
highlighter.width = -1;
Expand All @@ -210,7 +219,6 @@ int main(int argc, char** argv) {
highlighter.verse = 0;
highlighter.colour = (SDL_Colour){0x00, 0x00, 0x00, 0x3f};

OpenBook(&books[d.usedBook], font, &d, jsonBooks, xmlBible);
TTF_SetFontSize(font, d.origFontSize + 5);
SDL_Surface* surf = TTF_RenderUTF8_Blended_Wrapped(font, "Enter Bible verse (format: book chapter verse): ", (SDL_Colour){255, 255, 255, 255}, window.width);
TTF_SetFontSize(font, d.origFontSize);
Expand Down Expand Up @@ -239,6 +247,14 @@ int main(int argc, char** argv) {
ScrollAndZoom(books, &d, font, jsonBooks, xmlBible, &text);
ChangeChapter(books, &d, font, jsonBooks, xmlBible, &text, &textTransition);

if (globalWindow->droppedFile[0] != 0) {
printf("ok");
CloseBook(&books[d.usedBook]);
ChangeBibleVersion(globalWindow->droppedFile, &d, &xmlBible);
OpenBook(&books[d.usedBook], font, &d, jsonBooks, xmlBible);
for (int i = 0; i < 500; i++) globalWindow->droppedFile[i] = 0;
}

if (window.keys[SDL_SCANCODE_EQUALS] && !window.lastKeys[SDL_SCANCODE_EQUALS]) {
CloseBook(&books[d.usedBook]);
if ((int)round(d.wrapWidth * d.wrapWidthMult) < window.width - 100)
Expand Down

0 comments on commit c318d17

Please sign in to comment.