Basic Text rendering
Using SDL2_ttf and fmt
This commit is contained in:
parent
f911f6e2a8
commit
75fd208299
10 changed files with 264 additions and 14 deletions
BIN
assets/joystix/joystix.ttf
Normal file
BIN
assets/joystix/joystix.ttf
Normal file
Binary file not shown.
195
assets/joystix/read-this.html
Normal file
195
assets/joystix/read-this.html
Normal file
|
@ -0,0 +1,195 @@
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>Typodermic Fonts Inc. Freeware Font instructions 2014</title>
|
||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
margin:30px 20% 120px 20%;
|
||||||
|
padding:0px;
|
||||||
|
font-family:Consolas, Courier, sans-serif;
|
||||||
|
color:#4c4b44;
|
||||||
|
background-color:#c2c1b3;
|
||||||
|
|
||||||
|
/* IE10 Consumer Preview */
|
||||||
|
background-image: -ms-linear-gradient(top left, #DEDDD6 0%, #9D9B87 100%);
|
||||||
|
|
||||||
|
/* Mozilla Firefox */
|
||||||
|
background-image: -moz-linear-gradient(top left, #DEDDD6 0%, #9D9B87 100%);
|
||||||
|
|
||||||
|
/* Opera */
|
||||||
|
background-image: -o-linear-gradient(top left, #DEDDD6 0%, #9D9B87 100%);
|
||||||
|
|
||||||
|
/* Webkit (Safari/Chrome 10) */
|
||||||
|
background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0, #DEDDD6), color-stop(1, #9D9B87));
|
||||||
|
|
||||||
|
/* Webkit (Chrome 11+) */
|
||||||
|
background-image: -webkit-linear-gradient(top left, #DEDDD6 0%, #9D9B87 100%);
|
||||||
|
|
||||||
|
/* W3C Markup, IE10 Release Preview */
|
||||||
|
background-image: linear-gradient(to bottom right, #DEDDD6 0%, #9D9B87 100%);
|
||||||
|
|
||||||
|
}
|
||||||
|
h2 {color:#6d6c61;}
|
||||||
|
a {color:#8f5b54;}
|
||||||
|
a:hover {color:#ffffff; background-color:#9a998c;}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<svg width="350px" height="30px">
|
||||||
|
<path fill="#69685D" d="M0,4.006L0.554,0h20.674l-0.553,4.006l-2.559,2.772h-4.688l-0.682,4.816l-2.515,3.026l1.663,3.07
|
||||||
|
l-1.62,11.594H4.987l-1.448-1.79l2.94-20.716H1.791L0,4.006z"/>
|
||||||
|
<path fill="#69685D" d="M35.8,0h5.285l1.408,1.791l-1.876,13.343l-2.515,3.111h-4.264l-1.534,11.04h-5.286l-1.449-1.79l1.322-9.25
|
||||||
|
h-4.263l-1.705-3.111l1.875-13.343L24.76,0h5.242l-1.706,12.064h5.799L35.8,0z"/>
|
||||||
|
<path fill="#69685D" d="M62.09,0l2.899,3.453L63.412,14.58l-3.496,3.962h-9.805l-1.491,10.742h-5.244l-1.493-1.79l3.625-25.704
|
||||||
|
L47.469,0H62.09z M50.965,12.362h5.797l0.81-5.583h-5.799L50.965,12.362z"/>
|
||||||
|
<path fill="#69685D" d="M64.256,26.642l3.367-24.041L70.523,0h14.664l2.132,2.601l-3.368,24.041l-2.856,2.643H66.431L64.256,26.642
|
||||||
|
z M73.335,11.595l-2.514,3.026l1.663,3.07l-0.683,4.816H77.6l0.68-4.816l2.516-3.07l-1.663-3.026l0.681-4.816h-5.796L73.335,11.595
|
||||||
|
z"/>
|
||||||
|
<path fill="#69685D" d="M86.926,29.285L91.017,0h15.518l3.581,4.307l-2.899,20.673l-4.774,4.305H86.926z M96.345,11.595
|
||||||
|
l-2.515,3.026l1.664,3.07l-0.683,4.816h5.798l0.681-4.816l2.516-3.07l-1.663-3.026l0.681-4.816h-5.796L96.345,11.595z"/>
|
||||||
|
<path fill="#69685D" d="M127.114,29.285h-15.473l-1.492-1.79l3.624-25.704L115.731,0h15.389l-0.554,4.006l-2.557,2.772h-7.971
|
||||||
|
l-0.684,4.816h6.906l1.662,3.026l-2.515,3.111h-6.905l-0.683,4.775h8.057l1.791,2.771L127.114,29.285z"/>
|
||||||
|
<path fill="#69685D" d="M150.21,0l2.898,3.453l-1.405,9.977l-3.881,3.452l2.217,10.613l-1.748,1.79h-4.944l-2.387-11.553h-2.6
|
||||||
|
l-1.622,11.553h-5.241l-1.493-1.79l3.624-25.704L135.588,0H150.21z M145.691,6.779h-5.796l-0.683,4.816h5.799L145.691,6.779z"/>
|
||||||
|
<path fill="#69685D" d="M159.92,29.285h-5.242l-1.492-1.79l3.41-24.042L160.432,0h21.911l2.897,3.453l-3.409,24.042l-1.876,1.79
|
||||||
|
h-5.284l1.617-11.594l2.517-3.07l-1.662-3.026l0.681-4.816h-4.092l-3.154,22.506h-6.522l3.155-22.506h-4.134l-0.683,4.816
|
||||||
|
l-2.515,3.026l1.663,3.07L159.92,29.285z"/>
|
||||||
|
<path fill="#69685D" d="M191.879,29.285h-5.244l-1.492-1.79l3.624-25.704L190.728,0h5.242l-1.619,11.595l-2.516,3.026l1.663,3.07
|
||||||
|
L191.879,29.285z"/>
|
||||||
|
<path fill="#69685D" d="M213.018,25.279l-0.554,4.006h-13.854l-2.899-3.494l3.156-22.338L202.702,0h13.854l-0.555,4.006
|
||||||
|
l-2.558,2.772h-8.1l-0.683,4.816l-2.515,3.026l1.663,3.07l-0.683,4.816h8.1L213.018,25.279z"/>
|
||||||
|
<path fill="#69685D" d="M226.007,29.285l-1.492-1.79l3.624-25.704L230.1,0h15.473l-0.554,4.006l-2.557,2.772h-8.058l-0.724,5.115
|
||||||
|
h6.818l1.664,3.07l-2.557,3.11h-6.82l-1.535,11.211H226.007z"/>
|
||||||
|
<path fill="#69685D" d="M243.903,26.642l3.368-24.041L250.17,0h14.663l2.131,2.601l-3.367,24.041l-2.855,2.643h-14.664
|
||||||
|
L243.903,26.642z M252.983,11.595l-2.516,3.026l1.662,3.07l-0.681,4.816h5.796l0.684-4.816l2.515-3.07l-1.664-3.026l0.684-4.816
|
||||||
|
h-5.798L252.983,11.595z"/>
|
||||||
|
<path fill="#69685D" d="M280.639,19.822l-4.731-7.758l-2.516,3.069l1.662,3.069l-1.533,11.082h-5.244l-1.493-1.79l3.626-25.704
|
||||||
|
L272.37,0h4.773l4.902,9.677L283.41,0h5.285l1.407,1.791l-3.623,25.704l-1.877,1.79h-5.285L280.639,19.822z"/>
|
||||||
|
<path fill="#69685D" d="M291.926,4.006L292.48,0h20.674l-0.554,4.006l-2.557,2.772h-4.691l-0.681,4.816l-2.516,3.026l1.664,3.07
|
||||||
|
l-1.621,11.594h-5.285l-1.451-1.79l2.942-20.716h-4.689L291.926,4.006z"/>
|
||||||
|
<path fill="#69685D" d="M325.168,17.478h-9.209l-2.387-3.923l1.45-10.102L318.857,0h14.452l-0.682,4.86l-1.621,1.918h-9.506
|
||||||
|
l-0.64,4.561h9.208l2.388,3.878l-1.493,10.572l-3.836,3.494h-14.579l-1.107-1.917l0.682-4.86h12.362L325.168,17.478z"/>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<p translate="no">
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=de&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhivq6___mill12Uw6fPvMWyJxstkw">Deutsch</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=es&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhjAt3cpinDeMTX6Ro8UcZFqaE8K5Q">Español</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=fr&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhjObLPhFyyhwigF-dBoOZ3eXYdDsw">Français</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=ar&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhg2hs-st3zodt-AjmoeuPHfyJsTEg">العربية</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=zh-CN&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhiilVnjG1Ks0DN7UyRqbKExhxAT-Q">中国简体</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=zh-TW&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhiSCPRAYToARlHI4kxIK9eCIFKQhw">簡體字</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=cs&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhj3z2HOOmCXLT-ApYW2SCeBvTGvTA">Čeština</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=el&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhhoORG-43TvZ2NVrll3T0oyOZE0VA">Ελληνικά</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=iw&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhiP4kLXdDxVNuV6-9tHJ8Tbt-1xKw">עִבְרִית</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=hi&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhhJmUufReWrMTSaGKPPOqV7q5jpGQ">हिन्दी</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=hu&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhgfcL_UwP3jkr6Vvq35rkhETFuTug">Magyar</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=is&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhjpK9lELyRP50Vv3RNgqCJDb6d-GQ">Íslenska</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=id&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhiExV3gmyXBUVqcwNiGiUWQSRrgIQ">Indonesia</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=it&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhgMr2_uulaLYRSFz8C34rtcbN6XEg">Italiano</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=ko&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhhl_nNXiOMIiBERq879UXH1XYfZGw">한국말</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&ie=UTF8&prev=_t&sl=en&tl=ja&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhi2FvSFgSUub72-Sq2moIRAosCiLA">日本語</a>
|
||||||
|
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=no&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhhnf9AGd5hfxwA04e1w-tfYPha1ww">Norsk</a>
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=pl&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhjZTe5eJRrZffLe0zgqEHPrMb8pOQ">Język Polski</a>
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=pt-BR&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhg-zp3i6AcZCv02ONjZ5YvkcCFDBw">Português</a>
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=pa&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhhPEMoYvW59_DJT7y6fxgG2IMh23A">ਪੰਜਾਬੀ</a>
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=ro&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhgD0R8zxuQQh-YmFpQTJdvjhAYm2A">Română</a>
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=ru&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhgI6c7Pd-FCcipT4xc2NPTefj5JJg">Русский</a>
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=sv&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhhA8gW_-rjCbZQ5TK46zFMB3_StEQ">Svenska</a>
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=ta&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhiwxxCEPzu3pHBXP-fbTZaOzYqe3g">தமிழ்</a>
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=th&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhjP1N1DRUB1M81k5mi5KnRtt5C2-Q">ภาษาไทย</a>
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=tr&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhiTYbD039OWznCcGyQnMy89_v-1gA">Türkçe</a>
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=uk&u=http%3A%2F%2Ftypodermicfonts.com%2Fwp-content%2Fuploads%2F2014%2F02%2Fread-this.html">Українська мова</a>
|
||||||
|
<a href="http://translate.google.com/translate?hl=en&sl=en&tl=vi&u=http://typodermicfonts.com/wp-content/uploads/2014/02/read-this.html&sandbox=0&usg=ALkJrhirTQPOLCZognLpxOvJQT_158y07A">Tiếng Việt</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<p>Thanks for downloading a free font from <span translate="no">Typodermic Fonts Inc.</span> This font is <em>free for commercial use</em>. Read the attached license agreement for details.</p>
|
||||||
|
|
||||||
|
|
||||||
|
<h2>Installation</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Windows 8/7/Vista: Get the font out of the ZIP. Right-click on the font and <em>Install</em>
|
||||||
|
<li>Windows XP: Get the font out of the ZIP. Put it into <cite translate="no">Start Menu/Control Panel/Appearance and Themes/Fonts</cite>
|
||||||
|
<li>Mac OS X: Get the font out of the ZIP. Put it into <cite translate="no">/Library/Fonts</cite> or <cite translate="no">/Users/Your_username/Library/Fonts</cite>
|
||||||
|
<li>Mac OS X 10.3 or above: Double-click the font file and <em>Install font</em>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
<h2>Allowed</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>art
|
||||||
|
<li>sign
|
||||||
|
<li>poster
|
||||||
|
<li>banner
|
||||||
|
<li>book
|
||||||
|
<li>business card
|
||||||
|
<li>album
|
||||||
|
<li>movie
|
||||||
|
<li>television
|
||||||
|
<li>logo
|
||||||
|
<li>trademarked logo
|
||||||
|
<li>clothing
|
||||||
|
<li>sticker
|
||||||
|
<li>stamp
|
||||||
|
<li>product label
|
||||||
|
<li>web page (not embedded)
|
||||||
|
<li>app (not embedded)
|
||||||
|
<li>PDF (not editable)
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>Not allowed</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>ebook
|
||||||
|
<li>app (embedded)
|
||||||
|
<li>web page (embedded)
|
||||||
|
<li>product creation platform
|
||||||
|
<li>alphabet stamps
|
||||||
|
<li>advertisment server
|
||||||
|
<li>web template
|
||||||
|
<li>PDF (editable)
|
||||||
|
<li>OEM
|
||||||
|
<li>device embedding
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>It’s easy to get a different license agreement. Read the <a href="http://typodermicfonts.com/custom/">this page</a> for details.</p>
|
||||||
|
|
||||||
|
<h2>Other styles</h2>
|
||||||
|
|
||||||
|
<p>Many of my free fonts have other styles available. Please visit <a href="http://typodermicfonts.com">Typodermic Fonts</a> and search for the name of this font in the search bar.</p>
|
||||||
|
|
||||||
|
|
||||||
|
<h2>About me</h2>
|
||||||
|
|
||||||
|
<p>My name is <span translate="no">Ray Larabie</span> and I’ve been creating fonts since 1996.</p>
|
||||||
|
|
||||||
|
<p>Please visit <a href="http://typodermicfonts.com">typodermicfonts.com</a> to find out more.</p>
|
||||||
|
|
||||||
|
<p translate="no"><a href="https://www.facebook.com/pages/Typodermic-Fonts/7153899975">Facebook</a></p>
|
||||||
|
<p translate="no"><a href="http://about.me/raylarabie/#">About.me</a></p>
|
||||||
|
<p translate="no"><p><a href="https://twitter.com/typodermic">Twitter</a></p>
|
||||||
|
<p translate="no"><p><a href="http://www.pinterest.com/plywood747/">Pinterest</a></p>
|
||||||
|
|
||||||
|
</body>
|
BIN
assets/joystix/typodermic-eula-02-2014.pdf
Normal file
BIN
assets/joystix/typodermic-eula-02-2014.pdf
Normal file
Binary file not shown.
|
@ -1,6 +1,11 @@
|
||||||
find_package(sdl2-image CONFIG REQUIRED)
|
find_package(sdl2-image CONFIG REQUIRED)
|
||||||
|
find_package(sdl2-ttf CONFIG REQUIRED)
|
||||||
|
find_package(fmt CONFIG REQUIRED)
|
||||||
|
|
||||||
|
|
||||||
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp")
|
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp")
|
||||||
|
|
||||||
add_library(libpacman ${sources})
|
add_library(libpacman ${sources})
|
||||||
|
|
||||||
target_include_directories(libpacman PUBLIC .)
|
target_include_directories(libpacman PUBLIC .)
|
||||||
target_link_libraries(libpacman PUBLIC SDL2::SDL2-static SDL2::SDL2_image)
|
target_link_libraries(libpacman PUBLIC SDL2::SDL2-static SDL2::SDL2_image SDL2::SDL2_ttf fmt::fmt)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include "Canvas.hpp"
|
#include "Canvas.hpp"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <fmt/format.h>
|
||||||
#include "PacMan.hpp"
|
#include "PacMan.hpp"
|
||||||
#include "Pellets.hpp"
|
#include "Pellets.hpp"
|
||||||
#include "SuperPellets.hpp"
|
#include "SuperPellets.hpp"
|
||||||
|
@ -16,6 +15,7 @@ void Canvas::update(const PacMan & pacMan, const Pellets & pellets, const SuperP
|
||||||
renderPellets(pellets);
|
renderPellets(pellets);
|
||||||
renderSuperPellets(superPellets);
|
renderSuperPellets(superPellets);
|
||||||
renderPacMan(pacMan);
|
renderPacMan(pacMan);
|
||||||
|
renderScore(0);
|
||||||
|
|
||||||
window.render();
|
window.render();
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,13 @@ void Canvas::renderPacMan(const PacMan & pac_man) const {
|
||||||
renderSprite(pacmanSprite, SDL_Point{ int(pos.x), int(pos.y) });
|
renderSprite(pacmanSprite, SDL_Point{ int(pos.x), int(pos.y) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Canvas::renderScore(int score) {
|
||||||
|
const int x = LEFT_MARGIN + MAZE_WIDTH + LEFT_MARGIN;
|
||||||
|
const int y = TOP_MARGIN * 2;
|
||||||
|
window.drawText("SCORE", {x, y});
|
||||||
|
window.drawText(fmt::format("{}", score), {x, y + 20});
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Rect Canvas::windowDimensions() const {
|
SDL_Rect Canvas::windowDimensions() const {
|
||||||
return { 0, 0, LEFT_MARGIN + MAZE_WIDTH + SCORE_WIDTH, TOP_MARGIN + MAZE_HEIGHT + BOTTOM_MARGIN };
|
return { 0, 0, LEFT_MARGIN + MAZE_WIDTH + SCORE_WIDTH, TOP_MARGIN + MAZE_HEIGHT + BOTTOM_MARGIN };
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ private:
|
||||||
void renderPellets(const Pellets & pellets) const;
|
void renderPellets(const Pellets & pellets) const;
|
||||||
void renderSuperPellets(const SuperPellets & superPellets) const;
|
void renderSuperPellets(const SuperPellets & superPellets) const;
|
||||||
void renderSprite(Sprite sprite, SDL_Point point) const;
|
void renderSprite(Sprite sprite, SDL_Point point) const;
|
||||||
|
void renderScore(int score);
|
||||||
|
|
||||||
SDL_Rect windowDimensions() const;
|
SDL_Rect windowDimensions() const;
|
||||||
Sprite getSprite(SDL_Point rect) const;
|
Sprite getSprite(SDL_Point rect) const;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
SDLWindow::SDLWindow(SDL_Rect windowGeometry) {
|
SDLWindow::SDLWindow(SDL_Rect windowGeometry) {
|
||||||
initSDL();
|
initSDL();
|
||||||
initSDLImage();
|
initSDLImage();
|
||||||
|
initSDLTTF();
|
||||||
|
|
||||||
createWindow(windowGeometry.w, windowGeometry.h);
|
createWindow(windowGeometry.w, windowGeometry.h);
|
||||||
createRenderer();
|
createRenderer();
|
||||||
|
@ -24,11 +25,7 @@ void SDLWindow::render() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite SDLWindow::getBackground() const {
|
Sprite SDLWindow::getBackground() const {
|
||||||
int w, h;
|
auto [w, h] = textureSize(maze_texture.get());
|
||||||
if (SDL_QueryTexture(maze_texture.get(), nullptr, nullptr, &w, &h) != 0) {
|
|
||||||
exitFailure("Failed to get texture geometry");
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Rect maze_rect = { 0, 0, w, h };
|
SDL_Rect maze_rect = { 0, 0, w, h };
|
||||||
return { maze_texture.get(), maze_rect };
|
return { maze_texture.get(), maze_rect };
|
||||||
}
|
}
|
||||||
|
@ -42,6 +39,15 @@ void SDLWindow::renderSprite(Sprite sprite, SDL_Rect target) const {
|
||||||
exitFailure("Failed to copy texture to renderer");
|
exitFailure("Failed to copy texture to renderer");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDLWindow::drawText(const std::string & text, SDL_Point position, SDL_Color textColor) const
|
||||||
|
{
|
||||||
|
SDLSurfacePtr surface(TTF_RenderUTF8_Solid(font.get(), text.data(), textColor), SDL_Surface_Deleter{});
|
||||||
|
SDLTexturePtr textTexture(SDL_CreateTextureFromSurface(renderer.get(), surface.get()), SDL_Texture_Deleter{});
|
||||||
|
auto [w, h] = textureSize(textTexture.get());
|
||||||
|
SDL_Rect textLocation = { position.x, position.y, w, h };
|
||||||
|
SDL_RenderCopy(renderer.get(), textTexture.get(), NULL, &textLocation);
|
||||||
|
}
|
||||||
|
|
||||||
void SDLWindow::initSDL() {
|
void SDLWindow::initSDL() {
|
||||||
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
|
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
|
||||||
exitFailure("Failed to initialize the SDL2 library");
|
exitFailure("Failed to initialize the SDL2 library");
|
||||||
|
@ -53,6 +59,16 @@ void SDLWindow::initSDLImage() {
|
||||||
exitImgFailure("Failed to init SDL_Image with png");
|
exitImgFailure("Failed to init SDL_Image with png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDLWindow::initSDLTTF() {
|
||||||
|
if(TTF_Init() != 0) {
|
||||||
|
exitFailure("Unable to setup font library");
|
||||||
|
}
|
||||||
|
font.reset(TTF_OpenFont("joystix.ttf", 20));
|
||||||
|
if(!font) {
|
||||||
|
exitFailure("Failed to copy texture to renderer");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SDLWindow::createWindow(int width, int height) {
|
void SDLWindow::createWindow(int width, int height) {
|
||||||
window = std::unique_ptr<SDL_Window, SDL_Window_Deleter>(SDL_CreateWindow(
|
window = std::unique_ptr<SDL_Window, SDL_Window_Deleter>(SDL_CreateWindow(
|
||||||
"Pacman",
|
"Pacman",
|
||||||
|
@ -100,6 +116,15 @@ SDLWindow::loadTexture(const std::string & path) {
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::tuple<int, int> SDLWindow::textureSize(SDL_Texture* texture) const
|
||||||
|
{
|
||||||
|
int w, h;
|
||||||
|
if (SDL_QueryTexture(texture, nullptr, nullptr, &w, &h) != 0) {
|
||||||
|
exitFailure("Failed to get texture geometry");
|
||||||
|
}
|
||||||
|
return {w, h};
|
||||||
|
}
|
||||||
|
|
||||||
void SDLWindow::exitFailure(const std::string & message) {
|
void SDLWindow::exitFailure(const std::string & message) {
|
||||||
std::cerr << message << "\n";
|
std::cerr << message << "\n";
|
||||||
std::cerr << "SDL2 Error: " << SDL_GetError() << "\n";
|
std::cerr << "SDL2 Error: " << SDL_GetError() << "\n";
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "Sprite.hpp"
|
#include "Sprite.hpp"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
#include <SDL2/SDL_ttf.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -29,11 +30,16 @@ struct SDL_Texture_Deleter {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TextureSize {
|
struct SDL_Font_Deleter {
|
||||||
int width;
|
void operator()(TTF_Font* font) {
|
||||||
int height;
|
TTF_CloseFont(font);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using SDLTexturePtr = std::unique_ptr<SDL_Texture, SDL_Texture_Deleter>;
|
||||||
|
using SDLSurfacePtr = std::unique_ptr<SDL_Surface, SDL_Surface_Deleter>;
|
||||||
|
|
||||||
|
|
||||||
class PacMan;
|
class PacMan;
|
||||||
class Pellets;
|
class Pellets;
|
||||||
class SuperPellets;
|
class SuperPellets;
|
||||||
|
@ -42,6 +48,8 @@ class SDLWindow {
|
||||||
public:
|
public:
|
||||||
explicit SDLWindow(SDL_Rect windowGeometry);
|
explicit SDLWindow(SDL_Rect windowGeometry);
|
||||||
|
|
||||||
|
static constexpr auto White = SDL_Color{0xFF, 0xFF, 0xFF};
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
void render();
|
void render();
|
||||||
|
@ -49,15 +57,17 @@ public:
|
||||||
Sprite getBackground() const;
|
Sprite getBackground() const;
|
||||||
Sprite getSprite(SDL_Rect rect) const;
|
Sprite getSprite(SDL_Rect rect) const;
|
||||||
void renderSprite(Sprite sprite, SDL_Rect target) const;
|
void renderSprite(Sprite sprite, SDL_Rect target) const;
|
||||||
|
void drawText(const std::string &text, SDL_Point position, SDL_Color textColor = White) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr int16_t SCALE_FACTOR = 1;
|
static constexpr int16_t SCALE_FACTOR = 1;
|
||||||
|
|
||||||
std::unique_ptr<SDL_Window, SDL_Window_Deleter> window;
|
std::unique_ptr<SDL_Window, SDL_Window_Deleter> window;
|
||||||
std::unique_ptr<SDL_Renderer, SDL_Renderer_Deleter> renderer;
|
std::unique_ptr<SDL_Renderer, SDL_Renderer_Deleter> renderer;
|
||||||
std::unique_ptr<SDL_Surface, SDL_Surface_Deleter> window_surface;
|
SDLSurfacePtr window_surface;
|
||||||
std::unique_ptr<SDL_Texture, SDL_Texture_Deleter> maze_texture;
|
SDLTexturePtr maze_texture;
|
||||||
std::unique_ptr<SDL_Texture, SDL_Texture_Deleter> sprite_texture;
|
SDLTexturePtr sprite_texture;
|
||||||
|
std::unique_ptr<TTF_Font, SDL_Font_Deleter> font;
|
||||||
|
|
||||||
void createWindow(int width, int height);
|
void createWindow(int width, int height);
|
||||||
|
|
||||||
|
@ -69,6 +79,8 @@ private:
|
||||||
|
|
||||||
static void initSDLImage();
|
static void initSDLImage();
|
||||||
|
|
||||||
|
void initSDLTTF();
|
||||||
|
|
||||||
void setDrawColor();
|
void setDrawColor();
|
||||||
|
|
||||||
static void exitFailure(const std::string & message);
|
static void exitFailure(const std::string & message);
|
||||||
|
@ -79,4 +91,6 @@ private:
|
||||||
loadTexture(const std::string & path);
|
loadTexture(const std::string & path);
|
||||||
|
|
||||||
SDL_Rect windowDimensions() const;
|
SDL_Rect windowDimensions() const;
|
||||||
|
|
||||||
|
std::tuple<int, int> textureSize(SDL_Texture* texture) const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,6 +16,7 @@ add_custom_command(TARGET pacman POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
${PROJECT_SOURCE_DIR}/assets/maze.png
|
${PROJECT_SOURCE_DIR}/assets/maze.png
|
||||||
${PROJECT_SOURCE_DIR}/assets/sprites32.png
|
${PROJECT_SOURCE_DIR}/assets/sprites32.png
|
||||||
|
${PROJECT_SOURCE_DIR}/assets/joystix/joystix.ttf
|
||||||
$<TARGET_FILE_DIR:pacman>)
|
$<TARGET_FILE_DIR:pacman>)
|
||||||
|
|
||||||
#target_compile_options(pacman PRIVATE -fsanitize=address) # /MD will be used implicitly
|
#target_compile_options(pacman PRIVATE -fsanitize=address) # /MD will be used implicitly
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
"version": "0.1",
|
"version": "0.1",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"sdl2-image",
|
"sdl2-image",
|
||||||
|
"sdl2-ttf",
|
||||||
|
"fmt",
|
||||||
"gtest"
|
"gtest"
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in a new issue