mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-26 13:51:50 +03:00
Some docs for the SDL bindings.
This commit is contained in:
parent
e4dceb2405
commit
0567c8ef14
@ -251,6 +251,7 @@
|
||||
fps Int])
|
||||
|
||||
(defmodule SDLApp
|
||||
(doc create "creates an SDLApp instance that can then be used by `run-with-callbacks`.")
|
||||
(defn create [title width height]
|
||||
(let [win NULL
|
||||
ren NULL]
|
||||
@ -260,11 +261,13 @@
|
||||
(SDL.set-window-title win (cstr title))
|
||||
(SDLApp.init win ren 60))))
|
||||
|
||||
(hidden reduce-events)
|
||||
(defn reduce-events [app f state-to-reduce-over]
|
||||
(Array.reduce &(fn [s e] (~f app s e)) ;; Note, this will malloc an environment that captures the 'app' variable.
|
||||
state-to-reduce-over
|
||||
&(SDL.Event.all)))
|
||||
|
||||
(doc run-with-callbacks "starts the SDLApp and uses three callbacks to handle events, update state and render graphics.")
|
||||
(defn run-with-callbacks [app event-fn update-fn draw-fn initial-state]
|
||||
(let-do [rend @(SDLApp.renderer app)
|
||||
state initial-state
|
||||
@ -283,15 +286,18 @@
|
||||
(draw-fn app rend &state)
|
||||
(SDL.render-present rend)))))
|
||||
|
||||
(doc stop "stops the app. This function return 'a' to enable it to be called from anywhere.")
|
||||
(defn stop [app]
|
||||
(do (SDL.destroy-window @(window app))
|
||||
(SDL.quit)
|
||||
(System.exit 0)))
|
||||
|
||||
(doc default-draw "is a default rendering function that can be passed to `run-with-callbacks`.")
|
||||
(defn default-draw [app rend state-ref]
|
||||
(do (SDL.set-render-draw-color rend 0 0 0 255)
|
||||
(SDL.render-clear rend)))
|
||||
|
||||
(doc quit-on-esc "is a default event handling function that can be passed to `run-with-callbacks`. Allows the application to quit if the player presses the escape key.")
|
||||
(defn quit-on-esc [app state event]
|
||||
(case (SDL.Event.type event)
|
||||
SDL.Event.quit (SDLApp.stop app)
|
||||
|
@ -35,3 +35,5 @@
|
||||
Maybe
|
||||
Result
|
||||
)
|
||||
|
||||
(quit)
|
||||
|
1010
docs/sdl/SDL.html
Normal file
1010
docs/sdl/SDL.html
Normal file
File diff suppressed because it is too large
Load Diff
461
docs/sdl/SDLApp.html
Normal file
461
docs/sdl/SDLApp.html
Normal file
@ -0,0 +1,461 @@
|
||||
<!DOCTYPE HTML>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" href="carp_style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
<div class="logo">
|
||||
<a href="http://github.com/carp-lang/Carp">
|
||||
<img src="logo.png">
|
||||
</a>
|
||||
<div class="title">
|
||||
SDL
|
||||
</div>
|
||||
<div class="index">
|
||||
<ul>
|
||||
<li>
|
||||
<a href="SDL.html">
|
||||
SDL
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="SDLApp.html">
|
||||
SDLApp
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<h1>
|
||||
SDLApp
|
||||
</h1>
|
||||
<div class="module-description">
|
||||
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#copy">
|
||||
<h3 id="copy">
|
||||
copy
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref SDLApp)] SDLApp)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>copies a <code>SDLApp</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#create">
|
||||
<h3 id="create">
|
||||
create
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Int, Int] SDLApp)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(create title width height)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>creates an SDLApp instance that can then be used by <code>run-with-callbacks</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#default-draw">
|
||||
<h3 id="default-draw">
|
||||
default-draw
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [a, (Ptr SDL_Renderer), b] ())
|
||||
</p>
|
||||
<pre class="args">
|
||||
(default-draw app rend state-ref)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>is a default rendering function that can be passed to <code>run-with-callbacks</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#fps">
|
||||
<h3 id="fps">
|
||||
fps
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref SDLApp)] &Int)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>gets the <code>fps</code> property of a <code>SDLApp</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#init">
|
||||
<h3 id="init">
|
||||
init
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ptr SDL_Window), (Ptr SDL_Renderer), Int] SDLApp)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>creates a <code>SDLApp</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#prn">
|
||||
<h3 id="prn">
|
||||
prn
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref SDLApp)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>converts a <code>SDLApp</code> to a string.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#quit-on-esc">
|
||||
<h3 id="quit-on-esc">
|
||||
quit-on-esc
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref SDLApp), a, (Ref SDL_Event)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(quit-on-esc app state event)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>is a default event handling function that can be passed to <code>run-with-callbacks</code>. Allows the application to quit if the player presses the escape key.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#renderer">
|
||||
<h3 id="renderer">
|
||||
renderer
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref SDLApp)] (Ref (Ptr SDL_Renderer)))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>gets the <code>renderer</code> property of a <code>SDLApp</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#run-with-callbacks">
|
||||
<h3 id="run-with-callbacks">
|
||||
run-with-callbacks
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref SDLApp), (λ [(Ref SDLApp), a, (Ref SDL_Event)] a), (λ [a] a), (λ [(Ref SDLApp), (Ptr SDL_Renderer), &a] ()), a] ())
|
||||
</p>
|
||||
<pre class="args">
|
||||
(run-with-callbacks app event-fn update-fn draw-fn initial-state)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>starts the SDLApp and uses three callbacks to handle events, update state and render graphics.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#set-fps">
|
||||
<h3 id="set-fps">
|
||||
set-fps
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [SDLApp, Int] SDLApp)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>sets the <code>fps</code> property of a <code>SDLApp</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#set-fps!">
|
||||
<h3 id="set-fps!">
|
||||
set-fps!
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref SDLApp), Int] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>sets the <code>fps</code> property of a <code>SDLApp</code> in place.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#set-renderer">
|
||||
<h3 id="set-renderer">
|
||||
set-renderer
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [SDLApp, (Ptr SDL_Renderer)] SDLApp)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>sets the <code>renderer</code> property of a <code>SDLApp</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#set-renderer!">
|
||||
<h3 id="set-renderer!">
|
||||
set-renderer!
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref SDLApp), (Ptr SDL_Renderer)] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>sets the <code>renderer</code> property of a <code>SDLApp</code> in place.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#set-window">
|
||||
<h3 id="set-window">
|
||||
set-window
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [SDLApp, (Ptr SDL_Window)] SDLApp)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>sets the <code>window</code> property of a <code>SDLApp</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#set-window!">
|
||||
<h3 id="set-window!">
|
||||
set-window!
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref SDLApp), (Ptr SDL_Window)] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>sets the <code>window</code> property of a <code>SDLApp</code> in place.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#stop">
|
||||
<h3 id="stop">
|
||||
stop
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref SDLApp)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(stop app)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>stops the app. This function return 'a' to enable it to be called from anywhere.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#str">
|
||||
<h3 id="str">
|
||||
str
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref SDLApp)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>converts a <code>SDLApp</code> to a string.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#update-fps">
|
||||
<h3 id="update-fps">
|
||||
update-fps
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [SDLApp, (Ref (λ [Int] Int))] SDLApp)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>updates the <code>fps</code> property of a <code>SDLApp</code> using a function <code>f</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#update-renderer">
|
||||
<h3 id="update-renderer">
|
||||
update-renderer
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [SDLApp, (Ref (λ [(Ptr SDL_Renderer)] (Ptr SDL_Renderer)))] SDLApp)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>updates the <code>renderer</code> property of a <code>SDLApp</code> using a function <code>f</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#update-window">
|
||||
<h3 id="update-window">
|
||||
update-window
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [SDLApp, (Ref (λ [(Ptr SDL_Window)] (Ptr SDL_Window)))] SDLApp)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>updates the <code>window</code> property of a <code>SDLApp</code> using a function <code>f</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#window">
|
||||
<h3 id="window">
|
||||
window
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref SDLApp)] (Ref (Ptr SDL_Window)))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>gets the <code>window</code> property of a <code>SDLApp</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
39
docs/sdl/SDL_index.html
Normal file
39
docs/sdl/SDL_index.html
Normal file
@ -0,0 +1,39 @@
|
||||
<!DOCTYPE HTML>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" href="carp_style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
<a href="https://github.com/carp-lang/carp">
|
||||
<div class="logo">
|
||||
<img src="logo.png" alt="Logo">
|
||||
<div class="index">
|
||||
<ul>
|
||||
<li>
|
||||
<a href="SDL.html">
|
||||
SDL
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="SDLApp.html">
|
||||
SDLApp
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<h1>
|
||||
SDL
|
||||
</h1>
|
||||
<p>Docs for the official SDL bindings for Carp.</p>
|
||||
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
127
docs/sdl/carp_style.css
Normal file
127
docs/sdl/carp_style.css
Normal file
@ -0,0 +1,127 @@
|
||||
html {
|
||||
font-family: "Helvetica", sans-serif;
|
||||
font-size: 1.0em;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0em 0em 0.5em 0em;
|
||||
line-height: 1.5em;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #f00;
|
||||
}
|
||||
|
||||
.logo {
|
||||
text-align: right;
|
||||
float: right;
|
||||
width: 150px;
|
||||
font-family: "Hasklig", "Lucida Console", monospace;
|
||||
}
|
||||
|
||||
.logo img {
|
||||
width: 150px;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.args {
|
||||
background-color: #eee;
|
||||
padding: 3px;
|
||||
display: inline-block;
|
||||
margin-top: 0.3em;
|
||||
margin-bottom: 0.3em;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style-type: none;
|
||||
font-family: "Hasklig", "Lucida Console", monospace;
|
||||
line-height: 1.4em;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.content {
|
||||
margin: 3em auto auto auto;
|
||||
width: 80%;
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
|
||||
}
|
||||
|
||||
h3 {
|
||||
margin: 0em;
|
||||
}
|
||||
|
||||
.anchor {
|
||||
color: #000;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.anchor:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.binder {
|
||||
margin: 3.5em 0em 0em 0em;
|
||||
}
|
||||
|
||||
.sig {
|
||||
font-family: "Hasklig", "Source Code Pro", "Lucida Console", monospace;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: "Hasklig", "Source Code Pro", "Lucida Console", monospace;
|
||||
}
|
||||
|
||||
.doc {
|
||||
/* font-style: italic; */
|
||||
}
|
||||
|
||||
.description {
|
||||
margin-top: 0.5em;
|
||||
margin-bottom: 0.5em;
|
||||
font-size: 0.8em;
|
||||
color: #aaa;
|
||||
}
|
||||
|
||||
.module-description {
|
||||
margin: 0em;
|
||||
}
|
||||
|
||||
.huge {
|
||||
font-size: 15em;
|
||||
margin: 0em;
|
||||
}
|
||||
|
||||
/* Smaller screens */
|
||||
@media only screen and (max-width: 600px) {
|
||||
.logo {
|
||||
margin: 1em;
|
||||
text-align: left;
|
||||
float: left;
|
||||
width: 100%;
|
||||
}
|
||||
.logo img {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
width: 50%;
|
||||
}
|
||||
.content {
|
||||
margin: 0.5em;
|
||||
}
|
||||
.binder {
|
||||
margin: 0em 0em 1.5em 0em;
|
||||
}
|
||||
.sig {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
ul {
|
||||
padding: 0px;
|
||||
}
|
||||
}
|
14
docs/sdl/generate_sdl_docs.carp
Normal file
14
docs/sdl/generate_sdl_docs.carp
Normal file
@ -0,0 +1,14 @@
|
||||
(Project.config "title" "SDL")
|
||||
(Project.config "docs-directory" "./docs/sdl/")
|
||||
(Project.config "docs-logo" "logo.png")
|
||||
(Project.config "docs-prelude" "Docs for the official SDL bindings for Carp.")
|
||||
(Project.config "docs-url" "https://github.com/carp-lang/carp")
|
||||
|
||||
(load "SDL.carp")
|
||||
(load "SDL_Image.carp")
|
||||
|
||||
(save-docs SDL
|
||||
SDLApp
|
||||
)
|
||||
|
||||
(quit)
|
BIN
docs/sdl/logo.png
Executable file
BIN
docs/sdl/logo.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 761 KiB |
@ -58,6 +58,7 @@ if [[ ${NO_SDL} -eq 0 ]]; then
|
||||
fi
|
||||
|
||||
# Generate core docs
|
||||
stack exec carp -- ./docs/core/generate_core_docs.carp -b
|
||||
stack exec carp -- ./docs/core/generate_core_docs.carp
|
||||
stack exec carp -- ./docs/core/generate_sdl_docs.carp
|
||||
|
||||
echo "ALL TESTS DONE."
|
||||
|
Loading…
Reference in New Issue
Block a user