Version 0.4.2
Pre-release
Pre-release
Overview
This release is a major refactor of the library with a renewed architecture, a ton of new features, ergonomics and performance improvements.
[0.4.2] - 2021-09-02
Added
Core
crate::prelude
andcrate::prelude_3d
for common imports.Copy
,Clone
,Debug
,Default
,PartialEq
,Eq
, andHash
implementations for many/most structs where appropriate.Serialize
andDeserialize
implemented for most structs with with theserde
feature enabled.- New optional
AppState
methods:on_key_pressed()
: Called on key press and key repeat.on_key_released()
: Called on key release.on_key_typed()
: Called on character typed (ignores special keys like Ctrl and Backspace).on_mouse_dragged()
: Called on mouse motion while button is being heled.on_mouse_pressed()
: Called on mouse button press.on_mouse_released()
: Called on mouse button release.on_mouse_clicked()
: Called on mouse button released followed by a press.on_mouse_dbl_clicked()
: Called on mouse button double click.on_mouse_motion()
: Called on mouse motion.on_mouse_wheel()
: Called on mouse wheel scroll.on_window_event()
: Called on a window event (e.g. closed, resized, moved).on_event()
: Called for every user or system event as a catch-all.
PixEngineBuilder
struct added with several settings for configuring the
PixEngine
initialization.
State
PixState
methods for interacting with the window andPixEngine
state:delta_time()
: Time elapsed since last frame.frame_count()
Total number of frame since application start.frame_rate()
: Average frames per second rendered.target_frame_rate()
: Target frame rate.set_frame_rate()
: Set target frame rate.clear_frame_rate()
: Clear target frame rate.quit()
: Quit the application.abort_quit()
: Abort quitting the application (useful in
AppState::on_stop()
as a confirmation).
PixState
methods for controlling drawing and thePixEngine
render loop:background()
: Set the color for clearing the screen and clear to it immediately.fill()
: Set the fill color for drawing operations.no_fill()
: Clear the fill color to transparent.stroke()
: Set the stroke color for drawing operations.no_stroke()
: Clear the stroke color to transparent.clip()
: Set a clipping rectangle for drawing to the canvas.no_clip()
: Clear the clipping rectangle.running()
: Whether the engine loop is running and calling
AppState::on_update()
or not.run()
: Start the engine loop if it's not already running.no_run()
: Disable the engine loop if it's currently running.redraw()
: Run render loop one time if it's not currently running.runtimes()
: Run render loop N times if it's not currently running.show_frame_rate()
: Set whether to show the average frame rate in the title
bar or not.scale()
: Set the X, Y rendering scale for the canvas. Note this is
different thanPixEngineBuilder::scale
which scales the window dimensions.font_size()
: Set the font size.size_of()
: Get the dimensions of a given string with the currentfont_size
.font_style()
: Set the font style (e.g. NORMAL, BOLD, ITALIC, UNDERLINE,
STRIKETHROUGH).font_family()
: Set the font family. (e.g. "courier_new.ttf").rect_mode()
: Set how (x, y) coordinates are treated for drawing squares
and rectangles.ellipse_mode()
: Set how (x, y) coordinates are treated
for drawing circles and ellipses.image_mode()
: Set how (x, y) coordinates are treated for drawing images.angle_mode()
: Set whether angles are interpreted asRadians
orDegrees
.blend_mode()
: Set drawing blend mode for images and textures.push()
: Save the current drawing settings to a stack.pop()
: Restore previous drawing settings from the stack.
Window
WindowBuilder
struct for opening windows:new()
: Create a newWindowBuilder
instance.with_dimensions()
: Set window (width, height).with_title()
: Set window title.position()
: Set window (x, y) position.position_centered()
: Center window in the display.fullscreen()
: Make the window fullscreen.resizable()
: Allow window resizing.borderless()
: Disable window border.scale()
: Set window dimension scale.icon()
: Set window icon.build()
: Build window fromWindowBuilder
and open it.
PixState
window methods:focused()
: Wether the current window target has focus.primary_window_id()
: The primary window ID.window_id()
: The current window target ID.window()
: Create a newWindowBuilder
.close_window()
: Close a given window.dimensions()
: The current window target (width, height) dimensions.set_dimensions()
: Set the current window target (width, height) dimensions.width()
: The current window target width.set_width()
: Set the current window target width.height()
: The current window target height.set_height()
: Set the current window target height.display_dimensionsc()
: The current display (width, height) dimensions.display_width()
: The current display width.display_height()
: The current display height.show_window()
: Show the current window target if hidden.hide_window()
: Hide the current window target if shown.fullscreen()
: Whether the application is currently in fullscreen mode.set_fullscreen()
: Set fullscreen to true or false.vsync()
: Whether vertical sync is enabled.set_vsync()
: Set vertical sync to true or false.cursor()
: Set the mouse cursor icon to either a system icon or custom image.no_cursor()
: Clear mouse cursor back to default.with_window()
: Target a window for drawing operations with a closure.
window::Result
andwindow::Error
for window related failures.
Drawing
ColorMode
enum withRgb
,Hsb
, andHsl
variants.Color
struct with several methods for creating and converting between color
modes.Color
macrosrgb!()
,hsb!()
, andhsl!()
.- Additional
Color
constants matching the SVG 1.0 Color
Keywords. color::Result
andcolor::Error
types for conversion failures.Draw
trait for types that can be drawn usingPixState
.- Several new shape drawing methods on
PixState
. - New
Texture
struct and methods for hardware-accelerated rendering. Light
andLightSource
structs for doing basic 3D light rendering.
UI
- New Immediate-mode UI drawing methods for buttons. More to come in future
versions.
Shapes
- Made shape structs generic over their type and number of dimensions using new
const generics. - Conversion implementations to convert shapes between units for better
ergonomics. Deref
andDerefMut
into an array of values representing a shape.IntoIterator
for structs where applicable.Contains
andIntersects
traits and implementations for defining collision
detection.Draw
implementations.Rect
struct extended with several constructor and utility methods.- Several new shape structs:
Ellipse
,Line
,Point
,Quad
,Sphere
, and
Tri
with convenience macros.
Image
- New
Image
methods for converting and manipulating images. image::Result
andimage::Error
for image failures.
Events
WindowEvent
struct.KeyMod
struct for detecting key modifiers on key press and release events.
Misc
math
module for noise and randomization utilities.Num
trait for generic number handling.Vector
type for doing N-dimensional vector math.- Attribution for
Emulogic
font. - New
katakana
provided font along with default unicode fonts for fallbacks. - Several new examples:
2d_raycasting
3d_raytracing
colors
flocking
fluid_simulation
image
matrix
maze
textures
- Extensive documentation additions and README improvements.
Changed
description
,category
andkeywords
updated inCargo.toml
.- Updated to resolver 2
inCargo.toml
- Updated
LICENSE.md
toMIT/Apache-2.0
. - Updated
README
, documentation and usage examples. - Updated and refined examples.
Breaking
Core
- Root imports have been removed in favor of
crate::prelude
. PixEngineResult
renamed toPixResult
.PixEngineErr
renamed toPixError
andPixEngineErr::new()
removed.PixEngine
State
generic parameter removed in favor of passing application
toPixEngine::run()
.PixEngine::new()
removed. UsePixEngine::builder()
instead.PixEngine::set_icon()
moved toPixEngineBuilder::icon()
and changed to
takeAsRef<Path>
.PixEngine::fullscreen()
moved toPixEngineBuilder::fullscreen()
.PixEngine::vsync()
moved toPixEngineBuilder::vsync()
.PixEngine::set_audio_sample_rate()
moved to
PixEngineBuilder::audio_sample_rate()
.PixEngine::run()
now takes a type that implementsAppState
and returns
PixResult
instead ofPixEngineResult
.
State
State
trait renamed toAppState
.StateData
struct renamed toPixState
. Affects all methods from theState
trait which was renamed toPixState
.AppState::on_start
,AppState::on_update
, andAppState::on_stop
changed
to returnPixResult<()>
. UsePixState::quit()
instead of returningfalse
in order to terminate the application.AppState::on_update
no longer takeselapsed
. UsePixState::delta_time()
instead.StateData::enable_coord_wrapping()
removed. UsePoint::wrap()
and
Vector::wrap()
methods instead.StateData::wrap_coords()
removed in favor ofPoint::wrap()
and
Vector::wrap()
methods.StateData::create_texture()
changed to takewidth
,height
and optionalPixelFormat
.StateData::copy_draw_target()
removed.StateData::copy_texture()
renamed toPixState::update_texture()
and
parameters changed to take&mut Texture
,Into<Option<Rect<i32>>>
,
AsRef<[u8]>
, andpitch
.StateData::is_inside_circle()
removed. UseEllipse::contains_point()
instead.
Window
WindowId
type changed fromu32
tousize
.StateData::open_window()
renamed toPixState::create_window()
which creates aWindowBuilder
.StateData::close_window()
renamed toPixState::close_window()
.StateData::main_window_id()
renamed toPixState::primary_window_id()
.StateData::screen_width()
renamed toPixState::width()
.StateData::screen_height()
renamed toPixState::height()
.StateData::set_screen_size()
renamed toPixState::set_dimensions()
and now
takes a tuple(u32, u32)
.StateData::is_focused()
renamed toPixState::focused()
.StateData::fullscreen()
renamed toPixState::fullscreen()
and changed to
return the current fullscreen state. UsePixState::set_fullscreen()
to change
state.StateData::vsync()
renamed toPixState::vsync()
and changed to return the
current vsync state. UsePixState::set_vsync()
to change state.StateData::create_window_texture()
removed.StateData::copy_window_draw_target()
removed.StateData::copy_window_texture()
removed.
Drawing
Pixel
renamed toColor
with members made private.AlphaMode
renamed toBlendMode
.Normal
renamed toNone
.Mask
removed.Add
andMod
added.StateData::construct_font()
removed in favor ofsdl2::ttf
.StateData::get_draw_target()
removed.StateData::set_draw_target()
removed. UsePixState::with_texture()
instead.StateData::get_draw_target_dims()
removed. UseTexture::dimensions()
instead.StateData::clear_draw_target()
removed. Draw target is only set within
PixState::with_texture()
callback.StateData::get_alpha_mode()
removed.StateData::set_alpha_mode()
renamed toPixState::blend_mode()
.StateData::set_alpha_blend()
removed.StateData::get_draw_color()
removed.StateData::set_draw_color()
replaced withPixState::background()
,
PixState::fill()
andPixState::stroke()
.StateData::reset_draw_color()
removed.StateData::set_draw_scale()
removed. UsePixEngineBuilder::scale()
or
PixState::scale()
methods instead.StateData::fill()
renamed toPixState::background()
.StateData::clear()
renamed toPixState::clear()
and updated to fill screen
with currentbackground
color.StateData::draw()
renamed toPixState::point()
which now takes an
Into<Point>
to draw with the currentstroke
color.StateData::draw_line()
renamed toPixState::line()
which now takes an
Into<Line>
to draw with the currentstroke
color.StateData::draw_line_i32()
removed.StateData::draw_line_pattern()
removed.StateData::draw_circle()
renamed toPixState::circle()
which now takes an
Into<Ellipse>
to draw with the currentstroke
color.StateData::draw_partial_circle()
renamed toPixState::arc()
which now takes an
Into<Point>
, radius, start, and end to draw with the currentfill
and
stroke
colors.StateData::fill_circle()
renamed toPixState::circle()
which now takes an
Into<Ellipse>
to draw with the currentfill
color.StateData::draw_elipse()
renamed toPixState::ellipse()
which now takes an
Into<Ellipse>
to draw with the currentstroke
color.StateData::fill_elipse()
renamed toPixState::ellipse()
which now takes an
Into<Ellipse>
to draw with the currentfill
color.StateData::draw_rect()
renamed toPixState::rect()
which now takes an
Into<Rect>
to draw with the currentstroke
color.StateData::fill_rect()
renamed toPixState::rect()
which now takes an
Into<Rect>
to draw with the currentfill
color.StateData::draw_triangle()
renamed toPixState::triangle()
which now takes an
Into<Triangle>
to draw with the currentstroke
color.StateData::fill_triangle()
renamed toPixState::triangle()
which now takes an
Into<Triangle>
to draw with the currentfill
color.StateData::draw_image()
renamed toPixState::image()
which now takes an
Into<Point>
.StateData::draw_partial_image()
removed.StateData::draw_string()
renamed toPixState::text()
which now takes a
Into<Point>
to draw with the currentfill
color.StateData::draw_wireframe()
renamed toPixState::wireframe()
which now takes a
&[Vector]
and anInto<Vector>
in addition to angle and scale to draw a
polygon with the currentstroke
andfill
colors.StateData::draw_transform()
removed.
Shapes
Rect
members made private. Use getter/setter methods to accessx
,y
,
width
, andheight
instead.
Image
ImageRef
struct removed along with all related methods:new_ref()
,
ref_from()
,rgb_ref()
, andrgba_ref()
.rgb()
renamed towith_rgb()
.rgba()
renamed towith_rgba()
.from_bytes()
updated to takePixelFormat
parameter and now returns
image::Result
.put_pixel()
renamed toset_pixel()
.get_pixel()
andput_pixel()
updated to return and acceptColor
.ColorType
renamed toPixelFormat
.color_type()
renamed toformat()
and returnsPixelFormat
.bytes()
renamed toas_bytes()
.bytes()
now returns anIterator
ofu8
instead ofVec<u8>
.bytes_mut()
renamed toas_mut_bytes()
and changed to return&mut [u8]
instead of&mut Vec<u8>
.from_file()
updated to takeAsRef<Path>
instead of&str
and returns
image::Result
.save_to_file()
renamed tosave()
, updated to takeAsRef<Path>
instead of
&str
and returnsimage::Result
.
Events
Input
renamed toKeyEvent
.released
removed.held
changed to
repeat
.key
andkeymod
added.Axis::Unknown
added andAxis
made[non_exhaustive]
.Button
renamed toControllerButton
.ControllerButton::Unknown
added and
ControllerButton
made[non_exhaustive]
.Key
made[non_exhaustive]
.Mouse::X1
andMouse::X2
removed andMouse
made[non_exhaustive]
.PixEvent
renamed toEvent
and made[non_exhaustive]
. Several new events
added or changed.State::get_key()
removed in favor ofPixState::keys()
,
PixState::key_pressed()
,PixState::key_down()
andAppState::on_key_*
methods.State::get_mouse()
removed in favor ofPixState::mouse_pos()
,
PixState::mouse_pressed()
,PixState::mouse_down()
,
PixState::mouse_buttons()
andAppState::on_mouse_*
methods.State::get_mouse_x()
removed.State::get_mouse_y()
removed.State::get_mouse_wheel()
removed in favor ofAppState::on_mouse_wheel()
.State::poll()
removed. Use theAppState::on_*
methods to respond to events.