Skip to content

Commit

Permalink
Ensure code examples are autoformatted
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed May 13, 2021
1 parent c514676 commit 9984353
Showing 25 changed files with 111 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ jobs:
- name: Install dependencies
run: pip install -r docs/requirements.txt
- name: Build site
run: mkdocs build
run: LINT=1 mkdocs build
- name: Deploy to gh-pages
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: oprypin/push-to-gh-pages@v3
12 changes: 6 additions & 6 deletions docs/api/audio.md
Original file line number Diff line number Diff line change
@@ -862,7 +862,7 @@ if SF::SoundBufferRecorder.available?
# Record some audio data
recorder = SF::SoundBufferRecorder.new
recorder.start()
...
[...]
recorder.stop()
# Get the buffer containing the captured audio data
@@ -1020,23 +1020,23 @@ class CustomRecorder < SF::SoundRecorder
def on_start() # optional
# Initialize whatever has to be done before the capture starts
...
[...]
# Return true to start playing
true
end
def on_process_samples(samples)
# Do something with the new chunk of samples (store them, send them, ...)
...
[...]
# Return true to continue playing
true
end
def on_stop() # optional
# Clean up whatever has to be done after the capture ends
...
[...]
end
end
@@ -1047,7 +1047,7 @@ if (CustomRecorder.isAvailable())
if (!recorder.start())
return -1
...
[...]
recorder.stop()
end
```
@@ -1486,7 +1486,7 @@ Usage example:
class CustomStream < SF::SoundStream
def initialize(location : String)
# Open the source and get audio settings
...
[...]
# Initialize the stream -- important!
super(channel_count, sample_rate)
14 changes: 7 additions & 7 deletions docs/api/graphics.md
Original file line number Diff line number Diff line change
@@ -203,7 +203,7 @@ circle.radius = 150
circle.outline_color = SF::Color::Red
circle.outline_thickness = 5
circle.position = {10, 20}
...
[...]
window.draw circle
```

@@ -580,7 +580,7 @@ polygon[2] = SF.vector2f(25, 5)
polygon.outline_color = SF::Color::Red
polygon.outline_thickness = 5
polygon.position = {10, 20}
...
[...]
window.draw polygon
```

@@ -806,7 +806,7 @@ class MyDrawable
# ... or draw with OpenGL directly
glBegin(GL_QUADS)
...
[...]
glEnd()
end
@@ -1381,7 +1381,7 @@ rectangle.size = SF.vector2f(100, 50)
rectangle.outline_color = SF::Color::Red
rectangle.outline_thickness = 5
rectangle.position = {10, 20}
...
[...]
window.draw rectangle
```

