using System;
using StardewModdingAPI.Framework;
namespace StardewModdingAPI.Events
{
/// Events raised during the game's draw loop, when the game is rendering content to the window.
public static class GraphicsEvents
{
/*********
** Events
*********/
/****
** Generic events
****/
/// Raised after the game window is resized.
public static event EventHandler Resize;
/****
** Main render events
****/
/// Raised before drawing the world to the screen.
public static event EventHandler OnPreRenderEvent;
/// Raised after drawing the world to the screen.
public static event EventHandler OnPostRenderEvent;
/****
** HUD events
****/
/// Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The HUD is available at this point, but not necessarily visible. (For example, the event is raised even if a menu is open.)
public static event EventHandler OnPreRenderHudEvent;
/// Raised after drawing the HUD (item toolbar, clock, etc) to the screen. The HUD is available at this point, but not necessarily visible. (For example, the event is raised even if a menu is open.)
public static event EventHandler OnPostRenderHudEvent;
/****
** GUI events
****/
/// Raised before drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen.
public static event EventHandler OnPreRenderGuiEvent;
/// Raised after drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen.
public static event EventHandler OnPostRenderGuiEvent;
/*********
** Internal methods
*********/
/****
** Generic events
****/
/// Raise a event.
/// Encapsulates monitoring and logging.
/// The object which raised the event.
/// The event arguments.
internal static void InvokeResize(IMonitor monitor, object sender, EventArgs e)
{
monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.Resize)}", GraphicsEvents.Resize?.GetInvocationList(), sender, e);
}
/****
** Main render events
****/
/// Raise an event.
/// Encapsulates monitoring and logging.
internal static void InvokeOnPreRenderEvent(IMonitor monitor)
{
monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPreRenderEvent)}", GraphicsEvents.OnPreRenderEvent?.GetInvocationList());
}
/// Raise an event.
/// Encapsulates monitoring and logging.
internal static void InvokeOnPostRenderEvent(IMonitor monitor)
{
monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderEvent)}", GraphicsEvents.OnPostRenderEvent?.GetInvocationList());
}
/// Get whether there are any post-render event listeners.
internal static bool HasPostRenderListeners()
{
return GraphicsEvents.OnPostRenderEvent != null;
}
/****
** GUI events
****/
/// Raise an event.
/// Encapsulates monitoring and logging.
internal static void InvokeOnPreRenderGuiEvent(IMonitor monitor)
{
monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPreRenderGuiEvent)}", GraphicsEvents.OnPreRenderGuiEvent?.GetInvocationList());
}
/// Raise an event.
/// Encapsulates monitoring and logging.
internal static void InvokeOnPostRenderGuiEvent(IMonitor monitor)
{
monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderGuiEvent)}", GraphicsEvents.OnPostRenderGuiEvent?.GetInvocationList());
}
/****
** HUD events
****/
/// Raise an event.
/// Encapsulates monitoring and logging.
internal static void InvokeOnPreRenderHudEvent(IMonitor monitor)
{
monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPreRenderHudEvent)}", GraphicsEvents.OnPreRenderHudEvent?.GetInvocationList());
}
/// Raise an event.
/// Encapsulates monitoring and logging.
internal static void InvokeOnPostRenderHudEvent(IMonitor monitor)
{
monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderHudEvent)}", GraphicsEvents.OnPostRenderHudEvent?.GetInvocationList());
}
}
}