/*
        Frank Lyonnet 1993
        Settings Module
*/

#include "Bool.h"
#include "Settings.h"
#include "FYEOPaths.h"
#include "Modes.h"
#include <stdio.h>
#include "Erreur.h"
#include "RISC_OSLib:msgs.h"

void output_settings_default(output_settings * Output)
{
   Output -> UseCurrent = TRUE;
   Output -> Bpp = get_mode_bpp(get_cur_mode());
   if(Output -> Bpp < 8 )
      Output -> Bpp = 8;
   Output -> XDpi = get_mode_xdpi(get_cur_mode());
   Output -> YDpi = get_mode_ydpi(get_cur_mode());
   Output -> ColorSpace = FYEO_RGB;
   Output -> Scaling = FYEO_SCAL_1;
   Output -> CustomXMul = 1;
   Output -> CustomXDiv = 1;
   Output -> CustomYMul = 1;
   Output -> CustomYDiv = 1;
   Output -> Dither = DITHER_FLOYD;
}



void input_settings_default(input_settings * Input)
{
   Input -> XDpi = 90;
   Input -> YDpi = 90;
}

void misc_settings_default(misc_settings * Misc)
{
   Misc -> AutoFiletype = TRUE;
}

BOOL settings_load(FYEO_settings * Settings)
{
   // modified by Rick, 2004/02/25 while trying to find out why it failed...
   FILE *FSetts;

   FSetts = fopen(PREFS_PATH , "r");
   if ( FSetts == NULL )
      return(FALSE);

   fread(Settings, sizeof(FYEO_settings), 1, FSetts);
   fclose(FSetts);
   return(TRUE);
}



void settings_save(FYEO_settings * Settings)
{
    FILE *FSetts;

 if ((FSetts = fopen(PREFS_PATH, "w")) == NULL)
    erreur_fatal("Couldn't save Preferences !\n");
 fwrite(Settings, sizeof(FYEO_settings), 1, FSetts);
 fclose(FSetts);
}


void output_settings_mode_change_dependencies(output_settings * Output) {
   Output -> FillX = get_mode_width(get_cur_mode());
   Output -> FillY = get_mode_height(get_cur_mode());
   if(Output -> UseCurrent)
   {
      Output -> Bpp = get_mode_bpp(get_cur_mode());
      if(Output -> Bpp < 8 )
         Output -> Bpp = 8;
       Output -> XDpi = get_mode_xdpi(get_cur_mode());
       Output -> YDpi = get_mode_ydpi(get_cur_mode());
   };
}
