framer

Slide-show application for nerds ☝️🤓

NameSizeMode
..
src/main.c 2686B -rw-r--r--
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>

#include "raylib.h"
#include "frames.h"

#define MONITOR_WIDTH  1366
#define MONITOR_HEIGHT 768

static void *libplug = NULL;
void (*plug_load_frames)(Frames *fs);

bool reload_libplug(char *libplug_path)
{
  if (libplug != NULL) dlclose(libplug);

  libplug = dlopen(libplug_path, RTLD_NOW);
  if (libplug == NULL) {
    TraceLog(LOG_ERROR, "HOTRELOAD: could not load %s: %s",
             libplug_path, dlerror());
    return false;
  }

  const char *symbol = "plug_load_frames";
  plug_load_frames = dlsym(libplug, symbol);
  if (plug_load_frames == NULL) {
    TraceLog(LOG_ERROR, "HOTRELOAD: could not find %s symbol in %s: %s",
             symbol, libplug_path, dlerror());
    return false;
  }

  return true;
}

int main(int argc, char **argv)
{
  char * program_name = nob_shift(argv, argc);

  if (argc == 0) {
    TraceLog(LOG_ERROR, "No libplug path provided");
    TraceLog(LOG_ERROR, "USAGE: %s <libplug.so>", program_name);
    return EXIT_FAILURE;
  }

  char *libplug_path = nob_shift(argv, argc);
  if (!reload_libplug(libplug_path)) return EXIT_FAILURE;

  int width  = 800;
  int height = 450;

  float monitor_scale = (float)MONITOR_WIDTH/(float)width;

  InitWindow(width, height, "\"introdução a assembly\" slides");
  SetTargetFPS(60);
  SetExitKey(KEY_Q);

  Frames fs = {0};
  frames_load(&fs, plug_load_frames);

  float scale = 1.0;
  bool was_g_last_pressed  = false;
  while (!WindowShouldClose()) {
    if (IsWindowFullscreen()) {
      scale = monitor_scale;
      SetWindowSize(MONITOR_WIDTH, MONITOR_HEIGHT);
    } else {
      scale = 1.0;
      SetWindowSize(width, height);
    }

    int pressed = GetCharPressed();
    switch (pressed) {
    case 0: break;
    case 'G':
      frames_last(&fs);
      was_g_last_pressed = false;
      break;
    case 'g':
      if (was_g_last_pressed) {
        frames_first(&fs);
        was_g_last_pressed = false;
      } else {
        was_g_last_pressed = true;
      }
      break;
    case 'F':
    case 'f':
      ToggleFullscreen();
      was_g_last_pressed = false;
      break;
    case 'J':
    case 'j':
    case ' ':
      frames_next(&fs);
      was_g_last_pressed = false;
      break;
    case 'K':
    case 'k':
      frames_prev(&fs);
      was_g_last_pressed = false;
      break;
    case 'r':
    case 'R':
      if (!reload_libplug(libplug_path)) return EXIT_FAILURE;
      frames_load(&fs, plug_load_frames);
      was_g_last_pressed = false;
      break;
    default:
      was_g_last_pressed = false;
    }

    frames_tick(&fs, GetFrameTime());
    frames_draw(&fs, scale);
  }

  CloseWindow();

  return EXIT_SUCCESS;
}