Compare commits
391 Commits
alpha-0-3-
...
v0.8.5-pre
Author | SHA1 | Date | |
---|---|---|---|
af88277680 | |||
dd17a70551 | |||
ec0411373b | |||
222a13387d | |||
c1e471f23a | |||
6b48ba070c | |||
bbbfd60bb7 | |||
62fa5ede9d | |||
20c3a525c8 | |||
8b70d0e9b7 | |||
36e5676d9f | |||
f706193945 | |||
e24b704809 | |||
91bbcdb7a7 | |||
2cb54dd570 | |||
90dde05b79 | |||
1ae4ff72d3 | |||
9213a1d5dd | |||
ca52e6dae6 | |||
83946b1e66 | |||
61cb41ae29 | |||
bca1c36f75 | |||
3270842a1b | |||
bd7d21d489 | |||
cc5d669ab4 | |||
2c38997b4c | |||
a49bcd8712 | |||
dbaa4d912a | |||
8f2c877197 | |||
1ee4f6849e | |||
3d89e94823 | |||
228d0088fb | |||
86465b5f76 | |||
6af08275e9 | |||
3c7c12ef39 | |||
404761d712 | |||
83d948ef24 | |||
946deb210d | |||
c2cdf256ba | |||
f0f4a64dfc | |||
25ced38cba | |||
86166f87eb | |||
54cce27a34 | |||
4d6a24f51f | |||
2e6d2c3cd5 | |||
7f62666017 | |||
8b3173811a | |||
b40f6d738e | |||
d4f12cb9b0 | |||
690dd1d6ca | |||
c21e8192d4 | |||
d4878d4e3d | |||
0503fe7e5b | |||
cd20f32acb | |||
c0fe7eaab5 | |||
f1b712af4a | |||
3231bc8240 | |||
8f80a99fc6 | |||
2cc908b043 | |||
d07d2a246a | |||
bf51ecda77 | |||
d87235c4b5 | |||
6c22b58487 | |||
05835a5c07 | |||
fa948a7beb | |||
04741198e2 | |||
5fb7ca78a9 | |||
ce0d83912e | |||
26eb9b4970 | |||
02ea4c6b4b | |||
0d35167c90 | |||
51ab42a9b0 | |||
4ca9e96276 | |||
b71b359502 | |||
a75f37c2d4 | |||
a7a44b39dc | |||
f6eb34ed78 | |||
099f21345f | |||
c1876482f7 | |||
a70f243421 | |||
b100891c34 | |||
2f4e78b138 | |||
5163f19796 | |||
c3f737de14 | |||
809b0cfad6 | |||
cacf83d434 | |||
ca1e242997 | |||
165b3b347f | |||
2965c3945a | |||
8d28ae3754 | |||
7d327f22aa | |||
d0c2123996 | |||
6081c4d310 | |||
0dfb37cc1c | |||
f15e457947 | |||
5d3db56ee4 | |||
8bec3356e5 | |||
3b4e541d0e | |||
b03633e010 | |||
651a43574f | |||
8e7bee4ea2 | |||
db66485432 | |||
12d47e5482 | |||
39c1a0f991 | |||
3f548f2d09 | |||
6587d22d2c | |||
76da1a033f | |||
6c530c44bd | |||
85fa45201e | |||
10d4ad6fd5 | |||
d5a3da2c35 | |||
a8b0540ecc | |||
cc5579971d | |||
6123bd3307 | |||
ed0d9998ff | |||
483efd280a | |||
1e2b4c0476 | |||
3992096df3 | |||
7165d1edc4 | |||
27653c2350 | |||
67ecd0ceff | |||
de74aac8af | |||
e1e0d1cbd5 | |||
b6051242a2 | |||
ea778c004b | |||
b5dbe5ce78 | |||
7645b45992 | |||
c0bf1c7bf1 | |||
49805784b0 | |||
8b7b12007b | |||
88b329f1d0 | |||
5fbbae9f99 | |||
520eec7c9c | |||
f75078b42b | |||
16ef0ff65a | |||
fed723aa48 | |||
6813c50c12 | |||
3c18129f94 | |||
409161efe7 | |||
8e7958be76 | |||
9e5ce455ca | |||
94e90a3cd8 | |||
58b4667ec7 | |||
97aff8615a | |||
e57c15bddb | |||
82d8005529 | |||
acc0bdfd87 | |||
a7accb0bf5 | |||
c5c83a9c17 | |||
aed653f0c8 | |||
b5995e2f93 | |||
0977e0a80f | |||
54a9b80523 | |||
72adb90757 | |||
f2549997ba | |||
063a342ad5 | |||
20f7730448 | |||
aa5ca1a3f0 | |||
0dab5c6599 | |||
3f0f8f351c | |||
e150265bc4 | |||
6fd37ffd3d | |||
f7bd625610 | |||
20cec2442c | |||
dcf6d77979 | |||
0cfd1a0e42 | |||
303e4105cb | |||
8c8613aca6 | |||
ead304d698 | |||
edb634b79d | |||
d0e4d2296c | |||
078e0d0d8b | |||
855e312ad4 | |||
ffb313971d | |||
ef8e4a379c | |||
945038042a | |||
d59cf0f9e0 | |||
12d5b48632 | |||
489d4f54a1 | |||
80f53cb013 | |||
ab71f5c84f | |||
f3c8482c6d | |||
4bdc38b7d9 | |||
1f8c0fa06e | |||
4ec44b0f89 | |||
d82ec589bd | |||
51276fd171 | |||
1c5cd37a4f | |||
f3111623c1 | |||
4bacf86367 | |||
f1e6109fa5 | |||
fe2e9f0dcf | |||
9a2525e9e5 | |||
abef666256 | |||
d31f63a47e | |||
d4e4dbc565 | |||
b8cefcc12d | |||
ca4de52619 | |||
22b6f477ba | |||
fe13f3d6b4 | |||
c697ae9bd1 | |||
d22b7b718c | |||
61285be23e | |||
eb0ccc8b25 | |||
ca8db2564d | |||
c4a8c54da2 | |||
9d4f94dba2 | |||
4adf59193c | |||
7766b4071c | |||
3d0f3a3ab6 | |||
0e7ac54ef7 | |||
6c03dde215 | |||
aa6c96c9a3 | |||
28abaa62ff | |||
c8e65e39c3 | |||
4fe4232796 | |||
81fa120cb7 | |||
92fdc24a49 | |||
237c9108bf | |||
069cfba51b | |||
e4ef5b55fe | |||
a10e2aaab9 | |||
b35ed87573 | |||
ab867588d3 | |||
087b2a2bb0 | |||
c8fcce1de3 | |||
a5f3e60e3a | |||
fbc54e0065 | |||
1bbefb259a | |||
569e82f476 | |||
51822aef23 | |||
f0ae9c238c | |||
b9578e151d | |||
ad655021a4 | |||
9c66052878 | |||
d98707aa8f | |||
95dc698349 | |||
13916e3dff | |||
44f618e9d8 | |||
235c2c2d7e | |||
dfce1b2adb | |||
b68c7d29ae | |||
7737cba060 | |||
4cd82f2e25 | |||
a15b0bdb2d | |||
f7f0d26896 | |||
e73ee7c6db | |||
0d4cc6f30f | |||
d7c02bab33 | |||
4750ba5a6c | |||
8dabfd58ab | |||
16510f5261 | |||
60d85b2a5e | |||
69fe7d4cb4 | |||
0e772b1394 | |||
596d2a8611 | |||
f1f71b93e2 | |||
b0a74a0bf6 | |||
00ec77e6a3 | |||
d2145977c5 | |||
c733394277 | |||
43ea66236c | |||
0cd8eaa423 | |||
af296546ff | |||
26db113a09 | |||
e2ca5f27b6 | |||
ed2b2c4ed8 | |||
7c3e17e820 | |||
64045ebddf | |||
14800862be | |||
c640a2ec38 | |||
1a87a2519f | |||
52d7433385 | |||
03247039d3 | |||
9dc3feb1f3 | |||
a64f16e371 | |||
2327fcb284 | |||
0e56aa0905 | |||
d568126176 | |||
f11b74ba85 | |||
a4eac5221d | |||
31360d90f3 | |||
d3c1a8aaa6 | |||
e944cd8f55 | |||
5af0535d74 | |||
6548670e59 | |||
69f8a7fd51 | |||
8ba4bcdc1b | |||
0d104edab3 | |||
2c17269f84 | |||
8cf2c798e6 | |||
48cb6d4034 | |||
78b3ff7f68 | |||
e304bdf00f | |||
ad169b01cb | |||
dc7034db91 | |||
b01393cd33 | |||
54579d1f18 | |||
96dbdf3309 | |||
b690ea5822 | |||
fbe59355ce | |||
809ddbad47 | |||
9be2bb672a | |||
469896be32 | |||
6f8ec89373 | |||
4368d6d7ee | |||
3af5da9d3e | |||
560ee65932 | |||
e42d1ec20a | |||
bfa3b0a1c6 | |||
c2484c1892 | |||
fe15309b77 | |||
cadb23f9e2 | |||
c401c3f2e3 | |||
b2eccd5ebb | |||
48de80fe13 | |||
ba97c9ed70 | |||
e717a52491 | |||
006f16f32f | |||
184a97b2d7 | |||
b72caa1ba0 | |||
b81160bbd3 | |||
ae4212e5a6 | |||
6821dd2bca | |||
c5a3910ccf | |||
12ea3dc60f | |||
3d3f26bf57 | |||
66b8f6b921 | |||
cc5a011a89 | |||
83e0b11f8f | |||
165552b439 | |||
5eefebee43 | |||
762b08eb08 | |||
0032d26010 | |||
ee4fe4f131 | |||
5b926a7317 | |||
f0b02d64ef | |||
3e2af92e7e | |||
7384ba6f4f | |||
a1d9b4344a | |||
3fc36d5b14 | |||
87f9b915e2 | |||
fa1980d47c | |||
d80017fcb5 | |||
db27c91ec9 | |||
9036726e92 | |||
a0350b7814 | |||
0cd2f330ad | |||
9a5479d68b | |||
595828fe84 | |||
788d8f81a5 | |||
d8a6a9e45c | |||
113af5fabb | |||
c6b7099df2 | |||
db778f462a | |||
5d02c2c6f2 | |||
83eeee453e | |||
2d05d1e7a9 | |||
4d11cb9e91 | |||
cbbc4d54d9 | |||
22ae99f915 | |||
b7a544eadd | |||
328ff9d23b | |||
624b59db9d | |||
adf783c2a1 | |||
db89d5c60f | |||
9623606229 | |||
5200f27182 | |||
36f545855d | |||
c2b35fdf83 | |||
59fcc8c159 | |||
8431119ff5 | |||
c537fc095a | |||
f51ddecf3d | |||
fd167cd675 | |||
53dcfd0940 | |||
dd50e2c399 | |||
ccffe19a1e | |||
319582b680 | |||
fb0b1110d6 | |||
a6aac5f5cd | |||
3d1a50d2a7 | |||
51800b1960 | |||
4018047409 | |||
3c5adeef54 | |||
cf5fca1ea4 | |||
73c4485153 | |||
3a6fdc9441 | |||
a7295073f8 | |||
f6402a095b | |||
d5b66ad125 |
50
.github/workflows/Docs.yml
vendored
Normal file
50
.github/workflows/Docs.yml
vendored
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
name: 📄
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "!*" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "*" ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# This workflow contains a single job called "build"
|
||||||
|
build:
|
||||||
|
# The type of runner that the job will run on
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||||
|
steps:
|
||||||
|
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Extract branch name
|
||||||
|
shell: bash
|
||||||
|
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
|
||||||
|
id: branch
|
||||||
|
- name: Display branch name
|
||||||
|
shell: bash
|
||||||
|
run: echo ${{ steps.branch.outputs.branch }}
|
||||||
|
# Runs a single command using the runners shell
|
||||||
|
- name: Run a one-line script
|
||||||
|
run: |
|
||||||
|
git config --global user.email "tobid7@outlook.de"
|
||||||
|
git config --global user.name "Tobi-D7"
|
||||||
|
sudo apt-get install doxygen cmake -y
|
||||||
|
doxygen
|
||||||
|
echo done
|
||||||
|
ls -r
|
||||||
|
cd ..
|
||||||
|
git clone --depth 1 https://${{ secrets.TOKEN }}@github.com/NPI-D7/RenderD7.git RD7 -b gh-pages
|
||||||
|
|
||||||
|
mv -v RenderD7/doc/html/* RD7/
|
||||||
|
#rm -r doc
|
||||||
|
cd RD7
|
||||||
|
|
||||||
|
echo tobid7
|
||||||
|
git stage *
|
||||||
|
|
||||||
|
echo staged
|
||||||
|
git commit -m "Documentation1"
|
||||||
|
git tag doc
|
||||||
|
echo commited
|
||||||
|
git push origin gh-pages
|
||||||
|
echo pushed
|
50
.github/workflows/Update extlibs.yml
vendored
Normal file
50
.github/workflows/Update extlibs.yml
vendored
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
name: Extlibs
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ '!*' ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ '!*' ]
|
||||||
|
|
||||||
|
# Allows you to run this workflow manually from the Actions tab
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
||||||
|
jobs:
|
||||||
|
# This workflow contains a single job called "build"
|
||||||
|
build:
|
||||||
|
# The type of runner that the job will run on
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||||
|
steps:
|
||||||
|
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: update
|
||||||
|
run: |
|
||||||
|
#gl
|
||||||
|
cd ..
|
||||||
|
git clone https://github.com/lua/lua.git
|
||||||
|
cd RenderD7
|
||||||
|
mkdir -p extlibs/
|
||||||
|
mkdir -p extlibs/lua/
|
||||||
|
cp -r ../lua/*.c extlibs/lua/
|
||||||
|
cp -r ../lua/*.h extlibs/lua/
|
||||||
|
cp -r ../lua/*.md extlibs/lua/
|
||||||
|
#RenderD7
|
||||||
|
cd ..
|
||||||
|
git clone https://github.com/NPI-D7/RenderD7.git
|
||||||
|
cd lp-next-ctr
|
||||||
|
mkdir -p extlibs/
|
||||||
|
rm -r extlibs/RenderD7
|
||||||
|
mkdir -p extlibs/RenderD7/
|
||||||
|
cp -r ../RenderD7/*.c* extlibs/RenderD7/
|
||||||
|
cp -r ../RenderD7/*.h* extlibs/RenderD7/
|
||||||
|
cp -r ../RenderD7/*.md extlibs/RenderD7/
|
||||||
|
#config
|
||||||
|
git config --global user.email "tobid7@outlook.de"
|
||||||
|
git config --global user.name "Tobi-D7"
|
||||||
|
#commit
|
||||||
|
git stage *
|
||||||
|
git commit -m "update extlibs"
|
||||||
|
git push origin main
|
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
release/
|
||||||
|
debug/
|
||||||
|
lib/
|
||||||
|
*.bz2
|
16
.vscode/c_cpp_properties.json
vendored
Normal file
16
.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "3DS | Windows",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**",
|
||||||
|
"C:/devkitpro/libctru/include/**",
|
||||||
|
"C:/devkitpro/devkitARM/include/**",
|
||||||
|
"C:/devkitpro/devkitARM/arm-none-eabi/include/**",
|
||||||
|
"C:/devkitpro/portlibs/3ds/include/**"
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
91
.vscode/settings.json
vendored
Normal file
91
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"array": "cpp",
|
||||||
|
"*.tcc": "cpp",
|
||||||
|
"cctype": "cpp",
|
||||||
|
"clocale": "cpp",
|
||||||
|
"cmath": "cpp",
|
||||||
|
"cstdarg": "cpp",
|
||||||
|
"cstddef": "cpp",
|
||||||
|
"cstdint": "cpp",
|
||||||
|
"cstdio": "cpp",
|
||||||
|
"cstdlib": "cpp",
|
||||||
|
"cwchar": "cpp",
|
||||||
|
"cwctype": "cpp",
|
||||||
|
"unordered_map": "cpp",
|
||||||
|
"vector": "cpp",
|
||||||
|
"exception": "cpp",
|
||||||
|
"algorithm": "cpp",
|
||||||
|
"functional": "cpp",
|
||||||
|
"iterator": "cpp",
|
||||||
|
"memory": "cpp",
|
||||||
|
"numeric": "cpp",
|
||||||
|
"type_traits": "cpp",
|
||||||
|
"fstream": "cpp",
|
||||||
|
"initializer_list": "cpp",
|
||||||
|
"iosfwd": "cpp",
|
||||||
|
"iostream": "cpp",
|
||||||
|
"istream": "cpp",
|
||||||
|
"limits": "cpp",
|
||||||
|
"new": "cpp",
|
||||||
|
"optional": "cpp",
|
||||||
|
"ostream": "cpp",
|
||||||
|
"sstream": "cpp",
|
||||||
|
"stdexcept": "cpp",
|
||||||
|
"streambuf": "cpp",
|
||||||
|
"string": "cpp",
|
||||||
|
"string_view": "cpp",
|
||||||
|
"system_error": "cpp",
|
||||||
|
"tuple": "cpp",
|
||||||
|
"typeinfo": "cpp",
|
||||||
|
"utility": "cpp",
|
||||||
|
"atomic": "cpp",
|
||||||
|
"bit": "cpp",
|
||||||
|
"bitset": "cpp",
|
||||||
|
"chrono": "cpp",
|
||||||
|
"codecvt": "cpp",
|
||||||
|
"condition_variable": "cpp",
|
||||||
|
"cstring": "cpp",
|
||||||
|
"ctime": "cpp",
|
||||||
|
"deque": "cpp",
|
||||||
|
"forward_list": "cpp",
|
||||||
|
"map": "cpp",
|
||||||
|
"iomanip": "cpp",
|
||||||
|
"memory_resource": "cpp",
|
||||||
|
"ratio": "cpp",
|
||||||
|
"regex": "cpp",
|
||||||
|
"shared_mutex": "cpp",
|
||||||
|
"valarray": "cpp",
|
||||||
|
"random": "cpp",
|
||||||
|
"cuchar": "cpp",
|
||||||
|
"compare": "cpp",
|
||||||
|
"concepts": "cpp",
|
||||||
|
"numbers": "cpp",
|
||||||
|
"filesystem": "cpp",
|
||||||
|
"xstring": "cpp",
|
||||||
|
"charconv": "cpp",
|
||||||
|
"format": "cpp",
|
||||||
|
"ios": "cpp",
|
||||||
|
"list": "cpp",
|
||||||
|
"locale": "cpp",
|
||||||
|
"mutex": "cpp",
|
||||||
|
"stack": "cpp",
|
||||||
|
"stop_token": "cpp",
|
||||||
|
"thread": "cpp",
|
||||||
|
"xfacet": "cpp",
|
||||||
|
"xhash": "cpp",
|
||||||
|
"xiosbase": "cpp",
|
||||||
|
"xlocale": "cpp",
|
||||||
|
"xlocbuf": "cpp",
|
||||||
|
"xlocinfo": "cpp",
|
||||||
|
"xlocmes": "cpp",
|
||||||
|
"xlocmon": "cpp",
|
||||||
|
"xlocnum": "cpp",
|
||||||
|
"xloctime": "cpp",
|
||||||
|
"xmemory": "cpp",
|
||||||
|
"xstddef": "cpp",
|
||||||
|
"xtr1common": "cpp",
|
||||||
|
"xtree": "cpp",
|
||||||
|
"xutility": "cpp"
|
||||||
|
}
|
||||||
|
}
|
4
BuildAndInstall.sh
Executable file
4
BuildAndInstall.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
export DEVKITARM=/opt/devkitpro/devkitARM/
|
||||||
|
export DEVKITPRO=/opt/devkitpro/
|
||||||
|
make -j12
|
||||||
|
make install
|
@ -1,13 +0,0 @@
|
|||||||
#projectlogo img{
|
|
||||||
max-height: 70px;
|
|
||||||
}
|
|
||||||
img[src="logotype.svg"]{
|
|
||||||
width:10cm;
|
|
||||||
}
|
|
||||||
div.contents{
|
|
||||||
max-width: 85%;
|
|
||||||
margin-left: 2%;
|
|
||||||
}
|
|
||||||
.textblock h1{
|
|
||||||
border-bottom: 1px solid #666;
|
|
||||||
}
|
|
@ -32,14 +32,14 @@ DOXYFILE_ENCODING = UTF-8
|
|||||||
# title of most generated pages and in a few other places.
|
# title of most generated pages and in a few other places.
|
||||||
# The default value is: My Project.
|
# The default value is: My Project.
|
||||||
|
|
||||||
PROJECT_NAME = Renderd7-0.3.0
|
PROJECT_NAME = Renderd7-nightly
|
||||||
|
|
||||||
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
|
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
|
||||||
# could be handy for archiving the generated documentation or if some version
|
# could be handy for archiving the generated documentation or if some version
|
||||||
# control system is used.
|
# control system is used.
|
||||||
|
|
||||||
|
|
||||||
PROJECT_NUMBER = "v0.3.0"
|
PROJECT_NUMBER = "v0.7.0"
|
||||||
|
|
||||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||||
# for a project that appears at the top of each page and should give viewer a
|
# for a project that appears at the top of each page and should give viewer a
|
||||||
@ -52,7 +52,7 @@ PROJECT_BRIEF "3ds graphics helper"
|
|||||||
# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
|
# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
|
||||||
# the logo to the output directory.
|
# the logo to the output directory.
|
||||||
|
|
||||||
PROJECT_LOGO = Docs/logo.svg
|
PROJECT_LOGO =
|
||||||
|
|
||||||
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
|
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
|
||||||
# into which the generated documentation will be written. If a relative path is
|
# into which the generated documentation will be written. If a relative path is
|
||||||
@ -855,7 +855,7 @@ WARN_LOGFILE =
|
|||||||
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
|
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
|
||||||
# Note: If this tag is empty the current directory is searched.
|
# Note: If this tag is empty the current directory is searched.
|
||||||
|
|
||||||
INPUT = include doc/md
|
INPUT = .
|
||||||
|
|
||||||
# This tag can be used to specify the character encoding of the source files
|
# This tag can be used to specify the character encoding of the source files
|
||||||
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
|
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
|
||||||
@ -884,7 +884,7 @@ INPUT_ENCODING = UTF-8
|
|||||||
# *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, *.vhdl,
|
# *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, *.vhdl,
|
||||||
# *.ucf, *.qsf and *.ice.
|
# *.ucf, *.qsf and *.ice.
|
||||||
|
|
||||||
FILE_PATTERNS = *.hpp *.md
|
FILE_PATTERNS = *.hpp *.h *.cpp
|
||||||
|
|
||||||
# The RECURSIVE tag can be used to specify whether or not subdirectories should
|
# The RECURSIVE tag can be used to specify whether or not subdirectories should
|
||||||
# be searched for input files as well.
|
# be searched for input files as well.
|
||||||
@ -1192,7 +1192,7 @@ HTML_STYLESHEET =
|
|||||||
# list). For an example see the documentation.
|
# list). For an example see the documentation.
|
||||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||||
|
|
||||||
HTML_EXTRA_STYLESHEET = doc/custom.css
|
HTML_EXTRA_STYLESHEET = docsn.css
|
||||||
|
|
||||||
# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
|
# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
|
||||||
# other source files which should be copied to the HTML output directory. Note
|
# other source files which should be copied to the HTML output directory. Note
|
205
Makefile
Normal file
205
Makefile
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
.SUFFIXES:
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ifeq ($(strip $(DEVKITARM)),)
|
||||||
|
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||||
|
endif
|
||||||
|
|
||||||
|
include $(DEVKITARM)/3ds_rules
|
||||||
|
|
||||||
|
export renderd7_MAJOR := 0
|
||||||
|
export renderd7_MINOR := 8
|
||||||
|
export renderd7_PATCH := 5
|
||||||
|
|
||||||
|
VERSION := $(renderd7_MAJOR).$(renderd7_MINOR).$(renderd7_PATCH)
|
||||||
|
|
||||||
|
# If on a tagged commit, use the tag instead of the commit
|
||||||
|
ifneq ($(shell echo $(shell git tag -l --points-at HEAD) | head -c 1),)
|
||||||
|
GIT_VER := $(shell git tag -l --points-at HEAD)
|
||||||
|
else
|
||||||
|
GIT_VER := $(shell git rev-parse --short HEAD)
|
||||||
|
endif
|
||||||
|
|
||||||
|
TIME_TIME := $(shell date --iso=seconds)
|
||||||
|
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# TARGET is the name of the output
|
||||||
|
# BUILD is the directory where object files & intermediate files will be placed
|
||||||
|
# SOURCES is a list of directories containing source code
|
||||||
|
# DATA is a list of directories containing data files
|
||||||
|
# INCLUDES is a list of directories containing header files
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
TARGET := renderd7
|
||||||
|
SOURCES := source external/source external/libnsbmp/source
|
||||||
|
DATA := data
|
||||||
|
INCLUDES := include
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# options for code generation
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
|
||||||
|
|
||||||
|
CFLAGS := -g -Wall -Werror -mword-relocations -save-temps\
|
||||||
|
-DV_STRING=\"$(GIT_VER)\" \
|
||||||
|
-DV_TIME=\"$(TIME_TIME)\" \
|
||||||
|
-ffunction-sections -fdata-sections \
|
||||||
|
$(ARCH) $(BUILD_CFLAGS)
|
||||||
|
|
||||||
|
CFLAGS += $(INCLUDE) -D__3DS__ -D_GNU_SOURCE=1
|
||||||
|
|
||||||
|
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++20
|
||||||
|
|
||||||
|
ASFLAGS := -g $(ARCH) $(DEFINES)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# list of directories containing libraries, this must be the top level containing
|
||||||
|
# include and lib
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
LIBDIRS := $(PORTLIBS) $(CTRULIB)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# no real need to edit anything past this point unless you need to add additional
|
||||||
|
# rules for different file extensions
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||||
|
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||||
|
|
||||||
|
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||||
|
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||||
|
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||||
|
PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
|
||||||
|
SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
|
||||||
|
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# use CXX for linking C++ projects, CC for standard C
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ifeq ($(strip $(CPPFILES)),)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export LD := $(CC)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
else
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export LD := $(CXX)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
endif
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||||
|
|
||||||
|
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) \
|
||||||
|
$(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o)
|
||||||
|
|
||||||
|
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
|
||||||
|
|
||||||
|
export HFILES := $(PICAFILES:.v.pica=_shbin.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||||
|
|
||||||
|
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||||
|
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||||
|
-I.
|
||||||
|
|
||||||
|
.PHONY: clean all doc
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
all: lib/librenderd7.a lib/librenderd7d.a
|
||||||
|
|
||||||
|
doc:
|
||||||
|
@doxygen Doxyfile
|
||||||
|
|
||||||
|
dist-bin: all
|
||||||
|
@tar --exclude=*~ -cjf $(TARGET)-$(VERSION).tar.bz2 include lib
|
||||||
|
|
||||||
|
dist-src:
|
||||||
|
@tar --exclude=*~ -cjf $(TARGET)-src-$(VERSION).tar.bz2 include $(SOURCES) Makefile
|
||||||
|
|
||||||
|
dist: dist-src dist-bin
|
||||||
|
|
||||||
|
install: dist-bin
|
||||||
|
mkdir -p $(DEPSDIR)$(DEVKITPRO)/libctru
|
||||||
|
bzip2 -cd $(TARGET)-$(VERSION).tar.bz2 | tar -xf - -C $(DEPSDIR)$(DEVKITPRO)/libctru
|
||||||
|
|
||||||
|
lib:
|
||||||
|
@[ -d $@ ] || mkdir -p $@
|
||||||
|
|
||||||
|
release:
|
||||||
|
@[ -d $@ ] || mkdir -p $@
|
||||||
|
|
||||||
|
debug:
|
||||||
|
@[ -d $@ ] || mkdir -p $@
|
||||||
|
|
||||||
|
|
||||||
|
lib/librenderd7.a : lib release $(SOURCES) $(INCLUDES)
|
||||||
|
@$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \
|
||||||
|
BUILD_CFLAGS="-DNDEBUG=1 -O2 -fomit-frame-pointer" \
|
||||||
|
DEPSDIR=$(CURDIR)/release \
|
||||||
|
--no-print-directory -C release \
|
||||||
|
-f $(CURDIR)/Makefile
|
||||||
|
|
||||||
|
lib/librenderd7d.a : lib debug $(SOURCES) $(INCLUDES)
|
||||||
|
@$(MAKE) BUILD=debug OUTPUT=$(CURDIR)/$@ \
|
||||||
|
BUILD_CFLAGS="-DDEBUG=1 -Og" \
|
||||||
|
DEPSDIR=$(CURDIR)/debug \
|
||||||
|
--no-print-directory -C debug \
|
||||||
|
-f $(CURDIR)/Makefile
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
clean:
|
||||||
|
@echo clean ...
|
||||||
|
@rm -fr release debug lib includes
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
else
|
||||||
|
|
||||||
|
DEPENDS := $(OFILES:.o=.d)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# main targets
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
$(OUTPUT) : $(OFILES)
|
||||||
|
|
||||||
|
$(OFILES_SOURCES) : $(HFILES)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# you need a rule like this for each extension you use as binary data
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.bin.o %_bin.h : %.bin
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@$(bin2o)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# rules for assembling GPU shaders
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
define shader-as
|
||||||
|
$(eval CURBIN := $*.shbin)
|
||||||
|
$(eval DEPSFILE := $(DEPSDIR)/$*.shbin.d)
|
||||||
|
echo "$(CURBIN).o: $< $1" > $(DEPSFILE)
|
||||||
|
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
|
||||||
|
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
|
||||||
|
echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
|
||||||
|
picasso -o $(CURBIN) $1
|
||||||
|
bin2s $(CURBIN) | $(AS) -o $*.shbin.o
|
||||||
|
endef
|
||||||
|
|
||||||
|
%.shbin.o %_shbin.h : %.v.pica %.g.pica
|
||||||
|
@echo $(notdir $^)
|
||||||
|
@$(call shader-as,$^)
|
||||||
|
|
||||||
|
%.shbin.o %_shbin.h : %.v.pica
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@$(call shader-as,$<)
|
||||||
|
|
||||||
|
%.shbin.o %_shbin.h : %.shlist
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)$(file)))
|
||||||
|
|
||||||
|
-include $(DEPENDS)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------------
|
||||||
|
endif
|
||||||
|
#---------------------------------------------------------------------------------------
|
19
README.md
19
README.md
@ -1,5 +1,16 @@
|
|||||||
# RenderD7 030
|
# RenderD7 <img alt="LOGO" src="https://github.com/NPI-D7/RenderD7/blob/main/logo.png" height="30">
|
||||||
|
RenderD7 is now LibRenderD7.
|
||||||
|
### Installation (Ubuntu)
|
||||||
|
first run this
|
||||||
|
`sudo su`
|
||||||
|
then this
|
||||||
|
```
|
||||||
|
curl -L https://github.com/NPI-D7/RenderD7/releases/download/v0.8.0-pre1/renderd7-0.8.0.tar.bz2 -o renderd7-0.8.0.tar.bz2
|
||||||
|
mkdir -p /opt/devkitpro/libctru
|
||||||
|
bzip2 -cd renderd7-0.8.0.tar.bz2 | tar -xf - -C /opt/devkitpro/libctru
|
||||||
|
```
|
||||||
|
Make sure that `-lrenderd7` is before `-lcitro2d`, `-lcitro3d`, `-lctru`.
|
||||||
|
|
||||||
|
# RenderD7 (https://npi-d7.github.io/RenderD7/)
|
||||||
Simple and Easey to use UI and Graphics helper.
|
Simple and Easey to use UI and Graphics helper.
|
||||||
|
Create DOCS
|
||||||
|
|
||||||
|
|
||||||
|
638
docsn.css
Normal file
638
docsn.css
Normal file
@ -0,0 +1,638 @@
|
|||||||
|
/* This doxygen theme is free to use. If you like this, please Star https://github.com/kcwongjoe/doxygen_theme_flat_design */
|
||||||
|
|
||||||
|
/* Color Pattern. You can change this pattern to design your theme. */
|
||||||
|
|
||||||
|
:root {
|
||||||
|
/* Content */
|
||||||
|
--bgcolor: #ffffff;
|
||||||
|
--bgfont: #303030;
|
||||||
|
--bgfont2: #f3c60a;
|
||||||
|
--bgfont-hover: #f3c60a;
|
||||||
|
--bgfont-hover-text-decoration: none;
|
||||||
|
--bgborder: #7d7d7d;
|
||||||
|
--bgborder2: #f6f6f6;
|
||||||
|
/* Main Header */
|
||||||
|
--bg1color: #303030;
|
||||||
|
--bg1font: #ffffff;
|
||||||
|
--bg1font2: #f3c60a;
|
||||||
|
/* Second header */
|
||||||
|
--bg2color: #E2E2E2;
|
||||||
|
--bg2font: #7D7D7D;
|
||||||
|
--bg2-hover-bg: #ffffff;
|
||||||
|
--bg2-hover-font: #303030;
|
||||||
|
--bg2-hover-topborder: #f3c60a;
|
||||||
|
/* Third header */
|
||||||
|
--bg3color: #f6f6f6;
|
||||||
|
--bg3font: #303030;
|
||||||
|
--bg3font2: #7D7D7D;
|
||||||
|
/* Code */
|
||||||
|
--code-bg: #f6f6f6;
|
||||||
|
--code-comment: #7D7D7D;
|
||||||
|
--code-keyword: #d73a49;
|
||||||
|
--code-preprocessor: #d73a49;
|
||||||
|
--code-keywordtype: #d73a49;
|
||||||
|
--code-text: #303030;
|
||||||
|
--code-code: #6f42c1;
|
||||||
|
--code-line: #7D7D7D;
|
||||||
|
--code-line-bg: #D8D8D8;
|
||||||
|
/* Namespace List, Class List icon */
|
||||||
|
--icon-bg: #303030;
|
||||||
|
--icon-font: #f3c60a;
|
||||||
|
/* Class Index */
|
||||||
|
--qindex-menu-bg: #303030;
|
||||||
|
--qindex-menu-font: #ffffff;
|
||||||
|
--qindex-menu-font-hover: #f3c60a;
|
||||||
|
--qindex-icon-bg: #f3c60a;
|
||||||
|
--qindex-icon-font: #303030;
|
||||||
|
/* Member table */
|
||||||
|
--mem-title-bg: #303030;
|
||||||
|
--mem-title-font: #ffffff;
|
||||||
|
--mem-subtitle-bg: #f3c60a;
|
||||||
|
--mem-subtitle-font: #303030;
|
||||||
|
--mem-subtitle-font-hover: #303030;
|
||||||
|
--mem-content-bg: #ffffff;
|
||||||
|
--mem-content-font: #303030;
|
||||||
|
--mem-content-border: #f6f6f6;
|
||||||
|
/* Nav Tree */
|
||||||
|
--nav-tree-bg: #E2E2E2;
|
||||||
|
--nav-tree-bg-hover: #ffffff;
|
||||||
|
--nav-tree-font: #7D7D7D;
|
||||||
|
--nav-tree-font-hover: #303030;
|
||||||
|
--nav-tree-bg-selected: #f3c60a;
|
||||||
|
--nav-tree-font-selected: #303030;
|
||||||
|
}
|
||||||
|
|
||||||
|
body, table, div, p, dl {
|
||||||
|
color: var(--bgfont);
|
||||||
|
background-color: var(--bgcolor);
|
||||||
|
line-height: 150%;
|
||||||
|
font: 14px/22px, Roboto, Arial;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.contents {
|
||||||
|
margin: 20px 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.contents ul {
|
||||||
|
line-height: 200%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
/********** Project header *********/
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
#titlearea {
|
||||||
|
border-bottom: none;
|
||||||
|
padding-bottom: 20px;
|
||||||
|
padding-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#titlearea, #titlearea * {
|
||||||
|
color: var(--bg1font);
|
||||||
|
background-color: var(--bg1color);
|
||||||
|
}
|
||||||
|
|
||||||
|
#projectname {
|
||||||
|
padding: 0px 40px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#projectbrief {
|
||||||
|
padding: 0px 40px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#projectalign {
|
||||||
|
padding: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
/************ Main Menu ************/
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
/* Margin */
|
||||||
|
|
||||||
|
#main-menu {
|
||||||
|
padding: 0px 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main-menu a, #main-menu a:hover {
|
||||||
|
padding-top: 10px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Menu button */
|
||||||
|
|
||||||
|
#main-menu li a {
|
||||||
|
background-image: none;
|
||||||
|
font-family: Arial;
|
||||||
|
text-transform: uppercase;
|
||||||
|
text-shadow: none;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main-menu, #main-menu>li>a {
|
||||||
|
background-image: none;
|
||||||
|
background-color: var(--bg2color);
|
||||||
|
color: var(--bg2font);
|
||||||
|
transition: 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* hover Effect */
|
||||||
|
|
||||||
|
#main-menu>li {
|
||||||
|
border-top: 5px solid var(--bg2color);
|
||||||
|
}
|
||||||
|
|
||||||
|
#main-menu>li:hover {
|
||||||
|
color: var(--bg2-hover-font);
|
||||||
|
background-color: var(--bg2-hover-bg);
|
||||||
|
border-top: 5px solid var(--bg2-hover-topborder);
|
||||||
|
}
|
||||||
|
|
||||||
|
#main-menu>li:hover, #main-menu>li>a:hover, #main-menu>li>a.highlighted {
|
||||||
|
color: var(--bg2-hover-font);
|
||||||
|
background-color: var(--bg2-hover-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Search Bar */
|
||||||
|
|
||||||
|
#MSearchBox {
|
||||||
|
border-radius: 0;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#MSearchBox>span {
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main-menu>li:last-child {
|
||||||
|
padding: 25px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset search hover color*/
|
||||||
|
|
||||||
|
#main-menu>li:last-child:hover {
|
||||||
|
color: var(--bg2font);
|
||||||
|
background-color: var(--bg2color);
|
||||||
|
border-top: 5px solid var(--bg2color);
|
||||||
|
}
|
||||||
|
|
||||||
|
#MSearchResultsWindow {
|
||||||
|
border: 1px solid var(--bg3font2);
|
||||||
|
background-color: var(--bg3color);
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.SRPage, body.SRPage * {
|
||||||
|
font-family: Arial;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Sub Menu */
|
||||||
|
|
||||||
|
#main-menu>li ul {
|
||||||
|
transition: max-height 0.2s ease-in-out;
|
||||||
|
padding: 0px;
|
||||||
|
border-radius: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main-menu>li ul:before, #main-menu>li ul:after {
|
||||||
|
border-width: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main-menu>li>ul li a, #main-menu>li>ul li {
|
||||||
|
background-color: var(--bgcolor);
|
||||||
|
color: var(--bgfont);
|
||||||
|
background-image: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main-menu>li>ul li a:hover, #main-menu>li>ul li:hover {
|
||||||
|
background-color: var(--bgfont2);
|
||||||
|
color: var(--bgfont);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
/************** Header *************/
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
div.headertitle {
|
||||||
|
padding: 5px 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.header, div.header * {
|
||||||
|
color: var(--bg3font);
|
||||||
|
background-color: var(--bg3color);
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.summary {
|
||||||
|
padding-right: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
/************** Link *************/
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
a, a:visited, a:active, .contents a:visited, body.SRPage a, body.SRPage a:visited, body.SRPage a:active {
|
||||||
|
color: var(--bgfont);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover, .contents a:hover, body.SRPage a:hover {
|
||||||
|
color: var(--bgfont-hover);
|
||||||
|
text-decoration: var(--bgfont-hover-text-decoration);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
/************ Nav-path ************/
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
#nav-path, #nav-path ul {
|
||||||
|
background-image: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-path ul {
|
||||||
|
padding: 5px 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-path, #nav-path * {
|
||||||
|
color: var(--bg3font2);
|
||||||
|
background-color: var(--bg3color);
|
||||||
|
border: none;
|
||||||
|
font-family: Arial;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.navelem {
|
||||||
|
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbG5zOnN2Z2pzPSJodHRwOi8vc3ZnanMuY29tL3N2Z2pzIiB3aWR0aD0iNTEyIiBoZWlnaHQ9IjUxMiIgeD0iMCIgeT0iMCIgdmlld0JveD0iMCAwIDI5Mi4zNTkgMjkyLjM1OSIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNTEyIDUxMiIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgY2xhc3M9IiI+PGc+CjxnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+Cgk8cGF0aCBkPSJNMjIyLjk3OSwxMzMuMzMxTDk1LjA3Myw1LjQyNEM5MS40NTYsMS44MDcsODcuMTc4LDAsODIuMjI2LDBjLTQuOTUyLDAtOS4yMzMsMS44MDctMTIuODUsNS40MjQgICBjLTMuNjE3LDMuNjE3LTUuNDI0LDcuODk4LTUuNDI0LDEyLjg0N3YyNTUuODEzYzAsNC45NDgsMS44MDcsOS4yMzIsNS40MjQsMTIuODQ3YzMuNjIxLDMuNjE3LDcuOTAyLDUuNDI4LDEyLjg1LDUuNDI4ICAgYzQuOTQ5LDAsOS4yMy0xLjgxMSwxMi44NDctNS40MjhsMTI3LjkwNi0xMjcuOTA3YzMuNjE0LTMuNjEzLDUuNDI4LTcuODk3LDUuNDI4LTEyLjg0NyAgIEMyMjguNDA3LDE0MS4yMjksMjI2LjU5NCwxMzYuOTQ4LDIyMi45NzksMTMzLjMzMXoiIGZpbGw9IiM3ZDdkN2QiIGRhdGEtb3JpZ2luYWw9IiMwMDAwMDAiIHN0eWxlPSIiIGNsYXNzPSIiPjwvcGF0aD4KPC9nPgo8ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8L2c+CjxnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjwvZz4KPGcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPC9nPgo8ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8L2c+CjxnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjwvZz4KPGcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPC9nPgo8ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8L2c+CjxnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjwvZz4KPGcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPC9nPgo8ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8L2c+CjxnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjwvZz4KPGcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPC9nPgo8ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8L2c+CjxnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjwvZz4KPGcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPC9nPgo8L2c+PC9zdmc+);
|
||||||
|
background-size: 9px;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.navelem a {
|
||||||
|
margin-right: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
/*************** mem ***************/
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
.memtitle {
|
||||||
|
padding: 15px;
|
||||||
|
margin-top: 30px;
|
||||||
|
border-top-left-radius: 0px;
|
||||||
|
border-top-right-radius: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.memtitle, .memtitle *, .memtitle a:visited {
|
||||||
|
border: none;
|
||||||
|
background-image: none;
|
||||||
|
color: var(--mem-title-font);
|
||||||
|
background-color: var(--mem-title-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.memproto {
|
||||||
|
padding: 10px;
|
||||||
|
text-shadow: none;
|
||||||
|
padding: 20px;
|
||||||
|
border-top-right-radius: 0px;
|
||||||
|
-moz-border-radius-topright: 0px;
|
||||||
|
-webkit-border-top-right-radius: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.memproto, .memproto *, .memproto a:visited {
|
||||||
|
border: none;
|
||||||
|
background-image: none;
|
||||||
|
background-color: var(--mem-subtitle-bg);
|
||||||
|
color: var(--mem-subtitle-font);
|
||||||
|
font-size: inherit;
|
||||||
|
line-height: 100%
|
||||||
|
}
|
||||||
|
|
||||||
|
.memproto a:hover {
|
||||||
|
color: var(--mem-subtitle-font-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
.memdoc {
|
||||||
|
border-bottom: 1px solid var(--mem-content-border);
|
||||||
|
border-left: 1px solid var(--mem-content-border);
|
||||||
|
border-right: 1px solid var(--mem-content-border);
|
||||||
|
background-color: var(--mem-content-bg);
|
||||||
|
color: var(--mem-content-font);
|
||||||
|
border-bottom-left-radius: 0px;
|
||||||
|
border-bottom-right-radius: 0px;
|
||||||
|
-moz-border-radius-bottomleft: 0px;
|
||||||
|
-moz-border-radius-bottomright: 0px;
|
||||||
|
-webkit-border-bottom-left-radius: 0px;
|
||||||
|
-webkit-border-bottom-right-radius: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.memdoc p, .memdoc dt {
|
||||||
|
padding: 0px 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
/************* Contents ************/
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
a.anchor {
|
||||||
|
padding-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
/************* fragment ************/
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
h2.groupheader {
|
||||||
|
color: #303030;
|
||||||
|
font-size: 200%;
|
||||||
|
font-weight: bold;
|
||||||
|
border-bottom: none;
|
||||||
|
padding-top: 20px;
|
||||||
|
padding-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.fragment, pre.fragment {
|
||||||
|
border: none;
|
||||||
|
padding: 20px;
|
||||||
|
margin: none;
|
||||||
|
background-color: var(--code-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
div.line {
|
||||||
|
background-color: var(--code-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
span.comment {
|
||||||
|
color: var(--code-comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
span.keyword {
|
||||||
|
color: var(--code-keyword);
|
||||||
|
}
|
||||||
|
|
||||||
|
span.preprocessor {
|
||||||
|
color: var(--code-preprocessor);
|
||||||
|
}
|
||||||
|
|
||||||
|
span.keywordtype {
|
||||||
|
color: var(--code-keywordtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
span.mlabel {
|
||||||
|
background-color: var(--code-text);
|
||||||
|
color: var(--code-bg);
|
||||||
|
border-top: none;
|
||||||
|
border-left: none;
|
||||||
|
border-right: none;
|
||||||
|
border-bottom: none;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.code {
|
||||||
|
color: var(--code-code);
|
||||||
|
}
|
||||||
|
|
||||||
|
span.lineno, span.lineno>* {
|
||||||
|
color: var(--code-line);
|
||||||
|
border-right: none;
|
||||||
|
background-color: var(--code-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
span.lineno a {
|
||||||
|
background-color: var(--code-line-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
span.lineno a:hover {
|
||||||
|
color: var(--bg3font);
|
||||||
|
background-color: var(--code-line-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
/************* directory ***********/
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
.directory tr.even {
|
||||||
|
background-color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.iconfclosed {
|
||||||
|
background-image: url(closed-folder.png);
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.iconfopen {
|
||||||
|
background-image: url(opened-folder.png);
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icondoc {
|
||||||
|
background-image: url(document.png);
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow {
|
||||||
|
color: #7d7d7d;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icona {
|
||||||
|
vertical-align: middle;
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
background-color: var(--icon-bg);
|
||||||
|
color: var(--icon-font);
|
||||||
|
display: table-cell;
|
||||||
|
vertical-align: middle;
|
||||||
|
height: 20px;
|
||||||
|
width: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.ah {
|
||||||
|
background-color: var(--qindex-icon-bg);
|
||||||
|
color: var(--qindex-icon-font);
|
||||||
|
text-align: center;
|
||||||
|
background-image: none;
|
||||||
|
-webkit-box-shadow: none;
|
||||||
|
box-shadow: none;
|
||||||
|
-webkit-border-radius: 0px;
|
||||||
|
border-radius: 0px;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.qindex {
|
||||||
|
background-color: var(--qindex-menu-bg);
|
||||||
|
border: none;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.qindex {
|
||||||
|
color: var(--qindex-menu-font);
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover.qindex {
|
||||||
|
color: var(--qindex-menu-font-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
a:visited.qindex {
|
||||||
|
color: var(--qindex-menu-font);
|
||||||
|
}
|
||||||
|
|
||||||
|
table.classindex {
|
||||||
|
margin-top: 30px;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.classindex a.el {
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
/************** footer *************/
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
div.directory {
|
||||||
|
border-top: 1px solid var(--bgborder);
|
||||||
|
border-bottom: none;
|
||||||
|
margin: 20px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.directory a.el {
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.directory>table {
|
||||||
|
margin: 20px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr.footer {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contents>hr {
|
||||||
|
border-top: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
/*********** memberdecls ***********/
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
.memItemLeft, .memItemRight {
|
||||||
|
padding: 15px 30px;
|
||||||
|
background-color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mdescRight {
|
||||||
|
padding: 0px 30px 10px 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.memberdecls * {
|
||||||
|
background-color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.memSeparator {
|
||||||
|
border-bottom: 1px solid var(--bgborder2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.memTemplParams {
|
||||||
|
color: var(--bgfont);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
/*********** nav-tree ***********/
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
#nav-tree-contents {
|
||||||
|
background-color: var(--nav-tree-bg);
|
||||||
|
margin: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#side-nav, #nav-tree {
|
||||||
|
background-image: none;
|
||||||
|
background-color: var(--nav-tree-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-tree .item {
|
||||||
|
background-color: var(--nav-tree-bg);
|
||||||
|
font-family: Arial;
|
||||||
|
text-transform: uppercase;
|
||||||
|
text-shadow: none;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 700;
|
||||||
|
padding: 10px;
|
||||||
|
color: var(--nav-tree-font);
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-tree .arrow {
|
||||||
|
color: var(--nav-tree-font);
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-tree .selected {
|
||||||
|
background-image: none;
|
||||||
|
background-color: var(--nav-tree-bg-selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-tree .selected a {
|
||||||
|
color: var(--nav-tree-font-selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-tree .item:hover {
|
||||||
|
background-color: var(--nav-tree-bg-hover);
|
||||||
|
color: var(--nav-tree-font-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-tree .item a:hover {
|
||||||
|
color: var(--nav-tree-font-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
#side-nav .ui-resizable-e {
|
||||||
|
background-image: none;
|
||||||
|
background-color: var(--nav-tree-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-sync {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-sync>img {
|
||||||
|
content: url(off_sync.png);
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-sync.sync>img {
|
||||||
|
content: url(on_sync.png);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
/*********** Plant UML ***********/
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
|
|
||||||
|
.plantumlgraph > img {
|
||||||
|
width: 80%;
|
||||||
|
}
|
20
external/libnsbmp/COPYING
vendored
Normal file
20
external/libnsbmp/COPYING
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
Copyright (C) 2006 Richard Wilson
|
||||||
|
Copyright (C) 2008 Sean Fox
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
1388
external/libnsbmp/source/libnsbmp.c
vendored
Normal file
1388
external/libnsbmp/source/libnsbmp.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
386
external/source/fs.c
vendored
Normal file
386
external/source/fs.c
vendored
Normal file
@ -0,0 +1,386 @@
|
|||||||
|
#include <renderd7/external/fs.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define WORKING_DIR "/"
|
||||||
|
|
||||||
|
void Utils_U8_To_U16(u16 *buf, const u8 *input, size_t bufsize) {
|
||||||
|
ssize_t units = utf8_to_utf16(buf, input, bufsize);
|
||||||
|
|
||||||
|
if (units < 0)
|
||||||
|
units = 0;
|
||||||
|
|
||||||
|
buf[units] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FS_Archive archive, sdmc_archive, nand_archive;
|
||||||
|
|
||||||
|
Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID archiveID) {
|
||||||
|
Result ret = 0;
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSUSER_OpenArchive(archive, archiveID, fsMakePath(PATH_EMPTY, ""))))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FS_CloseArchive(FS_Archive archive) {
|
||||||
|
Result ret = 0;
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSUSER_CloseArchive(archive)))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FS_OpenDir(Handle *handle, FS_Archive archive, const char *path) {
|
||||||
|
Result ret = 0;
|
||||||
|
|
||||||
|
u16 path_u16[strlen(path) + 1];
|
||||||
|
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSUSER_OpenDirectory(handle, archive, fsMakePath(PATH_UTF16, path_u16))))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path, u32 flags, u32 attributes) {
|
||||||
|
Result ret = 0;
|
||||||
|
|
||||||
|
u16 path_u16[strlen(path) + 1];
|
||||||
|
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSUSER_OpenFile(handle, archive, fsMakePath(PATH_UTF16, path_u16), flags, attributes)))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FS_MakeDir(FS_Archive archive, const char *path) {
|
||||||
|
Result ret = 0;
|
||||||
|
|
||||||
|
u16 path_u16[strlen(path) + 1];
|
||||||
|
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSUSER_CreateDirectory(archive, fsMakePath(PATH_UTF16, path_u16), 0)))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FS_CreateFile(FS_Archive archive, const char *path, u64 size) {
|
||||||
|
Result ret = 0;
|
||||||
|
|
||||||
|
u16 path_u16[strlen(path) + 1];
|
||||||
|
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSUSER_CreateFile(archive, fsMakePath(PATH_UTF16, path_u16), 0, size)))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FS_RecursiveMakeDir(FS_Archive archive, const char *path) {
|
||||||
|
Result ret = 0;
|
||||||
|
char buf[256];
|
||||||
|
char *p = NULL;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "%s", path);
|
||||||
|
len = strlen(buf);
|
||||||
|
|
||||||
|
if (buf[len - 1] == '/')
|
||||||
|
buf[len - 1] = 0;
|
||||||
|
|
||||||
|
for (p = buf + 1; *p; p++) {
|
||||||
|
if (*p == '/') {
|
||||||
|
*p = 0;
|
||||||
|
|
||||||
|
if (!FS_DirExists(archive, buf))
|
||||||
|
ret = FS_MakeDir(archive, buf);
|
||||||
|
|
||||||
|
*p = '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!FS_DirExists(archive, buf))
|
||||||
|
ret = FS_MakeDir(archive, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FS_FileExists(FS_Archive archive, const char *path) {
|
||||||
|
Handle handle;
|
||||||
|
|
||||||
|
u16 path_u16[strlen(path) + 1];
|
||||||
|
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
|
||||||
|
|
||||||
|
if (R_FAILED(FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_READ, 0)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (R_FAILED(FSFILE_Close(handle)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FS_DirExists(FS_Archive archive, const char *path) {
|
||||||
|
Handle handle;
|
||||||
|
|
||||||
|
u16 path_u16[strlen(path) + 1];
|
||||||
|
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
|
||||||
|
|
||||||
|
if (R_FAILED(FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_UTF16, path_u16))))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (R_FAILED(FSDIR_Close(handle)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FS_GetFileSize(FS_Archive archive, const char *path, u64 *size) {
|
||||||
|
Result ret = 0;
|
||||||
|
Handle handle;
|
||||||
|
|
||||||
|
u16 path_u16[strlen(path) + 1];
|
||||||
|
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_READ, 0)))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSFILE_GetSize(handle, size))) {
|
||||||
|
FSFILE_Close(handle);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSFILE_Close(handle)))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 FS_GetFreeStorage(FS_SystemMediaType media_type) {
|
||||||
|
FS_ArchiveResource resource = {0};
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, media_type)))
|
||||||
|
return (((u64)resource.freeClusters * (u64)resource.clusterSize));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 FS_GetTotalStorage(FS_SystemMediaType media_type) {
|
||||||
|
FS_ArchiveResource resource = {0};
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, media_type)))
|
||||||
|
return (((u64)resource.totalClusters * (u64)resource.clusterSize));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 FS_GetUsedStorage(FS_SystemMediaType media_type) {
|
||||||
|
return 0;//(FS_GetTotalStorage(media_type) - FS_GetUsedStorage(media_type));
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FS_RemoveFile(FS_Archive archive, const char *path) {
|
||||||
|
Result ret = 0;
|
||||||
|
|
||||||
|
u16 path_u16[strlen(path) + 1];
|
||||||
|
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSUSER_DeleteFile(archive, fsMakePath(PATH_UTF16, path_u16))))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FS_RemoveDir(FS_Archive archive, const char *path) {
|
||||||
|
Result ret = 0;
|
||||||
|
|
||||||
|
u16 path_u16[strlen(path) + 1];
|
||||||
|
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSUSER_DeleteDirectory(archive, fsMakePath(PATH_UTF16, path_u16))))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FS_RemoveDirRecursive(FS_Archive archive, const char *path) {
|
||||||
|
Result ret = 0;
|
||||||
|
|
||||||
|
u16 path_u16[strlen(path) + 1];
|
||||||
|
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSUSER_DeleteDirectoryRecursively(archive, fsMakePath(PATH_UTF16, path_u16))))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FS_RenameFile(FS_Archive archive, const char *old_filename, const char *new_filename) {
|
||||||
|
Result ret = 0;
|
||||||
|
|
||||||
|
u16 old_filename_u16[strlen(old_filename) + 1];
|
||||||
|
Utils_U8_To_U16(old_filename_u16, (const u8 *)old_filename, strlen(old_filename) + 1);
|
||||||
|
|
||||||
|
u16 new_filename_u16[strlen(new_filename) + 1];
|
||||||
|
Utils_U8_To_U16(new_filename_u16, (const u8 *)new_filename, strlen(new_filename) + 1);
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSUSER_RenameFile(archive, fsMakePath(PATH_UTF16, old_filename_u16), archive, fsMakePath(PATH_UTF16, new_filename_u16))))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FS_RenameDir(FS_Archive archive, const char *old_dirname, const char *new_dirname) {
|
||||||
|
Result ret = 0;
|
||||||
|
|
||||||
|
u16 old_dirname_u16[strlen(old_dirname) + 1];
|
||||||
|
Utils_U8_To_U16(old_dirname_u16, (const u8 *)old_dirname, strlen(old_dirname) + 1);
|
||||||
|
|
||||||
|
u16 new_dirname_u16[strlen(new_dirname) + 1];
|
||||||
|
Utils_U8_To_U16(new_dirname_u16, (const u8 *)new_dirname, strlen(new_dirname) + 1);
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSUSER_RenameDirectory(archive, fsMakePath(PATH_UTF16, old_dirname_u16), archive, fsMakePath(PATH_UTF16, new_dirname_u16))))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FS_Read(FS_Archive archive, const char *path, u64 size, void *buf) {
|
||||||
|
Result ret = 0;
|
||||||
|
Handle handle;
|
||||||
|
|
||||||
|
u32 bytes_read = 0;
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FS_OpenFile(&handle, archive, path, FS_OPEN_READ, 0)))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSFILE_Read(handle, &bytes_read, 0, buf, size))) {
|
||||||
|
FSFILE_Close(handle);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSFILE_Close(handle)))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FS_Write(FS_Archive archive, const char *path, const void *buf, u32 size) {
|
||||||
|
Result ret = 0;
|
||||||
|
Handle handle;
|
||||||
|
u32 bytes_written = 0;
|
||||||
|
|
||||||
|
if (FS_FileExists(archive, path))
|
||||||
|
FS_RemoveFile(archive, path);
|
||||||
|
|
||||||
|
u16 path_u16[strlen(path) + 1];
|
||||||
|
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSUSER_CreateFile(archive, fsMakePath(PATH_UTF16, path_u16), 0, size)))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_WRITE, 0)))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSFILE_Write(handle, &bytes_written, 0, buf, size, FS_WRITE_FLUSH))) {
|
||||||
|
FSFILE_Close(handle);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (R_FAILED(ret = FSFILE_Close(handle)))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *FS_GetFileTimestamp(const char *path) {
|
||||||
|
static char timeStr[60];
|
||||||
|
u64 mtime = 0;
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(archive_getmtime(path, &mtime))) {
|
||||||
|
time_t mt = mtime;
|
||||||
|
struct tm *timeStruct = gmtime(&mt);
|
||||||
|
|
||||||
|
int hours = timeStruct->tm_hour;
|
||||||
|
int minutes = timeStruct->tm_min;
|
||||||
|
|
||||||
|
int day = timeStruct->tm_mday;
|
||||||
|
int month = timeStruct->tm_mon + 1; // January being 0
|
||||||
|
int year = timeStruct->tm_year + 1900;
|
||||||
|
|
||||||
|
snprintf(timeStr, 60, "%d/%d/%d %2i:%02i", year, month, day, hours, minutes);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return timeStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
FS_Path getPathInfo(const char * path, FS_ArchiveID * archive) {
|
||||||
|
*archive = ARCHIVE_SDMC;
|
||||||
|
FS_Path filePath = {0};
|
||||||
|
unsigned int prefixlen = 0;
|
||||||
|
|
||||||
|
if (!strncmp(path, "sdmc:/", 6)) {
|
||||||
|
prefixlen = 5;
|
||||||
|
} else if (*path != '/') {
|
||||||
|
//if the path is local (doesnt start with a slash), it needs to be appended to the working dir to be valid
|
||||||
|
char * actualPath = NULL;
|
||||||
|
asprintf(&actualPath, "%s%s", WORKING_DIR, path);
|
||||||
|
filePath = fsMakePath(PATH_ASCII, actualPath);
|
||||||
|
free(actualPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
//if the filePath wasnt set above, set it
|
||||||
|
if (filePath.size == 0) {
|
||||||
|
filePath = fsMakePath(PATH_ASCII, path+prefixlen);
|
||||||
|
}
|
||||||
|
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
Result makeDirs(const char * path) {
|
||||||
|
Result ret = 0;
|
||||||
|
FS_ArchiveID archiveID;
|
||||||
|
FS_Path filePath = getPathInfo(path, &archiveID);
|
||||||
|
FS_Archive archive;
|
||||||
|
|
||||||
|
ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
|
||||||
|
|
||||||
|
for (char * slashpos = strchr(path+1, '/'); slashpos != NULL; slashpos = strchr(slashpos+1, '/')) {
|
||||||
|
char bak = *(slashpos);
|
||||||
|
*(slashpos) = '\0';
|
||||||
|
Handle dirHandle;
|
||||||
|
|
||||||
|
ret = FSUSER_OpenDirectory(&dirHandle, archive, filePath);
|
||||||
|
if (R_SUCCEEDED(ret)) FSDIR_Close(dirHandle);
|
||||||
|
else ret = FSUSER_CreateDirectory(archive, filePath, FS_ATTRIBUTE_DIRECTORY);
|
||||||
|
|
||||||
|
*(slashpos) = bak;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSUSER_CloseArchive(archive);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result openFile(Handle* fileHandle, const char * path, bool write) {
|
||||||
|
FS_ArchiveID archive;
|
||||||
|
FS_Path filePath = getPathInfo(path, &archive);
|
||||||
|
u32 flags = (write ? (FS_OPEN_CREATE | FS_OPEN_WRITE) : FS_OPEN_READ);
|
||||||
|
|
||||||
|
Result ret = 0;
|
||||||
|
ret = makeDirs(strdup(path));
|
||||||
|
ret = FSUSER_OpenFileDirectly(fileHandle, archive, fsMakePath(PATH_EMPTY, ""), filePath, flags, 0);
|
||||||
|
if (write) ret = FSFILE_SetSize(*fileHandle, 0); //truncate the file to remove previous contents before writing
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
6464
external/source/lodepng.cpp
vendored
Normal file
6464
external/source/lodepng.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
extlibs/external.md
Normal file
1
extlibs/external.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
External Librarys
|
5
include/rd7.hpp
Normal file
5
include/rd7.hpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <renderd7/bmp.hpp>
|
||||||
|
#include <renderd7/renderd7.hpp>
|
||||||
|
#include <renderd7/StealConsole.hpp>
|
112
include/renderd7/BitmapPrinter.hpp
Normal file
112
include/renderd7/BitmapPrinter.hpp
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <renderd7/bmp.hpp>
|
||||||
|
#include <renderd7/bmpconverter.hpp>
|
||||||
|
|
||||||
|
#include <renderd7/Image.hpp>
|
||||||
|
|
||||||
|
#include <renderd7/Screen.hpp>
|
||||||
|
#include <renderd7/Time.hpp>
|
||||||
|
|
||||||
|
#include <renderd7/Fonts/NFontApi.hpp>
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
enum Encoder {
|
||||||
|
BITMAP, ///< Encode Data to Bitmap
|
||||||
|
DIRECT, ///< Encode Direct to Framebuffer(No Decoder Required)
|
||||||
|
C3D ///< Encode Directly to C3D_Tex (Just an Idea)
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Decoder {
|
||||||
|
BITMAP2C3D, ///< Decode and Encode to C3D_Tex (Currently Fastest) (47,4ms)
|
||||||
|
BITMAP2PNG2C3D ///< Decode Bitmap end Convert to Png, then C3D (Very Slow)
|
||||||
|
///< (201,4ms)
|
||||||
|
};
|
||||||
|
|
||||||
|
class BitmapPrinter {
|
||||||
|
public:
|
||||||
|
BitmapPrinter(int w, int h);
|
||||||
|
~BitmapPrinter();
|
||||||
|
bool DecodeFile(std::string file);
|
||||||
|
|
||||||
|
void SetDecoder(Decoder deccc) { decc = deccc; }
|
||||||
|
void DrawPixel(int x, int y, u8 b, u8 g, u8 r, u8 a);
|
||||||
|
void DrawRect(int x, int y, int w, int h, u8 line_w, u8 b, u8 g, u8 r, u8 a);
|
||||||
|
void DrawRectFilled(int x, int y, int w, int h, u8 b, u8 g, u8 r, u8 a);
|
||||||
|
void DrawBitmap(int x, int y, BMP map);
|
||||||
|
void UsePreMap(BMP map);
|
||||||
|
void UsePrePrintMap(BitmapPrinter printmap);
|
||||||
|
BMP GetBitmap() { return bitmap; }
|
||||||
|
void SaveBmp(std::string name);
|
||||||
|
void SavePng(std::string name);
|
||||||
|
|
||||||
|
void CreateScreen(C3D_RenderTarget *target);
|
||||||
|
bool DrawScreenDirectF(int framerate);
|
||||||
|
bool DrawScreenDirect();
|
||||||
|
void DrawScreenF(int framerate);
|
||||||
|
void DrawScreen();
|
||||||
|
bool UpdateScreenF(int framerate);
|
||||||
|
bool UpdateScreen();
|
||||||
|
void Clear(u8 b = 0, u8 g = 0, u8 r = 0, u8 a = 255);
|
||||||
|
void ClearBlank();
|
||||||
|
RenderD7::Image GetImage();
|
||||||
|
/// Test to Find out The Best Settings for BitmapPrinter
|
||||||
|
void Benchmark();
|
||||||
|
/// Setup the Benchmark
|
||||||
|
/// \param framerate The Fps of the ScreenUpdates
|
||||||
|
void SetupBenchmark(int framerate);
|
||||||
|
bool IsBenchmarkRunning() { return this->benchmark; }
|
||||||
|
|
||||||
|
void DrawDebugText(int x, int y, int t_size, u32 color, std::string text);
|
||||||
|
void DrawText(int x, int y, float t_size, u32 color, std::string text,
|
||||||
|
RenderD7::NFontApi font);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// funcs
|
||||||
|
bool Decode(Decoder deccc);
|
||||||
|
void DrawDebugChar(u32 posX, u32 posY, int t_size, u32 color, char character);
|
||||||
|
void DrawChar(int posX, int posY, float t_size, u32 color, char character,
|
||||||
|
RenderD7::NFontApi font);
|
||||||
|
// parameter
|
||||||
|
int frame = 0;
|
||||||
|
RenderD7::Image renderframe;
|
||||||
|
bool isscreen = false;
|
||||||
|
C3D_RenderTarget *targetr;
|
||||||
|
BMP bitmap = BMP(
|
||||||
|
20, 20,
|
||||||
|
true); // Need to Set e Predefined Bitmap. If not the System will Crash.
|
||||||
|
BMP blank = BMP(
|
||||||
|
20, 20,
|
||||||
|
true); // Need to Set e Predefined Bitmap. If not the System will Crash.
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Benchmark Stuff;
|
||||||
|
int testfpsd;
|
||||||
|
bool benchmark = false;
|
||||||
|
bool setupbenchmark;
|
||||||
|
float frametime = 0;
|
||||||
|
uint64_t lastTime = 0;
|
||||||
|
float dtt = 0.f;
|
||||||
|
float dtt2 = 0.f;
|
||||||
|
float dtt3 = 0.f;
|
||||||
|
float timer = 0;
|
||||||
|
float mhdtt = 0;
|
||||||
|
float mdtt2;
|
||||||
|
float mdtt3;
|
||||||
|
|
||||||
|
float fpsClock = 0.f;
|
||||||
|
int frameCounter = 0, fps = 0;
|
||||||
|
|
||||||
|
std::vector<float> hdttt;
|
||||||
|
std::vector<float> hdttt2;
|
||||||
|
std::vector<float> hdttt3;
|
||||||
|
std::vector<int> fpscountc;
|
||||||
|
int renderedframes = 0;
|
||||||
|
int testfps = 60;
|
||||||
|
Encoder encc = Encoder::BITMAP;
|
||||||
|
Decoder decc = Decoder::BITMAP2C3D;
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
};
|
||||||
|
} // namespace RenderD7
|
31
include/renderd7/Color.hpp
Normal file
31
include/renderd7/Color.hpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cstring>
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <regex>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define UNPACK_RGBA(col) (uint8_t)(col >> 24), (col >> 16), (col >> 8), (col)
|
||||||
|
#define UNPACK_BGRA(col) (uint8_t)(col >> 8), (col >> 16), (col >> 24), (col)
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
namespace Color {
|
||||||
|
struct rgba {
|
||||||
|
uint8_t r, g, b, a;
|
||||||
|
};
|
||||||
|
class RGBA {
|
||||||
|
public:
|
||||||
|
RGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
||||||
|
: m_r(r), m_g(g), m_b(b), m_a(a) {}
|
||||||
|
uint32_t toRGBA() const {
|
||||||
|
return (m_r << 24) | (m_g << 16) | (m_b << 8) | m_a;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t m_r, m_g, m_b, m_a;
|
||||||
|
};
|
||||||
|
std::string RGB2Hex(int r, int g, int b);
|
||||||
|
uint32_t Hex(const std::string color, uint8_t a = 255);
|
||||||
|
} // namespace Color
|
||||||
|
} // namespace RenderD7
|
28
include/renderd7/Draw.hpp
Normal file
28
include/renderd7/Draw.hpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <3ds.h>
|
||||||
|
#include <citro2d.h>
|
||||||
|
#include <citro3d.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
namespace Draw {
|
||||||
|
bool Rect(float x, float y, float w, float h, u32 color);
|
||||||
|
bool NFRect(float p1x, float p1y, float w, float h, u32 color, float scale = 1);
|
||||||
|
bool Px(float x, float y, u32 color);
|
||||||
|
void TextCentered(float x, float y, float size, u32 color, std::string Text,
|
||||||
|
int maxWidth = 0, int maxHeight = 0, C2D_Font fnt = nullptr);
|
||||||
|
void Text(float x, float y, float size, u32 color, std::string Text,
|
||||||
|
int maxWidth = 0, int maxHeight = 0, C2D_Font fnt = nullptr);
|
||||||
|
void TextRight(float x, float y, float size, u32 color, std::string Text,
|
||||||
|
int maxWidth = 0, int maxHeight = 0, C2D_Font fnt = nullptr);
|
||||||
|
float GetTextWidth(float size, std::string Text, C2D_Font fnt = nullptr);
|
||||||
|
void GetTextSize(float size, float *width, float *height, std::string Text,
|
||||||
|
C2D_Font fnt = nullptr);
|
||||||
|
float GetTextHeight(float size, std::string Text, C2D_Font fnt = nullptr);
|
||||||
|
Result LoadFont(C2D_Font &fnt, const char *Path = "");
|
||||||
|
Result UnloadFont(C2D_Font &fnt);
|
||||||
|
bool Circle(float x, float y, float radius, u32 color);
|
||||||
|
bool Image(C2D_Image img, float x, float y, float scaleX = 1.0f,
|
||||||
|
float scaleY = 1.0f);
|
||||||
|
} // namespace Draw
|
||||||
|
} // namespace RenderD7
|
17
include/renderd7/FileSystem.hpp
Normal file
17
include/renderd7/FileSystem.hpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// FileSystem based on libphyfs based on
|
||||||
|
// https://github.com/TurtleP/3ds-examples/blob/fs/physfs/fs/physfs/include/filesystem.h
|
||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
namespace FileSystem {
|
||||||
|
struct Entry {
|
||||||
|
std::string path;
|
||||||
|
std::string name;
|
||||||
|
bool dir = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<RenderD7::FileSystem::Entry> GetDirContent(std::string path);
|
||||||
|
} // namespace FileSystem
|
||||||
|
} // namespace RenderD7
|
142
include/renderd7/Fonts/NFontApi.hpp
Normal file
142
include/renderd7/Fonts/NFontApi.hpp
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <bitset>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <renderd7/external/stb_truetype.h>
|
||||||
|
|
||||||
|
#define MAXUNICODE 0x10FFFF
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
inline int utf8_decode(const char *o) {
|
||||||
|
static const unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF};
|
||||||
|
const unsigned char *s = (const unsigned char *)o;
|
||||||
|
unsigned int c = s[0];
|
||||||
|
unsigned int res = 0; /* final result */
|
||||||
|
if (c < 0x80) /* ascii? */
|
||||||
|
res = c;
|
||||||
|
else {
|
||||||
|
int count = 0; /* to count number of continuation bytes */
|
||||||
|
while (c & 0x40) { /* still have continuation bytes? */
|
||||||
|
int cc = s[++count]; /* read next byte */
|
||||||
|
if ((cc & 0xC0) != 0x80) /* not a continuation byte? */
|
||||||
|
return -1; /* invalid byte sequence */
|
||||||
|
res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */
|
||||||
|
c <<= 1; /* to test next bit */
|
||||||
|
}
|
||||||
|
res |= ((c & 0x7F) << (count * 5)); /* add first byte */
|
||||||
|
if (count > 3 || res > MAXUNICODE || res <= limits[count])
|
||||||
|
return -1; /* invalid byte sequence */
|
||||||
|
s += count; /* skip continuation bytes read */
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string IntToUtf8(int convertval) {
|
||||||
|
|
||||||
|
// We only care about plane 1 right now,
|
||||||
|
// but know that we have other options (0x10FFFF)
|
||||||
|
// Technically UTF-8 is "limited" to 4 bytes, so it's not
|
||||||
|
// Like it matters much anyways these days
|
||||||
|
|
||||||
|
if (convertval == 0)
|
||||||
|
return " ";
|
||||||
|
if ((convertval <= 0x7F) && (convertval > 0x00)) {
|
||||||
|
|
||||||
|
std::string out(".");
|
||||||
|
|
||||||
|
std::bitset<8> x(convertval);
|
||||||
|
|
||||||
|
unsigned long l = x.to_ulong();
|
||||||
|
unsigned char c = static_cast<unsigned char>(l);
|
||||||
|
out[0] = c;
|
||||||
|
|
||||||
|
return out;
|
||||||
|
|
||||||
|
} else if ((convertval >= 0x80) && (convertval <= 0x07FF)) {
|
||||||
|
|
||||||
|
std::string out("..");
|
||||||
|
|
||||||
|
int firstShift = (convertval >> 0x06) ^ 0xC0;
|
||||||
|
int secondShift = ((convertval ^ 0xFFC0) | 0x80) & ~0x40;
|
||||||
|
|
||||||
|
std::bitset<8> first(firstShift);
|
||||||
|
std::bitset<8> last(secondShift);
|
||||||
|
|
||||||
|
unsigned long l = first.to_ulong();
|
||||||
|
unsigned char c = static_cast<unsigned char>(l);
|
||||||
|
out[0] = c;
|
||||||
|
|
||||||
|
unsigned long ltwo = last.to_ulong();
|
||||||
|
unsigned char ctwo = static_cast<unsigned char>(ltwo);
|
||||||
|
out[1] = ctwo;
|
||||||
|
|
||||||
|
return out;
|
||||||
|
|
||||||
|
} else if ((convertval >= 0x0800) && (convertval <= 0xFFFF)) {
|
||||||
|
|
||||||
|
std::string out("...");
|
||||||
|
|
||||||
|
int firstShift = ((convertval ^ 0xFC0FFF) >> 0x0C) | 0xE0;
|
||||||
|
int secondShift = (((convertval ^ 0xFFF03F) >> 0x06) | 0x80) & ~0x40;
|
||||||
|
int thirdShift = ((convertval ^ 0xFFFC0) | 0x80) & ~0x40;
|
||||||
|
|
||||||
|
std::bitset<8> first(firstShift);
|
||||||
|
std::bitset<8> second(secondShift);
|
||||||
|
std::bitset<8> third(thirdShift);
|
||||||
|
|
||||||
|
unsigned long lone = first.to_ulong();
|
||||||
|
unsigned char cone = static_cast<unsigned char>(lone);
|
||||||
|
out[0] = cone;
|
||||||
|
|
||||||
|
unsigned long ltwo = second.to_ulong();
|
||||||
|
unsigned char ctwo = static_cast<unsigned char>(ltwo);
|
||||||
|
out[1] = ctwo;
|
||||||
|
|
||||||
|
unsigned long lthree = third.to_ulong();
|
||||||
|
unsigned char cthree = static_cast<unsigned char>(lthree);
|
||||||
|
out[2] = cthree;
|
||||||
|
|
||||||
|
return out;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#define I2U82I(val) RenderD7::utf8_decode(RenderD7::IntToUtf8(val).c_str())
|
||||||
|
|
||||||
|
class NFontApi {
|
||||||
|
public:
|
||||||
|
NFontApi();
|
||||||
|
~NFontApi();
|
||||||
|
void LoadTTF(std::string path);
|
||||||
|
unsigned char *GetGlyphBitmap(char glyph);
|
||||||
|
std::string GetStatus() { return status; }
|
||||||
|
float GetScale() { return scale; }
|
||||||
|
int GetGlyphWidth(char glyph);
|
||||||
|
int GetGlyphHeight(char glyph);
|
||||||
|
int GetLineHeight() { return l_h; }
|
||||||
|
int GetBaseHeight() { return height; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string status;
|
||||||
|
|
||||||
|
int height;
|
||||||
|
|
||||||
|
float scale;
|
||||||
|
int b_w;
|
||||||
|
int b_h;
|
||||||
|
int l_h;
|
||||||
|
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
|
|
||||||
|
int x0, y0, x1, y1;
|
||||||
|
int ascent, baseline, decent, linegap;
|
||||||
|
|
||||||
|
int linespace;
|
||||||
|
|
||||||
|
stbtt_fontinfo font;
|
||||||
|
};
|
||||||
|
} // namespace RenderD7
|
47
include/renderd7/Image.hpp
Normal file
47
include/renderd7/Image.hpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <citro2d.h>
|
||||||
|
#include <citro3d.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include <renderd7/Sheet.hpp>
|
||||||
|
#include <renderd7/bmp.hpp>
|
||||||
|
#include <renderd7/bmpconverter.hpp>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstring>
|
||||||
|
#include <renderd7/Color.hpp>
|
||||||
|
#include <renderd7/external/lodepng.h>
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
/// Image Class
|
||||||
|
class Image {
|
||||||
|
public:
|
||||||
|
Image() {}
|
||||||
|
~Image();
|
||||||
|
|
||||||
|
void Unload();
|
||||||
|
/// Load Image from Png
|
||||||
|
/// \param path path to png file
|
||||||
|
void LoadPng(const std::string path);
|
||||||
|
/// Load the Image from buffer
|
||||||
|
/// \param buffer the frame buffer
|
||||||
|
void LoadPFromBuffer(const std::vector<u8> &buffer);
|
||||||
|
void LoadFromBitmap(BMP bitmap);
|
||||||
|
void LoadJpg(std::string path);
|
||||||
|
/// Draw the Image directly
|
||||||
|
/// \param x The x position
|
||||||
|
/// \param y the y position
|
||||||
|
/// \param scaleX x scale from 0.0 to 1.0
|
||||||
|
/// \param scaleY y scale from 0.0 to 1.0
|
||||||
|
bool Draw(float x, float y, float scaleX = 1.0f, float scaleY = 1.0f);
|
||||||
|
/// \brief Get The Image
|
||||||
|
/// \return C2D_Image
|
||||||
|
C2D_Image Get() { return this->img; }
|
||||||
|
|
||||||
|
void FromSheet(RenderD7::Sheet sheet, size_t index);
|
||||||
|
/// \param img this is the C2D_Image
|
||||||
|
C2D_Image img;
|
||||||
|
/// \param loadet whether the image is loadet or not
|
||||||
|
bool loadet = false;
|
||||||
|
};
|
||||||
|
} // namespace RenderD7
|
17
include/renderd7/Ovl.hpp
Normal file
17
include/renderd7/Ovl.hpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
class Ovl {
|
||||||
|
public:
|
||||||
|
virtual ~Ovl() {}
|
||||||
|
virtual void Draw() const = 0;
|
||||||
|
virtual void Logic() = 0;
|
||||||
|
inline bool IsKilled() { return this->iskilled; }
|
||||||
|
inline void Kill() { iskilled = true; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool iskilled = false;
|
||||||
|
};
|
||||||
|
void AddOvl(std::unique_ptr<RenderD7::Ovl> scene);
|
||||||
|
} // namespace RenderD7
|
27
include/renderd7/ResultDecoder.hpp
Normal file
27
include/renderd7/ResultDecoder.hpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <3ds.h>
|
||||||
|
|
||||||
|
namespace RenderD7
|
||||||
|
{
|
||||||
|
class ResultDecoder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ResultDecoder(){}
|
||||||
|
~ResultDecoder(){}
|
||||||
|
void Load(Result rescode);
|
||||||
|
void Load(std::string rescode);
|
||||||
|
std::string GetCode();
|
||||||
|
std::string GetLevel();
|
||||||
|
int GetLevelInt();
|
||||||
|
std::string GetModule();
|
||||||
|
int GetModuleInt();
|
||||||
|
std::string GetDescription();
|
||||||
|
int GetDescriptionInt();
|
||||||
|
std::string GetSummary();
|
||||||
|
int GetSummaryInt();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Result m_rescode;
|
||||||
|
};
|
||||||
|
}
|
13
include/renderd7/Screen.hpp
Normal file
13
include/renderd7/Screen.hpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <citro2d.h>
|
||||||
|
#include <citro3d.h>
|
||||||
|
|
||||||
|
extern C3D_RenderTarget *Top;
|
||||||
|
extern C3D_RenderTarget *TopRight;
|
||||||
|
extern C3D_RenderTarget *Bottom;
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
/// Set current RenderScreen
|
||||||
|
/// \param target The RenderTarget Top, Bottom
|
||||||
|
void OnScreen(C3D_RenderTarget *target);
|
||||||
|
} // namespace RenderD7
|
21
include/renderd7/Sheet.hpp
Normal file
21
include/renderd7/Sheet.hpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <citro2d.h>
|
||||||
|
#include <citro3d.h>
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
/** The Spritesheet Class */
|
||||||
|
class Sheet {
|
||||||
|
public:
|
||||||
|
/// Construct sheet
|
||||||
|
Sheet();
|
||||||
|
// Deconstruct sheet
|
||||||
|
~Sheet();
|
||||||
|
/// Load a Sritesheet
|
||||||
|
/// \param path Path to the Spritesheet (.t3x)
|
||||||
|
Result Load(const char *path);
|
||||||
|
/// Unload the Spritesheet
|
||||||
|
void Free();
|
||||||
|
/// The Spritesheet
|
||||||
|
C2D_SpriteSheet spritesheet;
|
||||||
|
};
|
||||||
|
} // namespace RenderD7
|
39
include/renderd7/Sprite.hpp
Normal file
39
include/renderd7/Sprite.hpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <citro2d.h>
|
||||||
|
#include <citro3d.h>
|
||||||
|
|
||||||
|
#include <renderd7/Image.hpp>
|
||||||
|
#include <renderd7/Sheet.hpp>
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
/// Sprite Class
|
||||||
|
class Sprite {
|
||||||
|
public:
|
||||||
|
/// \brief Construct Sprite
|
||||||
|
Sprite();
|
||||||
|
/// \brief Deconstruct Sprite
|
||||||
|
~Sprite();
|
||||||
|
/// \brief Load a Sprite From SpriteSheet
|
||||||
|
/// \param sheet the Sheet to load from.(RenderD7::Sheet)
|
||||||
|
/// \param index the number of the Sprite in the Sheet
|
||||||
|
void FromSheet(RenderD7::Sheet *sheet, size_t index);
|
||||||
|
/// \brief Load a Sprite From SpriteSheet
|
||||||
|
/// \param img the Image to load from.(RenderD7::Image)
|
||||||
|
void FromImage(RenderD7::Image *img);
|
||||||
|
bool Draw();
|
||||||
|
void SetCenter(float x, float y);
|
||||||
|
void SetPos(float x, float y);
|
||||||
|
void SetScale(float x, float y);
|
||||||
|
void SetRotation(float rotation);
|
||||||
|
void Rotate(float speed);
|
||||||
|
float getWidth();
|
||||||
|
float getHeigh();
|
||||||
|
float getPosX();
|
||||||
|
float getPosY();
|
||||||
|
|
||||||
|
private:
|
||||||
|
C2D_ImageTint tint;
|
||||||
|
C2D_Sprite sprite;
|
||||||
|
};
|
||||||
|
} // namespace RenderD7
|
25
include/renderd7/SpriteAnimation.hpp
Normal file
25
include/renderd7/SpriteAnimation.hpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <renderd7/Sheet.hpp>
|
||||||
|
#include <renderd7/Sprite.hpp>
|
||||||
|
|
||||||
|
#include <citro2d.h>
|
||||||
|
#include <citro3d.h>
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
class SpriteSheetAnimation : public RenderD7::Sprite {
|
||||||
|
public:
|
||||||
|
SpriteSheetAnimation();
|
||||||
|
~SpriteSheetAnimation();
|
||||||
|
void Setup(RenderD7::Sheet *sheet, size_t imagecount, size_t startimage,
|
||||||
|
float frame_begin, float frame_finish);
|
||||||
|
void Play(float timespeed);
|
||||||
|
|
||||||
|
private:
|
||||||
|
size_t images;
|
||||||
|
size_t imgs = 0;
|
||||||
|
float D_totaltime;
|
||||||
|
RenderD7::Sheet *sheet;
|
||||||
|
float time;
|
||||||
|
};
|
||||||
|
} // namespace RenderD7
|
16
include/renderd7/StealConsole.hpp
Normal file
16
include/renderd7/StealConsole.hpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
class StealConsole {
|
||||||
|
public:
|
||||||
|
StealConsole();
|
||||||
|
~StealConsole();
|
||||||
|
std::string GetStdout();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::stringstream stolen_stdout;
|
||||||
|
};
|
||||||
|
} // namespace RenderD7
|
8
include/renderd7/Tasks.hpp
Normal file
8
include/renderd7/Tasks.hpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <3ds.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Tasks {
|
||||||
|
void create(ThreadFunc entrypoint);
|
||||||
|
void destroy(void);
|
||||||
|
} // namespace Tasks
|
7
include/renderd7/Time.hpp
Normal file
7
include/renderd7/Time.hpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
std::string FormatString(std::string fmt_str, ...);
|
||||||
|
std::string GetTimeStr(void);
|
||||||
|
} // namespace RenderD7
|
22
include/renderd7/Toast.hpp
Normal file
22
include/renderd7/Toast.hpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <renderd7/BitmapPrinter.hpp>
|
||||||
|
#include <renderd7/Color.hpp>
|
||||||
|
#include <renderd7/Image.hpp>
|
||||||
|
#include <renderd7/Ovl.hpp>
|
||||||
|
#include <renderd7/Screen.hpp>
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
class Toast : public RenderD7::Ovl {
|
||||||
|
public:
|
||||||
|
Toast(std::string head, std::string msg);
|
||||||
|
void Draw(void) const override;
|
||||||
|
void Logic() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
RenderD7::BitmapPrinter toast = RenderD7::BitmapPrinter(400, 70);
|
||||||
|
RenderD7::Image *toastrendered;
|
||||||
|
std::string head, msg;
|
||||||
|
int msgposy = 240;
|
||||||
|
int delay = 0;
|
||||||
|
};
|
||||||
|
} // namespace RenderD7
|
707
include/renderd7/bmp.hpp
Normal file
707
include/renderd7/bmp.hpp
Normal file
@ -0,0 +1,707 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <iterator>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
|
||||||
|
struct BMPFileHeader {
|
||||||
|
uint16_t file_type{0x4D42}; // File type always BM which is 0x4D42 (stored as
|
||||||
|
// hex uint16_t in little endian)
|
||||||
|
uint32_t file_size{0}; // Size of the file (in bytes)
|
||||||
|
uint16_t reserved1{0}; // Reserved, always 0
|
||||||
|
uint16_t reserved2{0}; // Reserved, always 0
|
||||||
|
uint32_t offset_data{
|
||||||
|
0}; // Start position of pixel data (bytes from the beginning of the file)
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BMPInfoHeader {
|
||||||
|
uint32_t size{0}; // Size of this header (in bytes)
|
||||||
|
int32_t width{0}; // width of bitmap in pixels
|
||||||
|
int32_t height{
|
||||||
|
0}; // height of bitmap in pixels
|
||||||
|
// (if positive, bottom-up, with origin in lower left corner)
|
||||||
|
// (if negative, top-down, with origin in upper left corner)
|
||||||
|
uint16_t planes{1}; // No. of planes for the target device, this is always 1
|
||||||
|
uint16_t bit_count{0}; // No. of bits per pixel
|
||||||
|
uint32_t compression{0}; // 0 or 3 - uncompressed. THIS PROGRAM CONSIDERS ONLY
|
||||||
|
// UNCOMPRESSED BMP images
|
||||||
|
uint32_t size_image{0}; // 0 - for uncompressed images
|
||||||
|
int32_t x_pixels_per_meter{0};
|
||||||
|
int32_t y_pixels_per_meter{0};
|
||||||
|
uint32_t colors_used{0}; // No. color indexes in the color table. Use 0 for
|
||||||
|
// the max number of colors allowed by bit_count
|
||||||
|
uint32_t colors_important{0}; // No. of colors used for displaying the bitmap.
|
||||||
|
// If 0 all colors are required
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BMPColorHeader {
|
||||||
|
uint32_t red_mask{0x00ff0000}; // Bit mask for the red channel
|
||||||
|
uint32_t green_mask{0x0000ff00}; // Bit mask for the green channel
|
||||||
|
uint32_t blue_mask{0x000000ff}; // Bit mask for the blue channel
|
||||||
|
uint32_t alpha_mask{0xff000000}; // Bit mask for the alpha channel
|
||||||
|
uint32_t color_space_type{0x73524742}; // Default "sRGB" (0x73524742)
|
||||||
|
uint32_t unused[16]{0}; // Unused data for sRGB color space
|
||||||
|
};
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
class BMP {
|
||||||
|
public:
|
||||||
|
BMPFileHeader file_header;
|
||||||
|
BMPInfoHeader bmp_info_header;
|
||||||
|
BMPColorHeader bmp_color_header;
|
||||||
|
std::vector<uint8_t> data;
|
||||||
|
|
||||||
|
BMP(const char *fname) { read(fname); }
|
||||||
|
|
||||||
|
int read(const char *fname) {
|
||||||
|
std::ifstream inp{fname, std::ios_base::binary};
|
||||||
|
if (inp) {
|
||||||
|
inp.read((char *)&file_header, sizeof(file_header));
|
||||||
|
if (file_header.file_type != 0x4D42) {
|
||||||
|
|
||||||
|
return 50;
|
||||||
|
// throw std::runtime_error("Error! Unrecognized file format.");
|
||||||
|
}
|
||||||
|
inp.read((char *)&bmp_info_header, sizeof(bmp_info_header));
|
||||||
|
|
||||||
|
// The BMPColorHeader is used only for transparent images
|
||||||
|
if (bmp_info_header.bit_count == 32) {
|
||||||
|
// Check if the file has bit mask color information
|
||||||
|
if (bmp_info_header.size >=
|
||||||
|
(sizeof(BMPInfoHeader) + sizeof(BMPColorHeader))) {
|
||||||
|
inp.read((char *)&bmp_color_header, sizeof(bmp_color_header));
|
||||||
|
// Check if the pixel data is stored as BGRA and if the color space
|
||||||
|
// type is sRGB
|
||||||
|
check_color_header(bmp_color_header);
|
||||||
|
} else {
|
||||||
|
// std::cerr << "Error! The file \"" << fname << "\" does not seem to
|
||||||
|
// contain bit mask information\n"; return 51;//throw
|
||||||
|
// std::runtime_error("Error! Unrecognized file format.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Jump to the pixel data location
|
||||||
|
inp.seekg(file_header.offset_data, inp.beg);
|
||||||
|
|
||||||
|
// Adjust the header fields for output.
|
||||||
|
// Some editors will put extra info in the image file, we only save the
|
||||||
|
// headers and the data.
|
||||||
|
if (bmp_info_header.bit_count == 32) {
|
||||||
|
bmp_info_header.size = sizeof(BMPInfoHeader) + sizeof(BMPColorHeader);
|
||||||
|
file_header.offset_data = sizeof(BMPFileHeader) +
|
||||||
|
sizeof(BMPInfoHeader) +
|
||||||
|
sizeof(BMPColorHeader);
|
||||||
|
} else {
|
||||||
|
bmp_info_header.size = sizeof(BMPInfoHeader);
|
||||||
|
file_header.offset_data = sizeof(BMPFileHeader) + sizeof(BMPInfoHeader);
|
||||||
|
}
|
||||||
|
file_header.file_size = file_header.offset_data;
|
||||||
|
|
||||||
|
if (bmp_info_header.height < 0) {
|
||||||
|
return 52; // throw std::runtime_error("The program can treat only BMP
|
||||||
|
// images with the origin in the bottom left corner!");
|
||||||
|
}
|
||||||
|
|
||||||
|
data.resize(bmp_info_header.width * bmp_info_header.height *
|
||||||
|
bmp_info_header.bit_count / 8);
|
||||||
|
|
||||||
|
// Here we check if we need to take into account row padding
|
||||||
|
if (bmp_info_header.width % 4 == 0) {
|
||||||
|
inp.read((char *)data.data(), data.size());
|
||||||
|
file_header.file_size += static_cast<uint32_t>(data.size());
|
||||||
|
} else {
|
||||||
|
row_stride = bmp_info_header.width * bmp_info_header.bit_count / 8;
|
||||||
|
uint32_t new_stride = make_stride_aligned(4);
|
||||||
|
std::vector<uint8_t> padding_row(new_stride - row_stride);
|
||||||
|
|
||||||
|
for (int y = 0; y < bmp_info_header.height; ++y) {
|
||||||
|
inp.read((char *)(data.data() + row_stride * y), row_stride);
|
||||||
|
inp.read((char *)padding_row.data(), padding_row.size());
|
||||||
|
}
|
||||||
|
file_header.file_size +=
|
||||||
|
static_cast<uint32_t>(data.size()) +
|
||||||
|
bmp_info_header.height * static_cast<uint32_t>(padding_row.size());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 53; // throw std::runtime_error("Unable to open the input image
|
||||||
|
// file "+std::string(fname));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int read_mem(std::vector<unsigned char> buffer) {
|
||||||
|
std::stringstream inp;
|
||||||
|
std::copy(buffer.begin(), buffer.end(),
|
||||||
|
std::ostream_iterator<unsigned char>(inp, "\n"));
|
||||||
|
std::cout << buffer.size() << std::endl;
|
||||||
|
if (inp) {
|
||||||
|
inp.read((char *)&file_header, sizeof(file_header));
|
||||||
|
if (file_header.file_type != 0x4D42) {
|
||||||
|
|
||||||
|
return 50;
|
||||||
|
// throw std::runtime_error("Error! Unrecognized file format. Header " +
|
||||||
|
// std::to_string(file_header.file_type));
|
||||||
|
}
|
||||||
|
inp.read((char *)&bmp_info_header, sizeof(bmp_info_header));
|
||||||
|
|
||||||
|
// The BMPColorHeader is used only for transparent images
|
||||||
|
if (bmp_info_header.bit_count == 32) {
|
||||||
|
// Check if the file has bit mask color information
|
||||||
|
if (bmp_info_header.size >=
|
||||||
|
(sizeof(BMPInfoHeader) + sizeof(BMPColorHeader))) {
|
||||||
|
inp.read((char *)&bmp_color_header, sizeof(bmp_color_header));
|
||||||
|
// Check if the pixel data is stored as BGRA and if the color space
|
||||||
|
// type is sRGB
|
||||||
|
check_color_header(bmp_color_header);
|
||||||
|
} else {
|
||||||
|
// std::cerr << "Error! The file \"" << fname << "\" does not seem to
|
||||||
|
// contain bit mask information\n";
|
||||||
|
return 51;
|
||||||
|
// throw std::runtime_error("Error! Unrecognized file format. Size");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Jump to the pixel data location
|
||||||
|
inp.seekg(file_header.offset_data, inp.beg);
|
||||||
|
|
||||||
|
// Adjust the header fields for output.
|
||||||
|
// Some editors will put extra info in the image file, we only save the
|
||||||
|
// headers and the data.
|
||||||
|
if (bmp_info_header.bit_count == 32) {
|
||||||
|
bmp_info_header.size = sizeof(BMPInfoHeader) + sizeof(BMPColorHeader);
|
||||||
|
file_header.offset_data = sizeof(BMPFileHeader) +
|
||||||
|
sizeof(BMPInfoHeader) +
|
||||||
|
sizeof(BMPColorHeader);
|
||||||
|
} else {
|
||||||
|
bmp_info_header.size = sizeof(BMPInfoHeader);
|
||||||
|
file_header.offset_data = sizeof(BMPFileHeader) + sizeof(BMPInfoHeader);
|
||||||
|
}
|
||||||
|
file_header.file_size = file_header.offset_data;
|
||||||
|
|
||||||
|
if (bmp_info_header.height < 0) {
|
||||||
|
return 52;
|
||||||
|
// throw std::runtime_error("The program can treat only BMP images with
|
||||||
|
// "
|
||||||
|
// "the origin in the bottom left corner!");
|
||||||
|
}
|
||||||
|
|
||||||
|
data.resize(bmp_info_header.width * bmp_info_header.height *
|
||||||
|
bmp_info_header.bit_count / 8);
|
||||||
|
|
||||||
|
// Here we check if we need to take into account row padding
|
||||||
|
if (bmp_info_header.width % 4 == 0) {
|
||||||
|
inp.read((char *)data.data(), data.size());
|
||||||
|
file_header.file_size += static_cast<uint32_t>(data.size());
|
||||||
|
} else {
|
||||||
|
row_stride = bmp_info_header.width * bmp_info_header.bit_count / 8;
|
||||||
|
uint32_t new_stride = make_stride_aligned(4);
|
||||||
|
std::vector<uint8_t> padding_row(new_stride - row_stride);
|
||||||
|
|
||||||
|
for (int y = 0; y < bmp_info_header.height; ++y) {
|
||||||
|
inp.read((char *)(data.data() + row_stride * y), row_stride);
|
||||||
|
inp.read((char *)padding_row.data(), padding_row.size());
|
||||||
|
}
|
||||||
|
file_header.file_size +=
|
||||||
|
static_cast<uint32_t>(data.size()) +
|
||||||
|
bmp_info_header.height * static_cast<uint32_t>(padding_row.size());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 53;
|
||||||
|
// throw std::runtime_error("Unable to open the input image buffer");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
BMP(int32_t width, int32_t height, bool has_alpha = true) {
|
||||||
|
if (width <= 0 || height <= 0) {
|
||||||
|
width = 1;
|
||||||
|
height = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bmp_info_header.width = width;
|
||||||
|
bmp_info_header.height = height;
|
||||||
|
if (has_alpha) {
|
||||||
|
bmp_info_header.size = sizeof(BMPInfoHeader) + sizeof(BMPColorHeader);
|
||||||
|
file_header.offset_data = sizeof(BMPFileHeader) + sizeof(BMPInfoHeader) +
|
||||||
|
sizeof(BMPColorHeader);
|
||||||
|
|
||||||
|
bmp_info_header.bit_count = 32;
|
||||||
|
bmp_info_header.compression = 3;
|
||||||
|
row_stride = width * 4;
|
||||||
|
data.resize(row_stride * height);
|
||||||
|
file_header.file_size = file_header.offset_data + data.size();
|
||||||
|
} else {
|
||||||
|
bmp_info_header.size = sizeof(BMPInfoHeader);
|
||||||
|
file_header.offset_data = sizeof(BMPFileHeader) + sizeof(BMPInfoHeader);
|
||||||
|
|
||||||
|
bmp_info_header.bit_count = 24;
|
||||||
|
bmp_info_header.compression = 0;
|
||||||
|
row_stride = width * 3;
|
||||||
|
data.resize(row_stride * height);
|
||||||
|
|
||||||
|
uint32_t new_stride = make_stride_aligned(4);
|
||||||
|
file_header.file_size =
|
||||||
|
file_header.offset_data + static_cast<uint32_t>(data.size()) +
|
||||||
|
bmp_info_header.height * (new_stride - row_stride);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned write(const char *fname) {
|
||||||
|
std::ofstream of{fname, std::ios_base::binary};
|
||||||
|
if (of) {
|
||||||
|
if (bmp_info_header.bit_count == 32) {
|
||||||
|
write_headers_and_data(of);
|
||||||
|
} else if (bmp_info_header.bit_count == 24) {
|
||||||
|
if (bmp_info_header.width % 4 == 0) {
|
||||||
|
write_headers_and_data(of);
|
||||||
|
} else {
|
||||||
|
uint32_t new_stride = make_stride_aligned(4);
|
||||||
|
std::vector<uint8_t> padding_row(new_stride - row_stride);
|
||||||
|
|
||||||
|
write_headers(of);
|
||||||
|
|
||||||
|
for (int y = 0; y < bmp_info_header.height; ++y) {
|
||||||
|
of.write((const char *)(data.data() + row_stride * y), row_stride);
|
||||||
|
of.write((const char *)padding_row.data(), padding_row.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 54; // throw std::runtime_error("The program can treat only 24 or
|
||||||
|
// 32 bits per pixel BMP files");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 55; // throw std::runtime_error("Unable to open the output image
|
||||||
|
// file.");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned char> DATA() {
|
||||||
|
std::stringstream ss;
|
||||||
|
if (ss) {
|
||||||
|
if (bmp_info_header.bit_count == 32) {
|
||||||
|
write_headers_and_datass(ss);
|
||||||
|
} else if (bmp_info_header.bit_count == 24) {
|
||||||
|
if (bmp_info_header.width % 4 == 0) {
|
||||||
|
write_headers_and_datass(ss);
|
||||||
|
} else {
|
||||||
|
uint32_t new_stride = make_stride_aligned(4);
|
||||||
|
std::vector<uint8_t> padding_row(new_stride - row_stride);
|
||||||
|
|
||||||
|
write_headersss(ss);
|
||||||
|
|
||||||
|
for (int y = 0; y < bmp_info_header.height; ++y) {
|
||||||
|
ss.write((const char *)(data.data() + row_stride * y), row_stride);
|
||||||
|
ss.write((const char *)padding_row.data(), padding_row.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
std::string test11 = ss.str();
|
||||||
|
std::vector<unsigned char> test12(test11.begin(), test11.end());
|
||||||
|
return test12;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned fill_region(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h,
|
||||||
|
uint8_t B, uint8_t G, uint8_t R, uint8_t A) {
|
||||||
|
uint32_t channels = bmp_info_header.bit_count / 8;
|
||||||
|
for (uint32_t y = y0; y < y0 + h; ++y) {
|
||||||
|
for (uint32_t x = x0; x < x0 + w; ++x) {
|
||||||
|
/*if (x + w > (uint32_t)bmp_info_header.width || y + h >
|
||||||
|
(uint32_t)bmp_info_header.height) {
|
||||||
|
//
|
||||||
|
}*/
|
||||||
|
// else{
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 0] = B;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 1] = G;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 2] = R;
|
||||||
|
if (channels == 4) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 3] = A;
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fill_region_df(uint32_t x1, uint32_t y1, uint32_t w, uint32_t h,
|
||||||
|
uint8_t B, uint8_t G, uint8_t R, uint8_t A) {
|
||||||
|
|
||||||
|
int x0 = x1;
|
||||||
|
int y0 = this->bmp_info_header.height - y1 - h;
|
||||||
|
|
||||||
|
uint32_t channels = bmp_info_header.bit_count / 8;
|
||||||
|
for (uint32_t y = y0; y < y0 + h; ++y) {
|
||||||
|
for (uint32_t x = x0; x < x0 + w; ++x) {
|
||||||
|
if ((x + w < (uint32_t)bmp_info_header.width) ||
|
||||||
|
this->bmp_info_header.height - y - h > 0) {
|
||||||
|
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 0] = B;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 1] = G;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 2] = R;
|
||||||
|
if (channels == 4) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 3] = A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void manipulate_region(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h,
|
||||||
|
uint8_t A) {
|
||||||
|
int choice, choice2, intensity;
|
||||||
|
cout << "What color do you want to change? " << endl;
|
||||||
|
cout << "Enter 1 for Blue, 2 for Green, 3 for Red " << endl;
|
||||||
|
cin >> choice;
|
||||||
|
cout << "To what color do you want to change it too?" << endl;
|
||||||
|
cout << "Enter 1 for Blue, 2 for Green, 3 for Red " << endl;
|
||||||
|
cin >> choice2;
|
||||||
|
cout << "Enter the intensity of the color. (From 0 to 255) " << endl;
|
||||||
|
cin >> intensity;
|
||||||
|
if (x0 + w > (uint32_t)bmp_info_header.width ||
|
||||||
|
y0 + h > (uint32_t)bmp_info_header.height) {
|
||||||
|
return; // throw std::runtime_error("The region does not fit in the
|
||||||
|
// image!");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t channels = bmp_info_header.bit_count / 8;
|
||||||
|
if (choice == 1 && choice2 == 1) {
|
||||||
|
for (uint32_t y = y0; y < y0 + h; ++y) {
|
||||||
|
for (uint32_t x = x0; x < x0 + w; ++x) {
|
||||||
|
cout << channels * (y * bmp_info_header.width + x) << endl;
|
||||||
|
// Make blue thing blue
|
||||||
|
if (data[channels * (y * bmp_info_header.width + x) + 0] > 80 &&
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 0] < 255) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 0] = intensity;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 1] = 0;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 2] = 0;
|
||||||
|
}
|
||||||
|
// data[channels * (y * bmp_info_header.width + x) + 0] = B;
|
||||||
|
// data[channels * (y * bmp_info_header.width + x) + 1] = G;
|
||||||
|
// data[channels * (y * bmp_info_header.width + x) + 2] = R;
|
||||||
|
if (channels == 4) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 3] = A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (choice == 1 && choice2 == 2) {
|
||||||
|
for (uint32_t y = y0; y < y0 + h; ++y) {
|
||||||
|
for (uint32_t x = x0; x < x0 + w; ++x) {
|
||||||
|
cout << channels * (y * bmp_info_header.width + x) << endl;
|
||||||
|
// Make blue thing green
|
||||||
|
if (data[channels * (y * bmp_info_header.width + x) + 0] > 80 &&
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 0] < 255) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 0] = 0;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 1] = intensity;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 2] = 0;
|
||||||
|
}
|
||||||
|
if (channels == 4) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 3] = A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (choice == 1 && choice2 == 3) {
|
||||||
|
for (uint32_t y = y0; y < y0 + h; ++y) {
|
||||||
|
for (uint32_t x = x0; x < x0 + w; ++x) {
|
||||||
|
cout << channels * (y * bmp_info_header.width + x) << endl;
|
||||||
|
// Make blue thing red
|
||||||
|
if (data[channels * (y * bmp_info_header.width + x) + 0] > 80 &&
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 0] < 255) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 0] = 0;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 1] = 0;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 2] = intensity;
|
||||||
|
}
|
||||||
|
if (channels == 4) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 3] = A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (choice == 2 && choice2 == 1) {
|
||||||
|
for (uint32_t y = y0; y < y0 + h; ++y) {
|
||||||
|
for (uint32_t x = x0; x < x0 + w; ++x) {
|
||||||
|
cout << channels * (y * bmp_info_header.width + x) << endl;
|
||||||
|
// Make green thing blue
|
||||||
|
if (data[channels * (y * bmp_info_header.width + x) + 1] > 80 &&
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 1] < 255) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 0] = intensity;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 1] = 0;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 2] = 0;
|
||||||
|
}
|
||||||
|
if (channels == 4) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 3] = A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (choice == 2 && choice2 == 2) {
|
||||||
|
for (uint32_t y = y0; y < y0 + h; ++y) {
|
||||||
|
for (uint32_t x = x0; x < x0 + w; ++x) {
|
||||||
|
cout << channels * (y * bmp_info_header.width + x) << endl;
|
||||||
|
// Make green thing green
|
||||||
|
if (data[channels * (y * bmp_info_header.width + x) + 1] > 80 &&
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 1] < 255) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 0] = 0;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 1] = intensity;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 2] = 0;
|
||||||
|
}
|
||||||
|
if (channels == 4) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 3] = A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (choice == 2 && choice2 == 3) {
|
||||||
|
for (uint32_t y = y0; y < y0 + h; ++y) {
|
||||||
|
for (uint32_t x = x0; x < x0 + w; ++x) {
|
||||||
|
cout << channels * (y * bmp_info_header.width + x) << endl;
|
||||||
|
// Make green thing red
|
||||||
|
if (data[channels * (y * bmp_info_header.width + x) + 1] > 80 &&
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 1] < 255) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 0] = 0;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 1] = 0;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 2] = intensity;
|
||||||
|
}
|
||||||
|
if (channels == 4) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 3] = A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (choice == 3 && choice2 == 1) {
|
||||||
|
for (uint32_t y = y0; y < y0 + h; ++y) {
|
||||||
|
for (uint32_t x = x0; x < x0 + w; ++x) {
|
||||||
|
cout << channels * (y * bmp_info_header.width + x) << endl;
|
||||||
|
// Make red thing blue
|
||||||
|
if (data[channels * (y * bmp_info_header.width + x) + 2] > 80 &&
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 2] < 255) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 0] = intensity;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 1] = 0;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 2] = 0;
|
||||||
|
}
|
||||||
|
if (channels == 4) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 3] = A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (choice == 3 && choice2 == 2) {
|
||||||
|
for (uint32_t y = y0; y < y0 + h; ++y) {
|
||||||
|
for (uint32_t x = x0; x < x0 + w; ++x) {
|
||||||
|
cout << channels * (y * bmp_info_header.width + x) << endl;
|
||||||
|
// Make red thing green
|
||||||
|
if (data[channels * (y * bmp_info_header.width + x) + 2] > 80 &&
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 2] < 255) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 0] = 0;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 1] = intensity;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 2] = 0;
|
||||||
|
}
|
||||||
|
if (channels == 4) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 3] = A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (choice == 3 && choice2 == 3) {
|
||||||
|
for (uint32_t y = y0; y < y0 + h; ++y) {
|
||||||
|
for (uint32_t x = x0; x < x0 + w; ++x) {
|
||||||
|
cout << channels * (y * bmp_info_header.width + x) << endl;
|
||||||
|
// Make red thing blue
|
||||||
|
if (data[channels * (y * bmp_info_header.width + x) + 2] > 80 &&
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 2] < 255) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 0] = 0;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 1] = 0;
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 2] = intensity;
|
||||||
|
}
|
||||||
|
if (channels == 4) {
|
||||||
|
data[channels * (y * bmp_info_header.width + x) + 3] = A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned set_pixel(uint32_t x0, uint32_t y0, uint8_t B, uint8_t G, uint8_t R,
|
||||||
|
uint8_t A) {
|
||||||
|
if (x0 >= (uint32_t)bmp_info_header.width ||
|
||||||
|
y0 >= (uint32_t)bmp_info_header.height || x0 < 0 || y0 < 0) {
|
||||||
|
return 59;
|
||||||
|
// std::string errr = "The point is outside the image boundaries! -> " +
|
||||||
|
// std::to_string(x0) + "," + std::to_string(y0); throw
|
||||||
|
// std::runtime_error(errr);
|
||||||
|
}
|
||||||
|
uint32_t channels = bmp_info_header.bit_count / 8;
|
||||||
|
data[channels * (y0 * bmp_info_header.width + x0) + 0] = B;
|
||||||
|
data[channels * (y0 * bmp_info_header.width + x0) + 1] = G;
|
||||||
|
data[channels * (y0 * bmp_info_header.width + x0) + 2] = R;
|
||||||
|
if (channels == 4) {
|
||||||
|
data[channels * (y0 * bmp_info_header.width + x0) + 3] = A;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_pixel_df(uint32_t x0, uint32_t y0, uint8_t B, uint8_t G, uint8_t R,
|
||||||
|
uint8_t A) {
|
||||||
|
uint32_t y1 = this->bmp_info_header.height - y0;
|
||||||
|
if (x0 >= (uint32_t)bmp_info_header.width ||
|
||||||
|
y1 <= (uint32_t)bmp_info_header.width || x0 < 0 || y0 > 0) {
|
||||||
|
return;
|
||||||
|
// throw std::runtime_error("The point is outside the image boundaries! ->
|
||||||
|
// " + std::to_string(x0) + "," + std::to_string(y1));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t channels = bmp_info_header.bit_count / 8;
|
||||||
|
data[channels * (y0 * bmp_info_header.width + x0) + 0] = B;
|
||||||
|
data[channels * (y0 * bmp_info_header.width + x0) + 1] = G;
|
||||||
|
data[channels * (y0 * bmp_info_header.width + x0) + 2] = R;
|
||||||
|
if (channels == 4) {
|
||||||
|
data[channels * (y0 * bmp_info_header.width + x0) + 3] = A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t get_pixel(uint32_t x0, uint32_t y0) {
|
||||||
|
if (x0 >= (uint32_t)bmp_info_header.width ||
|
||||||
|
y0 >= (uint32_t)bmp_info_header.height || x0 < 0 || y0 < 0) {
|
||||||
|
return 59; // throw std::runtime_error("The point is outside the image
|
||||||
|
// boundaries!");
|
||||||
|
}
|
||||||
|
uint32_t channels = bmp_info_header.bit_count / 8;
|
||||||
|
uint32_t outcol = 0;
|
||||||
|
uint8_t red = 0;
|
||||||
|
uint8_t green = 0;
|
||||||
|
uint8_t blue = 0;
|
||||||
|
uint8_t alpha = 255;
|
||||||
|
blue = data[channels * (y0 * bmp_info_header.width + x0) + 0];
|
||||||
|
green = data[channels * (y0 * bmp_info_header.width + x0) + 1];
|
||||||
|
red = data[channels * (y0 * bmp_info_header.width + x0) + 2];
|
||||||
|
if (channels == 4) {
|
||||||
|
alpha = data[channels * (y0 * bmp_info_header.width + x0) + 3];
|
||||||
|
}
|
||||||
|
outcol = ((red << 24) | (green << 16) | (blue << 8) | alpha);
|
||||||
|
return outcol;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t get_pixel_df(uint32_t x0, uint32_t y0) {
|
||||||
|
uint32_t y1 = this->bmp_info_header.height - y0;
|
||||||
|
if (x0 >= (uint32_t)bmp_info_header.width ||
|
||||||
|
y1 <= (uint32_t)bmp_info_header.width || x0 < 0 || y0 > 0) {
|
||||||
|
return 0; // throw std::runtime_error("The point is outside the image
|
||||||
|
// boundaries!");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t channels = bmp_info_header.bit_count / 8;
|
||||||
|
uint32_t outcol = 0;
|
||||||
|
uint8_t red = 0;
|
||||||
|
uint8_t green = 0;
|
||||||
|
uint8_t blue = 0;
|
||||||
|
uint8_t alpha = 255;
|
||||||
|
blue = data[channels * (y0 * bmp_info_header.width + x0) + 0];
|
||||||
|
green = data[channels * (y0 * bmp_info_header.width + x0) + 1];
|
||||||
|
red = data[channels * (y0 * bmp_info_header.width + x0) + 2];
|
||||||
|
if (channels == 4) {
|
||||||
|
alpha = data[channels * (y0 * bmp_info_header.width + x0) + 3];
|
||||||
|
}
|
||||||
|
outcol = ((red << 24) | (green << 16) | (blue << 8) | alpha);
|
||||||
|
return outcol;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned draw_rectangle(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h,
|
||||||
|
uint8_t B, uint8_t G, uint8_t R, uint8_t A,
|
||||||
|
uint8_t line_w) {
|
||||||
|
if (x0 + w > (uint32_t)bmp_info_header.width ||
|
||||||
|
y0 + h > (uint32_t)bmp_info_header.height) {
|
||||||
|
return 59; // throw std::runtime_error("The rectangle does not fit in the
|
||||||
|
// image!");
|
||||||
|
}
|
||||||
|
|
||||||
|
fill_region(x0, y0, w, line_w, B, G, R, A); // top line
|
||||||
|
fill_region(x0, (y0 + h - line_w), w, line_w, B, G, R, A); // bottom line
|
||||||
|
fill_region((x0 + w - line_w), (y0 + line_w), line_w, (h - (2 * line_w)), B,
|
||||||
|
G, R, A); // right line
|
||||||
|
fill_region(x0, (y0 + line_w), line_w, (h - (2 * line_w)), B, G, R,
|
||||||
|
A); // left line
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_rectangle_df(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h,
|
||||||
|
uint8_t B, uint8_t G, uint8_t R, uint8_t A,
|
||||||
|
uint8_t line_w) {
|
||||||
|
if (x0 + w > (uint32_t)bmp_info_header.width ||
|
||||||
|
y0 + h > (uint32_t)bmp_info_header.height) {
|
||||||
|
return; // throw std::runtime_error("The rectangle does not fit in the
|
||||||
|
// image!");
|
||||||
|
}
|
||||||
|
|
||||||
|
fill_region_df(x0, y0, w, line_w, B, G, R, A); // top line
|
||||||
|
fill_region_df(x0, (y0 + h - line_w), w, line_w, B, G, R, A); // bottom line
|
||||||
|
fill_region_df((x0 + w - line_w), (y0 + line_w), line_w, (h - (2 * line_w)),
|
||||||
|
B, G, R, A); // right line
|
||||||
|
fill_region_df(x0, (y0 + line_w), line_w, (h - (2 * line_w)), B, G, R,
|
||||||
|
A); // left line
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t row_stride{0};
|
||||||
|
|
||||||
|
void write_headers(std::ofstream &of) {
|
||||||
|
of.write((const char *)&file_header, sizeof(file_header));
|
||||||
|
of.write((const char *)&bmp_info_header, sizeof(bmp_info_header));
|
||||||
|
if (bmp_info_header.bit_count == 32) {
|
||||||
|
of.write((const char *)&bmp_color_header, sizeof(bmp_color_header));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_headers_and_data(std::ofstream &of) {
|
||||||
|
write_headers(of);
|
||||||
|
of.write((const char *)data.data(), data.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_headersss(std::stringstream &of) {
|
||||||
|
of.write((const char *)&file_header, sizeof(file_header));
|
||||||
|
of.write((const char *)&bmp_info_header, sizeof(bmp_info_header));
|
||||||
|
if (bmp_info_header.bit_count == 32) {
|
||||||
|
of.write((const char *)&bmp_color_header, sizeof(bmp_color_header));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_headers_and_datass(std::stringstream &of) {
|
||||||
|
write_headersss(of);
|
||||||
|
of.write((const char *)data.data(), data.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add 1 to the row_stride until it is divisible with align_stride
|
||||||
|
uint32_t make_stride_aligned(uint32_t align_stride) {
|
||||||
|
uint32_t new_stride = row_stride;
|
||||||
|
while (new_stride % align_stride != 0) {
|
||||||
|
new_stride++;
|
||||||
|
}
|
||||||
|
return new_stride;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the pixel data is stored as BGRA and if the color space type is
|
||||||
|
// sRGB
|
||||||
|
void check_color_header(BMPColorHeader &bmp_color_header) {
|
||||||
|
BMPColorHeader expected_color_header;
|
||||||
|
if (expected_color_header.red_mask != bmp_color_header.red_mask ||
|
||||||
|
expected_color_header.blue_mask != bmp_color_header.blue_mask ||
|
||||||
|
expected_color_header.green_mask != bmp_color_header.green_mask ||
|
||||||
|
expected_color_header.alpha_mask != bmp_color_header.alpha_mask) {
|
||||||
|
return; // throw std::runtime_error("Unexpected color mask format! The
|
||||||
|
// program expects the pixel data to be in the BGRA format");
|
||||||
|
}
|
||||||
|
if (expected_color_header.color_space_type !=
|
||||||
|
bmp_color_header.color_space_type) {
|
||||||
|
return; // throw std::runtime_error("Unexpected color space type! The
|
||||||
|
// program expects sRGB values");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
16
include/renderd7/bmpconverter.hpp
Normal file
16
include/renderd7/bmpconverter.hpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <renderd7/external/lodepng.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace BitmapConverter {
|
||||||
|
// returns 0 if all went ok, non-0 if error
|
||||||
|
// output image is always given in RGBA (with alpha channel), even if it's a BMP
|
||||||
|
// without alpha channel
|
||||||
|
unsigned decodeBMP(std::vector<unsigned char> &image, unsigned &w, unsigned &h,
|
||||||
|
const std::vector<unsigned char> &bmp);
|
||||||
|
|
||||||
|
std::vector<unsigned char> ConvertFile(std::string filename);
|
||||||
|
|
||||||
|
std::vector<unsigned char> ConvertData(std::vector<unsigned char> data);
|
||||||
|
} // namespace BitmapConverter
|
187
include/renderd7/debugfont.h
Normal file
187
include/renderd7/debugfont.h
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
/*
|
||||||
|
This file was autogenerated by raw2c.
|
||||||
|
Visit http://www.devkitpro.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
#ifndef _debugfont_h_
|
||||||
|
#define _debugfont_h_
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
static const unsigned char debugfont[] = {
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81,
|
||||||
|
0xbd, 0x99, 0x81, 0x7e, 0x7e, 0xff, 0xdb, 0xff, 0xc3, 0xe7, 0xff, 0x7e,
|
||||||
|
0x6c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x10, 0x38, 0x7c, 0xfe,
|
||||||
|
0x7c, 0x38, 0x10, 0x00, 0x3c, 0x3c, 0x18, 0xff, 0xe7, 0x18, 0x3c, 0x00,
|
||||||
|
0x10, 0x38, 0x7c, 0xfe, 0xee, 0x10, 0x38, 0x00, 0x00, 0x00, 0x18, 0x3c,
|
||||||
|
0x3c, 0x18, 0x00, 0x00, 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff,
|
||||||
|
0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00, 0xff, 0xc3, 0x99, 0xbd,
|
||||||
|
0xbd, 0x99, 0xc3, 0xff, 0x0f, 0x07, 0x0f, 0x7d, 0xcc, 0xcc, 0xcc, 0x78,
|
||||||
|
0x3c, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x08, 0x0c, 0x0a, 0x0a,
|
||||||
|
0x08, 0x78, 0xf0, 0x00, 0x18, 0x14, 0x1a, 0x16, 0x72, 0xe2, 0x0e, 0x1c,
|
||||||
|
0x10, 0x54, 0x38, 0xee, 0x38, 0x54, 0x10, 0x00, 0x80, 0xe0, 0xf8, 0xfe,
|
||||||
|
0xf8, 0xe0, 0x80, 0x00, 0x02, 0x0e, 0x3e, 0xfe, 0x3e, 0x0e, 0x02, 0x00,
|
||||||
|
0x18, 0x3c, 0x5a, 0x18, 0x5a, 0x3c, 0x18, 0x00, 0x66, 0x66, 0x66, 0x66,
|
||||||
|
0x66, 0x00, 0x66, 0x00, 0x7f, 0xdb, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x00,
|
||||||
|
0x1c, 0x22, 0x38, 0x44, 0x44, 0x38, 0x88, 0x70, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x7e, 0x7e, 0x7e, 0x00, 0x18, 0x3c, 0x5a, 0x18, 0x5a, 0x3c, 0x18, 0x7e,
|
||||||
|
0x18, 0x3c, 0x5a, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18,
|
||||||
|
0x5a, 0x3c, 0x18, 0x00, 0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00,
|
||||||
|
0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0,
|
||||||
|
0xc0, 0xfe, 0x00, 0x00, 0x00, 0x24, 0x42, 0xff, 0x42, 0x24, 0x00, 0x00,
|
||||||
|
0x00, 0x10, 0x38, 0x7c, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x7c,
|
||||||
|
0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x18, 0x3c, 0x3c, 0x18, 0x18, 0x00, 0x18, 0x00, 0x6c, 0x24, 0x24, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0xfe, 0x6c, 0xfe, 0x6c, 0x6c, 0x00,
|
||||||
|
0x10, 0x7c, 0xd0, 0x7c, 0x16, 0xfc, 0x10, 0x00, 0x00, 0x66, 0xac, 0xd8,
|
||||||
|
0x36, 0x6a, 0xcc, 0x00, 0x38, 0x4c, 0x38, 0x78, 0xce, 0xcc, 0x7a, 0x00,
|
||||||
|
0x30, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x60,
|
||||||
|
0x60, 0x30, 0x18, 0x00, 0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00,
|
||||||
|
0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x30, 0x30, 0xfc,
|
||||||
|
0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x10, 0x20,
|
||||||
|
0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x30, 0x00, 0x02, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x00,
|
||||||
|
0x7c, 0xce, 0xde, 0xf6, 0xe6, 0xe6, 0x7c, 0x00, 0x18, 0x38, 0x78, 0x18,
|
||||||
|
0x18, 0x18, 0x7e, 0x00, 0x7c, 0xc6, 0x06, 0x1c, 0x70, 0xc6, 0xfe, 0x00,
|
||||||
|
0x7c, 0xc6, 0x06, 0x3c, 0x06, 0xc6, 0x7c, 0x00, 0x1c, 0x3c, 0x6c, 0xcc,
|
||||||
|
0xfe, 0x0c, 0x1e, 0x00, 0xfe, 0xc0, 0xfc, 0x06, 0x06, 0xc6, 0x7c, 0x00,
|
||||||
|
0x7c, 0xc6, 0xc0, 0xfc, 0xc6, 0xc6, 0x7c, 0x00, 0xfe, 0xc6, 0x0c, 0x18,
|
||||||
|
0x30, 0x30, 0x30, 0x00, 0x7c, 0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0x7c, 0x00,
|
||||||
|
0x7c, 0xc6, 0xc6, 0x7e, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x30, 0x00, 0x00,
|
||||||
|
0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x10, 0x20,
|
||||||
|
0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x7e, 0x00,
|
||||||
|
0x00, 0x7e, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x18, 0x30, 0x60, 0x00,
|
||||||
|
0x78, 0xcc, 0x0c, 0x18, 0x30, 0x00, 0x30, 0x00, 0x7c, 0x82, 0x9e, 0xa6,
|
||||||
|
0x9e, 0x80, 0x7c, 0x00, 0x7c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00,
|
||||||
|
0xfc, 0x66, 0x66, 0x7c, 0x66, 0x66, 0xfc, 0x00, 0x7c, 0xc6, 0xc0, 0xc0,
|
||||||
|
0xc0, 0xc6, 0x7c, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x66, 0x66, 0xfc, 0x00,
|
||||||
|
0xfe, 0x62, 0x68, 0x78, 0x68, 0x62, 0xfe, 0x00, 0xfe, 0x62, 0x68, 0x78,
|
||||||
|
0x68, 0x60, 0xf0, 0x00, 0x7c, 0xc6, 0xc6, 0xc0, 0xce, 0xc6, 0x7e, 0x00,
|
||||||
|
0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00, 0x3c, 0x18, 0x18, 0x18,
|
||||||
|
0x18, 0x18, 0x3c, 0x00, 0x1e, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0x78, 0x00,
|
||||||
|
0xe6, 0x66, 0x6c, 0x78, 0x6c, 0x66, 0xe6, 0x00, 0xf0, 0x60, 0x60, 0x60,
|
||||||
|
0x62, 0x66, 0xfe, 0x00, 0x82, 0xc6, 0xee, 0xfe, 0xd6, 0xc6, 0xc6, 0x00,
|
||||||
|
0xc6, 0xe6, 0xf6, 0xde, 0xce, 0xc6, 0xc6, 0x00, 0x7c, 0xc6, 0xc6, 0xc6,
|
||||||
|
0xc6, 0xc6, 0x7c, 0x00, 0xfc, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xf0, 0x00,
|
||||||
|
0x7c, 0xc6, 0xc6, 0xc6, 0xd6, 0xde, 0x7c, 0x06, 0xfc, 0x66, 0x66, 0x7c,
|
||||||
|
0x66, 0x66, 0xe6, 0x00, 0x7c, 0xc6, 0xc0, 0x7c, 0x06, 0xc6, 0x7c, 0x00,
|
||||||
|
0x7e, 0x5a, 0x5a, 0x18, 0x18, 0x18, 0x3c, 0x00, 0xc6, 0xc6, 0xc6, 0xc6,
|
||||||
|
0xc6, 0xc6, 0x7c, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x10, 0x00,
|
||||||
|
0xc6, 0xc6, 0xd6, 0xfe, 0xee, 0xc6, 0x82, 0x00, 0xc6, 0x6c, 0x38, 0x38,
|
||||||
|
0x38, 0x6c, 0xc6, 0x00, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x18, 0x3c, 0x00,
|
||||||
|
0xfe, 0xc6, 0x8c, 0x18, 0x32, 0x66, 0xfe, 0x00, 0x78, 0x60, 0x60, 0x60,
|
||||||
|
0x60, 0x60, 0x78, 0x00, 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x02, 0x00,
|
||||||
|
0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00, 0x10, 0x38, 0x6c, 0xc6,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
|
||||||
|
0x30, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0c,
|
||||||
|
0x7c, 0xcc, 0x76, 0x00, 0xe0, 0x60, 0x60, 0x7c, 0x66, 0x66, 0x7c, 0x00,
|
||||||
|
0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc6, 0x7c, 0x00, 0x1c, 0x0c, 0x0c, 0x7c,
|
||||||
|
0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0x7c, 0x00,
|
||||||
|
0x1c, 0x36, 0x30, 0x78, 0x30, 0x30, 0x78, 0x00, 0x00, 0x00, 0x76, 0xcc,
|
||||||
|
0xcc, 0x7c, 0x0c, 0x78, 0xe0, 0x60, 0x6c, 0x76, 0x66, 0x66, 0xe6, 0x00,
|
||||||
|
0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x0c, 0x00, 0x1c,
|
||||||
|
0x0c, 0x0c, 0xcc, 0x78, 0xe0, 0x60, 0x66, 0x6c, 0x78, 0x6c, 0xe6, 0x00,
|
||||||
|
0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0xcc, 0xfe,
|
||||||
|
0xd6, 0xd6, 0xd6, 0x00, 0x00, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x00,
|
||||||
|
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0xdc, 0x66,
|
||||||
|
0x66, 0x7c, 0x60, 0xf0, 0x00, 0x00, 0x7c, 0xcc, 0xcc, 0x7c, 0x0c, 0x1e,
|
||||||
|
0x00, 0x00, 0xde, 0x76, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x7c, 0xc0,
|
||||||
|
0x7c, 0x06, 0x7c, 0x00, 0x10, 0x30, 0xfc, 0x30, 0x30, 0x34, 0x18, 0x00,
|
||||||
|
0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0xc6, 0xc6,
|
||||||
|
0x6c, 0x38, 0x10, 0x00, 0x00, 0x00, 0xc6, 0xd6, 0xd6, 0xfe, 0x6c, 0x00,
|
||||||
|
0x00, 0x00, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0xcc, 0xcc,
|
||||||
|
0xcc, 0x7c, 0x0c, 0xf8, 0x00, 0x00, 0xfc, 0x98, 0x30, 0x64, 0xfc, 0x00,
|
||||||
|
0x0e, 0x18, 0x18, 0x30, 0x18, 0x18, 0x0e, 0x00, 0x18, 0x18, 0x18, 0x00,
|
||||||
|
0x18, 0x18, 0x18, 0x00, 0xe0, 0x30, 0x30, 0x18, 0x30, 0x30, 0xe0, 0x00,
|
||||||
|
0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c,
|
||||||
|
0xc6, 0xc6, 0xfe, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc6, 0x7c, 0x18, 0x70,
|
||||||
|
0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x0e, 0x10, 0x7c, 0xc6,
|
||||||
|
0xfe, 0xc0, 0x7c, 0x00, 0x7c, 0x82, 0x38, 0x0c, 0x7c, 0xcc, 0x76, 0x00,
|
||||||
|
0xcc, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, 0xe0, 0x10, 0x78, 0x0c,
|
||||||
|
0x7c, 0xcc, 0x76, 0x00, 0x30, 0x30, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00,
|
||||||
|
0x00, 0x00, 0x7c, 0xc0, 0xc0, 0x7c, 0x18, 0x70, 0x7c, 0x82, 0x7c, 0xc6,
|
||||||
|
0xfe, 0xc0, 0x7c, 0x00, 0xc6, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0x7c, 0x00,
|
||||||
|
0xe0, 0x10, 0x7c, 0xc6, 0xfe, 0xc0, 0x7c, 0x00, 0x66, 0x00, 0x38, 0x18,
|
||||||
|
0x18, 0x18, 0x3c, 0x00, 0x7c, 0x82, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00,
|
||||||
|
0xe0, 0x10, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00, 0xc6, 0x00, 0x7c, 0xc6,
|
||||||
|
0xfe, 0xc6, 0xc6, 0x00, 0x38, 0x38, 0x7c, 0xc6, 0xfe, 0xc6, 0xc6, 0x00,
|
||||||
|
0x0e, 0x10, 0xfe, 0x60, 0x78, 0x60, 0xfe, 0x00, 0x00, 0x00, 0x7c, 0x12,
|
||||||
|
0x7e, 0xd0, 0x7e, 0x00, 0x7e, 0xc8, 0xc8, 0xfe, 0xc8, 0xc8, 0xce, 0x00,
|
||||||
|
0x7c, 0x82, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0xc6, 0x00, 0x7c, 0xc6,
|
||||||
|
0xc6, 0xc6, 0x7c, 0x00, 0xe0, 0x10, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0x00,
|
||||||
|
0x7c, 0x82, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0xe0, 0x10, 0xcc, 0xcc,
|
||||||
|
0xcc, 0xcc, 0x76, 0x00, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8,
|
||||||
|
0xc6, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0xc6, 0x00, 0xc6, 0xc6,
|
||||||
|
0xc6, 0xc6, 0x7c, 0x00, 0x18, 0x7c, 0xd6, 0xd0, 0xd6, 0x7c, 0x18, 0x00,
|
||||||
|
0x38, 0x6c, 0x60, 0xf0, 0x60, 0xf2, 0xdc, 0x00, 0x66, 0x3c, 0x18, 0x7e,
|
||||||
|
0x18, 0x7e, 0x18, 0x00, 0xf8, 0xcc, 0xf8, 0xc4, 0xcc, 0xde, 0xcc, 0x06,
|
||||||
|
0x0e, 0x1b, 0x18, 0x3c, 0x18, 0x18, 0xd8, 0x70, 0x0e, 0x10, 0x78, 0x0c,
|
||||||
|
0x7c, 0xcc, 0x76, 0x00, 0x0e, 0x10, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00,
|
||||||
|
0x0e, 0x10, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x0e, 0x10, 0xcc, 0xcc,
|
||||||
|
0xcc, 0xcc, 0x76, 0x00, 0x66, 0x98, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x00,
|
||||||
|
0x66, 0x98, 0xe6, 0xf6, 0xde, 0xce, 0xc6, 0x00, 0x38, 0x0c, 0x3c, 0x34,
|
||||||
|
0x00, 0x7e, 0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x7c, 0x00, 0x00,
|
||||||
|
0x30, 0x00, 0x30, 0x60, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0xfc,
|
||||||
|
0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0c, 0x00, 0x00,
|
||||||
|
0xc0, 0xc8, 0xd0, 0xfe, 0x46, 0x8c, 0x1e, 0x00, 0xc0, 0xc8, 0xd0, 0xec,
|
||||||
|
0x5c, 0xbe, 0x0c, 0x00, 0x18, 0x00, 0x18, 0x18, 0x3c, 0x3c, 0x18, 0x00,
|
||||||
|
0x00, 0x36, 0x6c, 0xd8, 0x6c, 0x36, 0x00, 0x00, 0x00, 0xd8, 0x6c, 0x36,
|
||||||
|
0x6c, 0xd8, 0x00, 0x00, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88,
|
||||||
|
0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0xdb, 0x77, 0xdb, 0xee,
|
||||||
|
0xdb, 0x77, 0xdb, 0xee, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
|
||||||
|
0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18,
|
||||||
|
0xf8, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x36, 0x36, 0x36,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0xfe, 0x36, 0x36, 0x36, 0x00, 0x00, 0xf8, 0x18,
|
||||||
|
0xf8, 0x18, 0x18, 0x18, 0x36, 0x36, 0xf6, 0x06, 0xf6, 0x36, 0x36, 0x36,
|
||||||
|
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0xfe, 0x06,
|
||||||
|
0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x06, 0xfe, 0x00, 0x00, 0x00,
|
||||||
|
0x36, 0x36, 0x36, 0x36, 0xfe, 0x00, 0x00, 0x00, 0x18, 0x18, 0xf8, 0x18,
|
||||||
|
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18,
|
||||||
|
0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18,
|
||||||
|
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18,
|
||||||
|
0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0xff, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18,
|
||||||
|
0x18, 0x18, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36,
|
||||||
|
0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x3f, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x3f, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0x00,
|
||||||
|
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xf7, 0x36, 0x36, 0x36,
|
||||||
|
0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, 0x00, 0x00, 0xff, 0x00,
|
||||||
|
0xff, 0x00, 0x00, 0x00, 0x36, 0x36, 0xf7, 0x00, 0xf7, 0x36, 0x36, 0x36,
|
||||||
|
0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36,
|
||||||
|
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
|
||||||
|
0x3f, 0x00, 0x00, 0x00, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x3f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff, 0x36, 0x36, 0x36,
|
||||||
|
0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
|
||||||
|
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x18, 0x18,
|
||||||
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
|
||||||
|
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0xcc, 0xc8, 0xdc, 0x76, 0x00,
|
||||||
|
0x78, 0xcc, 0xd8, 0xcc, 0xc6, 0xc6, 0xdc, 0x40, 0xfe, 0x62, 0x60, 0x60,
|
||||||
|
0x60, 0x60, 0xf0, 0x00, 0x00, 0x02, 0x7e, 0xec, 0x6c, 0x6c, 0x48, 0x00,
|
||||||
|
0xfe, 0x62, 0x30, 0x18, 0x30, 0x62, 0xfe, 0x00, 0x00, 0x00, 0x7e, 0xd0,
|
||||||
|
0xc8, 0xc8, 0x70, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xf8, 0x80,
|
||||||
|
0x00, 0x00, 0x7e, 0xd8, 0x18, 0x18, 0x10, 0x00, 0x38, 0x10, 0x7c, 0xd6,
|
||||||
|
0xd6, 0x7c, 0x10, 0x38, 0x7c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0x7c, 0x00,
|
||||||
|
0x7c, 0xc6, 0xc6, 0xc6, 0x6c, 0x28, 0xee, 0x00, 0x3c, 0x22, 0x18, 0x7c,
|
||||||
|
0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x66, 0x99, 0x99, 0x66, 0x00, 0x00,
|
||||||
|
0x00, 0x06, 0x7c, 0x9e, 0xf2, 0x7c, 0xc0, 0x00, 0x00, 0x00, 0x7c, 0xc0,
|
||||||
|
0xf8, 0xc0, 0x7c, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00,
|
||||||
|
0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18,
|
||||||
|
0x18, 0x00, 0x7e, 0x00, 0x30, 0x18, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0x00,
|
||||||
|
0x18, 0x30, 0x60, 0x30, 0x18, 0x00, 0x7c, 0x00, 0x0e, 0x1b, 0x1b, 0x18,
|
||||||
|
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0x70,
|
||||||
|
0x00, 0x18, 0x00, 0x7e, 0x00, 0x18, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00,
|
||||||
|
0x76, 0xdc, 0x00, 0x00, 0x38, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x18, 0x00, 0x00, 0x00, 0x0f, 0x0c, 0x0c, 0x0c, 0xec, 0x6c, 0x3c, 0x00,
|
||||||
|
0xd8, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x30, 0xc0, 0xf0,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
|
|
||||||
|
};
|
||||||
|
const int debugfont_size = sizeof(debugfont);
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
#endif //_font_h_
|
||||||
|
//---------------------------------------------------------------------------------
|
29
include/renderd7/external/fs.h
vendored
Normal file
29
include/renderd7/external/fs.h
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include <3ds.h>
|
||||||
|
|
||||||
|
extern FS_Archive archive, sdmc_archive, nand_archive;
|
||||||
|
|
||||||
|
Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID id);
|
||||||
|
Result FS_CloseArchive(FS_Archive archive);
|
||||||
|
Result FS_OpenDir(Handle *handle, FS_Archive archive, const char *path);
|
||||||
|
Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path, u32 flags, u32 attributes);
|
||||||
|
Result FS_MakeDir(FS_Archive archive, const char *path);
|
||||||
|
Result FS_CreateFile(FS_Archive archive, const char *path, u64 size);
|
||||||
|
Result FS_RecursiveMakeDir(FS_Archive archive, const char *path);
|
||||||
|
bool FS_FileExists(FS_Archive archive, const char *path);
|
||||||
|
bool FS_DirExists(FS_Archive archive, const char *path);
|
||||||
|
Result FS_GetFileSize(FS_Archive archive, const char *path, u64 *size);
|
||||||
|
u64 FS_GetFreeStorage(FS_SystemMediaType media_type);
|
||||||
|
u64 FS_GetTotalStorage(FS_SystemMediaType media_type);
|
||||||
|
u64 FS_GetUsedStorage(FS_SystemMediaType media_type);
|
||||||
|
Result FS_RemoveFile(FS_Archive archive, const char *path);
|
||||||
|
Result FS_RemoveDir(FS_Archive archive, const char *path);
|
||||||
|
Result FS_RemoveDirRecursive(FS_Archive archive, const char *path);
|
||||||
|
Result FS_RenameFile(FS_Archive archive, const char *old_filename, const char *new_filename);
|
||||||
|
Result FS_RenameDir(FS_Archive archive, const char *old_dirname, const char *new_dirname);
|
||||||
|
Result FS_Read(FS_Archive archive, const char *path, u64 size, void *buf);
|
||||||
|
Result FS_Write(FS_Archive archive, const char *path, const void *buf, u32 size);
|
||||||
|
char *FS_GetFileTimestamp(const char *path);
|
||||||
|
Result makeDirs(const char * path);
|
||||||
|
Result openFile(Handle* fileHandle, const char * path, bool write);
|
25447
include/renderd7/external/json.hpp
vendored
Normal file
25447
include/renderd7/external/json.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
250
include/renderd7/external/libnsbmp/libnsbmp.h
vendored
Normal file
250
include/renderd7/external/libnsbmp/libnsbmp.h
vendored
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2006 Richard Wilson <richard.wilson@netsurf-browser.org>
|
||||||
|
* Copyright 2008 Sean Fox <dyntryx@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of NetSurf's libnsbmp, http://www.netsurf-browser.org/
|
||||||
|
* Licenced under the MIT License,
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Bitmap file decoding interface.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef libnsbmp_h_
|
||||||
|
#define libnsbmp_h_
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
/* bmp flags */
|
||||||
|
#define BMP_NEW 0
|
||||||
|
/** image is opaque (as opposed to having an alpha mask) */
|
||||||
|
#define BMP_OPAQUE (1 << 0)
|
||||||
|
/** memory should be wiped */
|
||||||
|
#define BMP_CLEAR_MEMORY (1 << 1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* error return values
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
BMP_OK = 0,
|
||||||
|
BMP_INSUFFICIENT_MEMORY = 1,
|
||||||
|
BMP_INSUFFICIENT_DATA = 2,
|
||||||
|
BMP_DATA_ERROR = 3
|
||||||
|
} bmp_result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* encoding types
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
BMP_ENCODING_RGB = 0,
|
||||||
|
BMP_ENCODING_RLE8 = 1,
|
||||||
|
BMP_ENCODING_RLE4 = 2,
|
||||||
|
BMP_ENCODING_BITFIELDS = 3
|
||||||
|
} bmp_encoding;
|
||||||
|
|
||||||
|
/* API for Bitmap callbacks */
|
||||||
|
typedef void* (*bmp_bitmap_cb_create)(int width, int height, unsigned int state);
|
||||||
|
typedef void (*bmp_bitmap_cb_destroy)(void *bitmap);
|
||||||
|
typedef unsigned char* (*bmp_bitmap_cb_get_buffer)(void *bitmap);
|
||||||
|
typedef size_t (*bmp_bitmap_cb_get_bpp)(void *bitmap);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Bitmap callbacks function table
|
||||||
|
*/
|
||||||
|
typedef struct bmp_bitmap_callback_vt_s {
|
||||||
|
/** Callback to allocate bitmap storage. */
|
||||||
|
bmp_bitmap_cb_create bitmap_create;
|
||||||
|
/** Called to free bitmap storage. */
|
||||||
|
bmp_bitmap_cb_destroy bitmap_destroy;
|
||||||
|
/** Return a pointer to the pixel data in a bitmap. */
|
||||||
|
bmp_bitmap_cb_get_buffer bitmap_get_buffer;
|
||||||
|
/** Find the width of a pixel row in bytes. */
|
||||||
|
bmp_bitmap_cb_get_bpp bitmap_get_bpp;
|
||||||
|
} bmp_bitmap_callback_vt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bitmap image
|
||||||
|
*/
|
||||||
|
typedef struct bmp_image {
|
||||||
|
/** callbacks for bitmap functions */
|
||||||
|
bmp_bitmap_callback_vt bitmap_callbacks;
|
||||||
|
/** pointer to BMP data */
|
||||||
|
uint8_t *bmp_data;
|
||||||
|
/** width of BMP (valid after _analyse) */
|
||||||
|
uint32_t width;
|
||||||
|
/** heigth of BMP (valid after _analyse) */
|
||||||
|
uint32_t height;
|
||||||
|
/** whether the image has been decoded */
|
||||||
|
bool decoded;
|
||||||
|
/** decoded image */
|
||||||
|
void *bitmap;
|
||||||
|
|
||||||
|
/* Internal members are listed below */
|
||||||
|
/** total number of bytes of BMP data available */
|
||||||
|
uint32_t buffer_size;
|
||||||
|
/** pixel encoding type */
|
||||||
|
bmp_encoding encoding;
|
||||||
|
/** offset of bitmap data */
|
||||||
|
uint32_t bitmap_offset;
|
||||||
|
/** bits per pixel */
|
||||||
|
uint16_t bpp;
|
||||||
|
/** number of colours */
|
||||||
|
uint32_t colours;
|
||||||
|
/** colour table */
|
||||||
|
uint32_t *colour_table;
|
||||||
|
/** whether to use bmp's limited transparency */
|
||||||
|
bool limited_trans;
|
||||||
|
/** colour to display for "transparent" pixels when using limited
|
||||||
|
* transparency
|
||||||
|
*/
|
||||||
|
uint32_t trans_colour;
|
||||||
|
/** scanlines are top to bottom */
|
||||||
|
bool reversed;
|
||||||
|
/** image is part of an ICO, mask follows */
|
||||||
|
bool ico;
|
||||||
|
/** true if the bitmap does not contain an alpha channel */
|
||||||
|
bool opaque;
|
||||||
|
/** four bitwise mask */
|
||||||
|
uint32_t mask[4];
|
||||||
|
/** four bitwise shifts */
|
||||||
|
int32_t shift[4];
|
||||||
|
/** colour representing "transparency" in the bitmap */
|
||||||
|
uint32_t transparent_index;
|
||||||
|
} bmp_image;
|
||||||
|
|
||||||
|
typedef struct ico_image {
|
||||||
|
bmp_image bmp;
|
||||||
|
struct ico_image *next;
|
||||||
|
} ico_image;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* icon image collection
|
||||||
|
*/
|
||||||
|
typedef struct ico_collection {
|
||||||
|
/** callbacks for bitmap functions */
|
||||||
|
bmp_bitmap_callback_vt bitmap_callbacks;
|
||||||
|
/** width of largest BMP */
|
||||||
|
uint16_t width;
|
||||||
|
/** heigth of largest BMP */
|
||||||
|
uint16_t height;
|
||||||
|
|
||||||
|
/* Internal members are listed below */
|
||||||
|
/** pointer to ICO data */
|
||||||
|
uint8_t *ico_data;
|
||||||
|
/** total number of bytes of ICO data available */
|
||||||
|
uint32_t buffer_size;
|
||||||
|
/** root of linked list of images */
|
||||||
|
ico_image *first;
|
||||||
|
} ico_collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialises bitmap ready for analysing the bitmap.
|
||||||
|
*
|
||||||
|
* \param bmp The Bitmap to initialise
|
||||||
|
* \param callbacks The callbacks the library will call on operations.
|
||||||
|
* \return BMP_OK on success or appropriate error code.
|
||||||
|
*/
|
||||||
|
bmp_result bmp_create(bmp_image *bmp, bmp_bitmap_callback_vt *callbacks);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialises icon ready for analysing the icon
|
||||||
|
*
|
||||||
|
* \param bmp The Bitmap to initialise
|
||||||
|
* \param callbacks The callbacks the library will call on operations.
|
||||||
|
* \return BMP_OK on success or appropriate error code.
|
||||||
|
*/
|
||||||
|
bmp_result ico_collection_create(ico_collection *ico,
|
||||||
|
bmp_bitmap_callback_vt *callbacks);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyse a BMP prior to decoding.
|
||||||
|
*
|
||||||
|
* This will scan the data provided and perform checks to ensure the data is a
|
||||||
|
* valid BMP and prepare the bitmap image structure ready for decode.
|
||||||
|
*
|
||||||
|
* This function must be called and resturn BMP_OK before bmp_decode() as it
|
||||||
|
* prepares the bmp internal state for the decode process.
|
||||||
|
*
|
||||||
|
* \param bmp the BMP image to analyse.
|
||||||
|
* \param size The size of data in cdata.
|
||||||
|
* \param data The bitmap source data.
|
||||||
|
* \return BMP_OK on success or error code on faliure.
|
||||||
|
*/
|
||||||
|
bmp_result bmp_analyse(bmp_image *bmp, size_t size, uint8_t *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyse an ICO prior to decoding.
|
||||||
|
*
|
||||||
|
* This function will scan the data provided and perform checks to ensure the
|
||||||
|
* data is a valid ICO.
|
||||||
|
*
|
||||||
|
* This function must be called before ico_find().
|
||||||
|
*
|
||||||
|
* \param ico the ICO image to analyse
|
||||||
|
* \param size The size of data in cdata.
|
||||||
|
* \param data The bitmap source data.
|
||||||
|
* \return BMP_OK on success
|
||||||
|
*/
|
||||||
|
bmp_result ico_analyse(ico_collection *ico, size_t size, uint8_t *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode a BMP
|
||||||
|
*
|
||||||
|
* This function decodes the BMP data such that bmp->bitmap is a valid
|
||||||
|
* image. The state of bmp->decoded is set to TRUE on exit such that it
|
||||||
|
* can easily be identified which BMPs are in a fully decoded state.
|
||||||
|
*
|
||||||
|
* \param bmp the BMP image to decode
|
||||||
|
* \return BMP_OK on success
|
||||||
|
*/
|
||||||
|
bmp_result bmp_decode(bmp_image *bmp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode a BMP using "limited transparency"
|
||||||
|
*
|
||||||
|
* Bitmaps do not have native transparency support. However, there is a
|
||||||
|
* "trick" that is used in some instances in which the first pixel of the
|
||||||
|
* bitmap becomes the "transparency index". The decoding application can
|
||||||
|
* replace this index with whatever background colour it chooses to
|
||||||
|
* create the illusion of transparency.
|
||||||
|
*
|
||||||
|
* When to use transparency is at the discretion of the decoding
|
||||||
|
* application.
|
||||||
|
*
|
||||||
|
* \param bmp the BMP image to decode
|
||||||
|
* \param colour the colour to use as "transparent"
|
||||||
|
* \return BMP_OK on success
|
||||||
|
*/
|
||||||
|
bmp_result bmp_decode_trans(bmp_image *bmp, uint32_t transparent_colour);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the closest BMP within an ICO collection
|
||||||
|
*
|
||||||
|
* This function finds the BMP with dimensions as close to a specified set
|
||||||
|
* as possible from the images in the collection.
|
||||||
|
*
|
||||||
|
* \param ico the ICO collection to examine
|
||||||
|
* \param width the preferred width (0 to use ICO header width)
|
||||||
|
* \param height the preferred height (0 to use ICO header height)
|
||||||
|
*/
|
||||||
|
bmp_image *ico_find(ico_collection *ico, uint16_t width, uint16_t height);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finalise a BMP prior to destruction.
|
||||||
|
*
|
||||||
|
* \param bmp the BMP image to finalise.
|
||||||
|
*/
|
||||||
|
void bmp_finalise(bmp_image *bmp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finalise an ICO prior to destruction.
|
||||||
|
*
|
||||||
|
* \param ico the ICO image to finalise,
|
||||||
|
*/
|
||||||
|
void ico_finalise(ico_collection *ico);
|
||||||
|
|
||||||
|
#endif
|
27
include/renderd7/external/libnsbmp/log.h
vendored
Normal file
27
include/renderd7/external/libnsbmp/log.h
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
|
||||||
|
* Copyright 2004 John Tytgat <John.Tytgat@aaug.net>
|
||||||
|
*
|
||||||
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
||||||
|
* Licenced under the MIT License,
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifndef _LIBNSBMP_LOG_H_
|
||||||
|
#define _LIBNSBMP_LOG_H_
|
||||||
|
|
||||||
|
#ifdef NDEBUG
|
||||||
|
# define LOG(x) ((void) 0)
|
||||||
|
#else
|
||||||
|
# ifdef __GNUC__
|
||||||
|
# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0)
|
||||||
|
# elif defined(__CC_NORCROFT)
|
||||||
|
# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0)
|
||||||
|
# else
|
||||||
|
# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0)
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
1977
include/renderd7/external/lodepng.h
vendored
Normal file
1977
include/renderd7/external/lodepng.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
7897
include/renderd7/external/stb_image.h
vendored
Normal file
7897
include/renderd7/external/stb_image.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1724
include/renderd7/external/stb_image_write.h
vendored
Normal file
1724
include/renderd7/external/stb_image_write.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
5077
include/renderd7/external/stb_truetype.h
vendored
Normal file
5077
include/renderd7/external/stb_truetype.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
545
include/renderd7/ini.hpp
Normal file
545
include/renderd7/ini.hpp
Normal file
@ -0,0 +1,545 @@
|
|||||||
|
#ifndef INI_INI_H_
|
||||||
|
#define INI_INI_H_
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
|
#include <fstream>
|
||||||
|
#include <memory>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace INI {
|
||||||
|
namespace INIStringUtil {
|
||||||
|
const char *const whitespaceDelimiters = " \t\n\r\f\v";
|
||||||
|
inline void trim(std::string &str) {
|
||||||
|
str.erase(str.find_last_not_of(whitespaceDelimiters) + 1);
|
||||||
|
str.erase(0, str.find_first_not_of(whitespaceDelimiters));
|
||||||
|
}
|
||||||
|
#ifndef INI_CASE_SENSITIVE
|
||||||
|
inline void toLower(std::string &str) {
|
||||||
|
std::transform(str.begin(), str.end(), str.begin(), [](const char c) {
|
||||||
|
return static_cast<const char>(std::tolower(c));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
inline void replace(std::string &str, std::string const &a,
|
||||||
|
std::string const &b) {
|
||||||
|
if (!a.empty()) {
|
||||||
|
std::size_t pos = 0;
|
||||||
|
while ((pos = str.find(a, pos)) != std::string::npos) {
|
||||||
|
str.replace(pos, a.size(), b);
|
||||||
|
pos += b.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef _WIN32
|
||||||
|
const char *const endl = "\r\n";
|
||||||
|
#else
|
||||||
|
const char *const endl = "\n";
|
||||||
|
#endif
|
||||||
|
}; // namespace INIStringUtil
|
||||||
|
|
||||||
|
template <typename T> class INIMap {
|
||||||
|
private:
|
||||||
|
using T_DataIndexMap = std::unordered_map<std::string, std::size_t>;
|
||||||
|
using T_DataItem = std::pair<std::string, T>;
|
||||||
|
using T_DataContainer = std::vector<T_DataItem>;
|
||||||
|
using T_MultiArgs = typename std::vector<std::pair<std::string, T>>;
|
||||||
|
|
||||||
|
T_DataIndexMap dataIndexMap;
|
||||||
|
T_DataContainer data;
|
||||||
|
|
||||||
|
inline std::size_t setEmpty(std::string &key) {
|
||||||
|
std::size_t index = data.size();
|
||||||
|
dataIndexMap[key] = index;
|
||||||
|
data.emplace_back(key, T());
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
using const_iterator = typename T_DataContainer::const_iterator;
|
||||||
|
|
||||||
|
INIMap() {}
|
||||||
|
|
||||||
|
INIMap(INIMap const &other) {
|
||||||
|
std::size_t data_size = other.data.size();
|
||||||
|
for (std::size_t i = 0; i < data_size; ++i) {
|
||||||
|
auto const &key = other.data[i].first;
|
||||||
|
auto const &obj = other.data[i].second;
|
||||||
|
data.emplace_back(key, obj);
|
||||||
|
}
|
||||||
|
dataIndexMap = T_DataIndexMap(other.dataIndexMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
T &operator[](std::string key) {
|
||||||
|
INIStringUtil::trim(key);
|
||||||
|
#ifndef INI_CASE_SENSITIVE
|
||||||
|
INIStringUtil::toLower(key);
|
||||||
|
#endif
|
||||||
|
auto it = dataIndexMap.find(key);
|
||||||
|
bool hasIt = (it != dataIndexMap.end());
|
||||||
|
std::size_t index = (hasIt) ? it->second : setEmpty(key);
|
||||||
|
return data[index].second;
|
||||||
|
}
|
||||||
|
T get(std::string key) const {
|
||||||
|
INIStringUtil::trim(key);
|
||||||
|
#ifndef INI_CASE_SENSITIVE
|
||||||
|
INIStringUtil::toLower(key);
|
||||||
|
#endif
|
||||||
|
auto it = dataIndexMap.find(key);
|
||||||
|
if (it == dataIndexMap.end()) {
|
||||||
|
return T();
|
||||||
|
}
|
||||||
|
return T(data[it->second].second);
|
||||||
|
}
|
||||||
|
bool has(std::string key) const {
|
||||||
|
INIStringUtil::trim(key);
|
||||||
|
#ifndef INI_CASE_SENSITIVE
|
||||||
|
INIStringUtil::toLower(key);
|
||||||
|
#endif
|
||||||
|
return (dataIndexMap.count(key) == 1);
|
||||||
|
}
|
||||||
|
void set(std::string key, T obj) {
|
||||||
|
INIStringUtil::trim(key);
|
||||||
|
#ifndef INI_CASE_SENSITIVE
|
||||||
|
INIStringUtil::toLower(key);
|
||||||
|
#endif
|
||||||
|
auto it = dataIndexMap.find(key);
|
||||||
|
if (it != dataIndexMap.end()) {
|
||||||
|
data[it->second].second = obj;
|
||||||
|
} else {
|
||||||
|
dataIndexMap[key] = data.size();
|
||||||
|
data.emplace_back(key, obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void set(T_MultiArgs const &multiArgs) {
|
||||||
|
for (auto const &it : multiArgs) {
|
||||||
|
auto const &key = it.first;
|
||||||
|
auto const &obj = it.second;
|
||||||
|
set(key, obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool remove(std::string key) {
|
||||||
|
INIStringUtil::trim(key);
|
||||||
|
#ifndef INI_CASE_SENSITIVE
|
||||||
|
INIStringUtil::toLower(key);
|
||||||
|
#endif
|
||||||
|
auto it = dataIndexMap.find(key);
|
||||||
|
if (it != dataIndexMap.end()) {
|
||||||
|
std::size_t index = it->second;
|
||||||
|
data.erase(data.begin() + index);
|
||||||
|
dataIndexMap.erase(it);
|
||||||
|
for (auto &it2 : dataIndexMap) {
|
||||||
|
auto &vi = it2.second;
|
||||||
|
if (vi > index) {
|
||||||
|
vi--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void clear() {
|
||||||
|
data.clear();
|
||||||
|
dataIndexMap.clear();
|
||||||
|
}
|
||||||
|
std::size_t size() const { return data.size(); }
|
||||||
|
const_iterator begin() const { return data.begin(); }
|
||||||
|
const_iterator end() const { return data.end(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
using INIStructure = INIMap<INIMap<std::string>>;
|
||||||
|
|
||||||
|
namespace INIParser {
|
||||||
|
using T_ParseValues = std::pair<std::string, std::string>;
|
||||||
|
|
||||||
|
enum class PDataType : char {
|
||||||
|
PDATA_NONE,
|
||||||
|
PDATA_COMMENT,
|
||||||
|
PDATA_SECTION,
|
||||||
|
PDATA_KEYVALUE,
|
||||||
|
PDATA_UNKNOWN
|
||||||
|
};
|
||||||
|
|
||||||
|
inline PDataType parseLine(std::string line, T_ParseValues &parseData) {
|
||||||
|
parseData.first.clear();
|
||||||
|
parseData.second.clear();
|
||||||
|
INIStringUtil::trim(line);
|
||||||
|
if (line.empty()) {
|
||||||
|
return PDataType::PDATA_NONE;
|
||||||
|
}
|
||||||
|
char firstCharacter = line[0];
|
||||||
|
if (firstCharacter == ';') {
|
||||||
|
return PDataType::PDATA_COMMENT;
|
||||||
|
}
|
||||||
|
if (firstCharacter == '[') {
|
||||||
|
auto commentAt = line.find_first_of(';');
|
||||||
|
if (commentAt != std::string::npos) {
|
||||||
|
line = line.substr(0, commentAt);
|
||||||
|
}
|
||||||
|
auto closingBracketAt = line.find_last_of(']');
|
||||||
|
if (closingBracketAt != std::string::npos) {
|
||||||
|
auto section = line.substr(1, closingBracketAt - 1);
|
||||||
|
INIStringUtil::trim(section);
|
||||||
|
parseData.first = section;
|
||||||
|
return PDataType::PDATA_SECTION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto lineNorm = line;
|
||||||
|
INIStringUtil::replace(lineNorm, "\\=", " ");
|
||||||
|
auto equalsAt = lineNorm.find_first_of('=');
|
||||||
|
if (equalsAt != std::string::npos) {
|
||||||
|
auto key = line.substr(0, equalsAt);
|
||||||
|
INIStringUtil::trim(key);
|
||||||
|
INIStringUtil::replace(key, "\\=", "=");
|
||||||
|
auto value = line.substr(equalsAt + 1);
|
||||||
|
INIStringUtil::trim(value);
|
||||||
|
parseData.first = key;
|
||||||
|
parseData.second = value;
|
||||||
|
return PDataType::PDATA_KEYVALUE;
|
||||||
|
}
|
||||||
|
return PDataType::PDATA_UNKNOWN;
|
||||||
|
}
|
||||||
|
}; // namespace INIParser
|
||||||
|
|
||||||
|
class INIReader {
|
||||||
|
public:
|
||||||
|
using T_LineData = std::vector<std::string>;
|
||||||
|
using T_LineDataPtr = std::shared_ptr<T_LineData>;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::ifstream fileReadStream;
|
||||||
|
T_LineDataPtr lineData;
|
||||||
|
|
||||||
|
T_LineData readFile() {
|
||||||
|
std::string fileContents;
|
||||||
|
fileReadStream.seekg(0, std::ios::end);
|
||||||
|
fileContents.resize(fileReadStream.tellg());
|
||||||
|
fileReadStream.seekg(0, std::ios::beg);
|
||||||
|
std::size_t fileSize = fileContents.size();
|
||||||
|
fileReadStream.read(&fileContents[0], fileSize);
|
||||||
|
fileReadStream.close();
|
||||||
|
T_LineData output;
|
||||||
|
if (fileSize == 0) {
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
std::string buffer;
|
||||||
|
buffer.reserve(50);
|
||||||
|
for (std::size_t i = 0; i < fileSize; ++i) {
|
||||||
|
char &c = fileContents[i];
|
||||||
|
if (c == '\n') {
|
||||||
|
output.emplace_back(buffer);
|
||||||
|
buffer.clear();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (c != '\0' && c != '\r') {
|
||||||
|
buffer += c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output.emplace_back(buffer);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
INIReader(std::string const &filename, bool keepLineData = false) {
|
||||||
|
fileReadStream.open(filename, std::ios::in | std::ios::binary);
|
||||||
|
if (keepLineData) {
|
||||||
|
lineData = std::make_shared<T_LineData>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
~INIReader() {}
|
||||||
|
|
||||||
|
bool operator>>(INIStructure &data) {
|
||||||
|
if (!fileReadStream.is_open()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
T_LineData fileLines = readFile();
|
||||||
|
std::string section;
|
||||||
|
bool inSection = false;
|
||||||
|
INIParser::T_ParseValues parseData;
|
||||||
|
for (auto const &line : fileLines) {
|
||||||
|
auto parseResult = INIParser::parseLine(line, parseData);
|
||||||
|
if (parseResult == INIParser::PDataType::PDATA_SECTION) {
|
||||||
|
inSection = true;
|
||||||
|
data[section = parseData.first];
|
||||||
|
} else if (inSection &&
|
||||||
|
parseResult == INIParser::PDataType::PDATA_KEYVALUE) {
|
||||||
|
auto const &key = parseData.first;
|
||||||
|
auto const &value = parseData.second;
|
||||||
|
data[section][key] = value;
|
||||||
|
}
|
||||||
|
if (lineData && parseResult != INIParser::PDataType::PDATA_UNKNOWN) {
|
||||||
|
if (parseResult == INIParser::PDataType::PDATA_KEYVALUE && !inSection) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
lineData->emplace_back(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
T_LineDataPtr getLines() { return lineData; }
|
||||||
|
};
|
||||||
|
|
||||||
|
class INIGenerator {
|
||||||
|
private:
|
||||||
|
std::ofstream fileWriteStream;
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool prettyPrint = false;
|
||||||
|
|
||||||
|
INIGenerator(std::string const &filename) {
|
||||||
|
fileWriteStream.open(filename, std::ios::out | std::ios::binary);
|
||||||
|
}
|
||||||
|
~INIGenerator() {}
|
||||||
|
|
||||||
|
bool operator<<(INIStructure const &data) {
|
||||||
|
if (!fileWriteStream.is_open()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!data.size()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
auto it = data.begin();
|
||||||
|
for (;;) {
|
||||||
|
auto const §ion = it->first;
|
||||||
|
auto const &collection = it->second;
|
||||||
|
fileWriteStream << "[" << section << "]";
|
||||||
|
if (collection.size()) {
|
||||||
|
fileWriteStream << INIStringUtil::endl;
|
||||||
|
auto it2 = collection.begin();
|
||||||
|
for (;;) {
|
||||||
|
auto key = it2->first;
|
||||||
|
INIStringUtil::replace(key, "=", "\\=");
|
||||||
|
auto value = it2->second;
|
||||||
|
INIStringUtil::trim(value);
|
||||||
|
fileWriteStream << key << ((prettyPrint) ? " = " : "=") << value;
|
||||||
|
if (++it2 == collection.end()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fileWriteStream << INIStringUtil::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (++it == data.end()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fileWriteStream << INIStringUtil::endl;
|
||||||
|
if (prettyPrint) {
|
||||||
|
fileWriteStream << INIStringUtil::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class INIWriter {
|
||||||
|
private:
|
||||||
|
using T_LineData = std::vector<std::string>;
|
||||||
|
using T_LineDataPtr = std::shared_ptr<T_LineData>;
|
||||||
|
|
||||||
|
std::string filename;
|
||||||
|
|
||||||
|
T_LineData getLazyOutput(T_LineDataPtr const &lineData, INIStructure &data,
|
||||||
|
INIStructure &original) {
|
||||||
|
T_LineData output;
|
||||||
|
INIParser::T_ParseValues parseData;
|
||||||
|
std::string sectionCurrent;
|
||||||
|
bool parsingSection = false;
|
||||||
|
bool continueToNextSection = false;
|
||||||
|
bool discardNextEmpty = false;
|
||||||
|
bool writeNewKeys = false;
|
||||||
|
std::size_t lastKeyLine = 0;
|
||||||
|
for (auto line = lineData->begin(); line != lineData->end(); ++line) {
|
||||||
|
if (!writeNewKeys) {
|
||||||
|
auto parseResult = INIParser::parseLine(*line, parseData);
|
||||||
|
if (parseResult == INIParser::PDataType::PDATA_SECTION) {
|
||||||
|
if (parsingSection) {
|
||||||
|
writeNewKeys = true;
|
||||||
|
parsingSection = false;
|
||||||
|
--line;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sectionCurrent = parseData.first;
|
||||||
|
if (data.has(sectionCurrent)) {
|
||||||
|
parsingSection = true;
|
||||||
|
continueToNextSection = false;
|
||||||
|
discardNextEmpty = false;
|
||||||
|
output.emplace_back(*line);
|
||||||
|
lastKeyLine = output.size();
|
||||||
|
} else {
|
||||||
|
continueToNextSection = true;
|
||||||
|
discardNextEmpty = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (parseResult == INIParser::PDataType::PDATA_KEYVALUE) {
|
||||||
|
if (continueToNextSection) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (data.has(sectionCurrent)) {
|
||||||
|
auto &collection = data[sectionCurrent];
|
||||||
|
auto const &key = parseData.first;
|
||||||
|
auto const &value = parseData.second;
|
||||||
|
if (collection.has(key)) {
|
||||||
|
auto outputValue = collection[key];
|
||||||
|
if (value == outputValue) {
|
||||||
|
output.emplace_back(*line);
|
||||||
|
} else {
|
||||||
|
INIStringUtil::trim(outputValue);
|
||||||
|
auto lineNorm = *line;
|
||||||
|
INIStringUtil::replace(lineNorm, "\\=", " ");
|
||||||
|
auto equalsAt = lineNorm.find_first_of('=');
|
||||||
|
auto valueAt = lineNorm.find_first_not_of(
|
||||||
|
INIStringUtil::whitespaceDelimiters, equalsAt + 1);
|
||||||
|
std::string outputLine = line->substr(0, valueAt);
|
||||||
|
if (prettyPrint && equalsAt + 1 == valueAt) {
|
||||||
|
outputLine += " ";
|
||||||
|
}
|
||||||
|
outputLine += outputValue;
|
||||||
|
output.emplace_back(outputLine);
|
||||||
|
}
|
||||||
|
lastKeyLine = output.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (discardNextEmpty && line->empty()) {
|
||||||
|
discardNextEmpty = false;
|
||||||
|
} else if (parseResult != INIParser::PDataType::PDATA_UNKNOWN) {
|
||||||
|
output.emplace_back(*line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (writeNewKeys || std::next(line) == lineData->end()) {
|
||||||
|
T_LineData linesToAdd;
|
||||||
|
if (data.has(sectionCurrent) && original.has(sectionCurrent)) {
|
||||||
|
auto const &collection = data[sectionCurrent];
|
||||||
|
auto const &collectionOriginal = original[sectionCurrent];
|
||||||
|
for (auto const &it : collection) {
|
||||||
|
auto key = it.first;
|
||||||
|
if (collectionOriginal.has(key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto value = it.second;
|
||||||
|
INIStringUtil::replace(key, "=", "\\=");
|
||||||
|
INIStringUtil::trim(value);
|
||||||
|
linesToAdd.emplace_back(key + ((prettyPrint) ? " = " : "=") +
|
||||||
|
value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!linesToAdd.empty()) {
|
||||||
|
output.insert(output.begin() + lastKeyLine, linesToAdd.begin(),
|
||||||
|
linesToAdd.end());
|
||||||
|
}
|
||||||
|
if (writeNewKeys) {
|
||||||
|
writeNewKeys = false;
|
||||||
|
--line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto const &it : data) {
|
||||||
|
auto const §ion = it.first;
|
||||||
|
if (original.has(section)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (prettyPrint && output.size() > 0 && !output.back().empty()) {
|
||||||
|
output.emplace_back();
|
||||||
|
}
|
||||||
|
output.emplace_back("[" + section + "]");
|
||||||
|
auto const &collection = it.second;
|
||||||
|
for (auto const &it2 : collection) {
|
||||||
|
auto key = it2.first;
|
||||||
|
auto value = it2.second;
|
||||||
|
INIStringUtil::replace(key, "=", "\\=");
|
||||||
|
INIStringUtil::trim(value);
|
||||||
|
output.emplace_back(key + ((prettyPrint) ? " = " : "=") + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool prettyPrint = false;
|
||||||
|
|
||||||
|
INIWriter(std::string const &filename) : filename(filename) {}
|
||||||
|
~INIWriter() {}
|
||||||
|
|
||||||
|
bool operator<<(INIStructure &data) {
|
||||||
|
struct stat buf;
|
||||||
|
bool fileExists = (stat(filename.c_str(), &buf) == 0);
|
||||||
|
if (!fileExists) {
|
||||||
|
INIGenerator generator(filename);
|
||||||
|
generator.prettyPrint = prettyPrint;
|
||||||
|
return generator << data;
|
||||||
|
}
|
||||||
|
INIStructure originalData;
|
||||||
|
T_LineDataPtr lineData;
|
||||||
|
bool readSuccess = false;
|
||||||
|
{
|
||||||
|
INIReader reader(filename, true);
|
||||||
|
if ((readSuccess = reader >> originalData)) {
|
||||||
|
lineData = reader.getLines();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!readSuccess) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
T_LineData output = getLazyOutput(lineData, data, originalData);
|
||||||
|
std::ofstream fileWriteStream(filename, std::ios::out | std::ios::binary);
|
||||||
|
if (fileWriteStream.is_open()) {
|
||||||
|
if (output.size()) {
|
||||||
|
auto line = output.begin();
|
||||||
|
for (;;) {
|
||||||
|
fileWriteStream << *line;
|
||||||
|
if (++line == output.end()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fileWriteStream << INIStringUtil::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class INIFile {
|
||||||
|
private:
|
||||||
|
std::string filename;
|
||||||
|
|
||||||
|
public:
|
||||||
|
INIFile(std::string const &filename) : filename(filename) {}
|
||||||
|
|
||||||
|
~INIFile() {}
|
||||||
|
|
||||||
|
bool read(INIStructure &data) const {
|
||||||
|
if (data.size()) {
|
||||||
|
data.clear();
|
||||||
|
}
|
||||||
|
if (filename.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
INIReader reader(filename);
|
||||||
|
return reader >> data;
|
||||||
|
}
|
||||||
|
bool generate(INIStructure const &data, bool pretty = false) const {
|
||||||
|
if (filename.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
INIGenerator generator(filename);
|
||||||
|
generator.prettyPrint = pretty;
|
||||||
|
return generator << data;
|
||||||
|
}
|
||||||
|
bool write(INIStructure &data, bool pretty = false) const {
|
||||||
|
if (filename.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
INIWriter writer(filename);
|
||||||
|
writer.prettyPrint = pretty;
|
||||||
|
return writer << data;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace INI
|
||||||
|
|
||||||
|
#endif
|
15
include/renderd7/lang.hpp
Normal file
15
include/renderd7/lang.hpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <renderd7/external/json.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/// RenderD7::Lang
|
||||||
|
namespace RenderD7::Lang {
|
||||||
|
/// Get the 3ds System Language
|
||||||
|
std::string getSys();
|
||||||
|
/// Get a translated string
|
||||||
|
/// \param key The Key so the code can find your string
|
||||||
|
std::string get(const std::string &key);
|
||||||
|
/// Load the lang file from dir structure en/app.json for sample
|
||||||
|
/// \param lang the folder name en, fr, de ... . I prefer geSys()
|
||||||
|
void load(const std::string &lang);
|
||||||
|
} // namespace RenderD7::Lang
|
30
include/renderd7/log.hpp
Normal file
30
include/renderd7/log.hpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <fstream>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/** Log Class */
|
||||||
|
class Log {
|
||||||
|
public:
|
||||||
|
/** Construct */
|
||||||
|
Log();
|
||||||
|
/** Deconstruct */
|
||||||
|
~Log();
|
||||||
|
/// Init the log file
|
||||||
|
/// \param filename name for the file
|
||||||
|
void Init(const char *filename);
|
||||||
|
/// Write Text to logfile
|
||||||
|
/// \param debug_text your text
|
||||||
|
void Write(std::string debug_text);
|
||||||
|
/// Get the date
|
||||||
|
std::string logDate(void);
|
||||||
|
/// Format to logstyle
|
||||||
|
/// \param fmt_str the formatted style
|
||||||
|
std::string format(const std::string &fmt_str, ...);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \param filename the name of the logfile
|
||||||
|
std::string filename;
|
||||||
|
};
|
118
include/renderd7/parameter.hpp
Normal file
118
include/renderd7/parameter.hpp
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
class Parameter {
|
||||||
|
private:
|
||||||
|
using id = size_t;
|
||||||
|
|
||||||
|
template <typename T> struct type {
|
||||||
|
static void id() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T> static id type_id() {
|
||||||
|
return reinterpret_cast<id>(&type<T>::id);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> using decay = typename std::decay<T>::type;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using none =
|
||||||
|
typename std::enable_if<!std::is_same<Parameter, T>::value>::type;
|
||||||
|
|
||||||
|
struct base {
|
||||||
|
virtual ~base() {}
|
||||||
|
virtual bool is(id) const = 0;
|
||||||
|
virtual base *copy() const = 0;
|
||||||
|
} *p = nullptr;
|
||||||
|
|
||||||
|
template <typename T> struct data : base, std::tuple<T> {
|
||||||
|
using std::tuple<T>::tuple;
|
||||||
|
|
||||||
|
T &get() & { return std::get<0>(*this); }
|
||||||
|
T const &get() const & { return std::get<0>(*this); }
|
||||||
|
|
||||||
|
bool is(id i) const override { return i == type_id<T>(); }
|
||||||
|
base *copy() const override { return new data{get()}; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T> T &stat() { return static_cast<data<T> &>(*p).get(); }
|
||||||
|
|
||||||
|
template <typename T> T const &stat() const {
|
||||||
|
return static_cast<data<T> const &>(*p).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> T &dyn() { return dynamic_cast<data<T> &>(*p).get(); }
|
||||||
|
|
||||||
|
template <typename T> T const &dyn() const {
|
||||||
|
return dynamic_cast<data<T> const &>(*p).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Default constructor
|
||||||
|
*/
|
||||||
|
Parameter() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destructs the Parameter
|
||||||
|
*/
|
||||||
|
~Parameter() { delete p; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Copy constructor
|
||||||
|
* @param s The Parameter to copy
|
||||||
|
*/
|
||||||
|
Parameter(Parameter &&s) : p{s.p} { s.p = nullptr; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Const copy constructor
|
||||||
|
* @param s The Parameter to copy
|
||||||
|
*/
|
||||||
|
Parameter(Parameter const &s) : p{s.p->copy()} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initializes the Parameter with the given value
|
||||||
|
* @param x The value to initialize the Parameter with
|
||||||
|
*/
|
||||||
|
template <typename T, typename U = decay<T>, typename = none<U>>
|
||||||
|
Parameter(T &&x) : p{new data<U>{std::forward<T>(x)}} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Overloads the assignment operator
|
||||||
|
* @param s The value to set the Parameter to
|
||||||
|
*/
|
||||||
|
Parameter &operator=(Parameter s) {
|
||||||
|
swap(*this, s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend void swap(Parameter &s, Parameter &r) { std::swap(s.p, r.p); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clears the Parameter
|
||||||
|
*/
|
||||||
|
void clear() {
|
||||||
|
delete p;
|
||||||
|
p = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks whether the Parameter is the given type
|
||||||
|
* @tparam T The type to check
|
||||||
|
* @return Whether the Parameter has the given type or not
|
||||||
|
*/
|
||||||
|
template <typename T> bool is() const {
|
||||||
|
return p ? p->is(type_id<T>()) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the value of the Parameter
|
||||||
|
* @tparam T The type of the Parameter
|
||||||
|
* @return The value of the Parameter
|
||||||
|
* @warning If the type of the Parameter doesn't match the type of it's stored
|
||||||
|
* value, it will result in undefined behaviour.
|
||||||
|
*/
|
||||||
|
template <typename T> T &get() & { return stat<T>(); }
|
||||||
|
};
|
||||||
|
} // namespace RenderD7
|
288
include/renderd7/renderd7.hpp
Normal file
288
include/renderd7/renderd7.hpp
Normal file
@ -0,0 +1,288 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <3ds.h>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <citro2d.h>
|
||||||
|
#include <citro3d.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <functional>
|
||||||
|
#include <iostream>
|
||||||
|
#include <locale>
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <random>
|
||||||
|
#include <stack>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <codecvt>
|
||||||
|
|
||||||
|
#include <renderd7/BitmapPrinter.hpp>
|
||||||
|
#include <renderd7/Color.hpp>
|
||||||
|
#include <renderd7/Draw.hpp>
|
||||||
|
#include <renderd7/Image.hpp>
|
||||||
|
#include <renderd7/Ovl.hpp>
|
||||||
|
#include <renderd7/ResultDecoder.hpp>
|
||||||
|
#include <renderd7/Screen.hpp>
|
||||||
|
#include <renderd7/Sheet.hpp>
|
||||||
|
#include <renderd7/Sprite.hpp>
|
||||||
|
#include <renderd7/SpriteAnimation.hpp>
|
||||||
|
#include <renderd7/Time.hpp>
|
||||||
|
#include <renderd7/Toast.hpp>
|
||||||
|
#include <renderd7/bmp.hpp>
|
||||||
|
#include <renderd7/bmpconverter.hpp>
|
||||||
|
#include <renderd7/external/lodepng.h>
|
||||||
|
#include <renderd7/ini.hpp>
|
||||||
|
#include <renderd7/lang.hpp>
|
||||||
|
#include <renderd7/parameter.hpp>
|
||||||
|
#include <renderd7/stringtool.hpp>
|
||||||
|
#include <renderd7/thread.hpp>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <renderd7/external/fs.h>
|
||||||
|
}
|
||||||
|
|
||||||
|
#define RENDERD7VSTRING "0.8.5"
|
||||||
|
#define CHANGELOG \
|
||||||
|
"0.8.5: Fix Deltatime 0.8.4: A lot of Fixes and new Features for " \
|
||||||
|
"BitmapPrinter! 0.8.3: Addet " \
|
||||||
|
"Overlaycount to Info and Addet ResultDecoder for " \
|
||||||
|
"errors.0.8.2: Fix a lot of Stuff and add c++17 based filesystem " \
|
||||||
|
"class.\n0.8.1: " \
|
||||||
|
"Add abillity to Get Stdout as string to render it to the " \
|
||||||
|
"screen.\n0.8.0: Implement BitmapPrinter\n0.7.3: Implement Over Render " \
|
||||||
|
"Overlay " \
|
||||||
|
"Framework\n0.7.2: Implement MT to csv file saving. Add RGB2HEX. \n0.7.1: " \
|
||||||
|
"Add the New Overlay Handler. Its Just in code and does nothing yet. " \
|
||||||
|
"\n0.7.0: Made Big Progress In the MT Ovl but it still crashes On a Scnd " \
|
||||||
|
"C3D_FrameEnd(). Implement 800px but doesn't work that good. \n0.6.2: Fix " \
|
||||||
|
"Crash when exiting trouth Home Menu. \n0.6.10: rewrite Threadsystem, " \
|
||||||
|
"Improve framerate\n0.6.02: Fix Code in lang.hpp\nadd Draw Text Left " \
|
||||||
|
"Function.\nadd changelog\n0.6.01: add Threading system."
|
||||||
|
#define DEFAULT_CENTER 0.5f
|
||||||
|
|
||||||
|
/*extern C3D_RenderTarget* Top;
|
||||||
|
extern C3D_RenderTarget* TopRight;
|
||||||
|
extern C3D_RenderTarget* Bottom;*/
|
||||||
|
|
||||||
|
extern u32 d7_hDown;
|
||||||
|
extern u32 d7_hHeld;
|
||||||
|
extern u32 d7_hUp;
|
||||||
|
extern touchPosition d7_touch;
|
||||||
|
|
||||||
|
extern std::string dspststus;
|
||||||
|
|
||||||
|
/// RenderD7
|
||||||
|
namespace RenderD7 {
|
||||||
|
float GetDeltaTime();
|
||||||
|
enum kbd { SWKBD, BKBD };
|
||||||
|
enum kbd_type { NUMPAD, STANDARD };
|
||||||
|
struct TObject {
|
||||||
|
int x; // Position X
|
||||||
|
int y; // Position Y
|
||||||
|
int w; // Button Width
|
||||||
|
int h; // Button Height
|
||||||
|
std::string text = ""; // Text
|
||||||
|
float correctx = 0; // Correct X Position
|
||||||
|
float correcty = 0; // Correct Y Position
|
||||||
|
float txtsize = 0.7f; // Set Text Size
|
||||||
|
};
|
||||||
|
|
||||||
|
class Scene {
|
||||||
|
public:
|
||||||
|
static std::stack<std::unique_ptr<Scene>> scenes;
|
||||||
|
virtual ~Scene() {}
|
||||||
|
virtual void Logic(u32 hDown, u32 hHeld, u32 hUp, touchPosition touch) = 0;
|
||||||
|
virtual void Draw() const = 0;
|
||||||
|
// virtual void Ovl() const = 0;
|
||||||
|
static void Load(std::unique_ptr<Scene> scene, bool fade = false);
|
||||||
|
static void Back();
|
||||||
|
static void doDraw();
|
||||||
|
static void doLogic(u32 hDown, u32 hHeld, u32 hUp, touchPosition touch);
|
||||||
|
// static void HandleOvl();
|
||||||
|
};
|
||||||
|
|
||||||
|
class RSettings : public RenderD7::Scene {
|
||||||
|
private:
|
||||||
|
enum RState { RSETTINGS, RINFO };
|
||||||
|
RenderD7::RSettings::RState m_state = RenderD7::RSettings::RState::RSETTINGS;
|
||||||
|
|
||||||
|
std::string rd7srstate = "false";
|
||||||
|
std::string csvstate = "false";
|
||||||
|
std::string mtovlstate = "false";
|
||||||
|
std::string fpsstate = "60";
|
||||||
|
std::string mtscreenstate = "Top";
|
||||||
|
std::string mttxtcolstate = "#ffffff";
|
||||||
|
std::string mtcola = "255";
|
||||||
|
std::string mttxtcola = "255";
|
||||||
|
|
||||||
|
std::vector<RenderD7::TObject> buttons = {
|
||||||
|
{20, 35, 120, 35, "RD7SR", -11, 10},
|
||||||
|
{20, 85, 120, 35, "MT_CSV", -15, 9},
|
||||||
|
{20, 135, 120, 35, "MT_OVL", -19, 10},
|
||||||
|
{20, 185, 120, 35, "FPS", 6, 10},
|
||||||
|
{180, 35, 120, 35, "MTSCREEN", -29, 10},
|
||||||
|
{180, 85, 120, 35, "DSPERR", -13, 10},
|
||||||
|
{180, 135, 120, 35, "INFO", 2, 10},
|
||||||
|
{180, 185, 120, 35, "", -13, 10}};
|
||||||
|
|
||||||
|
public:
|
||||||
|
RSettings();
|
||||||
|
void Draw(void) const override;
|
||||||
|
~RSettings();
|
||||||
|
void Logic(u32 hDown, u32 hHeld, u32 hUp, touchPosition touch) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
void LoadSettings();
|
||||||
|
|
||||||
|
class DSP_NF : public RenderD7::Ovl {
|
||||||
|
public:
|
||||||
|
DSP_NF();
|
||||||
|
void Draw(void) const override;
|
||||||
|
void Logic() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int msgposy = 240;
|
||||||
|
int delay = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
int GetRandomInt(int b, int e);
|
||||||
|
void DrawMetrikOvl();
|
||||||
|
bool DrawImageFromSheet(RenderD7::Sheet *sheet, size_t index, float x, float y,
|
||||||
|
float scaleX = 1.0, float scaleY = 1.0);
|
||||||
|
namespace Error {
|
||||||
|
void DisplayError(std::string toptext, std::string errortext, int timesec = 3);
|
||||||
|
void DisplayFatalError(std::string toptext, std::string errortext);
|
||||||
|
} // namespace Error
|
||||||
|
namespace Init {
|
||||||
|
Result Main(std::string app_name = "RD7Game");
|
||||||
|
Result Reload();
|
||||||
|
void Graphics();
|
||||||
|
void NdspFirm(bool useit = false);
|
||||||
|
} // namespace Init
|
||||||
|
namespace Exit {
|
||||||
|
void Main();
|
||||||
|
void NdspFirm();
|
||||||
|
void Graphics();
|
||||||
|
} // namespace Exit
|
||||||
|
namespace Msg {
|
||||||
|
void Display(std::string titletxt, std::string subtext,
|
||||||
|
C3D_RenderTarget *target);
|
||||||
|
void DisplayWithProgress(std::string titletext, std::string subtext,
|
||||||
|
float current, float total, u32 prgbarcolor);
|
||||||
|
} // namespace Msg
|
||||||
|
|
||||||
|
namespace Convert {
|
||||||
|
inline float StringtoFloat(std::string inp) { return std::atof(inp.c_str()); }
|
||||||
|
inline int StringtoInt(std::string inp) { return std::atoi(inp.c_str()); }
|
||||||
|
inline bool FloatToBool(float inp) {
|
||||||
|
if (inp == 1)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} // namespace Convert
|
||||||
|
|
||||||
|
struct DirContent {
|
||||||
|
std::string name;
|
||||||
|
std::string path;
|
||||||
|
bool isDir;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace FS {
|
||||||
|
bool FileExist(const std::string &path);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsNdspInit();
|
||||||
|
void SetupLog(void);
|
||||||
|
std::string GetFramerate();
|
||||||
|
bool MainLoop();
|
||||||
|
void ExitApp();
|
||||||
|
|
||||||
|
void ClearTextBufs(void);
|
||||||
|
|
||||||
|
std::string Kbd(int lenght, SwkbdType tp);
|
||||||
|
|
||||||
|
void FrameEnd();
|
||||||
|
void ToggleRD7SR();
|
||||||
|
bool IsRD7SR();
|
||||||
|
|
||||||
|
struct TLBtn {
|
||||||
|
int x; // Position X
|
||||||
|
int y; // Position Y
|
||||||
|
int w; // Button Width
|
||||||
|
int h; // Button Height
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ScrollList1 {
|
||||||
|
std::string Text = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ScrollList2 {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float w;
|
||||||
|
float h;
|
||||||
|
std::string Text = "";
|
||||||
|
};
|
||||||
|
/*enum ListType
|
||||||
|
{
|
||||||
|
ONE,
|
||||||
|
TWO
|
||||||
|
};*/
|
||||||
|
void DrawList1(RenderD7::ScrollList1 &l, float txtsize, C3D_RenderTarget *t);
|
||||||
|
void DrawTObjects(std::vector<RenderD7::TObject> tobjects, u32 color,
|
||||||
|
u32 txtcolor, int selection = -1,
|
||||||
|
u32 selbgcolor = RenderD7::Color::Hex("#2D98AF"),
|
||||||
|
u32 selcolor = RenderD7::Color::Hex("#000000"));
|
||||||
|
void DrawSTObject(std::vector<RenderD7::TObject> tobject, int tobjectindex,
|
||||||
|
u32 color, u32 txtcolor);
|
||||||
|
bool touchTObj(touchPosition touch, RenderD7::TObject button);
|
||||||
|
bool touchTLBtn(touchPosition touch, RenderD7::TLBtn button);
|
||||||
|
void DrawTLBtns(std::vector<RenderD7::TLBtn> btns, u32 color,
|
||||||
|
int selection = -1,
|
||||||
|
u32 selbgcolor = RenderD7::Color::Hex("#2D98AF"),
|
||||||
|
u32 selcolor = RenderD7::Color::Hex("#000000"));
|
||||||
|
|
||||||
|
struct Checkbox {
|
||||||
|
float x, y, s;
|
||||||
|
bool is_chexked = false;
|
||||||
|
u32 outcol, incol, chcol;
|
||||||
|
};
|
||||||
|
void DrawCheckbox(Checkbox box);
|
||||||
|
|
||||||
|
class Console {
|
||||||
|
public:
|
||||||
|
Console();
|
||||||
|
Console(int x, int y, int w, int h, u8 a = 255);
|
||||||
|
Console(int x, int y, int w, int h, RenderD7::Color::rgba col);
|
||||||
|
Console(int x, int y, int w, int h, std::string name,
|
||||||
|
RenderD7::Color::rgba col = {255, 255, 255, 255},
|
||||||
|
RenderD7::Color::rgba barcol = {0, 0, 0, 255},
|
||||||
|
RenderD7::Color::rgba outlinecol = {222, 222, 222, 255});
|
||||||
|
void On(C3D_RenderTarget *t_cscreen);
|
||||||
|
bool Update();
|
||||||
|
~Console();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::string> m_lines;
|
||||||
|
int x, y, w, h;
|
||||||
|
std::string m_name = "";
|
||||||
|
C3D_RenderTarget *cscreen;
|
||||||
|
bool m_nconsole = false;
|
||||||
|
bool m_mconsole = false;
|
||||||
|
RenderD7::Color::rgba color = {255, 255, 255, 255};
|
||||||
|
RenderD7::Color::rgba outlinecol = {222, 222, 222, 255};
|
||||||
|
RenderD7::Color::rgba barcolor = {0, 0, 0, 255};
|
||||||
|
};
|
||||||
|
|
||||||
|
void GetDirContentsExt(std::vector<RenderD7::DirContent> &dircontent,
|
||||||
|
const std::vector<std::string> &extensions);
|
||||||
|
void GetDirContents(std::vector<RenderD7::DirContent> &dircontent);
|
||||||
|
|
||||||
|
} // namespace RenderD7
|
27
include/renderd7/sound.hpp
Normal file
27
include/renderd7/sound.hpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <3ds.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/** Sound Class */
|
||||||
|
class sound {
|
||||||
|
public:
|
||||||
|
/// \brief Construct new Soundeffect
|
||||||
|
/// \param path Path to the .wav file
|
||||||
|
/// \param channel the channel 1-23
|
||||||
|
/// \param toloop true:loop the sound, false: don't loop
|
||||||
|
sound(const std::string &path, int channel = 1, bool toloop = false);
|
||||||
|
/** deconstruct the sound */
|
||||||
|
~sound();
|
||||||
|
/** play the sound */
|
||||||
|
void play();
|
||||||
|
/** stop the sound */
|
||||||
|
void stop();
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \param dataSize the Size of the filedata
|
||||||
|
u32 dataSize;
|
||||||
|
ndspWaveBuf waveBuf;
|
||||||
|
u8 *data = NULL;
|
||||||
|
int chnl;
|
||||||
|
};
|
40
include/renderd7/stringtool.hpp
Normal file
40
include/renderd7/stringtool.hpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
inline bool NameIsEndingWith(const std::string &name,
|
||||||
|
const std::vector<std::string> &extensions) {
|
||||||
|
if (name.substr(0, 2) == "._")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (name.size() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (extensions.size() == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
for (int i = 0; i < (int)extensions.size(); i++) {
|
||||||
|
const std::string ext = extensions.at(i);
|
||||||
|
if (strcasecmp(name.c_str() + name.size() - ext.size(), ext.c_str()) == 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} // namespace RenderD7
|
||||||
|
template <class T> T GetFileName(T const &path, T const &delims = "/\\") {
|
||||||
|
return path.substr(path.find_last_of(delims) + 1);
|
||||||
|
}
|
||||||
|
template <class T> T remove_ext(T const &filename) {
|
||||||
|
typename T::size_type const p(filename.find_last_of('.'));
|
||||||
|
return p > 0 && p != T::npos ? filename.substr(0, p) : filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> std::string Int_To_Hex(T i) {
|
||||||
|
std::stringstream stream;
|
||||||
|
stream << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex
|
||||||
|
<< i;
|
||||||
|
return stream.str();
|
||||||
|
}
|
136
include/renderd7/thread.hpp
Normal file
136
include/renderd7/thread.hpp
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <3ds.h>
|
||||||
|
#include <atomic>
|
||||||
|
#include <functional>
|
||||||
|
#include <renderd7/parameter.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using CTRU_Thread = Thread;
|
||||||
|
|
||||||
|
#define THREAD_STACK_SIZE 0x1000
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
namespace Threads {
|
||||||
|
inline bool threadrunning = false;
|
||||||
|
|
||||||
|
struct Thread {
|
||||||
|
Handle handle;
|
||||||
|
void (*ep)(void);
|
||||||
|
bool finished;
|
||||||
|
void *stacktop;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool Create();
|
||||||
|
bool Join();
|
||||||
|
void Exit();
|
||||||
|
} // namespace Threads
|
||||||
|
class Thread {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Default constructor
|
||||||
|
* @note This should only be called when calling m3d::Thread::initialize()
|
||||||
|
* before calling m3d::Thread::start()
|
||||||
|
*/
|
||||||
|
Thread();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs the thread
|
||||||
|
* @param t_function The thread function
|
||||||
|
* @param t_parameter The parameter to pass to the function
|
||||||
|
* @param t_autostart Whether the thread should start instantly
|
||||||
|
* @param t_detached Whether the thread starts detached or not
|
||||||
|
* @param t_stackSize The stacksize allocated for the thread in bytes (rounded
|
||||||
|
* to multiples of 8 bytes)
|
||||||
|
* @note t_function needs to be of type `void` and take one (and only one)
|
||||||
|
* parameter of type m3d::Parameter
|
||||||
|
* @warning If the thread priority is lower than the priority of the calling
|
||||||
|
* thread, the thread will never get executed. Use
|
||||||
|
* m3d::Thread::getCurrentPriority() to get the priority of the current thread
|
||||||
|
*/
|
||||||
|
Thread(std::function<void(RenderD7::Parameter)> t_function,
|
||||||
|
RenderD7::Parameter t_parameter = nullptr, bool t_autostart = false,
|
||||||
|
bool t_detached = false,
|
||||||
|
unsigned long long int t_stackSize = 4 * 1024);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destructs the thread
|
||||||
|
*/
|
||||||
|
virtual ~Thread();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initializes the thread
|
||||||
|
* @param t_function The thread function
|
||||||
|
* @param t_parameter The parameter to pass to the function
|
||||||
|
* @param t_autostart Whether the thread should start instantly
|
||||||
|
* @param t_detached Whether the thread starts detached or not
|
||||||
|
* @param t_stackSize The stacksize allocated for the thread in bytes (rounded
|
||||||
|
* to multiples of 8 bytes)
|
||||||
|
* @note t_function needs to be of type `void` and take one (and only one)
|
||||||
|
* parameter of type m3d::Parameter
|
||||||
|
* @warning If the thread priority is lower than the priority of the calling
|
||||||
|
* thread, the thread will never get executed. Use
|
||||||
|
* m3d::Thread::getCurrentPriority() to get the priority of the current thread
|
||||||
|
*/
|
||||||
|
void initialize(std::function<void(RenderD7::Parameter)> t_function,
|
||||||
|
RenderD7::Parameter t_parameter = nullptr,
|
||||||
|
bool t_autostart = false, bool t_detached = false,
|
||||||
|
unsigned long long int t_stackSize = 4 * 1024);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the size of the stack that gets allocated for the next thread
|
||||||
|
* that get's started
|
||||||
|
* @param t_stackSize The allocated space in bytes (rounded to multiples of 8
|
||||||
|
* bytes)
|
||||||
|
*/
|
||||||
|
void setStackSize(unsigned long long int t_stackSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Starts the thread. To restart it, call Thread::join() before
|
||||||
|
* @param t_detached Whether the thread should start detached or not
|
||||||
|
*/
|
||||||
|
void start(bool t_detached = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Detaches the thread
|
||||||
|
*/
|
||||||
|
void kill();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Waits for the thread to finish
|
||||||
|
* @param t_timeout The timeout in nanoseconds. Leave it for no timeout
|
||||||
|
*/
|
||||||
|
void join(long long unsigned int t_timeout = U64_MAX);
|
||||||
|
|
||||||
|
bool isRunning();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Puts the thread to sleep
|
||||||
|
*
|
||||||
|
* This is needed if you have multiple threads running at the same time. It
|
||||||
|
* doesn't affect the execution-time of the thread, it just makes it possible
|
||||||
|
* for the other threads to get their chance to shine.
|
||||||
|
*/
|
||||||
|
static void sleep();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sleeps for the given time
|
||||||
|
* @param t_milliseconds The time to sleep in milliseconds
|
||||||
|
*/
|
||||||
|
static void sleep(int t_milliseconds);
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct ThreadData {
|
||||||
|
RenderD7::Parameter m_parameter;
|
||||||
|
std::function<void(RenderD7::Parameter)> m_function;
|
||||||
|
std::atomic<bool> *m_running;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void threadFunction(void *t_arg);
|
||||||
|
/* data */
|
||||||
|
int m_priority, m_stackSize;
|
||||||
|
bool m_started;
|
||||||
|
std::atomic<bool> m_running;
|
||||||
|
RenderD7::Thread::ThreadData m_data;
|
||||||
|
CTRU_Thread m_thread;
|
||||||
|
};
|
||||||
|
} // namespace RenderD7
|
18
include/renderd7/tween.hpp
Normal file
18
include/renderd7/tween.hpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include <renderd7/Clock.hpp>
|
||||||
|
|
||||||
|
namespace rnd7 {
|
||||||
|
enum class TweenType : int { Position = 1, Color, Alpha };
|
||||||
|
|
||||||
|
enum class TweenLoop : int {
|
||||||
|
None = 1,
|
||||||
|
Loop = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class TweenDirection : int { Current, Forward, Backward };
|
||||||
|
|
||||||
|
enum class TweenState : int { Playing = 1, Stopped };
|
||||||
|
class Tween {
|
||||||
|
public:
|
||||||
|
Tween(float from, float to, float duration, TweenLoop loop, TweenState state);
|
||||||
|
};
|
||||||
|
} // namespace rnd7
|
59
log.cpp
59
log.cpp
@ -1,59 +0,0 @@
|
|||||||
#include "log.hpp"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
std::string Log::format(const std::string& fmt_str, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
char* fp = NULL;
|
|
||||||
va_start(ap, fmt_str);
|
|
||||||
vasprintf(&fp, fmt_str.c_str(), ap);
|
|
||||||
va_end(ap);
|
|
||||||
std::unique_ptr<char, decltype(free)*> formatted(fp, free);
|
|
||||||
return std::string(formatted.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Log::logDate(void)
|
|
||||||
{
|
|
||||||
time_t unixTime;
|
|
||||||
struct tm timeStruct;
|
|
||||||
time(&unixTime);
|
|
||||||
localtime_r(&unixTime, &timeStruct);
|
|
||||||
return format("%04i-%02i-%02i %02i:%02i:%02i", timeStruct.tm_year + 1900, timeStruct.tm_mon + 1, timeStruct.tm_mday,
|
|
||||||
timeStruct.tm_hour, timeStruct.tm_min, timeStruct.tm_sec);
|
|
||||||
}
|
|
||||||
|
|
||||||
Log::Log()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Log::Init(const char *filename)
|
|
||||||
{
|
|
||||||
this->filename = filename;
|
|
||||||
if ((access(filename, F_OK) == 0))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FILE* logfile = fopen((filename), "w");
|
|
||||||
fclose(logfile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Log::Write(std::string debug_text)
|
|
||||||
{
|
|
||||||
std::ofstream logFile;
|
|
||||||
logFile.open((this->filename), std::ofstream::app);
|
|
||||||
std::string writeDebug = "[";
|
|
||||||
writeDebug += logDate();
|
|
||||||
writeDebug += "] ";
|
|
||||||
writeDebug += debug_text.c_str();
|
|
||||||
logFile << writeDebug << std::endl;
|
|
||||||
logFile.close();
|
|
||||||
}
|
|
||||||
Log::~Log()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
19
log.hpp
19
log.hpp
@ -1,19 +0,0 @@
|
|||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string>
|
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
class Log
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Log();
|
|
||||||
~Log();
|
|
||||||
void Init(const char *filename);
|
|
||||||
void Write(std::string debug_text);
|
|
||||||
std::string logDate(void);
|
|
||||||
std::string format(const std::string& fmt_str, ...);
|
|
||||||
private:
|
|
||||||
std::string filename;
|
|
||||||
};
|
|
566
renderd7.cpp
566
renderd7.cpp
@ -1,566 +0,0 @@
|
|||||||
#include "renderd7.hpp"
|
|
||||||
#include "log.hpp"
|
|
||||||
#include <regex>
|
|
||||||
|
|
||||||
#define RGBA8(r, g, b, a) ((((r) & 0xFF) << 0) | (((g) & 0xFF) << 8) | (((b) & 0xFF) << 16) | (((a) & 0xFF) << 24))
|
|
||||||
#define D7_NOTHING C2D_Color32(0, 0, 0, 0)
|
|
||||||
Log renderd7log;
|
|
||||||
float animtime;
|
|
||||||
bool isndspinit = false;
|
|
||||||
bool running = true;
|
|
||||||
std::stack<std::unique_ptr<RenderD7::Scene>> RenderD7::Scene::scenes;
|
|
||||||
|
|
||||||
u32 d7_hDown;
|
|
||||||
u32 d7_hHeld;
|
|
||||||
u32 d7_hUp;
|
|
||||||
touchPosition d7_touch;
|
|
||||||
|
|
||||||
C2D_TextBuf TextBuf;
|
|
||||||
C2D_Font Font;
|
|
||||||
|
|
||||||
// Fps Calc
|
|
||||||
static float current_fps = 0.0f;
|
|
||||||
static unsigned int frames = 0;
|
|
||||||
static u64 last_time = 0;
|
|
||||||
float d11framerate = 0;
|
|
||||||
//-----------------
|
|
||||||
|
|
||||||
bool currentScreen = false;
|
|
||||||
|
|
||||||
C3D_RenderTarget* Top;
|
|
||||||
C3D_RenderTarget* TopRight;
|
|
||||||
C3D_RenderTarget* Bottom;
|
|
||||||
|
|
||||||
#define DSEVENBLACK C2D_Color32(0, 0 ,0, 255)
|
|
||||||
#define DSEVENWHITE C2D_Color32(255, 255, 255, 255)
|
|
||||||
RenderD7::SpriteSheetAnimation::SpriteSheetAnimation()
|
|
||||||
{
|
|
||||||
renderd7log.Write("SpriteSheetAnimation createt!");
|
|
||||||
}
|
|
||||||
RenderD7::SpriteSheetAnimation::~SpriteSheetAnimation()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
bool RenderD7::DrawImageFromSheet(RenderD7::Sheet* sheet, size_t index, float x, float y, float scaleX, float scaleY)
|
|
||||||
{
|
|
||||||
if (sheet->spritesheet != nullptr)
|
|
||||||
{
|
|
||||||
if (C2D_SpriteSheetCount(sheet->spritesheet) >= index)
|
|
||||||
{
|
|
||||||
return C2D_DrawImageAt(C2D_SpriteSheetGetImage(sheet->spritesheet, index), x, y, 0.5f, nullptr, scaleX, scaleY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void RenderD7::Init::NdspFirm(bool useit)
|
|
||||||
{
|
|
||||||
if (useit)
|
|
||||||
{
|
|
||||||
if ( access( "sdmc:/3ds/dspfirm.cdc", F_OK ) != -1 )
|
|
||||||
{
|
|
||||||
ndspInit();
|
|
||||||
isndspinit = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
renderd7log.Write("RenderD7: SoundEngine Error! ndspfirm not found!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void RenderD7::Exit::NdspFirm()
|
|
||||||
{
|
|
||||||
if (isndspinit)
|
|
||||||
{
|
|
||||||
ndspExit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void RenderD7::Msg::Display(std::string titletxt, std::string txt, C3D_RenderTarget *target)
|
|
||||||
{
|
|
||||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
|
||||||
C2D_TargetClear(Top, DSEVENBLACK);
|
|
||||||
C2D_TargetClear(Bottom, DSEVENBLACK);
|
|
||||||
RenderD7::ClearTextBufs();
|
|
||||||
RenderD7::OnScreen(Top);
|
|
||||||
RenderD7::DrawRect(0, 0, 400, 240, RenderD7::Color::Hex("#111111"));
|
|
||||||
RenderD7::OnScreen(Bottom);
|
|
||||||
RenderD7::DrawRect(0, 0, 320, 240, RenderD7::Color::Hex("#111111"));
|
|
||||||
RenderD7::OnScreen(target);
|
|
||||||
RenderD7::DrawRect(0, 0, 400, 26, RenderD7::Color::Hex("#333333", 200));
|
|
||||||
RenderD7::DrawText(5, 2, 0.7f, DSEVENWHITE, titletxt);
|
|
||||||
RenderD7::DrawText(5, 30, 0.6f, DSEVENWHITE, txt);
|
|
||||||
|
|
||||||
C3D_FrameEnd(0);
|
|
||||||
}
|
|
||||||
void RenderD7::SetupLog()
|
|
||||||
{
|
|
||||||
renderd7log.Init("sdmc:/Flappy-Bird-RenderD7.log");
|
|
||||||
}
|
|
||||||
void RenderD7::SpriteSheetAnimation::Setup(RenderD7::Sheet *sheet, size_t imagecount, size_t startimage, float frame_begin, float frame_finish)
|
|
||||||
{
|
|
||||||
|
|
||||||
D_totaltime = frame_begin;
|
|
||||||
renderd7log.Write("frame_begin success");
|
|
||||||
this->images = imagecount;
|
|
||||||
renderd7log.Write("imagecount success");
|
|
||||||
this->sheet = sheet;
|
|
||||||
renderd7log.Write("sheet success");
|
|
||||||
this->time = frame_finish;
|
|
||||||
renderd7log.Write("frame_finish success");
|
|
||||||
RenderD7::SpriteSheetAnimation::FromSheet(this->sheet, startimage);
|
|
||||||
}
|
|
||||||
void RenderD7::SpriteSheetAnimation::Play(float timespeed)
|
|
||||||
{
|
|
||||||
D_totaltime += timespeed;
|
|
||||||
if (D_totaltime >= time)
|
|
||||||
{
|
|
||||||
D_totaltime -= time;
|
|
||||||
imgs++;
|
|
||||||
if (imgs == images)
|
|
||||||
{
|
|
||||||
imgs = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RenderD7::SpriteSheetAnimation::FromSheet(sheet, imgs);
|
|
||||||
//RenderD7::SpriteSheetAnimation::Draw();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderD7::Error::DisplayError(std::string toptext, std::string errortext)
|
|
||||||
{
|
|
||||||
RenderD7::ClearTextBufs();
|
|
||||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
|
||||||
C2D_TargetClear(Top, DSEVENBLACK);
|
|
||||||
C2D_TargetClear(Bottom, DSEVENBLACK);
|
|
||||||
RenderD7::DrawTextCentered(0, 0, 0.7f, DSEVENWHITE, toptext, 400);
|
|
||||||
RenderD7::DrawTextCentered(0, 100, 0.6f, DSEVENWHITE, errortext, 400);
|
|
||||||
C3D_FrameEnd(0);
|
|
||||||
for (int i = 0; i < 60*20; i++) {
|
|
||||||
gspWaitForVBlank();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
u32 RenderD7::Color::Hex(const std::string color, u8 a)
|
|
||||||
{
|
|
||||||
if (color.length() < 7 || std::regex_search(color.substr(1), std::regex("[^0-9A-Fa-f]"))) { // invalid color.
|
|
||||||
return D7_NOTHING;
|
|
||||||
}
|
|
||||||
int r = std::stoi(color.substr(1, 2), nullptr, 16);
|
|
||||||
int g = std::stoi(color.substr(3, 2), nullptr, 16);
|
|
||||||
int b = std::stoi(color.substr(5, 2), nullptr, 16);
|
|
||||||
return RGBA8(r, g, b, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderD7::Scene::doDraw() {
|
|
||||||
if(!RenderD7::Scene::scenes.empty())
|
|
||||||
RenderD7::Scene::scenes.top()->Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderD7::Scene::doLogic(u32 hDown, u32 hHeld, u32 hUp, touchPosition touch) {
|
|
||||||
if(!RenderD7::Scene::scenes.empty())
|
|
||||||
RenderD7::Scene::scenes.top()->Logic(hDown, hHeld, hUp, touch);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderD7::Scene::Load(std::unique_ptr<Scene> scene)
|
|
||||||
{
|
|
||||||
Scene::scenes.push(std::move(scene));
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderD7::Scene::Back() {
|
|
||||||
if(RenderD7::Scene::scenes.size() > 0)
|
|
||||||
RenderD7::Scene::scenes.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderD7::OnScreen(C3D_RenderTarget *target)
|
|
||||||
{
|
|
||||||
C2D_SceneBegin(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderD7::MainLoop()
|
|
||||||
{
|
|
||||||
if (!aptMainLoop()) return false;
|
|
||||||
hidScanInput();
|
|
||||||
d7_hDown = hidKeysDown();
|
|
||||||
d7_hUp = hidKeysUp();
|
|
||||||
d7_hHeld = hidKeysHeld();
|
|
||||||
hidTouchRead(&d7_touch);
|
|
||||||
|
|
||||||
RenderD7::ClearTextBufs();
|
|
||||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
|
||||||
C2D_TargetClear(Top, C2D_Color32(0, 0, 0, 0));
|
|
||||||
C2D_TargetClear(Bottom, C2D_Color32(0, 0, 0, 0));
|
|
||||||
|
|
||||||
return running;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
RenderD7::Sheet::Sheet()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
RenderD7::Sheet::~Sheet()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Result RenderD7::Sheet::Load(const char *path)
|
|
||||||
{
|
|
||||||
this->spritesheet = C2D_SpriteSheetLoad(path);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderD7::Sheet::Free()
|
|
||||||
{
|
|
||||||
C2D_SpriteSheetFree(this->spritesheet);
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderD7::Sprite::Sprite()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
RenderD7::Sprite::~Sprite()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
void RenderD7::Sprite::FromSheet(RenderD7::Sheet *sheet, size_t index)
|
|
||||||
{
|
|
||||||
C2D_SpriteFromSheet(&this->sprite, sheet->spritesheet, index);
|
|
||||||
}
|
|
||||||
bool RenderD7::Sprite::Draw()
|
|
||||||
{
|
|
||||||
return C2D_DrawSprite(&this->sprite);
|
|
||||||
}
|
|
||||||
void RenderD7::Sprite::SetCenter(float x, float y)
|
|
||||||
{
|
|
||||||
C2D_SpriteSetCenter(&this->sprite, x, y);
|
|
||||||
}
|
|
||||||
void RenderD7::Sprite::SetPos(float x, float y)
|
|
||||||
{
|
|
||||||
C2D_SpriteSetPos(&this->sprite, x, y);
|
|
||||||
}
|
|
||||||
void RenderD7::Sprite::SetRotation(float rotation)
|
|
||||||
{
|
|
||||||
C2D_SpriteSetRotation(&this->sprite, rotation);
|
|
||||||
}
|
|
||||||
void RenderD7::Sprite::Rotate(float speed)
|
|
||||||
{
|
|
||||||
C2D_SpriteRotateDegrees(&this->sprite, speed);
|
|
||||||
}
|
|
||||||
float RenderD7::Sprite::getHeigh()
|
|
||||||
{
|
|
||||||
return this->sprite.params.pos.h;
|
|
||||||
}
|
|
||||||
float RenderD7::Sprite::getWidth()
|
|
||||||
{
|
|
||||||
return this->sprite.params.pos.w;
|
|
||||||
}
|
|
||||||
float RenderD7::Sprite::getPosX()
|
|
||||||
{
|
|
||||||
return this->sprite.params.pos.x;
|
|
||||||
}
|
|
||||||
float RenderD7::Sprite::getPosY()
|
|
||||||
{
|
|
||||||
return this->sprite.params.pos.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderD7::ClearTextBufs(void)
|
|
||||||
{
|
|
||||||
C2D_TextBufClear(TextBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
void frameloop()
|
|
||||||
{
|
|
||||||
frames++;
|
|
||||||
u64 delta_time = osGetTime() - last_time;
|
|
||||||
if (delta_time >= 1000) {
|
|
||||||
current_fps = frames/(delta_time/1000.0f)+1;
|
|
||||||
frames = 0;
|
|
||||||
last_time = osGetTime();
|
|
||||||
}
|
|
||||||
d11framerate = current_fps;
|
|
||||||
}
|
|
||||||
float getframerate()
|
|
||||||
{
|
|
||||||
frameloop();
|
|
||||||
return d11framerate;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderD7::DrawRect(float x, float y, float w, float h, u32 color)
|
|
||||||
{
|
|
||||||
return C2D_DrawRectSolid(x, y, 0.5f, w, h, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderD7::DrawTextCentered(float x, float y, float size, u32 color, std::string Text, int maxWidth, int maxHeight, C2D_Font fnt) {
|
|
||||||
float lineHeight, widthScale;
|
|
||||||
|
|
||||||
// Check for the lineHeight.
|
|
||||||
if (fnt != nullptr) {
|
|
||||||
lineHeight = RenderD7::GetTextHeight(size, " ", fnt);
|
|
||||||
} else {
|
|
||||||
lineHeight = RenderD7::GetTextHeight(size, " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
int line = 0;
|
|
||||||
while(Text.find('\n') != Text.npos) {
|
|
||||||
if (maxWidth == 0) {
|
|
||||||
// Do the widthScale.
|
|
||||||
if (fnt != nullptr) {
|
|
||||||
widthScale = RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n')), fnt);
|
|
||||||
} else {
|
|
||||||
widthScale = RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n')));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Do the widthScale 2.
|
|
||||||
if (fnt != nullptr) {
|
|
||||||
widthScale = std::min((float)maxWidth, RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n')), fnt));
|
|
||||||
} else {
|
|
||||||
widthScale = std::min((float)maxWidth, RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n'))));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fnt != nullptr) {
|
|
||||||
RenderD7::DrawText((currentScreen ? 200 : 160)+x-(widthScale/2), y+(lineHeight*line), size, color, Text.substr(0, Text.find('\n')), maxWidth, maxHeight, fnt);
|
|
||||||
} else {
|
|
||||||
RenderD7::DrawText((currentScreen ? 200 : 160)+x-(widthScale/2), y+(lineHeight*line), size, color, Text.substr(0, Text.find('\n')), maxWidth, maxHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
Text = Text.substr(Text.find('\n')+1);
|
|
||||||
line++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (maxWidth == 0) {
|
|
||||||
// Do the next WidthScale.
|
|
||||||
if (fnt != nullptr) {
|
|
||||||
widthScale = RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n')), fnt);
|
|
||||||
} else {
|
|
||||||
widthScale = RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n')));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// And again.
|
|
||||||
if (fnt != nullptr) {
|
|
||||||
widthScale = std::min((float)maxWidth, RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n')), fnt));
|
|
||||||
} else {
|
|
||||||
widthScale = std::min((float)maxWidth, RenderD7::GetTextWidth(size, Text.substr(0, Text.find('\n'))));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (fnt != nullptr) {
|
|
||||||
RenderD7::DrawText((currentScreen ? 200 : 160)+x-(widthScale/2), y+(lineHeight*line), size, color, Text.substr(0, Text.find('\n')), maxWidth, maxHeight, fnt);
|
|
||||||
} else {
|
|
||||||
RenderD7::DrawText((currentScreen ? 200 : 160)+x-(widthScale/2), y+(lineHeight*line), size, color, Text.substr(0, Text.find('\n')), maxWidth, maxHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw String or Text.
|
|
||||||
void RenderD7::DrawText(float x, float y, float size, u32 color, std::string Text, int maxWidth, int maxHeight, C2D_Font fnt) {
|
|
||||||
C2D_Text c2d_text;
|
|
||||||
|
|
||||||
if (fnt != nullptr) {
|
|
||||||
C2D_TextFontParse(&c2d_text, fnt, TextBuf, Text.c_str());
|
|
||||||
} else {
|
|
||||||
C2D_TextFontParse(&c2d_text, Font, TextBuf, Text.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
C2D_TextOptimize(&c2d_text);
|
|
||||||
|
|
||||||
float heightScale;
|
|
||||||
if (maxHeight == 0) {
|
|
||||||
heightScale = size;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if (fnt != nullptr) {
|
|
||||||
heightScale = std::min(size, size*(maxHeight/RenderD7::GetTextHeight(size, Text, fnt)));
|
|
||||||
} else {
|
|
||||||
heightScale = std::min(size, size*(maxHeight/RenderD7::GetTextHeight(size, Text)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (maxWidth == 0) {
|
|
||||||
C2D_DrawText(&c2d_text, C2D_WithColor, x, y, 0.5f, size, heightScale, color);
|
|
||||||
} else {
|
|
||||||
if (fnt != nullptr) {
|
|
||||||
C2D_DrawText(&c2d_text, C2D_WithColor, x, y, 0.5f, std::min(size, size*(maxWidth/RenderD7::GetTextWidth(size, Text, fnt))), heightScale, color);
|
|
||||||
} else {
|
|
||||||
C2D_DrawText(&c2d_text, C2D_WithColor, x, y, 0.5f, std::min(size, size*(maxWidth/RenderD7::GetTextWidth(size, Text))), heightScale, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get String or Text Width.
|
|
||||||
float RenderD7::GetTextWidth(float size, std::string Text, C2D_Font fnt) {
|
|
||||||
float width = 0;
|
|
||||||
if (fnt != nullptr) {
|
|
||||||
GetTextSize(size, &width, NULL, Text, fnt);
|
|
||||||
} else {
|
|
||||||
GetTextSize(size, &width, NULL, Text);
|
|
||||||
}
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get String or Text Size.
|
|
||||||
void RenderD7::GetTextSize(float size, float *width, float *height, std::string Text, C2D_Font fnt) {
|
|
||||||
C2D_Text c2d_text;
|
|
||||||
if (fnt != nullptr) {
|
|
||||||
C2D_TextFontParse(&c2d_text, fnt, TextBuf, Text.c_str());
|
|
||||||
} else {
|
|
||||||
C2D_TextFontParse(&c2d_text, Font, TextBuf, Text.c_str());
|
|
||||||
}
|
|
||||||
C2D_TextGetDimensions(&c2d_text, size, size, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Get String or Text Height.
|
|
||||||
float RenderD7::GetTextHeight(float size, std::string Text, C2D_Font fnt) {
|
|
||||||
float height = 0;
|
|
||||||
if (fnt != nullptr) {
|
|
||||||
GetTextSize(size, NULL, &height, Text.c_str(), fnt);
|
|
||||||
} else {
|
|
||||||
GetTextSize(size, NULL, &height, Text.c_str());
|
|
||||||
}
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result RenderD7::loadFont(C2D_Font &fnt, const char* Path) {
|
|
||||||
fnt = C2D_FontLoad(Path); // Only load if found.
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unload a Font.
|
|
||||||
Result RenderD7::unloadFont(C2D_Font &fnt) {
|
|
||||||
if (fnt != nullptr) {
|
|
||||||
C2D_FontFree(fnt); // Make sure to only unload if not nullptr.
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderD7::DrawCircle(float x, float y, float radius, u32 color)
|
|
||||||
{
|
|
||||||
return C2D_DrawCircleSolid(x, y, 0.5f, radius, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result RenderD7::Init::Main()
|
|
||||||
{
|
|
||||||
gfxInitDefault();
|
|
||||||
aptInit();
|
|
||||||
romfsInit();
|
|
||||||
cfguInit();
|
|
||||||
osSetSpeedupEnable(true);
|
|
||||||
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
|
|
||||||
C2D_Init(C2D_DEFAULT_MAX_OBJECTS);
|
|
||||||
C2D_Prepare();
|
|
||||||
Top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
|
|
||||||
TopRight = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT);
|
|
||||||
Bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
|
|
||||||
TextBuf = C2D_TextBufNew(4096);
|
|
||||||
Font = C2D_FontLoadSystem(CFG_REGION_USA);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
void RenderD7::Exit::Main()
|
|
||||||
{
|
|
||||||
C2D_TextBufDelete(TextBuf);
|
|
||||||
C2D_Fini();
|
|
||||||
C3D_Fini();
|
|
||||||
aptExit();
|
|
||||||
romfsExit();
|
|
||||||
cfguExit();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string RenderD7::GetFramerate()
|
|
||||||
{
|
|
||||||
frameloop();
|
|
||||||
return (std::to_string(d11framerate).substr(0, 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderD7::DrawTObjects(std::vector<RenderD7::TObject> tobjects, u32 color, u32 txtcolor, int selection, u32 selbgcolor, u32 selcolor)
|
|
||||||
{
|
|
||||||
for(int i = 0; i < (int)tobjects.size(); i++)
|
|
||||||
{
|
|
||||||
if (selection == i)
|
|
||||||
{
|
|
||||||
RenderD7::DrawRect(tobjects[i].x - 2, tobjects[i].y - 2, tobjects[i].w + 4, tobjects[i].h + 4, selbgcolor);
|
|
||||||
RenderD7::DrawRect(tobjects[i].x, tobjects[i].y, tobjects[i].w, tobjects[i].h, color);
|
|
||||||
RenderD7::DrawRect(tobjects[i].x, tobjects[i].y, tobjects[i].w, tobjects[i].h, selcolor);
|
|
||||||
RenderD7::DrawText(tobjects[i].x + (tobjects[i].w/2) - RenderD7::GetTextHeight(tobjects[i].txtsize , tobjects[i].text) + tobjects[i].correctx, tobjects[i].y + (tobjects[i].h/2) - RenderD7::GetTextHeight(tobjects[i].txtsize, tobjects[i].text) + tobjects[i].correcty, tobjects[i].txtsize, txtcolor, tobjects[i].text);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RenderD7::DrawRect(tobjects[i].x, tobjects[i].y - 1, tobjects[i].w, tobjects[i].h, color);
|
|
||||||
RenderD7::DrawText(tobjects[i].x + (tobjects[i].w/2) - RenderD7::GetTextHeight(tobjects[i].txtsize , tobjects[i].text) + tobjects[i].correctx, tobjects[i].y + (tobjects[i].h/2) - RenderD7::GetTextHeight(tobjects[i].txtsize, tobjects[i].text) + tobjects[i].correcty, tobjects[i].txtsize, txtcolor, tobjects[i].text);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void RenderD7::ExitApp()
|
|
||||||
{
|
|
||||||
running = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderD7::touchTObj(touchPosition touch, RenderD7::TObject button)
|
|
||||||
{
|
|
||||||
if (touch.px >= button.x && touch.px <= (button.x + button.w) && touch.py >= button.y && touch.py <= (button.y + button.h)) return true;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderD7::DrawSTObject(std::vector<RenderD7::TObject> tobject, int tobjectindex, u32 color, u32 txtcolor)
|
|
||||||
{
|
|
||||||
RenderD7::DrawRect(tobject[tobjectindex].x, tobject[tobjectindex].y, tobject[tobjectindex].w, tobject[tobjectindex].h, color);
|
|
||||||
RenderD7::DrawText(tobject[tobjectindex].x + (tobject[tobjectindex].w/2) - RenderD7::GetTextHeight(tobject[tobjectindex].txtsize , tobject[tobjectindex].text) + tobject[tobjectindex].correctx, tobject[tobjectindex].y + (tobject[tobjectindex].h/2) - RenderD7::GetTextHeight(tobject[tobjectindex].txtsize, tobject[tobjectindex].text) + tobject[tobjectindex].correcty, tobject[tobjectindex].txtsize, txtcolor, tobject[tobjectindex].text);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderD7::NameIsEndingWith(const std::string &name, const std::vector<std::string> &extensions) {
|
|
||||||
if (name.substr(0, 2) == "._") return false;
|
|
||||||
|
|
||||||
if (name.size() == 0) return false;
|
|
||||||
|
|
||||||
if (extensions.size() == 0) return true;
|
|
||||||
|
|
||||||
for(int i = 0; i < (int)extensions.size(); i++) {
|
|
||||||
const std::string ext = extensions.at(i);
|
|
||||||
if (strcasecmp(name.c_str() + name.size() - ext.size(), ext.c_str()) == 0) return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool dirEntryPredicate(const RenderD7::DirContent &lhs, const RenderD7::DirContent &rhs) {
|
|
||||||
if (!lhs.isDir && rhs.isDir) return false;
|
|
||||||
if (lhs.isDir && !rhs.isDir) return true;
|
|
||||||
|
|
||||||
return strcasecmp(lhs.name.c_str(), rhs.name.c_str()) < 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderD7::GetDirContentsExt(std::vector<RenderD7::DirContent> &dircontent, const std::vector<std::string> &extensions) {
|
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
dircontent.clear();
|
|
||||||
|
|
||||||
DIR *pdir = opendir(".");
|
|
||||||
|
|
||||||
if (pdir != nullptr) {
|
|
||||||
while(true) {
|
|
||||||
RenderD7::DirContent dirEntry;
|
|
||||||
|
|
||||||
struct dirent *pent = readdir(pdir);
|
|
||||||
if (pent == NULL) break;
|
|
||||||
|
|
||||||
stat(pent->d_name, &st);
|
|
||||||
dirEntry.name = pent->d_name;
|
|
||||||
dirEntry.isDir = (st.st_mode & S_IFDIR) ? true : false;
|
|
||||||
|
|
||||||
if (dirEntry.name.compare(".") != 0 && (dirEntry.isDir || RenderD7::NameIsEndingWith(dirEntry.name, extensions))) {
|
|
||||||
dircontent.push_back(dirEntry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir(pdir);
|
|
||||||
}
|
|
||||||
|
|
||||||
sort(dircontent.begin(), dircontent.end(), dirEntryPredicate);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderD7::GetDirContents(std::vector<RenderD7::DirContent> &dircontent) {
|
|
||||||
RenderD7::GetDirContentsExt(dircontent, {});
|
|
||||||
}
|
|
158
renderd7.hpp
158
renderd7.hpp
@ -1,158 +0,0 @@
|
|||||||
#include <3ds.h>
|
|
||||||
#include <citro2d.h>
|
|
||||||
#include <citro3d.h>
|
|
||||||
#include <memory>
|
|
||||||
#include <stack>
|
|
||||||
#include <string>
|
|
||||||
#include <functional>
|
|
||||||
#include <vector>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <cstring>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#define DEFAULT_CENTER 0.5f
|
|
||||||
|
|
||||||
extern C3D_RenderTarget* Top;
|
|
||||||
extern C3D_RenderTarget* TopRight;
|
|
||||||
extern C3D_RenderTarget* Bottom;
|
|
||||||
|
|
||||||
extern u32 d7_hDown;
|
|
||||||
extern u32 d7_hHeld;
|
|
||||||
extern u32 d7_hUp;
|
|
||||||
extern touchPosition d7_touch;
|
|
||||||
|
|
||||||
namespace RenderD7
|
|
||||||
{
|
|
||||||
void OnScreen(C3D_RenderTarget *target);
|
|
||||||
class Sheet
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Sheet();
|
|
||||||
~Sheet();
|
|
||||||
Result Load(const char *path);
|
|
||||||
void Free();
|
|
||||||
C2D_SpriteSheet spritesheet;
|
|
||||||
|
|
||||||
};
|
|
||||||
class Sprite
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Sprite();
|
|
||||||
~Sprite();
|
|
||||||
void FromSheet(RenderD7::Sheet *sheet, size_t index);
|
|
||||||
bool Draw();
|
|
||||||
void SetCenter(float x, float y);
|
|
||||||
void SetPos(float x, float y);
|
|
||||||
void SetRotation(float rotation);
|
|
||||||
void Rotate(float speed);
|
|
||||||
float getWidth();
|
|
||||||
float getHeigh();
|
|
||||||
float getPosX();
|
|
||||||
float getPosY();
|
|
||||||
private:
|
|
||||||
C2D_ImageTint tint;
|
|
||||||
C2D_Sprite sprite;
|
|
||||||
};
|
|
||||||
class Scene {
|
|
||||||
public:
|
|
||||||
static std::stack<std::unique_ptr<Scene>> scenes;
|
|
||||||
virtual ~Scene() {}
|
|
||||||
virtual void Logic(u32 hDown, u32 hHeld, u32 hUp, touchPosition touch) = 0;
|
|
||||||
virtual void Draw() const = 0;
|
|
||||||
static void Load(std::unique_ptr<Scene> scene);
|
|
||||||
static void Back();
|
|
||||||
static void doDraw();
|
|
||||||
static void doLogic(u32 hDown, u32 hHeld, u32 hUp, touchPosition touch);
|
|
||||||
|
|
||||||
};
|
|
||||||
namespace Color
|
|
||||||
{
|
|
||||||
u32 Hex(const std::string color, u8 a = 255);
|
|
||||||
}
|
|
||||||
bool DrawImageFromSheet(RenderD7::Sheet* sheet, size_t index, float x, float y, float scaleX = 1.0, float scaleY = 1.0);
|
|
||||||
namespace Error
|
|
||||||
{
|
|
||||||
void DisplayError(std::string toptext, std::string errortext);
|
|
||||||
void DisplayFatalError(std::string toptext, std::string errortext);
|
|
||||||
}
|
|
||||||
namespace Init
|
|
||||||
{
|
|
||||||
Result Main();
|
|
||||||
void NdspFirm(bool useit = false);
|
|
||||||
}
|
|
||||||
namespace Exit
|
|
||||||
{
|
|
||||||
void Main();
|
|
||||||
void NdspFirm();
|
|
||||||
}
|
|
||||||
namespace Msg
|
|
||||||
{
|
|
||||||
void Display(std::string titletxt, std::string, C3D_RenderTarget *target);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SetupLog(void);
|
|
||||||
std::string GetFramerate();
|
|
||||||
bool MainLoop();
|
|
||||||
void ExitApp();
|
|
||||||
|
|
||||||
void ClearTextBufs(void);
|
|
||||||
|
|
||||||
bool DrawRect(float x, float y, float w, float h, u32 color);
|
|
||||||
void DrawTextCentered(float x, float y, float size, u32 color, std::string Text, int maxWidth = 0, int maxHeight = 0, C2D_Font fnt = nullptr);
|
|
||||||
void DrawText(float x, float y, float size, u32 color, std::string Text, int maxWidth = 0, int maxHeight = 0, C2D_Font fnt = nullptr);
|
|
||||||
float GetTextWidth(float size, std::string Text, C2D_Font fnt = nullptr);
|
|
||||||
void GetTextSize(float size, float *width, float *height, std::string Text, C2D_Font fnt = nullptr);
|
|
||||||
float GetTextHeight(float size, std::string Text, C2D_Font fnt = nullptr);
|
|
||||||
Result loadFont(C2D_Font &fnt, const char * Path = "");
|
|
||||||
Result unloadFont(C2D_Font &fnt);
|
|
||||||
bool DrawCircle(float x, float y, float radius, u32 color);
|
|
||||||
|
|
||||||
|
|
||||||
class SpriteSheetAnimation : public RenderD7::Sprite
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
SpriteSheetAnimation();
|
|
||||||
~SpriteSheetAnimation();
|
|
||||||
void Setup(RenderD7::Sheet *sheet, size_t imagecount, size_t startimage, float frame_begin, float frame_finish);
|
|
||||||
void Play(float timespeed);
|
|
||||||
private:
|
|
||||||
size_t images;
|
|
||||||
size_t imgs = 0;
|
|
||||||
float D_totaltime;
|
|
||||||
RenderD7::Sheet *sheet;
|
|
||||||
float time;
|
|
||||||
|
|
||||||
};
|
|
||||||
struct TObject
|
|
||||||
{
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int w;
|
|
||||||
int h;
|
|
||||||
std::string text = "";
|
|
||||||
float correctx = 0;
|
|
||||||
float correcty = 0;
|
|
||||||
float txtsize = 0.7f;
|
|
||||||
|
|
||||||
};
|
|
||||||
void DrawTObjects(std::vector<RenderD7::TObject> tobjects, u32 color, u32 txtcolor, int selection = -1, u32 selbgcolor = RenderD7::Color::Hex("#2D98AF"), u32 selcolor = RenderD7::Color::Hex("#000000"));
|
|
||||||
void DrawSTObject(std::vector<RenderD7::TObject> tobject, int tobjectindex, u32 color, u32 txtcolor);
|
|
||||||
bool touchTObj(touchPosition touch, RenderD7::TObject button);
|
|
||||||
|
|
||||||
struct DirContent
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
std::string path;
|
|
||||||
bool isDir;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool NameIsEndingWith(const std::string &name, const std::vector<std::string> &extensions);
|
|
||||||
void GetDirContentsExt(std::vector<RenderD7::DirContent> &dircontent, const std::vector<std::string> &extensions);
|
|
||||||
void GetDirContents(std::vector<RenderD7::DirContent> &dircontent);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
125
sound.cpp
125
sound.cpp
@ -1,125 +0,0 @@
|
|||||||
#include "sound.hpp"
|
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstring>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
// Reference: http://yannesposito.com/Scratch/en/blog/2010-10-14-Fun-with-wav/
|
|
||||||
typedef struct _WavHeader {
|
|
||||||
char magic[4]; // "RIFF"
|
|
||||||
u32 totallength; // Total file length, minus 8.
|
|
||||||
char wavefmt[8]; // Should be "WAVEfmt "
|
|
||||||
u32 format; // 16 for PCM format
|
|
||||||
u16 pcm; // 1 for PCM format
|
|
||||||
u16 channels; // Channels
|
|
||||||
u32 frequency; // Sampling frequency
|
|
||||||
u32 bytes_per_second;
|
|
||||||
u16 bytes_by_capture;
|
|
||||||
u16 bits_per_sample;
|
|
||||||
char data[4]; // "data"
|
|
||||||
u32 bytes_in_data;
|
|
||||||
} WavHeader;
|
|
||||||
static_assert(sizeof(WavHeader) == 44, "WavHeader size is not 44 bytes.");
|
|
||||||
|
|
||||||
sound::sound(const string& path, int channel, bool toloop) {
|
|
||||||
ndspSetOutputMode(NDSP_OUTPUT_STEREO);
|
|
||||||
ndspSetOutputCount(2); // Num of buffers
|
|
||||||
|
|
||||||
// Reading wav file
|
|
||||||
FILE* fp = fopen(path.c_str(), "rb");
|
|
||||||
|
|
||||||
if (!fp) {
|
|
||||||
printf("Could not open the WAV file: %s\n", path.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
WavHeader wavHeader;
|
|
||||||
size_t read = fread(&wavHeader, 1, sizeof(wavHeader), fp);
|
|
||||||
if (read != sizeof(wavHeader)) {
|
|
||||||
// Short read.
|
|
||||||
printf("WAV file header is too short: %s\n", path.c_str());
|
|
||||||
fclose(fp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify the header.
|
|
||||||
static const char RIFF_magic[4] = {'R','I','F','F'};
|
|
||||||
if (memcmp(wavHeader.magic, RIFF_magic, sizeof(wavHeader.magic)) != 0) {
|
|
||||||
// Incorrect magic number.
|
|
||||||
printf("Wrong file format.\n");
|
|
||||||
fclose(fp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wavHeader.totallength == 0 ||
|
|
||||||
(wavHeader.channels != 1 && wavHeader.channels != 2) ||
|
|
||||||
(wavHeader.bits_per_sample != 8 && wavHeader.bits_per_sample != 16)) {
|
|
||||||
// Unsupported WAV file.
|
|
||||||
printf("Corrupted wav file.\n");
|
|
||||||
fclose(fp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the file size.
|
|
||||||
fseek(fp, 0, SEEK_END);
|
|
||||||
dataSize = ftell(fp) - sizeof(wavHeader);
|
|
||||||
|
|
||||||
// Allocating and reading samples
|
|
||||||
data = static_cast<u8*>(linearAlloc(dataSize));
|
|
||||||
fseek(fp, 44, SEEK_SET);
|
|
||||||
fread(data, 1, dataSize, fp);
|
|
||||||
fclose(fp);
|
|
||||||
dataSize /= 2; // FIXME: 16-bit or stereo?
|
|
||||||
|
|
||||||
// Find the right format
|
|
||||||
u16 ndspFormat;
|
|
||||||
if (wavHeader.bits_per_sample == 8) {
|
|
||||||
ndspFormat = (wavHeader.channels == 1) ?
|
|
||||||
NDSP_FORMAT_MONO_PCM8 :
|
|
||||||
NDSP_FORMAT_STEREO_PCM8;
|
|
||||||
} else {
|
|
||||||
ndspFormat = (wavHeader.channels == 1) ?
|
|
||||||
NDSP_FORMAT_MONO_PCM16 :
|
|
||||||
NDSP_FORMAT_STEREO_PCM16;
|
|
||||||
}
|
|
||||||
|
|
||||||
ndspChnReset(channel);
|
|
||||||
ndspChnSetInterp(channel, NDSP_INTERP_NONE);
|
|
||||||
ndspChnSetRate(channel, float(wavHeader.frequency));
|
|
||||||
ndspChnSetFormat(channel, ndspFormat);
|
|
||||||
|
|
||||||
// Create and play a wav buffer
|
|
||||||
memset(&waveBuf, 0, sizeof(waveBuf));
|
|
||||||
|
|
||||||
waveBuf.data_vaddr = reinterpret_cast<u32*>(data);
|
|
||||||
waveBuf.nsamples = dataSize / (wavHeader.bits_per_sample >> 3);
|
|
||||||
waveBuf.looping = toloop;
|
|
||||||
waveBuf.status = NDSP_WBUF_FREE;
|
|
||||||
chnl = channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
sound::~sound() {
|
|
||||||
waveBuf.data_vaddr = 0;
|
|
||||||
waveBuf.nsamples = 0;
|
|
||||||
waveBuf.looping = false;
|
|
||||||
waveBuf.status = 0;
|
|
||||||
ndspChnWaveBufClear(chnl);
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
linearFree(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sound::play() {
|
|
||||||
if (!data) return;
|
|
||||||
DSP_FlushDataCache(data, dataSize);
|
|
||||||
ndspChnWaveBufAdd(chnl, &waveBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sound::stop() {
|
|
||||||
if (!data) return;
|
|
||||||
ndspChnWaveBufClear(chnl);
|
|
||||||
}
|
|
21
sound.hpp
21
sound.hpp
@ -1,21 +0,0 @@
|
|||||||
#ifndef _UNIVERSAL_UPDATER_SOUND_H
|
|
||||||
#define _UNIVERSAL_UPDATER_SOUND_H
|
|
||||||
|
|
||||||
#include <3ds.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class sound {
|
|
||||||
public:
|
|
||||||
sound(const std::string& path, int channel = 1, bool toloop = false);
|
|
||||||
~sound();
|
|
||||||
void play();
|
|
||||||
void stop();
|
|
||||||
|
|
||||||
private:
|
|
||||||
u32 dataSize;
|
|
||||||
ndspWaveBuf waveBuf;
|
|
||||||
u8* data = NULL;
|
|
||||||
int chnl;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
475
source/BitmapPrinter.cpp
Normal file
475
source/BitmapPrinter.cpp
Normal file
@ -0,0 +1,475 @@
|
|||||||
|
#include <renderd7/BitmapPrinter.hpp>
|
||||||
|
#include <renderd7/Ovl.hpp>
|
||||||
|
#include <renderd7/Toast.hpp>
|
||||||
|
#include <renderd7/stringtool.hpp>
|
||||||
|
|
||||||
|
extern bool shouldbe_disabled;
|
||||||
|
extern std::string csvpc;
|
||||||
|
|
||||||
|
RenderD7::BitmapPrinter::BitmapPrinter(int w, int h) {
|
||||||
|
BMP newmap(w, h, true);
|
||||||
|
bitmap = newmap;
|
||||||
|
// renderframe.LoadPFromBuffer(BitmapConverter::ConvertData(bitmap.DATA()));
|
||||||
|
blank = newmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderD7::BitmapPrinter::~BitmapPrinter() {
|
||||||
|
if (this->renderframe.loadet)
|
||||||
|
this->renderframe.Unload();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RenderD7::BitmapPrinter::DecodeFile(std::string file) {
|
||||||
|
unsigned error = bitmap.read(file.c_str());
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
|
||||||
|
"BitmapPrinter", "Error Code: " + std::to_string(error)));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::BitmapPrinter::DrawPixel(int x, int y, u8 b, u8 g, u8 r, u8 a) {
|
||||||
|
unsigned error =
|
||||||
|
bitmap.set_pixel(x, bitmap.bmp_info_header.height - y, b, g, r, a);
|
||||||
|
if (error) {
|
||||||
|
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
|
||||||
|
"BitmapPrinter->Pixel", "Error Code: " + std::to_string(error)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void RenderD7::BitmapPrinter::DrawRect(int x, int y, int w, int h, u8 line_w,
|
||||||
|
u8 b, u8 g, u8 r, u8 a) {
|
||||||
|
unsigned error = bitmap.draw_rectangle(
|
||||||
|
x, bitmap.bmp_info_header.height - y - h, w, h, b, g, r, a, line_w);
|
||||||
|
if (error) {
|
||||||
|
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
|
||||||
|
"BitmapPrinter->Rect", "Error Code: " + std::to_string(error)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::BitmapPrinter::DrawRectFilled(int x, int y, int w, int h, u8 b,
|
||||||
|
u8 g, u8 r, u8 a) {
|
||||||
|
unsigned error = bitmap.fill_region(x, bitmap.bmp_info_header.height - h - y,
|
||||||
|
w, h, b, g, r, a);
|
||||||
|
if (error) {
|
||||||
|
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
|
||||||
|
"BitmapPrinter->RectF", "Error Code: " + std::to_string(error)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::BitmapPrinter::SaveBmp(std::string name) {
|
||||||
|
if (!RenderD7::NameIsEndingWith(name, {"bmp"})) {
|
||||||
|
name += ".bmp";
|
||||||
|
}
|
||||||
|
bitmap.write(name.c_str());
|
||||||
|
}
|
||||||
|
void RenderD7::BitmapPrinter::SavePng(std::string name) {
|
||||||
|
if (!RenderD7::NameIsEndingWith(name, {"png"})) {
|
||||||
|
name += ".png";
|
||||||
|
}
|
||||||
|
std::vector<unsigned char> ImageBuffer;
|
||||||
|
ImageBuffer = BitmapConverter::ConvertData(bitmap.DATA());
|
||||||
|
lodepng::save_file(ImageBuffer, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::BitmapPrinter::CreateScreen(C3D_RenderTarget *target) {
|
||||||
|
isscreen = true;
|
||||||
|
targetr = target;
|
||||||
|
if (target == Top) {
|
||||||
|
bitmap = BMP(400, 240, true);
|
||||||
|
blank = BMP(400, 240, true);
|
||||||
|
}
|
||||||
|
if (target == TopRight) {
|
||||||
|
bitmap = BMP(400, 240, true);
|
||||||
|
blank = BMP(400, 240, true);
|
||||||
|
}
|
||||||
|
if (target == Bottom) {
|
||||||
|
bitmap = BMP(320, 240, true);
|
||||||
|
blank = BMP(320, 240, true);
|
||||||
|
}
|
||||||
|
renderframe.LoadPFromBuffer(BitmapConverter::ConvertData(bitmap.DATA()));
|
||||||
|
}
|
||||||
|
bool RenderD7::BitmapPrinter::DrawScreenDirectF(int framerate) {
|
||||||
|
bool updtt = false;
|
||||||
|
if (isscreen) {
|
||||||
|
if (frame == (60 / framerate)) {
|
||||||
|
RenderD7::OnScreen(targetr);
|
||||||
|
if (renderframe.loadet)
|
||||||
|
renderframe.Unload();
|
||||||
|
this->Decode(decc);
|
||||||
|
frame = 0;
|
||||||
|
updtt = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (renderframe.loadet)
|
||||||
|
renderframe.Draw(0, 0);
|
||||||
|
frame++;
|
||||||
|
}
|
||||||
|
return updtt;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RenderD7::BitmapPrinter::DrawScreenDirect() {
|
||||||
|
bool updtt = false;
|
||||||
|
if (isscreen) {
|
||||||
|
RenderD7::OnScreen(targetr);
|
||||||
|
if (renderframe.loadet)
|
||||||
|
renderframe.Unload();
|
||||||
|
this->Decode(decc);
|
||||||
|
updtt = true;
|
||||||
|
if (renderframe.loadet)
|
||||||
|
renderframe.Draw(0, 0);
|
||||||
|
}
|
||||||
|
return updtt;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderD7::Image RenderD7::BitmapPrinter::GetImage() {
|
||||||
|
RenderD7::Image img;
|
||||||
|
img.LoadFromBitmap(bitmap);
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::BitmapPrinter::UsePreMap(BMP map) { bitmap = map; }
|
||||||
|
void RenderD7::BitmapPrinter::UsePrePrintMap(BitmapPrinter printmap) {
|
||||||
|
bitmap = printmap.GetBitmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::BitmapPrinter::Clear(u8 b, u8 g, u8 r, u8 a) {
|
||||||
|
bitmap.fill_region(0, 0, bitmap.bmp_info_header.width,
|
||||||
|
bitmap.bmp_info_header.height, b, g, r, a);
|
||||||
|
}
|
||||||
|
void RenderD7::BitmapPrinter::ClearBlank() { bitmap = blank; }
|
||||||
|
|
||||||
|
void RenderD7::BitmapPrinter::DrawScreenF(int framerate) {
|
||||||
|
if (isscreen) {
|
||||||
|
if (frame == (60 / framerate)) {
|
||||||
|
RenderD7::OnScreen(targetr);
|
||||||
|
frame = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (renderframe.loadet)
|
||||||
|
renderframe.Draw(0, 0);
|
||||||
|
frame++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void RenderD7::BitmapPrinter::DrawScreen() {
|
||||||
|
if (isscreen) {
|
||||||
|
RenderD7::OnScreen(targetr);
|
||||||
|
if (renderframe.loadet)
|
||||||
|
renderframe.Draw(0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool RenderD7::BitmapPrinter::UpdateScreenF(int framerate) {
|
||||||
|
bool updtt = false;
|
||||||
|
if (isscreen) {
|
||||||
|
if (frame == (60 / framerate)) {
|
||||||
|
if (renderframe.loadet)
|
||||||
|
renderframe.Unload();
|
||||||
|
// renderframe.LoadFromBitmap(bitmap);
|
||||||
|
this->Decode(decc);
|
||||||
|
frame = 0;
|
||||||
|
updtt = true;
|
||||||
|
}
|
||||||
|
frame++;
|
||||||
|
}
|
||||||
|
return updtt;
|
||||||
|
}
|
||||||
|
bool RenderD7::BitmapPrinter::UpdateScreen() {
|
||||||
|
bool updtt = false;
|
||||||
|
if (isscreen) {
|
||||||
|
if (renderframe.loadet)
|
||||||
|
renderframe.Unload();
|
||||||
|
this->Decode(decc);
|
||||||
|
updtt = true;
|
||||||
|
}
|
||||||
|
return updtt;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TICKS_PER_MSEC 268111.856
|
||||||
|
|
||||||
|
void RenderD7::BitmapPrinter::Benchmark() {
|
||||||
|
if (setupbenchmark) {
|
||||||
|
frametime = 0;
|
||||||
|
renderedframes = 0;
|
||||||
|
timer = 0;
|
||||||
|
setupbenchmark = false;
|
||||||
|
lastTime = svcGetSystemTick();
|
||||||
|
}
|
||||||
|
if (benchmark) {
|
||||||
|
if (timer >= 60) {
|
||||||
|
std::string renderedf = std::to_string(renderedframes);
|
||||||
|
std::string avgdtt = std::to_string(mhdtt);
|
||||||
|
float alldtt = 0;
|
||||||
|
for (size_t i = 1; i < hdttt.size(); i++) {
|
||||||
|
alldtt += hdttt[i];
|
||||||
|
}
|
||||||
|
float alldtt2 = 0;
|
||||||
|
for (size_t i = 0; i < hdttt2.size(); i++) {
|
||||||
|
alldtt2 += hdttt2[i];
|
||||||
|
}
|
||||||
|
float alldtt3 = 0;
|
||||||
|
for (size_t i = 0; i < hdttt3.size(); i++) {
|
||||||
|
alldtt3 += hdttt3[i];
|
||||||
|
}
|
||||||
|
int allfps = 0;
|
||||||
|
for (size_t f = 1; f < fpscountc.size(); f++) {
|
||||||
|
allfps += fpscountc[f];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string avgcpu = std::to_string((alldtt / (float)hdttt.size() - 1));
|
||||||
|
std::string avgcpu2 =
|
||||||
|
std::to_string(((alldtt2 / (float)hdttt2.size()) * 1000));
|
||||||
|
std::string avgcpu3 =
|
||||||
|
std::to_string(((alldtt3 / (float)hdttt3.size()) * 1000));
|
||||||
|
std::string avgfps = std::to_string((allfps / (int)fpscountc.size() - 1));
|
||||||
|
|
||||||
|
std::string resultt =
|
||||||
|
"TestMode: " + std::to_string(testfpsd) + "fps" +
|
||||||
|
"\nRendered Frames: " + renderedf + "\nMax Cpu Time: " + avgdtt +
|
||||||
|
"\nAvg Cpu Time: " + avgcpu + "\nAvg Fps: " + avgfps +
|
||||||
|
"\nAvg EncodeTime: " + avgcpu2 + "ms/f\nAvg DecodeTime: " + avgcpu3 +
|
||||||
|
"ms\n";
|
||||||
|
this->ClearBlank();
|
||||||
|
this->DrawRectFilled(0, 0, this->bitmap.bmp_info_header.width,
|
||||||
|
this->bitmap.bmp_info_header.height, 0, 0, 0, 255);
|
||||||
|
this->DrawDebugText(0, 0, 0, RenderD7::Color::Hex("#ffffff"), resultt);
|
||||||
|
std::string outname =
|
||||||
|
csvpc + "/benchmark_" + RenderD7::GetTimeStr() + ".png";
|
||||||
|
this->SavePng(outname);
|
||||||
|
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
|
||||||
|
"Benchmark", "Saved to: \n" + outname));
|
||||||
|
benchmark = false;
|
||||||
|
}
|
||||||
|
uint64_t currentTime = svcGetSystemTick();
|
||||||
|
dtt = ((float)(currentTime / (float)TICKS_PER_MSEC) -
|
||||||
|
(float)(lastTime / (float)TICKS_PER_MSEC)) /
|
||||||
|
1000.f;
|
||||||
|
lastTime = currentTime;
|
||||||
|
lastTime = currentTime;
|
||||||
|
frameCounter++;
|
||||||
|
fpsClock += dtt;
|
||||||
|
if (fpsClock >= 1.f) {
|
||||||
|
fps = frameCounter;
|
||||||
|
frameCounter = 0;
|
||||||
|
fpsClock = 0.f;
|
||||||
|
}
|
||||||
|
uint64_t lastTime2 = svcGetSystemTick();
|
||||||
|
this->ClearBlank();
|
||||||
|
this->DrawRectFilled(0, 0, this->bitmap.bmp_info_header.width,
|
||||||
|
this->bitmap.bmp_info_header.width, 255, 255, 255,
|
||||||
|
255);
|
||||||
|
this->DrawRect(5, 5, this->bitmap.bmp_info_header.width - 10,
|
||||||
|
this->bitmap.bmp_info_header.height - 10, 5, 0, 0, 0, 0);
|
||||||
|
// this->DrawDebugText(20, 20, 0, RenderD7::Color::Hex("#ffffff"), "Fps: " +
|
||||||
|
// std::to_string(fps));
|
||||||
|
this->DrawDebugText(0, 0, 0.5f, RenderD7::Color::Hex("#ff0000"),
|
||||||
|
"Time: " + std::to_string(timer));
|
||||||
|
this->DrawDebugText(0, 10, 0.5f, RenderD7::Color::Hex("#ff0000"),
|
||||||
|
"Fps: " + std::to_string(fps));
|
||||||
|
this->DrawDebugText(0, 20, 0.5f, RenderD7::Color::Hex("#ff0000"),
|
||||||
|
"dt: " + std::to_string(dtt));
|
||||||
|
this->DrawDebugText(0, 30, 0.5f, RenderD7::Color::Hex("#ff0000"),
|
||||||
|
"MaxEncodeTime: " + std::to_string(mdtt2 * 1000) +
|
||||||
|
"ms/f");
|
||||||
|
this->DrawDebugText(0, 40, 0.5f, RenderD7::Color::Hex("#ff0000"),
|
||||||
|
"MaxDecodeTime: " + std::to_string(mdtt3 * 1000) +
|
||||||
|
"ms");
|
||||||
|
uint64_t currentTime2 = svcGetSystemTick();
|
||||||
|
dtt2 = ((float)(currentTime2 / (float)TICKS_PER_MSEC) -
|
||||||
|
(float)(lastTime2 / (float)TICKS_PER_MSEC)) /
|
||||||
|
1000.f;
|
||||||
|
hdttt2.push_back(dtt2);
|
||||||
|
lastTime2 = svcGetSystemTick();
|
||||||
|
bool updgg = this->UpdateScreenF(testfps);
|
||||||
|
currentTime2 = svcGetSystemTick();
|
||||||
|
dtt3 = ((float)(currentTime2 / (float)TICKS_PER_MSEC) -
|
||||||
|
(float)(lastTime2 / (float)TICKS_PER_MSEC)) /
|
||||||
|
1000.f;
|
||||||
|
if (updgg)
|
||||||
|
hdttt3.push_back(dtt3);
|
||||||
|
if (!shouldbe_disabled)
|
||||||
|
this->DrawScreen();
|
||||||
|
renderedframes++;
|
||||||
|
if (mdtt2 < dtt2) {
|
||||||
|
mdtt2 = dtt2;
|
||||||
|
}
|
||||||
|
if (mdtt3 < dtt3 && updgg) {
|
||||||
|
mdtt3 = dtt3;
|
||||||
|
}
|
||||||
|
timer += 1 * dtt;
|
||||||
|
float hdtt = C3D_GetProcessingTime();
|
||||||
|
hdttt.push_back(hdtt);
|
||||||
|
fpscountc.push_back(fps);
|
||||||
|
if (mhdtt < hdtt) {
|
||||||
|
mhdtt = C3D_GetProcessingTime();
|
||||||
|
}
|
||||||
|
/*if (!shouldbe_disabled)
|
||||||
|
{
|
||||||
|
RenderD7::OnScreen(Bottom);
|
||||||
|
RenderD7::DrawText(0, 0, 0.5f, RenderD7::Color::Hex("#ff0000"),
|
||||||
|
"Time: " + std::to_string(timer)); RenderD7::DrawText(0, 20, 0.5f,
|
||||||
|
RenderD7::Color::Hex("#ff0000"), "Fps: " + std::to_string(fps));
|
||||||
|
RenderD7::DrawText(0, 40, 0.5f, RenderD7::Color::Hex("#ff0000"),
|
||||||
|
"dt: " + std::to_string(dtt)); RenderD7::DrawText(0, 60, 0.5f,
|
||||||
|
RenderD7::Color::Hex("#ff0000"), "MaxRenderTime: " +
|
||||||
|
std::to_string(mdtt2*1000) + "ms/f"); RenderD7::DrawText(0, 80, 0.5f,
|
||||||
|
RenderD7::Color::Hex("#ff0000"), "MaxConvertTime: " +
|
||||||
|
std::to_string(mdtt3*1000) + "ms");
|
||||||
|
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::BitmapPrinter::SetupBenchmark(int framerate) {
|
||||||
|
benchmark = true;
|
||||||
|
setupbenchmark = true;
|
||||||
|
this->testfps = framerate;
|
||||||
|
this->testfpsd = framerate;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <renderd7/debugfont.h>
|
||||||
|
|
||||||
|
void RenderD7::BitmapPrinter::DrawDebugChar(u32 posX, u32 posY, int t_size,
|
||||||
|
u32 color, char character) {
|
||||||
|
bool isscale = (t_size > 1) ? true : false;
|
||||||
|
for (u32 y = 0; y < 8; y++) {
|
||||||
|
char charPos = debugfont[character * 8 + y];
|
||||||
|
|
||||||
|
for (u32 x = 0; x < 8; x++)
|
||||||
|
if (((charPos >> (7 - x)) & 1) == 1) {
|
||||||
|
if (!isscale)
|
||||||
|
DrawPixel((int)posX + x + 1, (int)posY + y + 1, UNPACK_BGRA(color));
|
||||||
|
if (isscale)
|
||||||
|
DrawRectFilled(((int)posX) + (x * t_size) + 1,
|
||||||
|
((int)posY) + (y * t_size) + 1, t_size, t_size,
|
||||||
|
UNPACK_BGRA(color));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::BitmapPrinter::DrawChar(int posX, int posY, float t_size,
|
||||||
|
u32 color, char character,
|
||||||
|
RenderD7::NFontApi font) {
|
||||||
|
for (int y = 0; y < font.GetGlyphHeight(character); y++) {
|
||||||
|
for (int x = 0; x < font.GetGlyphWidth(character); x++) {
|
||||||
|
DrawPixel(posX + x + 1, posY + y + 1, 255, 255, 255,
|
||||||
|
font.GetGlyphBitmap(
|
||||||
|
character)[((y * font.GetGlyphWidth(character) + x) * 1)]);
|
||||||
|
if (((font.GetGlyphBitmap(
|
||||||
|
character)[font.GetGlyphHeight(character) + y] >>
|
||||||
|
(font.GetGlyphWidth(character - 1) - x)) &
|
||||||
|
1) == 1) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// for(int y = 0; y < font.GetGlyphHeight(character) *
|
||||||
|
// font.GetGlyphWidth(character); y++)
|
||||||
|
//{
|
||||||
|
// DrawPixel(posX + x + 1, posY + y + 1, UNPACK_BGRA(color));
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SPACING_Y 10
|
||||||
|
#define SPACING_X 8
|
||||||
|
|
||||||
|
void RenderD7::BitmapPrinter::DrawDebugText(int x, int y, int t_size, u32 color,
|
||||||
|
std::string text) {
|
||||||
|
if (t_size < 1) {
|
||||||
|
t_size = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (u32 i = 0, line_i = 0; i < strlen(text.c_str()); i++)
|
||||||
|
switch (text[i]) {
|
||||||
|
case '\n':
|
||||||
|
y += (SPACING_Y * t_size);
|
||||||
|
line_i = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\t':
|
||||||
|
line_i += 2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Make sure we never get out of the screen
|
||||||
|
if (line_i >= (((u32)this->bitmap.bmp_info_header.width) - (u32)x) /
|
||||||
|
(SPACING_X * t_size)) {
|
||||||
|
y += (SPACING_Y * t_size);
|
||||||
|
line_i = 1; // Little offset so we know the same text continues
|
||||||
|
if (text[i] == ' ')
|
||||||
|
break; // Spaces at the start look weird
|
||||||
|
}
|
||||||
|
|
||||||
|
this->DrawDebugChar((u32)x + line_i * (SPACING_X * t_size), (u32)y,
|
||||||
|
t_size, color, text[i]);
|
||||||
|
|
||||||
|
line_i++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::BitmapPrinter::DrawText(int x, int y, float t_size, u32 color,
|
||||||
|
std::string text,
|
||||||
|
RenderD7::NFontApi font) {
|
||||||
|
if (t_size < 1) {
|
||||||
|
t_size = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (u32 i = 0, line_i = 0; i < strlen(text.c_str()); i++)
|
||||||
|
switch (text[i]) {
|
||||||
|
case '\n':
|
||||||
|
y += (font.GetLineHeight());
|
||||||
|
line_i = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\t':
|
||||||
|
line_i += 2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Make sure we never get out of the screen
|
||||||
|
if (line_i >= (((u32)this->bitmap.bmp_info_header.width) - (u32)x) /
|
||||||
|
(u32)(font.GetGlyphWidth(text[i]))) {
|
||||||
|
y += (SPACING_Y * t_size);
|
||||||
|
line_i = 1; // Little offset so we know the same text continues
|
||||||
|
if (text[i] == ' ')
|
||||||
|
break; // Spaces at the start look weird
|
||||||
|
}
|
||||||
|
|
||||||
|
this->DrawChar(x + line_i * (font.GetGlyphWidth(text[i])), y, t_size,
|
||||||
|
color, text[i], font);
|
||||||
|
|
||||||
|
line_i++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RenderD7::BitmapPrinter::Decode(Decoder deccc) {
|
||||||
|
bool res = false;
|
||||||
|
|
||||||
|
switch (deccc) {
|
||||||
|
case Decoder::BITMAP2PNG2C3D:
|
||||||
|
renderframe.LoadPFromBuffer(
|
||||||
|
BitmapConverter::ConvertData(this->bitmap.DATA()));
|
||||||
|
res = true;
|
||||||
|
break;
|
||||||
|
case Decoder::BITMAP2C3D:
|
||||||
|
renderframe.LoadFromBitmap(this->bitmap);
|
||||||
|
res = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
res = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::BitmapPrinter::DrawBitmap(int x, int y, BMP map) {
|
||||||
|
for (int i = 0; i < map.bmp_info_header.width; i++) {
|
||||||
|
for (int j = 0; j < map.bmp_info_header.height; j++) {
|
||||||
|
bitmap.set_pixel(
|
||||||
|
x + i, (bitmap.bmp_info_header.height - 1) - (y + j),
|
||||||
|
UNPACK_BGRA(map.get_pixel(i, (map.bmp_info_header.height - 1) - j)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
source/Color.cpp
Normal file
24
source/Color.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <renderd7/Color.hpp>
|
||||||
|
|
||||||
|
#define RGBA8(r, g, b, a) \
|
||||||
|
((((r)&0xFF) << 0) | (((g)&0xFF) << 8) | (((b)&0xFF) << 16) | \
|
||||||
|
(((a)&0xFF) << 24))
|
||||||
|
|
||||||
|
uint32_t RenderD7::Color::Hex(const std::string color, uint8_t a) {
|
||||||
|
if (color.length() < 7 ||
|
||||||
|
std::regex_search(color.substr(1),
|
||||||
|
std::regex("[^0-9A-Fa-f]"))) { // invalid color.
|
||||||
|
return RenderD7::Color::Hex("#000000", 0);
|
||||||
|
}
|
||||||
|
int r = std::stoi(color.substr(1, 2), nullptr, 16);
|
||||||
|
int g = std::stoi(color.substr(3, 2), nullptr, 16);
|
||||||
|
int b = std::stoi(color.substr(5, 2), nullptr, 16);
|
||||||
|
return RGBA8(r, g, b, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string RenderD7::Color::RGB2Hex(int r, int g, int b) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "#";
|
||||||
|
ss << std::hex << (r << 16 | g << 8 | b);
|
||||||
|
return ss.str();
|
||||||
|
}
|
216
source/Draw.cpp
Normal file
216
source/Draw.cpp
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
#include <renderd7/Draw.hpp>
|
||||||
|
|
||||||
|
extern C2D_TextBuf TextBuf;
|
||||||
|
extern C2D_Font Font;
|
||||||
|
extern bool currentScreen;
|
||||||
|
|
||||||
|
bool RenderD7::Draw::Rect(float x, float y, float w, float h, u32 color) {
|
||||||
|
return C2D_DrawRectSolid(x, y, 0.5f, w, h, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RenderD7::Draw::Px(float x, float y, u32 color) {
|
||||||
|
return C2D_DrawRectSolid(x, y, 0.5f, 1, 1, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::Draw::TextCentered(float x, float y, float size, u32 color,
|
||||||
|
std::string Text, int maxWidth, int maxHeight,
|
||||||
|
C2D_Font fnt) {
|
||||||
|
float lineHeight, widthScale;
|
||||||
|
|
||||||
|
// Check for the lineHeight.
|
||||||
|
if (fnt != nullptr) {
|
||||||
|
lineHeight = RenderD7::Draw::GetTextHeight(size, " ", fnt);
|
||||||
|
} else {
|
||||||
|
lineHeight = RenderD7::Draw::GetTextHeight(size, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
int line = 0;
|
||||||
|
while (Text.find('\n') != Text.npos) {
|
||||||
|
if (maxWidth == 0) {
|
||||||
|
// Do the widthScale.
|
||||||
|
if (fnt != nullptr) {
|
||||||
|
widthScale = RenderD7::Draw::GetTextWidth(
|
||||||
|
size, Text.substr(0, Text.find('\n')), fnt);
|
||||||
|
} else {
|
||||||
|
widthScale =
|
||||||
|
RenderD7::Draw::GetTextWidth(size, Text.substr(0, Text.find('\n')));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Do the widthScale 2.
|
||||||
|
if (fnt != nullptr) {
|
||||||
|
widthScale = std::min((float)maxWidth,
|
||||||
|
RenderD7::Draw::GetTextWidth(
|
||||||
|
size, Text.substr(0, Text.find('\n')), fnt));
|
||||||
|
} else {
|
||||||
|
widthScale = std::min((float)maxWidth,
|
||||||
|
RenderD7::Draw::GetTextWidth(
|
||||||
|
size, Text.substr(0, Text.find('\n'))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fnt != nullptr) {
|
||||||
|
RenderD7::Draw::Text((currentScreen ? 200 : 160) + x - (widthScale / 2),
|
||||||
|
y + (lineHeight * line), size, color,
|
||||||
|
Text.substr(0, Text.find('\n')), maxWidth, maxHeight,
|
||||||
|
fnt);
|
||||||
|
} else {
|
||||||
|
RenderD7::Draw::Text((currentScreen ? 200 : 160) + x - (widthScale / 2),
|
||||||
|
y + (lineHeight * line), size, color,
|
||||||
|
Text.substr(0, Text.find('\n')), maxWidth,
|
||||||
|
maxHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
Text = Text.substr(Text.find('\n') + 1);
|
||||||
|
line++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxWidth == 0) {
|
||||||
|
// Do the next WidthScale.
|
||||||
|
if (fnt != nullptr) {
|
||||||
|
widthScale = RenderD7::Draw::GetTextWidth(
|
||||||
|
size, Text.substr(0, Text.find('\n')), fnt);
|
||||||
|
} else {
|
||||||
|
widthScale =
|
||||||
|
RenderD7::Draw::GetTextWidth(size, Text.substr(0, Text.find('\n')));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// And again.
|
||||||
|
if (fnt != nullptr) {
|
||||||
|
widthScale = std::min((float)maxWidth,
|
||||||
|
RenderD7::Draw::GetTextWidth(
|
||||||
|
size, Text.substr(0, Text.find('\n')), fnt));
|
||||||
|
} else {
|
||||||
|
widthScale = std::min(
|
||||||
|
(float)maxWidth,
|
||||||
|
RenderD7::Draw::GetTextWidth(size, Text.substr(0, Text.find('\n'))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fnt != nullptr) {
|
||||||
|
RenderD7::Draw::Text((currentScreen ? 200 : 160) + x - (widthScale / 2),
|
||||||
|
y + (lineHeight * line), size, color,
|
||||||
|
Text.substr(0, Text.find('\n')), maxWidth, maxHeight,
|
||||||
|
fnt);
|
||||||
|
} else {
|
||||||
|
RenderD7::Draw::Text((currentScreen ? 200 : 160) + x - (widthScale / 2),
|
||||||
|
y + (lineHeight * line), size, color,
|
||||||
|
Text.substr(0, Text.find('\n')), maxWidth, maxHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw String or Text.
|
||||||
|
void RenderD7::Draw::Text(float x, float y, float size, u32 color,
|
||||||
|
std::string Text, int maxWidth, int maxHeight,
|
||||||
|
C2D_Font fnt) {
|
||||||
|
C2D_Text c2d_text;
|
||||||
|
|
||||||
|
if (fnt != nullptr) {
|
||||||
|
C2D_TextFontParse(&c2d_text, fnt, TextBuf, Text.c_str());
|
||||||
|
} else {
|
||||||
|
C2D_TextFontParse(&c2d_text, Font, TextBuf, Text.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
C2D_TextOptimize(&c2d_text);
|
||||||
|
|
||||||
|
float heightScale;
|
||||||
|
if (maxHeight == 0) {
|
||||||
|
heightScale = size;
|
||||||
|
} else {
|
||||||
|
if (fnt != nullptr) {
|
||||||
|
heightScale = std::min(
|
||||||
|
size,
|
||||||
|
size * (maxHeight / RenderD7::Draw::GetTextHeight(size, Text, fnt)));
|
||||||
|
} else {
|
||||||
|
heightScale = std::min(
|
||||||
|
size, size * (maxHeight / RenderD7::Draw::GetTextHeight(size, Text)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxWidth == 0) {
|
||||||
|
C2D_DrawText(&c2d_text, C2D_WithColor, x, y, 0.5f, size, heightScale,
|
||||||
|
color);
|
||||||
|
} else {
|
||||||
|
if (fnt != nullptr) {
|
||||||
|
C2D_DrawText(
|
||||||
|
&c2d_text, C2D_WithColor, x, y, 0.5f,
|
||||||
|
std::min(size, size * (maxWidth / RenderD7::Draw::GetTextWidth(
|
||||||
|
size, Text, fnt))),
|
||||||
|
heightScale, color);
|
||||||
|
} else {
|
||||||
|
C2D_DrawText(
|
||||||
|
&c2d_text, C2D_WithColor, x, y, 0.5f,
|
||||||
|
std::min(size, size * (maxWidth /
|
||||||
|
RenderD7::Draw::GetTextWidth(size, Text))),
|
||||||
|
heightScale, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void RenderD7::Draw::TextRight(float x, float y, float size, u32 color,
|
||||||
|
std::string Text, int maxWidth, int maxHeight,
|
||||||
|
C2D_Font fnt) {
|
||||||
|
RenderD7::Draw::Text(x - RenderD7::Draw::GetTextWidth(size, Text, fnt), y,
|
||||||
|
size, color, Text, maxWidth, maxHeight, fnt);
|
||||||
|
}
|
||||||
|
// Get String or Text Width.
|
||||||
|
float RenderD7::Draw::GetTextWidth(float size, std::string Text, C2D_Font fnt) {
|
||||||
|
float width = 0;
|
||||||
|
if (fnt != nullptr) {
|
||||||
|
GetTextSize(size, &width, NULL, Text, fnt);
|
||||||
|
} else {
|
||||||
|
GetTextSize(size, &width, NULL, Text);
|
||||||
|
}
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get String or Text Size.
|
||||||
|
void RenderD7::Draw::GetTextSize(float size, float *width, float *height,
|
||||||
|
std::string Text, C2D_Font fnt) {
|
||||||
|
C2D_Text c2d_text;
|
||||||
|
if (fnt != nullptr) {
|
||||||
|
C2D_TextFontParse(&c2d_text, fnt, TextBuf, Text.c_str());
|
||||||
|
} else {
|
||||||
|
C2D_TextFontParse(&c2d_text, Font, TextBuf, Text.c_str());
|
||||||
|
}
|
||||||
|
C2D_TextGetDimensions(&c2d_text, size, size, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get String or Text Height.
|
||||||
|
float RenderD7::Draw::GetTextHeight(float size, std::string Text,
|
||||||
|
C2D_Font fnt) {
|
||||||
|
float height = 0;
|
||||||
|
if (fnt != nullptr) {
|
||||||
|
GetTextSize(size, NULL, &height, Text.c_str(), fnt);
|
||||||
|
} else {
|
||||||
|
GetTextSize(size, NULL, &height, Text.c_str());
|
||||||
|
}
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result RenderD7::Draw::LoadFont(C2D_Font &fnt, const char *Path) {
|
||||||
|
fnt = C2D_FontLoad(Path); // Only load if found.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unload a Font.
|
||||||
|
Result RenderD7::Draw::UnloadFont(C2D_Font &fnt) {
|
||||||
|
if (fnt != nullptr) {
|
||||||
|
C2D_FontFree(fnt); // Make sure to only unload if not nullptr.
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RenderD7::Draw::Circle(float x, float y, float radius, u32 color) {
|
||||||
|
return C2D_DrawCircleSolid(x, y, 0.5f, radius, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RenderD7::Draw::Image(C2D_Image img, float x, float y, float scaleX,
|
||||||
|
float scaleY) {
|
||||||
|
return C2D_DrawImageAt(img, x, y, 0.5f, nullptr, scaleX, scaleY);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RenderD7::Draw::NFRect(float p1x, float p1y, float w, float h, u32 color,
|
||||||
|
float scale) {
|
||||||
|
C2D_DrawLine(p1x, p1y, color, w, p1y, color, scale, 1);
|
||||||
|
C2D_DrawLine(w, p1y, color, w, h, color, scale, 1);
|
||||||
|
C2D_DrawLine(w, h, color, p1x, h, color, scale, 1);
|
||||||
|
C2D_DrawLine(p1x, h, color, p1x, p1y, color, scale, 1);
|
||||||
|
return true;
|
||||||
|
}
|
20
source/FileSystem.cpp
Normal file
20
source/FileSystem.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <3ds.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <renderd7/FileSystem.hpp>
|
||||||
|
// Debugging
|
||||||
|
#include <memory>
|
||||||
|
#include <renderd7/Ovl.hpp>
|
||||||
|
#include <renderd7/Toast.hpp>
|
||||||
|
#include <renderd7/stringtool.hpp>
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
std::vector<RenderD7::FileSystem::Entry> RenderD7::FileSystem::GetDirContent(std::string path)
|
||||||
|
{
|
||||||
|
std::vector<RenderD7::FileSystem::Entry> res;
|
||||||
|
for(const auto& entry : std::filesystem::directory_iterator(std::filesystem::path(path)))
|
||||||
|
{
|
||||||
|
res.push_back({entry.path().string(), GetFileName(entry.path().string()), entry.is_directory()});
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
348
source/Image.cpp
Normal file
348
source/Image.cpp
Normal file
@ -0,0 +1,348 @@
|
|||||||
|
#include <renderd7/Image.hpp>
|
||||||
|
#include <renderd7/Ovl.hpp>
|
||||||
|
#include <renderd7/Toast.hpp>
|
||||||
|
|
||||||
|
#include <renderd7/external/stb_image.h>
|
||||||
|
extern bool usedbgmsg;
|
||||||
|
|
||||||
|
static u32 GetNextPowerOf2(u32 v) {
|
||||||
|
v--;
|
||||||
|
v |= v >> 1;
|
||||||
|
v |= v >> 2;
|
||||||
|
v |= v >> 4;
|
||||||
|
v |= v >> 8;
|
||||||
|
v |= v >> 16;
|
||||||
|
v++;
|
||||||
|
return (v >= 64 ? v : 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool C3DTexToC2DImage(C2D_Image *texture, u32 width, u32 height,
|
||||||
|
u8 *buf) {
|
||||||
|
if (width >= 1024 || height >= 1024)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
C3D_Tex *tex = new C3D_Tex[sizeof(C3D_Tex)];
|
||||||
|
Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture[sizeof(Tex3DS_SubTexture)];
|
||||||
|
subtex->width = static_cast<u16>(width);
|
||||||
|
subtex->height = static_cast<u16>(height);
|
||||||
|
// RGBA -> ABGR
|
||||||
|
for (u32 row = 0; row < subtex->width; row++) {
|
||||||
|
for (u32 col = 0; col < subtex->height; col++) {
|
||||||
|
u32 z = (row + col * subtex->width) * 4;
|
||||||
|
|
||||||
|
u8 r = *(u8 *)(buf + z);
|
||||||
|
u8 g = *(u8 *)(buf + z + 1);
|
||||||
|
u8 b = *(u8 *)(buf + z + 2);
|
||||||
|
u8 a = *(u8 *)(buf + z + 3);
|
||||||
|
|
||||||
|
*(buf + z) = a;
|
||||||
|
*(buf + z + 1) = b;
|
||||||
|
*(buf + z + 2) = g;
|
||||||
|
*(buf + z + 3) = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 w_pow2 = GetNextPowerOf2(subtex->width);
|
||||||
|
u32 h_pow2 = GetNextPowerOf2(subtex->height);
|
||||||
|
subtex->left = 0.f;
|
||||||
|
subtex->top = 1.f;
|
||||||
|
subtex->right = (subtex->width / static_cast<float>(w_pow2));
|
||||||
|
subtex->bottom = (1.0 - (subtex->height / static_cast<float>(h_pow2)));
|
||||||
|
C3D_TexInit(tex, static_cast<u16>(w_pow2), static_cast<u16>(h_pow2),
|
||||||
|
GPU_RGBA8);
|
||||||
|
C3D_TexSetFilter(tex, GPU_NEAREST, GPU_NEAREST);
|
||||||
|
|
||||||
|
std::memset(tex->data, 0, tex->size);
|
||||||
|
|
||||||
|
for (u32 x = 0; x < subtex->width; x++) {
|
||||||
|
for (u32 y = 0; y < subtex->height; y++) {
|
||||||
|
u32 dst_pos = ((((y >> 3) * (w_pow2 >> 3) + (x >> 3)) << 6) +
|
||||||
|
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
|
||||||
|
((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
|
||||||
|
4;
|
||||||
|
u32 src_pos = (y * subtex->width + x) * 4;
|
||||||
|
std::memcpy(&(static_cast<u8 *>(tex->data))[dst_pos],
|
||||||
|
&(static_cast<u8 *>(buf))[src_pos], 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
C3D_TexFlush(tex);
|
||||||
|
tex->border = RenderD7::Color::Hex("#000000", 0);
|
||||||
|
C3D_TexSetWrap(tex, GPU_CLAMP_TO_BORDER, GPU_CLAMP_TO_BORDER);
|
||||||
|
if (tex && subtex) {
|
||||||
|
texture->tex = tex;
|
||||||
|
texture->subtex = subtex;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void OLD_C3DTexToC2DImage(C3D_Tex *tex, Tex3DS_SubTexture *subtex, u8 *buf, u32 size, u32 width, u32 height, GPU_TEXCOLOR format) {
|
||||||
|
// RGBA -> ABGR
|
||||||
|
for (u32 row = 0; row < width; row++) {
|
||||||
|
for (u32 col = 0; col < height; col++) {
|
||||||
|
u32 z = (row + col * width) * 4;
|
||||||
|
|
||||||
|
u8 r = *(u8 *)(buf + z);
|
||||||
|
u8 g = *(u8 *)(buf + z + 1);
|
||||||
|
u8 b = *(u8 *)(buf + z + 2);
|
||||||
|
u8 a = *(u8 *)(buf + z + 3);
|
||||||
|
|
||||||
|
*(buf + z) = a;
|
||||||
|
*(buf + z + 1) = b;
|
||||||
|
*(buf + z + 2) = g;
|
||||||
|
*(buf + z + 3) = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 w_pow2 = GetNextPowerOf2(width);
|
||||||
|
u32 h_pow2 = GetNextPowerOf2(height);
|
||||||
|
|
||||||
|
subtex->width = (u16)width;
|
||||||
|
subtex->height = (u16)height;
|
||||||
|
subtex->left = 0.0f;
|
||||||
|
subtex->top = 1.0f;
|
||||||
|
subtex->right = (width / (float)w_pow2);
|
||||||
|
subtex->bottom = 1.0 - (height / (float)h_pow2);
|
||||||
|
|
||||||
|
C3D_TexInit(tex, (u16)w_pow2, (u16)h_pow2, format);
|
||||||
|
C3D_TexSetFilter(tex, GPU_NEAREST, GPU_NEAREST);
|
||||||
|
|
||||||
|
u32 pixel_size = (size / width / height);
|
||||||
|
|
||||||
|
memset(tex->data, 0, tex->size);
|
||||||
|
|
||||||
|
for (u32 x = 0; x < width; x++) {
|
||||||
|
for (u32 y = 0; y < height; y++) {
|
||||||
|
u32 dst_pos = ((((y >> 3) * (w_pow2 >> 3) + (x >> 3)) << 6) + ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) * pixel_size;
|
||||||
|
u32 src_pos = (y * width + x) * pixel_size;
|
||||||
|
|
||||||
|
memcpy(&((u8*)tex->data)[dst_pos], &((u8*)buf)[src_pos], pixel_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
C3D_TexFlush(tex);
|
||||||
|
|
||||||
|
tex->border = 0x00000000;
|
||||||
|
C3D_TexSetWrap(tex, GPU_CLAMP_TO_BORDER, GPU_CLAMP_TO_BORDER);
|
||||||
|
linearFree(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IMG_LoadImageFile(C2D_Image *texture, const char *path) {
|
||||||
|
stbi_uc *image = NULL;
|
||||||
|
int width = 0, height = 0;
|
||||||
|
int nc;
|
||||||
|
|
||||||
|
image = stbi_load(path, &width, &height, &nc, 4);
|
||||||
|
|
||||||
|
if (width > 1024 || height > 1024) {
|
||||||
|
stbi_image_free(image);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
C3D_Tex *tex = new C3D_Tex;
|
||||||
|
Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture;
|
||||||
|
OLD_C3DTexToC2DImage(tex, subtex, image, (u32)(width * height * 4), (u32)width, (u32)height, GPU_RGBA8);
|
||||||
|
texture->tex = tex;
|
||||||
|
texture->subtex = subtex;
|
||||||
|
stbi_image_free(image);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <renderd7/external/libnsbmp/libnsbmp.h>
|
||||||
|
}
|
||||||
|
static const u32 BYTES_PER_PIXEL = 4;
|
||||||
|
#define MAX_IMAGE_BYTES (48 * 1024 * 1024)
|
||||||
|
|
||||||
|
namespace LIBBMP {
|
||||||
|
static void *bitmap_create(int width, int height,
|
||||||
|
[[maybe_unused]] unsigned int state) {
|
||||||
|
/* ensure a stupidly large (>50Megs or so) bitmap is not created */
|
||||||
|
if ((static_cast<long long>(width) * static_cast<long long>(height)) >
|
||||||
|
(MAX_IMAGE_BYTES / BYTES_PER_PIXEL))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return std::calloc(width * height, BYTES_PER_PIXEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned char *bitmap_get_buffer(void *bitmap) {
|
||||||
|
assert(bitmap);
|
||||||
|
return static_cast<unsigned char *>(bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t bitmap_get_bpp([[maybe_unused]] void *bitmap) {
|
||||||
|
return BYTES_PER_PIXEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void bitmap_destroy(void *bitmap) {
|
||||||
|
assert(bitmap);
|
||||||
|
std::free(bitmap);
|
||||||
|
}
|
||||||
|
} // namespace LIBBMP
|
||||||
|
|
||||||
|
unsigned Image_to_C3D(C2D_Image img, const std::vector<unsigned char> &bmpc) {
|
||||||
|
bmp_bitmap_callback_vt bitmap_callbacks = {
|
||||||
|
LIBBMP::bitmap_create, LIBBMP::bitmap_destroy, LIBBMP::bitmap_get_buffer,
|
||||||
|
LIBBMP::bitmap_get_bpp};
|
||||||
|
|
||||||
|
bmp_result code = BMP_OK;
|
||||||
|
bmp_image bmp;
|
||||||
|
bmp_create(&bmp, &bitmap_callbacks);
|
||||||
|
|
||||||
|
code = bmp_analyse(&bmp, bmpc.size(), (u8 *)bmpc.data());
|
||||||
|
if (code != BMP_OK) {
|
||||||
|
bmp_finalise(&bmp);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = bmp_decode(&bmp);
|
||||||
|
if (code != BMP_OK) {
|
||||||
|
if ((code != BMP_INSUFFICIENT_DATA) && (code != BMP_DATA_ERROR)) {
|
||||||
|
bmp_finalise(&bmp);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* skip if the decoded image would be ridiculously large */
|
||||||
|
if ((bmp.width * bmp.height) > 200000) {
|
||||||
|
bmp_finalise(&bmp);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
C2D_Image *texture = new C2D_Image();
|
||||||
|
bool ret = C3DTexToC2DImage(texture, static_cast<u32>(bmp.width),
|
||||||
|
static_cast<u32>(bmp.height),
|
||||||
|
static_cast<u8 *>(bmp.bitmap));
|
||||||
|
bmp_finalise(&bmp);
|
||||||
|
delete texture;
|
||||||
|
if (!ret) {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::Image::LoadPng(const std::string path) {
|
||||||
|
if (usedbgmsg) {
|
||||||
|
// RenderD7::Msg::Display("RenderD7", "Loading Png:" + path, Top);
|
||||||
|
}
|
||||||
|
std::vector<u8> ImageBuffer;
|
||||||
|
unsigned width, height;
|
||||||
|
if (loadet) {
|
||||||
|
C3D_TexDelete(this->img.tex);
|
||||||
|
loadet = false;
|
||||||
|
}
|
||||||
|
lodepng::decode(ImageBuffer, width, height, path);
|
||||||
|
|
||||||
|
this->img.tex = new C3D_Tex;
|
||||||
|
this->img.subtex =
|
||||||
|
new Tex3DS_SubTexture({(u16)width, (u16)height, 0.0f, 1.0f,
|
||||||
|
width / 1024.0f, 1.0f - (height / 1024.0f)});
|
||||||
|
|
||||||
|
C3D_TexInit(this->img.tex, 1024, 1024, GPU_RGBA8);
|
||||||
|
C3D_TexSetFilter(this->img.tex, GPU_LINEAR, GPU_LINEAR);
|
||||||
|
this->img.tex->border = 0xFFFFFFFF;
|
||||||
|
C3D_TexSetWrap(this->img.tex, GPU_CLAMP_TO_BORDER, GPU_CLAMP_TO_BORDER);
|
||||||
|
|
||||||
|
for (u32 x = 0; x < width && x < 1024; x++) {
|
||||||
|
for (u32 y = 0; y < height && y < 1024; y++) {
|
||||||
|
const u32 dstPos = ((((y >> 3) * (1024 >> 3) + (x >> 3)) << 6) +
|
||||||
|
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
|
||||||
|
((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
|
||||||
|
4;
|
||||||
|
|
||||||
|
const u32 srcPos = (y * width + x) * 4;
|
||||||
|
((uint8_t *)this->img.tex->data)[dstPos + 0] =
|
||||||
|
ImageBuffer.data()[srcPos + 3];
|
||||||
|
((uint8_t *)this->img.tex->data)[dstPos + 1] =
|
||||||
|
ImageBuffer.data()[srcPos + 2];
|
||||||
|
((uint8_t *)this->img.tex->data)[dstPos + 2] =
|
||||||
|
ImageBuffer.data()[srcPos + 1];
|
||||||
|
((uint8_t *)this->img.tex->data)[dstPos + 3] =
|
||||||
|
ImageBuffer.data()[srcPos + 0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderD7::Image::~Image() {
|
||||||
|
if (loadet)
|
||||||
|
C3D_TexDelete(img.tex);
|
||||||
|
loadet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::Image::Unload() {
|
||||||
|
if (loadet)
|
||||||
|
C3D_TexDelete(img.tex);
|
||||||
|
loadet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::Image::LoadPFromBuffer(const std::vector<u8> &buffer) {
|
||||||
|
std::vector<u8> ImageBuffer;
|
||||||
|
if (loadet) {
|
||||||
|
C3D_TexDelete(this->img.tex);
|
||||||
|
loadet = false;
|
||||||
|
}
|
||||||
|
unsigned width, height;
|
||||||
|
lodepng::decode(ImageBuffer, width, height, buffer);
|
||||||
|
|
||||||
|
img.tex = new C3D_Tex;
|
||||||
|
img.subtex =
|
||||||
|
new Tex3DS_SubTexture({(u16)width, (u16)height, 0.0f, 1.0f,
|
||||||
|
width / 512.0f, 1.0f - (height / 512.0f)});
|
||||||
|
|
||||||
|
C3D_TexInit(img.tex, 512, 512, GPU_RGBA8);
|
||||||
|
C3D_TexSetFilter(img.tex, GPU_LINEAR, GPU_LINEAR);
|
||||||
|
img.tex->border = 0xFFFFFFFF;
|
||||||
|
C3D_TexSetWrap(img.tex, GPU_CLAMP_TO_BORDER, GPU_CLAMP_TO_BORDER);
|
||||||
|
|
||||||
|
for (u32 x = 0; x < width && x < 512; x++) {
|
||||||
|
for (u32 y = 0; y < height && y < 512; y++) {
|
||||||
|
const u32 dstPos = ((((y >> 3) * (512 >> 3) + (x >> 3)) << 6) +
|
||||||
|
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
|
||||||
|
((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
|
||||||
|
4;
|
||||||
|
|
||||||
|
const u32 srcPos = (y * width + x) * 4;
|
||||||
|
((uint8_t *)img.tex->data)[dstPos + 0] = ImageBuffer.data()[srcPos + 3];
|
||||||
|
((uint8_t *)img.tex->data)[dstPos + 1] = ImageBuffer.data()[srcPos + 2];
|
||||||
|
((uint8_t *)img.tex->data)[dstPos + 2] = ImageBuffer.data()[srcPos + 1];
|
||||||
|
((uint8_t *)img.tex->data)[dstPos + 3] = ImageBuffer.data()[srcPos + 0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::Image::FromSheet(RenderD7::Sheet sheet, size_t index) {}
|
||||||
|
|
||||||
|
bool RenderD7::Image::Draw(float x, float y, float scaleX, float scaleY) {
|
||||||
|
if (loadet)
|
||||||
|
return C2D_DrawImageAt(this->img, x, y, 0.5f, nullptr, scaleX, scaleY);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::Image::LoadFromBitmap(BMP bitmap) {
|
||||||
|
loadet = false;
|
||||||
|
unsigned error = Image_to_C3D(this->img, bitmap.DATA());
|
||||||
|
if (error == 0) {
|
||||||
|
this->loadet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
std::cout << "BMP decoding error " << error << std::endl;
|
||||||
|
RenderD7::AddOvl(std::make_unique<RenderD7::Toast>(
|
||||||
|
"Bmp - Error", "Code: " + std::to_string(error)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
void Image::LoadJpg(std::string path) {
|
||||||
|
if (usedbgmsg) {
|
||||||
|
// RenderD7::Msg::Display("RenderD7", "Loading Png:" + path, Top);
|
||||||
|
}
|
||||||
|
if (loadet) {
|
||||||
|
C3D_TexDelete(this->img.tex);
|
||||||
|
loadet = false;
|
||||||
|
}
|
||||||
|
IMG_LoadImageFile(&this->img, path.c_str());
|
||||||
|
loadet = true;
|
||||||
|
}
|
||||||
|
} // namespace RenderD7
|
66
source/NFontApi.cpp
Normal file
66
source/NFontApi.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include <renderd7/Fonts/NFontApi.hpp>
|
||||||
|
#define STB_TRUETYPE_IMPLEMENTATION // force following include to generate
|
||||||
|
// implementation
|
||||||
|
#include <renderd7/external/stb_truetype.h>
|
||||||
|
|
||||||
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
#include <renderd7/external/stb_image_write.h>
|
||||||
|
|
||||||
|
RenderD7::NFontApi::NFontApi() {}
|
||||||
|
|
||||||
|
RenderD7::NFontApi::~NFontApi() {}
|
||||||
|
|
||||||
|
void RenderD7::NFontApi::LoadTTF(std::string path) {
|
||||||
|
/////READ FILE
|
||||||
|
unsigned char *buffer;
|
||||||
|
long size = 0;
|
||||||
|
FILE *ttf__ = fopen(path.c_str(), "rb");
|
||||||
|
fseek(ttf__, 0, SEEK_END);
|
||||||
|
size = ftell(ttf__);
|
||||||
|
fseek(ttf__, 0, SEEK_SET);
|
||||||
|
buffer = (unsigned char *)malloc(size);
|
||||||
|
fread(buffer, size, 1, ttf__);
|
||||||
|
fclose(ttf__);
|
||||||
|
/////Setup Font
|
||||||
|
if (!stbtt_InitFont(&font, buffer, 0)) {
|
||||||
|
printf("failed\n");
|
||||||
|
status += "failed\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
status += "success!\n";
|
||||||
|
b_h = 128;
|
||||||
|
b_w = 512;
|
||||||
|
l_h = 24; /* line height */
|
||||||
|
scale = stbtt_ScaleForPixelHeight(&font, l_h);
|
||||||
|
|
||||||
|
stbtt_GetFontVMetrics(&font, &ascent, &decent, &linegap);
|
||||||
|
linespace = scale * (ascent - decent + linegap);
|
||||||
|
|
||||||
|
baseline = (int)(ascent * scale);
|
||||||
|
height = (int)((ascent - decent) * scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char *RenderD7::NFontApi::GetGlyphBitmap(char glyph) {
|
||||||
|
// stbtt_GetGlyphBitmapBox(&font, glyph, scale, scale, &x0, &y0, &x1, &y1);
|
||||||
|
stbtt_GetCodepointBitmapBox(&font, glyph, scale, scale, &x0, &y0, &x1, &y1);
|
||||||
|
w = x1 - x0;
|
||||||
|
h = y1 - y0;
|
||||||
|
|
||||||
|
unsigned char *bitmap;
|
||||||
|
bitmap = stbtt_GetCodepointBitmap(&font, scale, scale, glyph, &w, &h, 0, 0);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
int RenderD7::NFontApi::GetGlyphHeight(char glyph) {
|
||||||
|
stbtt_GetCodepointBitmapBox(&font, glyph, scale, scale, &x0, &y0, &x1, &y1);
|
||||||
|
w = x1 - x0;
|
||||||
|
h = y1 - y0;
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
int RenderD7::NFontApi::GetGlyphWidth(char glyph) {
|
||||||
|
stbtt_GetCodepointBitmapBox(&font, glyph, scale, scale, &x0, &y0, &x1, &y1);
|
||||||
|
w = x1 - x0;
|
||||||
|
h = y1 - y0;
|
||||||
|
return w;
|
||||||
|
}
|
422
source/ResultDecoder.cpp
Normal file
422
source/ResultDecoder.cpp
Normal file
@ -0,0 +1,422 @@
|
|||||||
|
#include <map>
|
||||||
|
#include <renderd7/ResultDecoder.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
static std::map<int, std::string> modules = {
|
||||||
|
{0, "common"},
|
||||||
|
{1, "kernel"},
|
||||||
|
{2, "util"},
|
||||||
|
{3, "file server"},
|
||||||
|
{4, "loader server"},
|
||||||
|
{5, "tcb"},
|
||||||
|
{6, "os"},
|
||||||
|
{7, "dbg"},
|
||||||
|
{8, "dmnt"},
|
||||||
|
{9, "pdn"},
|
||||||
|
{10, "gsp"},
|
||||||
|
{11, "i2c"},
|
||||||
|
{12, "gpio"},
|
||||||
|
{13, "dd"},
|
||||||
|
{14, "codec"},
|
||||||
|
{15, "spi"},
|
||||||
|
{16, "pxi"},
|
||||||
|
{17, "fs"},
|
||||||
|
{18, "di"},
|
||||||
|
{19, "hid"},
|
||||||
|
{20, "cam"},
|
||||||
|
{21, "pi"},
|
||||||
|
{22, "pm"},
|
||||||
|
{23, "pm_low"},
|
||||||
|
{24, "fsi"},
|
||||||
|
{25, "srv"},
|
||||||
|
{26, "ndm"},
|
||||||
|
{27, "nwm"},
|
||||||
|
{28, "soc"},
|
||||||
|
{29, "ldr"},
|
||||||
|
{30, "acc"},
|
||||||
|
{31, "romfs"},
|
||||||
|
{32, "am"},
|
||||||
|
{33, "hio"},
|
||||||
|
{34, "updater"},
|
||||||
|
{35, "mic"},
|
||||||
|
{36, "fnd"},
|
||||||
|
{37, "mp"},
|
||||||
|
{38, "mpwl"},
|
||||||
|
{39, "ac"},
|
||||||
|
{40, "http"},
|
||||||
|
{41, "dsp"},
|
||||||
|
{42, "snd"},
|
||||||
|
{43, "dlp"},
|
||||||
|
{44, "hio_low"},
|
||||||
|
{45, "csnd"},
|
||||||
|
{46, "ssl"},
|
||||||
|
{47, "am_low"},
|
||||||
|
{48, "nex"},
|
||||||
|
{49, "friends"},
|
||||||
|
{50, "rdt"},
|
||||||
|
{51, "applet"},
|
||||||
|
{52, "nim"},
|
||||||
|
{53, "ptm"},
|
||||||
|
{54, "midi"},
|
||||||
|
{55, "mc"},
|
||||||
|
{56, "swc"},
|
||||||
|
{57, "fatfs"},
|
||||||
|
{58, "ngc"},
|
||||||
|
{59, "card"},
|
||||||
|
{60, "cardnor"},
|
||||||
|
{61, "sdmc"},
|
||||||
|
{62, "boss"},
|
||||||
|
{63, "dbm"},
|
||||||
|
{64, "config"},
|
||||||
|
{65, "ps"},
|
||||||
|
{66, "cec"},
|
||||||
|
{67, "ir"},
|
||||||
|
{68, "uds"},
|
||||||
|
{69, "pl"},
|
||||||
|
{70, "cup"},
|
||||||
|
{71, "gyroscope"},
|
||||||
|
{72, "mcu"},
|
||||||
|
{73, "ns"},
|
||||||
|
{74, "news"},
|
||||||
|
{75, "ro"},
|
||||||
|
{76, "gd"},
|
||||||
|
{77, "card spi"},
|
||||||
|
{78, "ec"},
|
||||||
|
{79, "web browser"},
|
||||||
|
{80, "test"},
|
||||||
|
{81, "enc"},
|
||||||
|
{82, "pia"},
|
||||||
|
{83, "act"},
|
||||||
|
{84, "vctl"},
|
||||||
|
{85, "olv"},
|
||||||
|
{86, "neia"},
|
||||||
|
{87, "npns"},
|
||||||
|
{90, "avd"},
|
||||||
|
{91, "l2b"},
|
||||||
|
{92, "mvd"},
|
||||||
|
{93, "nfc"},
|
||||||
|
{94, "uart"},
|
||||||
|
{95, "spm"},
|
||||||
|
{96, "qtm"},
|
||||||
|
{97, "nfp"},
|
||||||
|
{254, "application"},
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::map<int, std::string> levels = {
|
||||||
|
{0, "Success"}, {1, "Info"}, {25, "Status"},
|
||||||
|
{26, "Temporary"}, {27, "Permanent"}, {28, "Usage"},
|
||||||
|
{29, "Reinitialize"}, {30, "Reset"}, {31, "Fatal"},
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::map<int, std::string> summaries = {
|
||||||
|
{0, "Success"},
|
||||||
|
{1, "Nothing happened"},
|
||||||
|
{2, "Would block"},
|
||||||
|
{3, "Out of resource"},
|
||||||
|
{4, "Not found"},
|
||||||
|
{5, "Invalid state"},
|
||||||
|
{6, "Not supported"},
|
||||||
|
{7, "Invalid argument"},
|
||||||
|
{8, "Wrong argument"},
|
||||||
|
{9, "Canceled"},
|
||||||
|
{10, "Status changed"},
|
||||||
|
{11, "Internal"},
|
||||||
|
{63, "Invalid result value"},
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::map<int, std::string> desccommon = {
|
||||||
|
{0, "Success"},
|
||||||
|
{1000, "Invalid selection"},
|
||||||
|
{1001, "Too large"},
|
||||||
|
{1002, "Not authorized"},
|
||||||
|
{1003, "Already done"},
|
||||||
|
{1004, "Invalid size"},
|
||||||
|
{1005, "Invalid enum value"},
|
||||||
|
{1006, "Invalid combination"},
|
||||||
|
{1007, "No data"},
|
||||||
|
{1008, "Busy"},
|
||||||
|
{1009, "Misaligned address"},
|
||||||
|
{1010, "Misaligned size"},
|
||||||
|
{1011, "Out of memory"},
|
||||||
|
{1012, "Not implemented"},
|
||||||
|
{1013, "Invalid address"},
|
||||||
|
{1014, "Invalid pointer"},
|
||||||
|
{1015, "Invalid handle"},
|
||||||
|
{1016, "Not initialized"},
|
||||||
|
{1017, "Already initialized"},
|
||||||
|
{1018, "Not found"},
|
||||||
|
{1019, "Cancel requested"},
|
||||||
|
{1020, "Already exists"},
|
||||||
|
{1021, "Out of range"},
|
||||||
|
{1022, "Timeout"},
|
||||||
|
{1023, "Invalid result value"},
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::map<int, std::string> desckernel = {
|
||||||
|
{2, "Invalid memory permissions."},
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::map<int, std::string> descos = {
|
||||||
|
{10, "Not enough memory."},
|
||||||
|
{26, "Session closed by remote."},
|
||||||
|
{47, "Invalid command header."},
|
||||||
|
};
|
||||||
|
|
||||||
|
//Need to Fix The Range based Values
|
||||||
|
static std::map<int, std::string> descfs = {
|
||||||
|
{101, "Archive not mounted or mount-point not found."},
|
||||||
|
{120, "Title or object not found."},
|
||||||
|
{141, "Gamecard not inserted."},
|
||||||
|
{230, "Invalid open flags or permissions."},
|
||||||
|
{391, "NCCH hash check failed."},
|
||||||
|
{302, "RSA or AES-MAC verification failed."},
|
||||||
|
{395, "RomFS or Savedata hash check failed."},
|
||||||
|
{630, "Command not allowed, or missing permissions."},
|
||||||
|
{702, "Invalid path."},
|
||||||
|
{761, "Incorrect ExeFS read size."},
|
||||||
|
{100, "[Media] not found."},
|
||||||
|
{180, "Exists already."},
|
||||||
|
{200, "Not enough space."},
|
||||||
|
{220, "Invalidated archive."},
|
||||||
|
{230, "Unacceptable or write protected."},
|
||||||
|
{340, "0x01"},
|
||||||
|
{360, "Bad format."},
|
||||||
|
{390, "Verification failure."},
|
||||||
|
{400, "0x01"},
|
||||||
|
{600, "Out of resources."},
|
||||||
|
{630, "Access denied."},
|
||||||
|
{661, "0x01"},
|
||||||
|
{700, "Invalid argument."},
|
||||||
|
{730, "Not initialized."},
|
||||||
|
{750, "Already initialized."},
|
||||||
|
{760, "Not supported."},
|
||||||
|
{780, "0x01"},
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::map<int, std::string> descsrv = {
|
||||||
|
{5, "Invalid string length (service name length is zero or longer than 8 "
|
||||||
|
"chars)."},
|
||||||
|
{6, "Access to service denied (requested a service the application does "
|
||||||
|
"not have access to)."},
|
||||||
|
{7, "String size does not match contents (service name contains unexpected "
|
||||||
|
"null byte)."},
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::map<int, std::string> descnwm = {
|
||||||
|
{2, "This error usually indicates the wifi chipset in the console is dying "
|
||||||
|
"or dead."},
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::map<int, std::string> descam = {
|
||||||
|
{4, "Invalid ticket version."},
|
||||||
|
{32, "Empty CIA."},
|
||||||
|
{37, "Invalid NCCH."},
|
||||||
|
{39, "Invalid title version."},
|
||||||
|
{43, "Database doesn\"t exist, or it failed to open."},
|
||||||
|
{44, "Trying to uninstall system-app."},
|
||||||
|
{106, "Invalid signature/CIA. Usually happens when developer UNITINFO is "
|
||||||
|
"enabled in Luma3DS."},
|
||||||
|
{393, "Invalid database."},
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::map<int, std::string> deschttp = {
|
||||||
|
{105, "Request timed out."},
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::map<int, std::string> descnim = {
|
||||||
|
{1, "Invalid string IPC paramater (non null terminated at its indicated "
|
||||||
|
"length)."},
|
||||||
|
{12, "Invalid country code returned by CFG module reading config save "
|
||||||
|
"0xB0000."},
|
||||||
|
{13, "Zero string length console serial number or '000000000000000' "
|
||||||
|
"returned by CFG's SecureInfoGetSerialNo."},
|
||||||
|
{18, "General data reading error of NIM's .dat files from its system save, "
|
||||||
|
"bad data or bad data lengths."},
|
||||||
|
{22, "General invalid data or length of data returned from nintendo "
|
||||||
|
"servers. (Only applicable for some operations)"},
|
||||||
|
{25, "IntegrityVerificationSeed is waiting on servers to be synced into "
|
||||||
|
"console. Can't processed with online services without sync being "
|
||||||
|
"completed first over IPC request."},
|
||||||
|
{26, "Unavailable/unaccessable IntegrityVerificationSeed on Nintendo "
|
||||||
|
"servers. May happen if NIM is told to import "
|
||||||
|
"IntegrityVerificationSeed from servers at any time other than after "
|
||||||
|
"the successful System Transfer reboot."},
|
||||||
|
{27, "Invalid country language code returned by CFG module reading config "
|
||||||
|
"save 0xA0002."},
|
||||||
|
{37, "Service is in Standby Mode. (eShop ban? General service is down? "
|
||||||
|
"This caused by a server response flag on account information. "
|
||||||
|
"Account is not referring to NNID.)"},
|
||||||
|
{39, "HTTP Status non 200. (Only applicable for some operations)"},
|
||||||
|
{40, "General XML read/write error while processing Auto Delivery XMLs."},
|
||||||
|
{41, "General XML read/write error while processing Auto Delivery XMLs. "
|
||||||
|
"(Stubbed virtual call was called)"},
|
||||||
|
{58,
|
||||||
|
"Invalid NPNS token returned by CFG module reading config save 0xF0006."},
|
||||||
|
{67, "HTTP Status 404 while trying to download a game's seed."},
|
||||||
|
{68, "HTTP Status 503 while trying to download a game's seed."},
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::map<int, std::string> descmvd = {
|
||||||
|
{271, "Invalid configuration."},
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::map<int, std::string> descqtm = {
|
||||||
|
{8, "Camera is already in use or busy."},
|
||||||
|
};
|
||||||
|
|
||||||
|
//Need to Fix The Range based Values
|
||||||
|
static std::map<int, std::string> descapplication = {
|
||||||
|
{0, "The application raised an error. Please consult the application's "
|
||||||
|
"source code or ask the author for assistance with it."},
|
||||||
|
{1024, "0x01"},
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
void ResultDecoder::Load(Result rescode) { this->m_rescode = rescode; }
|
||||||
|
void ResultDecoder::Load(std::string rescode) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << rescode;
|
||||||
|
ss >> std::hex >> this->m_rescode;
|
||||||
|
}
|
||||||
|
std::string RenderD7::ResultDecoder::GetCode() {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::hex << m_rescode;
|
||||||
|
std::string reshex(ss.str());
|
||||||
|
return reshex;
|
||||||
|
}
|
||||||
|
std::string ResultDecoder::GetLevel() {
|
||||||
|
std::string res = levels.at(this->GetLevelInt()) + " (" +
|
||||||
|
std::to_string(this->GetLevelInt()) + ")";
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
int ResultDecoder::GetLevelInt() { return R_LEVEL(m_rescode); }
|
||||||
|
std::string ResultDecoder::GetModule() {
|
||||||
|
std::string res = modules.at(this->GetModuleInt()) + " (" +
|
||||||
|
std::to_string(this->GetModuleInt()) + ")";
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
int ResultDecoder::GetModuleInt() { return R_MODULE(m_rescode); }
|
||||||
|
std::string ResultDecoder::GetDescription() {
|
||||||
|
std::string res = "Desc Not Implemented!";
|
||||||
|
switch (this->GetModuleInt()) {
|
||||||
|
case 0:
|
||||||
|
res = desccommon.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if ((desckernel.find(this->GetDescriptionInt()) == desckernel.end())) {
|
||||||
|
res = desccommon.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
} else {
|
||||||
|
res = desckernel.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
if ((descos.find(this->GetDescriptionInt()) == descos.end())) {
|
||||||
|
res = desccommon.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
} else {
|
||||||
|
res = descos.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 17:
|
||||||
|
if ((descfs.find(this->GetDescriptionInt()) == descfs.end())) {
|
||||||
|
res = desccommon.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
} else {
|
||||||
|
res = descfs.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 25:
|
||||||
|
if ((descsrv.find(this->GetDescriptionInt()) == descsrv.end())) {
|
||||||
|
res = desccommon.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
} else {
|
||||||
|
res = descsrv.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 27:
|
||||||
|
if ((descnwm.find(this->GetDescriptionInt()) == descnwm.end())) {
|
||||||
|
res = desccommon.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
} else {
|
||||||
|
res = descnwm.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 32:
|
||||||
|
if ((descam.find(this->GetDescriptionInt()) == descam.end())) {
|
||||||
|
res = desccommon.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
} else {
|
||||||
|
res = descam.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 40:
|
||||||
|
if ((deschttp.find(this->GetDescriptionInt()) == deschttp.end())) {
|
||||||
|
res = desccommon.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
} else {
|
||||||
|
res = deschttp.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 52:
|
||||||
|
if ((descnim.find(this->GetDescriptionInt()) == descnim.end())) {
|
||||||
|
res = desccommon.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
} else {
|
||||||
|
res = descnim.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 92:
|
||||||
|
if ((descmvd.find(this->GetDescriptionInt()) == descmvd.end())) {
|
||||||
|
res = desccommon.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
} else {
|
||||||
|
res = descmvd.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 96:
|
||||||
|
if ((descqtm.find(this->GetDescriptionInt()) == descqtm.end())) {
|
||||||
|
res = desccommon.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
} else {
|
||||||
|
res = descqtm.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 254:
|
||||||
|
if ((descapplication.find(this->GetDescriptionInt()) ==
|
||||||
|
descapplication.end())) {
|
||||||
|
res = desccommon.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
} else {
|
||||||
|
res = descapplication.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
res = desccommon.at(this->GetDescriptionInt()) + " (" +
|
||||||
|
std::to_string(this->GetDescriptionInt()) + ")";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
int ResultDecoder::GetDescriptionInt() { return R_DESCRIPTION(m_rescode); }
|
||||||
|
std::string ResultDecoder::GetSummary() {
|
||||||
|
std::string res = summaries.at(this->GetSummaryInt()) + " (" +
|
||||||
|
std::to_string(this->GetSummaryInt()) + ")";
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ResultDecoder::GetSummaryInt() { return R_SUMMARY(m_rescode); }
|
||||||
|
} // namespace RenderD7
|
8
source/Screen.cpp
Normal file
8
source/Screen.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include <renderd7/Screen.hpp>
|
||||||
|
|
||||||
|
extern bool currentScreen;
|
||||||
|
|
||||||
|
void RenderD7::OnScreen(C3D_RenderTarget *target) {
|
||||||
|
C2D_SceneBegin(target);
|
||||||
|
currentScreen = (target == Top || target == TopRight) ? 1 : 0;
|
||||||
|
}
|
15
source/Sheet.cpp
Normal file
15
source/Sheet.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <renderd7/Sheet.hpp>
|
||||||
|
|
||||||
|
RenderD7::Sheet::Sheet() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
RenderD7::Sheet::~Sheet() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
Result RenderD7::Sheet::Load(const char *path) {
|
||||||
|
this->spritesheet = C2D_SpriteSheetLoad(path);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::Sheet::Free() { C2D_SpriteSheetFree(this->spritesheet); }
|
36
source/Sprite.cpp
Normal file
36
source/Sprite.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include <renderd7/Sprite.hpp>
|
||||||
|
|
||||||
|
RenderD7::Sprite::Sprite() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
RenderD7::Sprite::~Sprite() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
void RenderD7::Sprite::FromSheet(RenderD7::Sheet *sheet, size_t index) {
|
||||||
|
C2D_SpriteFromSheet(&this->sprite, sheet->spritesheet, index);
|
||||||
|
}
|
||||||
|
bool RenderD7::Sprite::Draw() { return C2D_DrawSprite(&this->sprite); }
|
||||||
|
void RenderD7::Sprite::SetCenter(float x, float y) {
|
||||||
|
C2D_SpriteSetCenter(&this->sprite, x, y);
|
||||||
|
}
|
||||||
|
void RenderD7::Sprite::SetPos(float x, float y) {
|
||||||
|
C2D_SpriteSetPos(&this->sprite, x, y);
|
||||||
|
}
|
||||||
|
void RenderD7::Sprite::SetRotation(float rotation) {
|
||||||
|
C2D_SpriteSetRotation(&this->sprite, rotation);
|
||||||
|
}
|
||||||
|
void RenderD7::Sprite::Rotate(float speed) {
|
||||||
|
C2D_SpriteRotateDegrees(&this->sprite, speed);
|
||||||
|
}
|
||||||
|
float RenderD7::Sprite::getHeigh() { return this->sprite.params.pos.h; }
|
||||||
|
float RenderD7::Sprite::getWidth() { return this->sprite.params.pos.w; }
|
||||||
|
float RenderD7::Sprite::getPosX() { return this->sprite.params.pos.x; }
|
||||||
|
float RenderD7::Sprite::getPosY() { return this->sprite.params.pos.y; }
|
||||||
|
|
||||||
|
void RenderD7::Sprite::FromImage(RenderD7::Image *img) {
|
||||||
|
C2D_SpriteFromImage(&this->sprite, img->img);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::Sprite::SetScale(float x, float y) {
|
||||||
|
C2D_SpriteScale(&this->sprite, x, y);
|
||||||
|
}
|
38
source/SpriteSheetAnimation.cpp
Normal file
38
source/SpriteSheetAnimation.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <renderd7/SpriteAnimation.hpp>
|
||||||
|
#include <renderd7/log.hpp>
|
||||||
|
|
||||||
|
extern Log renderd7log;
|
||||||
|
|
||||||
|
RenderD7::SpriteSheetAnimation::SpriteSheetAnimation() {
|
||||||
|
renderd7log.Write("SpriteSheetAnimation createt!");
|
||||||
|
}
|
||||||
|
RenderD7::SpriteSheetAnimation::~SpriteSheetAnimation() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::SpriteSheetAnimation::Setup(RenderD7::Sheet *sheet,
|
||||||
|
size_t imagecount, size_t startimage,
|
||||||
|
float frame_begin,
|
||||||
|
float frame_finish) {
|
||||||
|
D_totaltime = frame_begin;
|
||||||
|
renderd7log.Write("frame_begin success");
|
||||||
|
this->images = imagecount;
|
||||||
|
renderd7log.Write("imagecount success");
|
||||||
|
this->sheet = sheet;
|
||||||
|
renderd7log.Write("sheet success");
|
||||||
|
this->time = frame_finish;
|
||||||
|
renderd7log.Write("frame_finish success");
|
||||||
|
RenderD7::SpriteSheetAnimation::FromSheet(this->sheet, startimage);
|
||||||
|
}
|
||||||
|
void RenderD7::SpriteSheetAnimation::Play(float timespeed) {
|
||||||
|
D_totaltime += timespeed;
|
||||||
|
if (D_totaltime >= time) {
|
||||||
|
D_totaltime -= time;
|
||||||
|
imgs++;
|
||||||
|
if (imgs == images) {
|
||||||
|
imgs = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RenderD7::SpriteSheetAnimation::FromSheet(sheet, imgs);
|
||||||
|
// RenderD7::SpriteSheetAnimation::Draw();
|
||||||
|
}
|
24
source/StealConsole.cpp
Normal file
24
source/StealConsole.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <renderd7/StealConsole.hpp>
|
||||||
|
|
||||||
|
namespace RenderD7 {
|
||||||
|
StealConsole::StealConsole() {
|
||||||
|
std::streambuf *old = std::cout.rdbuf(this->stolen_stdout.rdbuf());
|
||||||
|
if (old) {
|
||||||
|
// To prevent from unused error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StealConsole::~StealConsole() {
|
||||||
|
// Do Nothing Here
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StealConsole::GetStdout() {
|
||||||
|
if (this->stolen_stdout.str().length() < 400) {
|
||||||
|
return this->stolen_stdout.str();
|
||||||
|
} else {
|
||||||
|
return this->stolen_stdout.str().substr(stolen_stdout.str().length() - 400);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
} // namespace RenderD7
|
22
source/Tasks.cpp
Normal file
22
source/Tasks.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include <renderd7/Tasks.hpp>
|
||||||
|
|
||||||
|
#include <3ds.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static std::vector<Thread> threads;
|
||||||
|
|
||||||
|
void Tasks::create(ThreadFunc entrypoint) {
|
||||||
|
s32 prio = 0;
|
||||||
|
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||||
|
Thread thread = threadCreate((ThreadFunc)entrypoint, NULL, 64 * 1024,
|
||||||
|
prio - 1, -2, false);
|
||||||
|
threads.push_back(thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tasks::destroy(void) {
|
||||||
|
for (u32 i = 0; i < threads.size(); i++) {
|
||||||
|
threadJoin(threads.at(i), U64_MAX);
|
||||||
|
threadFree(threads.at(i));
|
||||||
|
}
|
||||||
|
}
|
30
source/Time.cpp
Normal file
30
source/Time.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include <fstream>
|
||||||
|
#include <memory>
|
||||||
|
#include <renderd7/Time.hpp>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <string>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
std::string RenderD7::FormatString(std::string fmt_str, ...) {
|
||||||
|
va_list ap;
|
||||||
|
char *fp = NULL;
|
||||||
|
va_start(ap, fmt_str);
|
||||||
|
vasprintf(&fp, fmt_str.c_str(), ap);
|
||||||
|
va_end(ap);
|
||||||
|
std::unique_ptr<char, decltype(free) *> formatted(fp, free);
|
||||||
|
return std::string(formatted.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string RenderD7::GetTimeStr(void) {
|
||||||
|
time_t unixTime;
|
||||||
|
struct tm timeStruct;
|
||||||
|
time(&unixTime);
|
||||||
|
localtime_r(&unixTime, &timeStruct);
|
||||||
|
return FormatString("%04i-%02i-%02i_%02i-%02i-%02i",
|
||||||
|
timeStruct.tm_year + 1900, timeStruct.tm_mon + 1,
|
||||||
|
timeStruct.tm_mday, timeStruct.tm_hour, timeStruct.tm_min,
|
||||||
|
timeStruct.tm_sec);
|
||||||
|
}
|
38
source/Toast.cpp
Normal file
38
source/Toast.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <renderd7/Draw.hpp>
|
||||||
|
#include <renderd7/Toast.hpp>
|
||||||
|
|
||||||
|
RenderD7::Toast::Toast(std::string head, std::string msg) {
|
||||||
|
this->head = head;
|
||||||
|
this->msg = msg;
|
||||||
|
/*this->toast = RenderD7::BitmapPrinter(400, 70);
|
||||||
|
this->toast.ClearBlank();
|
||||||
|
this->toast.DrawRectFilled(0, 0, 400, 70, 40, 40, 40, 255);
|
||||||
|
this->toast.DrawRectFilled(0, 0, 400, 25, 70, 70, 70, 255);
|
||||||
|
this->toast.DrawDebugText(4, 5, 0, RenderD7::Color::Hex("#ffffff"),
|
||||||
|
this->head); this->toast.DrawDebugText(4, 40, 0,
|
||||||
|
RenderD7::Color::Hex("#ffffff"), this->msg);
|
||||||
|
this->toastrendered->LoadPFromBuffer(BitmapConverter::ConvertData(toast.GetBitmap().DATA()));*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::Toast::Draw(void) const {
|
||||||
|
RenderD7::OnScreen(Top);
|
||||||
|
RenderD7::Draw::Rect(0, msgposy, 400, 70, RenderD7::Color::Hex("#111111"));
|
||||||
|
RenderD7::Draw::Rect(0, msgposy, 400, 25, RenderD7::Color::Hex("#222222"));
|
||||||
|
RenderD7::Draw::Text(2, msgposy + 3, 0.7f, RenderD7::Color::Hex("#ffffff"),
|
||||||
|
head);
|
||||||
|
RenderD7::Draw::Text(2, msgposy + 30, 0.6f, RenderD7::Color::Hex("#ffffff"),
|
||||||
|
msg);
|
||||||
|
// toastrendered->Draw(0, msgposy);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::Toast::Logic() {
|
||||||
|
this->delay++ /*=1*(int)RenderD7::GetDeltaTime()*/;
|
||||||
|
if (msgposy > 170 && delay < 2 * 60)
|
||||||
|
msgposy-- /*=(int)RenderD7::GetDeltaTime()*/;
|
||||||
|
|
||||||
|
if (delay >= 5 * 60) {
|
||||||
|
msgposy++ /*=(int)RenderD7::GetDeltaTime*/;
|
||||||
|
if (msgposy > 400)
|
||||||
|
this->Kill();
|
||||||
|
}
|
||||||
|
}
|
110
source/bmpconverter.cpp
Normal file
110
source/bmpconverter.cpp
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
#include <renderd7/bmpconverter.hpp>
|
||||||
|
|
||||||
|
namespace BitmapConverter {
|
||||||
|
|
||||||
|
// returns 0 if all went ok, non-0 if error
|
||||||
|
// output image is always given in RGBA (with alpha channel), even if it's a BMP
|
||||||
|
// without alpha channel
|
||||||
|
unsigned decodeBMP(std::vector<unsigned char> &image, unsigned &w, unsigned &h,
|
||||||
|
const std::vector<unsigned char> &bmp) {
|
||||||
|
static const unsigned MINHEADER = 54; // minimum BMP header size
|
||||||
|
|
||||||
|
if (bmp.size() < MINHEADER)
|
||||||
|
return -1;
|
||||||
|
if (bmp[0] != 'B' || bmp[1] != 'M')
|
||||||
|
return 1; // It's not a BMP file if it doesn't start with marker 'BM'
|
||||||
|
unsigned pixeloffset = bmp[10] + 256 * bmp[11]; // where the pixel data starts
|
||||||
|
// read width and height from BMP header
|
||||||
|
w = bmp[18] + bmp[19] * 256;
|
||||||
|
h = bmp[22] + bmp[23] * 256;
|
||||||
|
// read number of channels from BMP header
|
||||||
|
if (bmp[28] != 24 && bmp[28] != 32)
|
||||||
|
return 2; // only 24-bit and 32-bit BMPs are supported.
|
||||||
|
unsigned numChannels = bmp[28] / 8;
|
||||||
|
|
||||||
|
// The amount of scanline bytes is width of image times channels, with extra
|
||||||
|
// bytes added if needed to make it a multiple of 4 bytes.
|
||||||
|
unsigned scanlineBytes = w * numChannels;
|
||||||
|
if (scanlineBytes % 4 != 0)
|
||||||
|
scanlineBytes = (scanlineBytes / 4) * 4 + 4;
|
||||||
|
|
||||||
|
unsigned dataSize = scanlineBytes * h;
|
||||||
|
if (bmp.size() < dataSize + pixeloffset)
|
||||||
|
return 3; // BMP file too small to contain all pixels
|
||||||
|
|
||||||
|
image.resize(w * h * 4);
|
||||||
|
|
||||||
|
/*
|
||||||
|
There are 3 differences between BMP and the raw image buffer for LodePNG:
|
||||||
|
-it's upside down
|
||||||
|
-it's in BGR instead of RGB format (or BRGA instead of RGBA)
|
||||||
|
-each scanline has padding bytes to make it a multiple of 4 if needed
|
||||||
|
The 2D for loop below does all these 3 conversions at once.
|
||||||
|
*/
|
||||||
|
for (unsigned y = 0; y < h; y++)
|
||||||
|
for (unsigned x = 0; x < w; x++) {
|
||||||
|
// pixel start byte position in the BMP
|
||||||
|
unsigned bmpos =
|
||||||
|
pixeloffset + (h - y - 1) * scanlineBytes + numChannels * x;
|
||||||
|
// pixel start byte position in the new raw image
|
||||||
|
unsigned newpos = 4 * y * w + 4 * x;
|
||||||
|
if (numChannels == 3) {
|
||||||
|
image[newpos + 0] = bmp[bmpos + 2]; // R
|
||||||
|
image[newpos + 1] = bmp[bmpos + 1]; // G
|
||||||
|
image[newpos + 2] = bmp[bmpos + 0]; // B
|
||||||
|
image[newpos + 3] = 255; // A
|
||||||
|
} else {
|
||||||
|
image[newpos + 0] = bmp[bmpos + 2]; // R
|
||||||
|
image[newpos + 1] = bmp[bmpos + 1]; // G
|
||||||
|
image[newpos + 2] = bmp[bmpos + 0]; // B
|
||||||
|
image[newpos + 3] = bmp[bmpos + 3]; // A
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned char> ConvertFile(std::string filename) {
|
||||||
|
|
||||||
|
std::vector<unsigned char> bmp;
|
||||||
|
lodepng::load_file(bmp, filename);
|
||||||
|
|
||||||
|
std::vector<unsigned char> image;
|
||||||
|
unsigned w, h;
|
||||||
|
unsigned error = BitmapConverter::decodeBMP(image, w, h, bmp);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
std::cout << "BMP decoding error " << error << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned char> png;
|
||||||
|
error = lodepng::encode(png, image, w, h);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
std::cout << "PNG encoding error " << error << ": "
|
||||||
|
<< lodepng_error_text(error) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return png;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned char> ConvertData(std::vector<unsigned char> data) {
|
||||||
|
|
||||||
|
std::vector<unsigned char> image;
|
||||||
|
unsigned w, h;
|
||||||
|
unsigned error = BitmapConverter::decodeBMP(image, w, h, data);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
std::cout << "BMP decoding error " << error << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned char> png;
|
||||||
|
error = lodepng::encode(png, image, w, h);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
std::cout << "PNG encoding error " << error << ": "
|
||||||
|
<< lodepng_error_text(error) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return png;
|
||||||
|
}
|
||||||
|
} // namespace BitmapConverter
|
97
source/lang.cpp
Normal file
97
source/lang.cpp
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
#include <3ds.h>
|
||||||
|
#include <renderd7/lang.hpp>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
static nlohmann::json appJson;
|
||||||
|
|
||||||
|
std::string RenderD7::Lang::getSys() {
|
||||||
|
|
||||||
|
u8 language = 1;
|
||||||
|
CFGU_GetSystemLanguage(&language);
|
||||||
|
|
||||||
|
switch (language) {
|
||||||
|
case 0:
|
||||||
|
return "jp"; // Japanese
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
return "en"; // English
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
return "fr"; // French
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
return "de"; // German
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
return "it"; // Italian
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
return "es"; // Spanish
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
return "zh-CN"; // Chinese (Simplified)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// case 7:
|
||||||
|
// return "ko"; // Korean
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// case 8:
|
||||||
|
// return "nl"; // Dutch
|
||||||
|
// break;
|
||||||
|
|
||||||
|
case 9:
|
||||||
|
return "pt"; // Portuguese
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 10:
|
||||||
|
return "ru"; // Russian
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 11:
|
||||||
|
return "zh-TW"; // Chinese (Traditional)
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "en"; // Fall back to English if missing
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::string RenderD7::Lang::get(const std::string &key) {
|
||||||
|
if (!appJson.contains(key))
|
||||||
|
return key;
|
||||||
|
|
||||||
|
return appJson.at(key).get_ref<const std::string &>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderD7::Lang::load(const std::string &lang) {
|
||||||
|
FILE *values;
|
||||||
|
|
||||||
|
if (access(("romfs:/lang/" + lang + "/app.json").c_str(), F_OK) == 0) {
|
||||||
|
values = fopen(("romfs:/lang/" + lang + "/app.json").c_str(), "rt");
|
||||||
|
if (values) {
|
||||||
|
appJson = nlohmann::json::parse(values, nullptr, false);
|
||||||
|
fclose(values);
|
||||||
|
}
|
||||||
|
if (appJson.is_discarded())
|
||||||
|
appJson = {};
|
||||||
|
return;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
values = fopen("romfs:/lang/en/app.json", "rt");
|
||||||
|
if (values) {
|
||||||
|
appJson = nlohmann::json::parse(values, nullptr, false);
|
||||||
|
fclose(values);
|
||||||
|
}
|
||||||
|
if (appJson.is_discarded())
|
||||||
|
appJson = {};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
51
source/log.cpp
Normal file
51
source/log.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include <renderd7/log.hpp>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
std::string Log::format(const std::string &fmt_str, ...) {
|
||||||
|
va_list ap;
|
||||||
|
char *fp = NULL;
|
||||||
|
va_start(ap, fmt_str);
|
||||||
|
vasprintf(&fp, fmt_str.c_str(), ap);
|
||||||
|
va_end(ap);
|
||||||
|
std::unique_ptr<char, decltype(free) *> formatted(fp, free);
|
||||||
|
return std::string(formatted.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Log::logDate(void) {
|
||||||
|
time_t unixTime;
|
||||||
|
struct tm timeStruct;
|
||||||
|
time(&unixTime);
|
||||||
|
localtime_r(&unixTime, &timeStruct);
|
||||||
|
return format("%04i-%02i-%02i_%02i-%02i-%02i", timeStruct.tm_year + 1900,
|
||||||
|
timeStruct.tm_mon + 1, timeStruct.tm_mday, timeStruct.tm_hour,
|
||||||
|
timeStruct.tm_min, timeStruct.tm_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::Log() {}
|
||||||
|
|
||||||
|
void Log::Init(const char *filename) {
|
||||||
|
printf("%s\n", filename);
|
||||||
|
std::string fn = filename;
|
||||||
|
std::string name = fn + ".txt";
|
||||||
|
this->filename = name.c_str();
|
||||||
|
if ((access(name.c_str(), F_OK) == 0)) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
FILE *logfile = fopen((name.c_str()), "w");
|
||||||
|
fclose(logfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Log::Write(std::string debug_text) {
|
||||||
|
printf("%s\n", debug_text.c_str());
|
||||||
|
std::ofstream logFile;
|
||||||
|
logFile.open((this->filename), std::ofstream::app);
|
||||||
|
std::string writeDebug = "[";
|
||||||
|
writeDebug += logDate();
|
||||||
|
writeDebug += "] ";
|
||||||
|
writeDebug += debug_text.c_str();
|
||||||
|
logFile << writeDebug << std::endl;
|
||||||
|
logFile.close();
|
||||||
|
}
|
||||||
|
Log::~Log() {}
|
1030
source/renderd7.cpp
Normal file
1030
source/renderd7.cpp
Normal file
File diff suppressed because it is too large
Load Diff
134
source/sound.cpp
Normal file
134
source/sound.cpp
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
#include <renderd7/sound.hpp>
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
extern bool isndspinit;
|
||||||
|
using std::string;
|
||||||
|
|
||||||
|
// Reference: http://yannesposito.com/Scratch/en/blog/2010-10-14-Fun-with-wav/
|
||||||
|
typedef struct _WavHeader {
|
||||||
|
char magic[4]; // "RIFF"
|
||||||
|
u32 totallength; // Total file length, minus 8.
|
||||||
|
char wavefmt[8]; // Should be "WAVEfmt "
|
||||||
|
u32 format; // 16 for PCM format
|
||||||
|
u16 pcm; // 1 for PCM format
|
||||||
|
u16 channels; // Channels
|
||||||
|
u32 frequency; // Sampling frequency
|
||||||
|
u32 bytes_per_second;
|
||||||
|
u16 bytes_by_capture;
|
||||||
|
u16 bits_per_sample;
|
||||||
|
char data[4]; // "data"
|
||||||
|
u32 bytes_in_data;
|
||||||
|
} WavHeader;
|
||||||
|
static_assert(sizeof(WavHeader) == 44, "WavHeader size is not 44 bytes.");
|
||||||
|
|
||||||
|
sound::sound(const string &path, int channel, bool toloop) {
|
||||||
|
if (isndspinit) {
|
||||||
|
ndspSetOutputMode(NDSP_OUTPUT_STEREO);
|
||||||
|
ndspSetOutputCount(2); // Num of buffers
|
||||||
|
|
||||||
|
// Reading wav file
|
||||||
|
FILE *fp = fopen(path.c_str(), "rb");
|
||||||
|
|
||||||
|
if (!fp) {
|
||||||
|
printf("Could not open the WAV file: %s\n", path.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WavHeader wavHeader;
|
||||||
|
size_t read = fread(&wavHeader, 1, sizeof(wavHeader), fp);
|
||||||
|
if (read != sizeof(wavHeader)) {
|
||||||
|
// Short read.
|
||||||
|
printf("WAV file header is too short: %s\n", path.c_str());
|
||||||
|
fclose(fp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify the header.
|
||||||
|
static const char RIFF_magic[4] = {'R', 'I', 'F', 'F'};
|
||||||
|
if (memcmp(wavHeader.magic, RIFF_magic, sizeof(wavHeader.magic)) != 0) {
|
||||||
|
// Incorrect magic number.
|
||||||
|
printf("Wrong file format.\n");
|
||||||
|
fclose(fp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wavHeader.totallength == 0 ||
|
||||||
|
(wavHeader.channels != 1 && wavHeader.channels != 2) ||
|
||||||
|
(wavHeader.bits_per_sample != 8 && wavHeader.bits_per_sample != 16)) {
|
||||||
|
// Unsupported WAV file.
|
||||||
|
printf("Corrupted wav file.\n");
|
||||||
|
fclose(fp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the file size.
|
||||||
|
fseek(fp, 0, SEEK_END);
|
||||||
|
dataSize = ftell(fp) - sizeof(wavHeader);
|
||||||
|
|
||||||
|
// Allocating and reading samples
|
||||||
|
data = static_cast<u8 *>(linearAlloc(dataSize));
|
||||||
|
fseek(fp, 44, SEEK_SET);
|
||||||
|
fread(data, 1, dataSize, fp);
|
||||||
|
fclose(fp);
|
||||||
|
dataSize /= 2; // FIXME: 16-bit or stereo?
|
||||||
|
|
||||||
|
// Find the right format
|
||||||
|
u16 ndspFormat;
|
||||||
|
if (wavHeader.bits_per_sample == 8) {
|
||||||
|
ndspFormat = (wavHeader.channels == 1) ? NDSP_FORMAT_MONO_PCM8
|
||||||
|
: NDSP_FORMAT_STEREO_PCM8;
|
||||||
|
} else {
|
||||||
|
ndspFormat = (wavHeader.channels == 1) ? NDSP_FORMAT_MONO_PCM16
|
||||||
|
: NDSP_FORMAT_STEREO_PCM16;
|
||||||
|
}
|
||||||
|
|
||||||
|
ndspChnReset(channel);
|
||||||
|
ndspChnSetInterp(channel, NDSP_INTERP_NONE);
|
||||||
|
ndspChnSetRate(channel, float(wavHeader.frequency));
|
||||||
|
ndspChnSetFormat(channel, ndspFormat);
|
||||||
|
|
||||||
|
// Create and play a wav buffer
|
||||||
|
memset(&waveBuf, 0, sizeof(waveBuf));
|
||||||
|
|
||||||
|
waveBuf.data_vaddr = reinterpret_cast<u32 *>(data);
|
||||||
|
waveBuf.nsamples = dataSize / (wavHeader.bits_per_sample >> 3);
|
||||||
|
waveBuf.looping = toloop;
|
||||||
|
waveBuf.status = NDSP_WBUF_FREE;
|
||||||
|
chnl = channel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sound::~sound() {
|
||||||
|
if (isndspinit) {
|
||||||
|
waveBuf.data_vaddr = 0;
|
||||||
|
waveBuf.nsamples = 0;
|
||||||
|
waveBuf.looping = false;
|
||||||
|
waveBuf.status = 0;
|
||||||
|
ndspChnWaveBufClear(chnl);
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
linearFree(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sound::play() {
|
||||||
|
if (isndspinit) {
|
||||||
|
if (!data)
|
||||||
|
return;
|
||||||
|
DSP_FlushDataCache(data, dataSize);
|
||||||
|
ndspChnWaveBufAdd(chnl, &waveBuf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sound::stop() {
|
||||||
|
if (isndspinit) {
|
||||||
|
if (!data)
|
||||||
|
return;
|
||||||
|
ndspChnWaveBufClear(chnl);
|
||||||
|
}
|
||||||
|
}
|
2
source/stb.cpp
Normal file
2
source/stb.cpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#include <renderd7/external/stb_image.h>
|
79
source/thread.cpp
Normal file
79
source/thread.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include <renderd7/thread.hpp>
|
||||||
|
namespace RenderD7 {
|
||||||
|
void Threads::Exit() {}
|
||||||
|
Thread::Thread() : m_started(false), m_running(false) { /* do nothing */
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread::Thread(std::function<void(RenderD7::Parameter)> t_function,
|
||||||
|
RenderD7::Parameter t_parameter, bool t_autostart,
|
||||||
|
bool t_detached, unsigned long long int t_stackSize)
|
||||||
|
: m_started(false), m_running(false) {
|
||||||
|
initialize(t_function, t_parameter, t_autostart, t_detached, t_stackSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread::~Thread() {
|
||||||
|
join();
|
||||||
|
|
||||||
|
if (m_started)
|
||||||
|
threadFree(m_thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thread::initialize(std::function<void(RenderD7::Parameter)> t_function,
|
||||||
|
RenderD7::Parameter t_parameter, bool t_autostart,
|
||||||
|
bool t_detached, unsigned long long int t_stackSize) {
|
||||||
|
m_stackSize = t_stackSize;
|
||||||
|
m_data.m_parameter = t_parameter;
|
||||||
|
m_data.m_function = t_function;
|
||||||
|
m_data.m_running = &m_running;
|
||||||
|
|
||||||
|
if (t_autostart) {
|
||||||
|
start(t_detached);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thread::setStackSize(unsigned long long int t_stackSize) {
|
||||||
|
m_stackSize = t_stackSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thread::start(bool t_detached) {
|
||||||
|
if (!m_running) {
|
||||||
|
m_started = true;
|
||||||
|
m_running = true;
|
||||||
|
s32 prio;
|
||||||
|
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||||
|
m_thread = threadCreate(threadFunction, &m_data, m_stackSize, prio + 1, -2,
|
||||||
|
t_detached);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thread::kill() {
|
||||||
|
threadDetach(m_thread);
|
||||||
|
m_running = false;
|
||||||
|
m_started = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thread::join(long long unsigned int t_timeout) {
|
||||||
|
if (m_running) {
|
||||||
|
threadJoin(m_thread, t_timeout);
|
||||||
|
threadFree(m_thread);
|
||||||
|
m_running = false;
|
||||||
|
m_started = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Thread::isRunning() { return m_running; }
|
||||||
|
|
||||||
|
void Thread::sleep() { svcSleepThread(0); }
|
||||||
|
|
||||||
|
void Thread::sleep(int t_milliseconds) {
|
||||||
|
svcSleepThread(1000000 * t_milliseconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
// private methods
|
||||||
|
void Thread::threadFunction(void *arg) {
|
||||||
|
RenderD7::Thread::ThreadData data =
|
||||||
|
*static_cast<RenderD7::Thread::ThreadData *>(arg);
|
||||||
|
data.m_function(data.m_parameter);
|
||||||
|
*data.m_running = false;
|
||||||
|
}
|
||||||
|
} // namespace RenderD7
|
11
tools/rd7cc/source/main.cpp
Normal file
11
tools/rd7cc/source/main.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//rd7cc
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
std::ofstream result ("result.hpp");
|
||||||
|
|
||||||
|
result << "//Result" << std::endl;
|
||||||
|
|
||||||
|
result.close();
|
||||||
|
}
|
Reference in New Issue
Block a user