Skip to content

Commit

Permalink
Zwischenstand
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Dec 4, 2023
1 parent 018862a commit dd8b161
Show file tree
Hide file tree
Showing 21 changed files with 433 additions and 98 deletions.
15 changes: 15 additions & 0 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ AudioInterface::AudioInterface(const Game_ConfigAudio& cfg) : cfg(cfg) {
Game_ConfigAudio AudioInterface::GetConfig() const {
auto acfg = cfg;
acfg.Hide();

#if !defined(HAVE_FLUIDSYNTH) && !defined(HAVE_FLUIDLITE)
acfg.fluidsynth_midi.SetOptionVisible(false);
acfg.soundfont.SetOptionVisible(false);
#endif
#ifndef HAVE_LIBWILDMIDI
acfg.wildmidi_midi.SetOptionVisible(false);
#endif
#ifndef HAVE_NATIVE_MIDI
acfg.native_midi.SetOptionVisible(false);
#endif
#ifndef WANT_FMMIDI
acfg.fmmidi_midi.SetOptionVisible(false);
#endif

vGetConfig(acfg);
return acfg;
}
Expand Down
21 changes: 20 additions & 1 deletion src/baseui.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,15 @@ class BaseUi {
/** Toggle whether we should show fps */
void ToggleShowFps();

/** Toggle wheter we should show fps on the titlebar */
/** Toggle whether we should show fps on the titlebar */
void ToggleShowFpsOnTitle();

/**
* Set whether the program pauses the execution when the program focus is lost.
* @param value
*/
void SetPauseWhenFocusLost(bool value);

/**
* @return the minimum amount of time each physical frame should take.
* If the UI manages time (i.e.) vsync, will return a 0 duration.
Expand All @@ -228,6 +234,15 @@ class BaseUi {
*/
void SetGameResolution(GameResolution resolution);

/**
* Opens the specified URL through the operating system.
* Opens a file browser when file:// is provided.
*
* @param url URL to open
* @return true when successful
*/
virtual bool OpenURL(StringView path) { (void)path; return false; }

/** Toggles "stretch to screen width" on or off */
virtual void ToggleStretch() {};

Expand Down Expand Up @@ -385,6 +400,10 @@ inline void BaseUi::ToggleShowFpsOnTitle() {
vcfg.fps_render_window.Toggle();
}

inline void BaseUi::SetPauseWhenFocusLost(bool value) {
vcfg.pause_when_focus_lost.Set(value);
}

inline Game_Clock::duration BaseUi::GetFrameLimit() const {
return IsFrameRateSynchronized() ? Game_Clock::duration(0) : frame_limit;
}
Expand Down
28 changes: 14 additions & 14 deletions src/bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,64 +334,64 @@ void Bitmap::HueChangeBlit(int x, int y, Bitmap const& src, Rect const& src_rect
}

Point Bitmap::TextDraw(Rect const& rect, int color, StringView text, Text::Alignment align) {
FontRef font = Font::Default();

switch (align) {
case Text::AlignLeft:
return TextDraw(rect.x, rect.y, color, text);
break;
case Text::AlignCenter: {
Rect text_rect = Text::GetSize(*font, text);
auto f = font ? font : Font::Default();
Rect text_rect = Text::GetSize(*f, text);
int dx = rect.x + (rect.width - text_rect.width) / 2;
return TextDraw(dx, rect.y, color, text);
break;
}
case Text::AlignRight: {
Rect text_rect = Text::GetSize(*font, text);
auto f = font ? font : Font::Default();
Rect text_rect = Text::GetSize(*f, text);
int dx = rect.x + rect.width - text_rect.width;
return TextDraw(dx, rect.y, color, text);
break;
}
default: assert(false);
}

return Point();
return {};
}

Point Bitmap::TextDraw(int x, int y, int color, StringView text, Text::Alignment align) {
auto font = Font::Default();
auto f = font ? font : Font::Default();
auto system = Cache::SystemOrBlack();
return Text::Draw(*this, x, y, *font, *system, color, text, align);
return Text::Draw(*this, x, y, *f, *system, color, text, align);
}

Point Bitmap::TextDraw(Rect const& rect, Color color, StringView text, Text::Alignment align) {
FontRef font = Font::Default();

switch (align) {
case Text::AlignLeft:
return TextDraw(rect.x, rect.y, color, text);
break;
case Text::AlignCenter: {
Rect text_rect = Text::GetSize(*font, text);
auto f = font ? font : Font::Default();
Rect text_rect = Text::GetSize(*f, text);
int dx = rect.x + (rect.width - text_rect.width) / 2;
return TextDraw(dx, rect.y, color, text);
break;
}
case Text::AlignRight: {
Rect text_rect = Text::GetSize(*font, text);
auto f = font ? font : Font::Default();
Rect text_rect = Text::GetSize(*f, text);
int dx = rect.x + rect.width - text_rect.width;
return TextDraw(dx, rect.y, color, text);
break;
}
default: assert(false);
}

return Point();
return {};
}

Point Bitmap::TextDraw(int x, int y, Color color, StringView text) {
auto font = Font::Default();
return Text::Draw(*this, x, y, *font, color, text);
auto f = font ? font : Font::Default();
return Text::Draw(*this, x, y, *f, color, text);
}

Rect Bitmap::TransformRectangle(const Transform& xform, const Rect& rect) {
Expand Down
20 changes: 16 additions & 4 deletions src/bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class Bitmap {
Color GetColorAt(int x, int y) const;

/**
* Draws text to bitmap using the Font::Default() font.
* Draws text to bitmap using the configured Font or the Font::Default() font.
*
* @param x x coordinate where text rendering starts.
* @param y y coordinate where text rendering starts.
Expand All @@ -246,7 +246,7 @@ class Bitmap {
Point TextDraw(int x, int y, int color, StringView text, Text::Alignment align = Text::AlignLeft);

/**
* Draws text to bitmap using the Font::Default() font.
* Draws text to bitmap using the configured Font or the Font::Default() font.
*
* @param rect bounding rectangle.
* @param color system color index.
Expand All @@ -257,7 +257,7 @@ class Bitmap {
Point TextDraw(Rect const& rect, int color, StringView text, Text::Alignment align = Text::AlignLeft);

/**
* Draws text to bitmap using the Font::Default() font.
* Draws text to bitmap using the configured Font or the Font::Default() font.
*
* @param x x coordinate where text rendering starts.
* @param y y coordinate where text rendering starts.
Expand All @@ -268,7 +268,7 @@ class Bitmap {
Point TextDraw(int x, int y, Color color, StringView text);

/**
* Draws text to bitmap using the Font::Default() font.
* Draws text to bitmap using the configured Font or the Font::Default() font.
*
* @param rect bounding rectangle.
* @param color text color.
Expand Down Expand Up @@ -587,6 +587,9 @@ class Bitmap {
int bpp() const;
int pitch() const;

FontRef GetFont() const;
void SetFont(FontRef font);

ImageOpacity ComputeImageOpacity() const;
ImageOpacity ComputeImageOpacity(Rect rect) const;

Expand All @@ -596,6 +599,7 @@ class Bitmap {
ImageOpacity image_opacity = ImageOpacity::Alpha_8Bit;
TileOpacity tile_opacity;
Color bg_color, sh_color;
FontRef font;

std::string filename;

Expand Down Expand Up @@ -672,4 +676,12 @@ inline StringView Bitmap::GetFilename() const {
return filename;
}

inline FontRef Bitmap::GetFont() const {
return font;
}

inline void Bitmap::SetFont(FontRef font) {
this->font = font;
}

#endif
11 changes: 11 additions & 0 deletions src/config_param.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define EP_CONFIG_PARAM_H

#include "string_view.h"
#include "filefinder.h"
#include <array>
#include <cstdint>
#include <lcf/inireader.h>
Expand Down Expand Up @@ -431,4 +432,14 @@ class EnumConfigParam : public ConfigParamBase<E> {
}
};

class PathConfigParam : public StringConfigParam {
public:
PathConfigParam(StringView name, StringView description, StringView config_section, StringView config_key, std::string value) :
StringConfigParam(name, description, config_section, config_key, value) {}

std::string ValueToString() const override {
return std::get<1>(FileFinder::GetPathAndFilename(Get()));
}
};

#endif
9 changes: 0 additions & 9 deletions src/filefinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,9 @@ namespace {
auto MOVIE_TYPES = { ".avi", ".mpg" };
#endif

std::string fonts_path;
std::shared_ptr<Filesystem> root_fs;
FilesystemView game_fs;
FilesystemView save_fs;

constexpr const auto IMG_TYPES = Utils::MakeSvArray(".bmp", ".png", ".xyz");
constexpr const auto MUSIC_TYPES = Utils::MakeSvArray(
".opus", ".oga", ".ogg", ".wav", ".mid", ".midi", ".mp3", ".wma");
constexpr const auto SOUND_TYPES = Utils::MakeSvArray(
".opus", ".oga", ".ogg", ".wav", ".mp3", ".wma");
constexpr const auto FONTS_TYPES = Utils::MakeSvArray(".fon", ".fnt", ".bdf", ".ttf", ".ttc", ".otf", ".woff2", ".woff");
constexpr const auto TEXT_TYPES = Utils::MakeSvArray(".txt", ".csv", ""); // "" = Complete Filename (incl. extension) provided by the user
}

FilesystemView FileFinder::Game() {
Expand Down
8 changes: 8 additions & 0 deletions src/filefinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
* insensitive files paths.
*/
namespace FileFinder {
constexpr const auto IMG_TYPES = Utils::MakeSvArray(".bmp", ".png", ".xyz");
constexpr const auto MUSIC_TYPES = Utils::MakeSvArray(
".opus", ".oga", ".ogg", ".wav", ".mid", ".midi", ".mp3", ".wma");
constexpr const auto SOUND_TYPES = Utils::MakeSvArray(
".opus", ".oga", ".ogg", ".wav", ".mp3", ".wma");
constexpr const auto FONTS_TYPES = Utils::MakeSvArray(".fon", ".fnt", ".bdf", ".ttf", ".ttc", ".otf", ".woff2", ".woff");
constexpr const auto TEXT_TYPES = Utils::MakeSvArray(".txt", ".csv", ""); // "" = Complete Filename (incl. extension) provided by the user

/**
* Quits FileFinder.
*/
Expand Down
18 changes: 16 additions & 2 deletions src/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ FontRef Font::CreateFtFont(Filesystem_Stream::InputStream is, int size, bool bol

FreeFontMemory();

std::string key = ToString(is.GetName()) + ":" + (bold ? "T" : "F") + (italic ? "T" : "F");
std::string key = ToString(is.GetName()) + ":" + std::to_string(size) + ":" + (bold ? "T" : "F") + (italic ? "T" : "F");

auto it = ft_cache.find(key);

Expand All @@ -594,10 +594,24 @@ FontRef Font::CreateFtFont(Filesystem_Stream::InputStream is, int size, bool bol
void Font::ResetDefault() {
SetDefault(nullptr, true);
SetDefault(nullptr, false);

#ifdef HAVE_FREETYPE
const auto& cfg = Player::player_config;
if (!cfg.font1.Get().empty()) {
auto is = FileFinder::Root().OpenInputStream(cfg.font1.Get());
SetDefault(CreateFtFont(std::move(is), cfg.font1_size.Get(), false, false), false);
}

if (!cfg.font2.Get().empty()) {
auto is = FileFinder::Root().OpenInputStream(cfg.font2.Get());
SetDefault(CreateFtFont(std::move(is), cfg.font2_size.Get(), false, false), true);
}
#endif
}

void Font::Dispose() {
ResetDefault();
SetDefault(nullptr, true);
SetDefault(nullptr, false);

#ifdef HAVE_FREETYPE
if (library) {
Expand Down
Loading

0 comments on commit dd8b161

Please sign in to comment.