@@ -2301,16 +2301,16 @@ window = SF::RenderWindow.new(SF::VideoMode.new(800, 600), "SFML OpenGL")
# Create a sprite and a text to display
sprite = SF::Sprite.new
text = SF::Text.new
...
[...]
# Perform OpenGL initializations
glMatrixMode(GL_PROJECTION)
...
[...]
# Start the rendering loop
while window.open?
# Process events
...
[...]
# Draw a background sprite
window.push_gl_states()
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -6,3 +6,4 @@ git+https://github.com/oprypin/mkdocstrings-crystal@master
git+https://github.com/oprypin/mkdocs-literate-nav@master
git+https://github.com/oprypin/mkdocs-section-index@master
git+https://github.com/oprypin/mkdocs-gen-files@master
git+https://github.com/oprypin/mkdocs-code-validator@master
14 changes: 7 additions & 7 deletions docs/tutorials/audio/recording.md
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ This can be achieved with the very simple interface of the [SF::SoundBufferRecor
# first check if an input audio device is available on the system
if !SF::SoundBufferRecorder.available?
# error: audio capture is not available on this system
...
[...]
end
# create the recorder
@@ -79,8 +79,8 @@ recorder = SF::SoundBufferRecorder.new
# set the device
unless recorder.device = input_device
# error: device selection failed
...
# error: device selection failed
[...]
end
# use recorder as usual
@@ -106,23 +106,23 @@ Here is the skeleton of a complete derived class:
class MyRecorder < SF::SoundRecorder
def on_start # optional
# initialize whatever has to be done before the capture starts
...
[...]
# return true to start the capture, or false to cancel it
true
end
def on_process_samples(samples, sample_count)
# do something useful with the new chunk of samples
...
[...]
# return true to continue the capture, or false to stop it
true
end
def on_stop # optional
# clean up whatever has to be done after the capture is finished
...
[...]
end
end
```
@@ -136,7 +136,7 @@ end
recorder = MyRecorder.new
recorder.start
...
[...]
recorder.stop
```
5 changes: 2 additions & 3 deletions docs/tutorials/audio/sounds.md
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ Now that the audio data is loaded, we can play it with a [SF::Sound][] instance.

```crystal
# load something into the sound buffer...
buffer = ...
buffer = [...]
sound = SF::Sound.new(buffer)
sound.play
@@ -125,7 +125,7 @@ Remember that a music needs its source as long as it is played. A music file on

```crystal
# we start with a music file in memory (imagine that we extracted it from a zip archive)
file_data = ...
file_data = [...]
# we play it
music = SF::Music.from_memory(file_data)
@@ -136,4 +136,3 @@ file_data.clear
# ERROR: the music was still streaming the contents of file_data! The behavior is now undefined
```

6 changes: 3 additions & 3 deletions docs/tutorials/audio/streams.md
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ In order to define your own audio stream, you need to inherit from the [SF::Soun

```crystal
class MyAudioStream < SF::SoundStream
def on_get_data() : Slice(Int16)?
def on_get_data : Slice(Int16)?
end
def on_seek(time_offset : Time)
@@ -28,7 +28,7 @@ end

```crystal
class MyAudioStream < SF::SoundStream
def get_data()
def get_data
samples_array.to_slice
end
end
@@ -82,7 +82,7 @@ class MyStream < SF::SoundStream
super(buffer.channel_count, buffer.sample_rate)
end
def on_get_data()
def on_get_data
# number of samples to stream every time the function is called;
# in a more robust implementation, it should be a fixed
# amount of time rather than an arbitrary number of samples
2 changes: 1 addition & 1 deletion docs/tutorials/graphics/draw.md
Original file line number Diff line number Diff line change
@@ -117,7 +117,7 @@ thread.launch
# the event/logic/whatever loop
while window.open?
...
[...]
end
```

7 changes: 3 additions & 4 deletions docs/tutorials/graphics/shader.md
Original file line number Diff line number Diff line change
@@ -51,14 +51,14 @@ Shaders can also be loaded directly from strings, with the `from_memory` class m
vertex_shader = "
void main()
{
...
[...]
}
"
fragment_shader = "
void main()
{
...
[...]
}
"
@@ -177,7 +177,7 @@ To activate a [SF::Shader][] for drawing (the equivalent of `glUseProgram`), you

```crystal
shader = SF::Shader.new
...
[...]
# bind the shader
SF::Shader.bind(shader)
@@ -187,4 +187,3 @@ SF::Shader.bind(shader)
# bind no shader
SF::Shader.bind(nil)
```

6 changes: 4 additions & 2 deletions docs/tutorials/graphics/shape.md
Original file line number Diff line number Diff line change
@@ -167,7 +167,7 @@ Line without thickness:
```crystal
line = [
SF::Vertex.new(SF.vector2(10, 10)),
SF::Vertex.new(SF.vector2(150, 150))
SF::Vertex.new(SF.vector2(150, 150)),
]
window.draw(line, SF::Lines)
@@ -200,14 +200,16 @@ class EllipseShape < SF::Shape
def radius
@radius
end
def radius=(radius : SF::Vector2f)
@radius = radius
update
end
def point_count
40 # fixed, but could be an attribute of the class if needed
40 # fixed, but could be an attribute of the class if needed
end
def get_point(index)
angle = index * 2*Math::PI / point_count
11 changes: 5 additions & 6 deletions docs/tutorials/graphics/sprite.md
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ sprite.texture_rect = SF.int_rect(10, 10, 32, 32)
You can also change the color of a sprite. The color that you set is modulated (multiplied) with the texture of the sprite. This can also be used to change the global transparency (alpha) of the sprite.

```crystal
sprite.color = SF.color(0, 255, 0) # green
sprite.color = SF.color(0, 255, 0) # green
sprite.color = SF.color(255, 255, 255, 128) # half transparent
```

@@ -122,15 +122,15 @@ Sprites can also be transformed: They have a position, an orientation and a scal
```crystal
# position
sprite.position = SF.vector2(10, 50) # absolute position
sprite.move(SF.vector2(5, 10)) # offset relative to the current position
sprite.move(SF.vector2(5, 10)) # offset relative to the current position
# rotation
sprite.rotation = 90 # absolute angle
sprite.rotate(15) # offset relative to the current angle
sprite.rotate(15) # offset relative to the current angle
# scale
sprite.scale = SF.vector2(0.5, 2.0) # absolute scale factor
sprite.scale(SF.vector2(1.5, 3.0)) # factor relative to the current scale
sprite.scale(SF.vector2(1.5, 3.0)) # factor relative to the current scale
```

By default, the origin for these three transformations is the top-left corner of the sprite. If you want to set the origin to a different point (for example the center of the sprite, or another corner), you can use the `origin=` method.
@@ -156,7 +156,7 @@ If you're using OpenGL rather than the graphics entities of CrSFML, you can stil
To bind a [SF::Texture][] for drawing (basically `glBindTexture`), you call the `bind` class method:

```crystal
texture = ...
texture = [...]
# bind the texture
SF::Texture.bind texture
@@ -166,4 +166,3 @@ SF::Texture.bind texture
# bind no texture
SF::Texture.bind nil
```

3 changes: 1 addition & 2 deletions docs/tutorials/graphics/text.md
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ text.color = SF::Color::Red
# set the text style
text.style = (SF::Text::Bold | SF::Text::Underlined)
...
[...]
# inside the main loop, between window.clear() and window.display()
window.draw(text)
@@ -87,4 +87,3 @@ line_spacing = font.get_line_spacing(character_size)
kerning = font.get_kerning(character_1, character_2, character_size)
```

8 changes: 4 additions & 4 deletions docs/tutorials/graphics/transform.md
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ Note that changing the origin also changes where the entity is drawn on screen,

```crystal
class MyGraphicalEntity < SF::Transformable
# ...
[...]
end
entity.position = SF.vector2(10, 30)
@@ -169,14 +169,14 @@ The bounding box is very useful when implementing collision detection: Checks ag
bounding_box = entity.global_bounds
# check collision with a point
point = ...
point = [...]
if bounding_box.contains? point
# collision!
end
# check collision with another box (like the bounding box of another entity)
other_box = ...
other_box = [...]
if bounding_box.intersects? other_box
# collision!
@@ -212,7 +212,7 @@ class Node
end
private def on_draw(target, transform)
...
[...]
end
end
Loading

0 comments on commit 9984353

Please sign in to comment.