Compare commits

...
Sign in to create a new pull request.

22 commits
main ... dev

Author SHA1 Message Date
zy
2514d4da7b save 2024-12-29 19:25:51 +01:00
Zy
dd4edcd397 s 2024-10-13 23:55:21 +02:00
Zy
8876fa7939 dev: add TODO 2024-10-13 19:44:05 +02:00
Zy
cca1adca0c part: add mlx_hook.h functions 2024-10-13 19:38:36 +02:00
Zy
a93af5c48f dev: norm 2024-10-12 22:33:06 +02:00
Zy
1c023df1ff dev: clean xpm files from the original minilibx *
- rename the source files of the original minilibx to xpm_*.*
- make the changes between the original files as minimal as possible
2024-10-12 22:22:58 +02:00
Zy
6592ec43fd dev: add -Wextra in Makefile and clean warnings 2024-10-12 19:48:10 +02:00
Zy
9264c47494 part: implement mlx_xpm_file_to_image() 2024-10-12 19:42:46 +02:00
Zy
8649e86eaa part: implement mlx3ds_assets_open/read/close() 2024-10-12 15:52:49 +02:00
Zy
3f5e13b2f2 dev: utilsconsole: merge c and cpp files 2024-10-12 15:52:45 +02:00
Zy
236cb9a780 fix: embedassets.sh for big files 2024-10-12 15:19:05 +02:00
Zy
ee94d85a8c dev: fix 'navigate' tester 2024-10-11 23:12:55 +02:00
Zy
898162121d dev: clean docs and everything, add TODOs 2024-10-11 23:12:23 +02:00
Zy
8fdc653722 docs: mlx3ds.h and mlx3ds_embeddedassets.h 2024-10-11 19:20:18 +02:00
Zy
d305f831e8 dev: clean some unnecessary things 2024-10-11 19:10:39 +02:00
Zy
09e319024d part: add mlx3ds_assets_get() and file embedding *
TODO: docs
also add tester for sdcard files
2024-10-10 23:25:15 +02:00
Zy
d57afcccc6 part: implement mlx_xpm_to_image() (TODO *)
TODO:
- implement mlx_xpm_file_to_image()
- clean unused mlx files (all in the same file and static)
- norminette
2024-10-08 19:42:01 +02:00
Zy
d82da8811b dev: add uc_pause() for C (not only C++) 2024-10-08 19:41:00 +02:00
Zy
97db58cd33 dev: fix several little things *
- Makefile: remove flags -lcitro2d -lcitro3d
- .gitignore: add /mlx3ds.lst
- mlx_internal.h: header protection + little fix
2024-10-08 19:32:03 +02:00
Zy
13b93106ee part: implement some functions (windows & display)
part:
- remove mlx3ds_3dskey.h, instead use hid.h
- add definitions of:
  - mlx_init()
  - mlx_new_window()
  - mlx_clear_window()
  - mlx_destroy_window()
  - mlx_pixel_put()
  - mlx_new_image()
  - mlx_get_data_addr()
  - mlx_put_image_to_window()
  - mlx_destroy_image()

dev:
- Makefile: add rule check_headers
- Makefile: add variable FLAGS
    (call 'make rule FLAGS=flags'
	to add flags to compilation)
- add /dev/norm.sh: nicer norminette
- add tester in main(), and related utilsconsole.*

docs:
- make clear mlx_get_data_addr() docs
2024-10-06 16:53:59 +02:00
Zy
c7d0dba4fd part: add headers for all mlx 2024-10-05 12:38:41 +02:00
Zy
d606305241 init: dev 2024-10-04 18:21:18 +02:00
41 changed files with 4212 additions and 117 deletions

5
.gitignore vendored
View file

@ -42,3 +42,8 @@ output/
# Debug files
*.dSYM/
# VSCode
/.vscode/
/mlx3ds.lst

View file

@ -1,21 +1 @@
MIT License
Copyright (c) 2017 [Brandon W.]
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
TODO being compatible with licenses from: 3ds-template, minilibx, xpm and devkitpro

View file

@ -1,3 +1,7 @@
# From (where?) (<-- TODO answer)
# Modified by Zy to work with the MinilibX For 3DS project
# (at https://github.com/frzysk/mlx3ds).
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
@ -21,6 +25,7 @@ include $(DEVKITARM)/3ds_rules
# GFXBUILD is the directory where converted graphics files will be placed
# If set to $(BUILD), it will statically link in the converted
# files as if they were data files.
# ASSETS is the directory of assets to embed in the rom (rule for __embeddedassets.o)
#
# NO_SMDH: if set to anything, no SMDH file is generated.
# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional)
@ -43,6 +48,7 @@ OUTPUT := output
RESOURCES := resources
ROMFS := romfs
GFXBUILD := $(ROMFS)/gfx
ASSETS := assets
#---------------------------------------------------------------------------------
# Resource Setup
#---------------------------------------------------------------------------------
@ -56,7 +62,7 @@ RSF := $(TOPDIR)/$(RESOURCES)/template.rsf
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
COMMON := -Wall -O2 -mword-relocations -fomit-frame-pointer -ffunction-sections $(ARCH) $(INCLUDE) -D__3DS__
COMMON := -Wall -Wextra -O2 -mword-relocations -fomit-frame-pointer -ffunction-sections $(ARCH) $(INCLUDE) -D__3DS__ $(FLAGS)
CFLAGS := $(COMMON) -std=gnu99
CXXFLAGS := $(COMMON) -fno-rtti -fno-exceptions -std=gnu++11
ASFLAGS := $(ARCH)
@ -65,7 +71,7 @@ LDFLAGS = -specs=3dsx.specs $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# Libraries needed to link into the executable.
#---------------------------------------------------------------------------------
LIBS := -lcitro2d -lcitro3d -lctru -lm
LIBS := -lctru -lm
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
@ -112,7 +118,7 @@ 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) \
$(if $(filter $(BUILD),$(GFXBUILD)),$(addsuffix .o,$(T3XFILES)))
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) __embeddedassets.o
export HFILES := $(PICAFILES:.v.pica=_shbin.h) $(SHLISTFILES:.shlist=_shbin.h) \
$(addsuffix .h,$(subst .,_,$(BINFILES))) \
$(GFXFILES:.t3s=.h)
@ -343,3 +349,37 @@ endef
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
# Added by Zy
# To check if the headers are protected and if they include everything they need.
check_headers :
@ERROR=0; \
for HEADER in $(wildcard *.h) $(wildcard **/*.h) $(wildcard *.hpp) $(wildcard **/*.hpp); \
do \
echo "check header $$HEADER..."; \
> __tmp_check_header.cpp echo "#include \"$$HEADER\""; \
>> __tmp_check_header.cpp echo "#include \"$$HEADER\""; \
>> __tmp_check_header.cpp echo "int main(void) {}"; \
$(CPP) $(INCLUDE) $(COMMON) $(LIBS) -o __tmp_check_header.out -c __tmp_check_header.cpp; \
if [ $$? -ne 0 ]; \
then \
ERROR=1; \
/bin/echo " ### error :( ###"; \
else \
/bin/echo " ### good :) ###"; \
fi; \
2> /dev/null rm -- "__tmp_check_header.out" "__tmp_check_header.c"; \
done; \
if [ $$ERROR -eq 0 ]; then true; else false; fi;
.PHONY : check_headers
# Added by Zy
# To embed assets in the rom.
__embeddedassets.o : $(shell find $(TOPDIR)/$(ASSETS)/ -type f)
$(TOPDIR)/embedassets.sh $(TOPDIR)/$(ASSETS)/ $^
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ __embeddedassets.c
.PHONY : __embeddedassets.o

View file

@ -1,69 +1 @@
# 3ds-template
A starter template for various 3DS homebrew applications. This template is geared specifically towards the Code::Blocks IDE. This template can also be used without Code::Blocks just use the `Makefile` and directory structure provided.
This is designed to be a simple and fairly minimal setup required to begin developing homebrew for the 3ds system. As such it doesn't include everything needed to build everything out of the box if you want to build 3ds or cia homebrew.
## Usage
| Targets | Action |
| ------------| ----------------------------------------------------------------------------------------- |
| 3ds | Builds `<project name>.3ds`. <sup>1</sup>
| 3dsx | Builds `<project name>.3dsx` and `<project name>.smdh`.
| cia | Builds `<project name>.cia`. <sup>1</sup>
| citra | Builds and automatically runs `citra` for testing.<sup>2</sup>
| elf | Builds `<project name>.elf`.
| release | Release build, creates a `cia`, `3ds`, and a zip file containing the `smdh` and `3dsx`. <sup>3</sup>
**Notes:**
* <sup>1</sup> This requires having [makerom] and [bannertool] in your `$PATH`
* <sup>2</sup> `make citra` requires having [citra] installed and in your `$PATH`
* <sup>3</sup> If you are on Windows you will need both of the following in your `$PATH` [zip] and [libbz2.dll]
## Setting up devkitPro
* Follow the steps installing devkitPro at the gbatemp [wiki]
### If you want to build cia and 3ds then follow these extra steps:
* Aquire makerom and bannertool binaries from [buildtools], or compile them yourself from [makerom] and [bannertool]
* Copy the makerom/bannertool to `$DEVKITARM/bin` or some other directory in your `$PATH`
## Code::Blocks Setup
1. Simply open `3ds.cbp` in Code::Blocks
2. Choose File > Save as user-template and enter a template name. The project setup is now a user template to create new projects.
3. When creating a new project select File > New > From template and follow the wizard's instructions.
4. Ensure you have the environment variables plugin installed (in linux you can install this by installing the codeblocks-contrib package)
5. Choose Settings > Environment and scroll down to the Environment Variables section.
6. Add `DEVKITPRO` and point it to where devkitpro is installed
7. Add `DEVKITARM` and point it to where devkitarm is.
To compile in Code::Blocks simply select your target from the list and click the Gear icon to automatically invoke the `Makefile`
**Note** Make sure you are using MSYS2's make (make.exe) and not MINGW's make (mingw32-make.exe)
## Creating a new project
1. Make a new Code::Blocks project via a user-template you just created above. Or simply copy this directory.
2. (Only needed for cia/3ds builds) Edit the file `resources/AppInfo`
1. Edit those values and ensure you choose a unique id see [unique_id_list].
2. Replace the existing files in the `resources` directory to suit your needs.
**Note** please ensure that no folder/directory used in the project contains spaces. Devkitpro's Makefiles apparently does not like this.
That is, do not have it in a folder like `C:/3DS Hacking/3ds-template` rather `C:/3DS_Hacking/3ds-template`
## Credits
All of this would not have been possible without the work of
* [Smealum](https://github.com/smealum)
* [Steveice10](https://github.com/Steveice10) for the [buildtools]
* [amaredeus](https://github.com/amaredeus) for various improvements to the template (such as the formatting in this README)
[//]: # (These are reference links used in the body of this note and get stripped out when the markdown processor does its job. There is no need to format nicely because it shouldn't be seen. Thanks SO - http://stackoverflow.com/questions/4823468/store-comments-in-markdown-syntax)
[buildtools]: <https://github.com/Steveice10/buildtools>
[bannertool]: <https://github.com/Steveice10/buildtools>
[citra]: <https://github.com/citra-emu/citra>
[libbz2.dll]: <http://downloads.sourceforge.net/gnuwin32/zip-3.0-dep.zip>
[makerom]: <https://github.com/profi200/Project_CTR>
[unique_id_list]: <https://gbatemp.net/threads/homebrew-cias-uniqueid-collection.379362>
[wiki]: <https://wiki.gbatemp.net/wiki/3DS_Homebrew_Development#Install_devkitARM>
[zip]: <http://downloads.sourceforge.net/gnuwin32/zip-3.0-bin.zip>
TODO README.md

11
TODO Normal file
View file

@ -0,0 +1,11 @@
TODO move mlx .c and .h files in its own directory
TODO lower dimensions
TODO higher dimensions (option change mode)
TODO pointer from touchscreen (and laptop way) (option change mode) (option for touchscreen: no MotionNotify event)
TODO bottom screen window
TODO 3d window, with put image with depth, and 3d images
TODO mlx_exit()
TODO hook functions should be compatible again
TODO mlx_init: use GSP_RGBA8_OES, and change mlx_get_data_addr accordingly
TODO use GSPGPU

1
assets/bonjour Normal file
View file

@ -0,0 +1 @@
yo

1
assets/hello Normal file
View file

@ -0,0 +1 @@
hiya

266
assets/snas.xpm Normal file
View file

@ -0,0 +1,266 @@
/* XPM */
static char *down[] = {
/* columns rows colors chars-per-pixel */
"150 150 110 2 ",
" c #000000",
". c #00040B",
"X c #090709",
"o c #04080F",
"O c #0B0B0C",
"+ c #000611",
"@ c #030A13",
"# c #010B1C",
"$ c #0F1010",
"% c #07101D",
"& c #131314",
"* c #171518",
"= c #1C151D",
"- c #17191A",
"; c #1A1B1C",
": c #000E25",
"> c #000F28",
", c #001029",
"< c #1E1F20",
"1 c #001231",
"2 c #001639",
"3 c #00183F",
"4 c #1F2021",
"5 c #0E213B",
"6 c #232425",
"7 c #262728",
"8 c #2D212F",
"9 c #2A2B2C",
"0 c #2F3031",
"q c #323335",
"w c #373A3E",
"e c #3A3B3D",
"r c #001A44",
"t c #001C49",
"y c #002053",
"u c #00245D",
"i c #3E3F41",
"p c #002664",
"a c #00286A",
"s c #002C75",
"d c #4A364D",
"f c #533D56",
"g c #3F4145",
"h c #3F4651",
"j c #424345",
"k c #47494B",
"l c #494B4D",
"z c #4C4E50",
"x c #535457",
"c c #545659",
"v c #57595C",
"b c #595B5E",
"n c #5D4460",
"m c #5C5E61",
"M c #664B6A",
"N c #5F6164",
"B c #616366",
"V c #646669",
"C c #66696C",
"Z c #696B6F",
"A c #6F7275",
"S c #737679",
"D c #76797D",
"F c #003283",
"G c #00358A",
"H c #003894",
"J c #003EA2",
"K c #0040A7",
"L c #0041AA",
"P c #7A7D81",
"I c #004AC3",
"U c #004ECD",
"Y c #0051D5",
"T c #0056E1",
"R c #0059EB",
"E c #005DF5",
"W c #0061FF",
"Q c #826087",
"! c #906A95",
"~ c #9A71A0",
"^ c #7F8185",
"/ c #828589",
"( c #86898D",
") c #909397",
"_ c #919599",
"` c #979A9F",
"' c #989CA0",
"] c #9DA1A6",
"[ c #9FA3A8",
"{ c #A1A4A9",
"} c #A6AAAF",
"| c #AAADB3",
" . c #AEB2B7",
".. c #AFB3B8",
"X. c #B1B5BA",
"o. c #BC8AC3",
"O. c #B9BDC3",
"+. c #E3A7EB",
"@. c #ECAEF5",
"#. c #F6B5FF",
"$. c #BEC2C8",
"%. c #C1C5CB",
"&. c #C4C8CE",
"*. c #CACED5",
"=. c #D2D7DD",
"-. c #D3D8DE",
";. c #DCE1E7",
":. c #DCE1E8",
">. c #E5EAF1",
",. c white",
/* pixels */
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" X X ",
" X $ 0 A ' *.>.>.>...S e & ",
" X 7 [ :.>.>.>.>.>.>.>.>.>.>.;.] 7 O ",
" ; ` >.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.X.9 X X ",
" O S -.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.) $ ",
" & _ >.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.$.< ",
" & %.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.=.e ",
" O _ >.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.-.7 ",
" S >.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.X.$ ",
" q >.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.S ",
" O ..>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.-.- ",
" ; >.>.>.>.>.;.) 0 & & ; b :.>.>.>.>.>.>.} e ; & e $.>.>.>.>.>.>.>.( ",
" v >.>.>.>.-.4 N >.>.>.>.>.{ X X q &.>.>.>.>.>.$.O ",
" ' >.>.>...$ X =.>.>.>.>.m - X.>.>.>.>.>.4 ",
" X =.>.>.>.m ' >.>.>.>.e X k >.>.>.>.>.k ",
" X >.>.>.>.D _ >.>.>.>.e X X 9 >.>.>.>.>.b ",
" X >.>.>.>.;.6 $.>.>.>.>.m X X c >.>.>.>.>.S X ",
" X >.>.>.>.>...7 0 >.>.>.>.>...- X b ;.>.>.>.>.>.x ",
" X j b .>.>.>.X.0 X X X $ v *.>.>.>.>.>.>.` O X O & z $.>.>.>.>.>.>.>.e X ",
" O O ` >.>.>.>.>.;.} } -.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>._ A & ",
" & %.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.e O ",
" B >.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.*.$.;.>.>.>.>.>.j X ",
" $.>.>.>.%.6 - i _ *.>.>.>.>.>.>.:.&.) A g 4 $ X 0 } >.>.>.>.C ",
" _ >.>.>.A X X X X $ & $ & O X X X X X X X X X X w >.>.>.>.^ ",
" l >.>.>.N X X O X X X X X X X X O X X 7 k O ; >.>.>.>.S ",
" & -.>.>.{ O O ^ $ X b D 7 X $ ;.>.- X i i X X S >.>.>.>.q ",
" X c >.>.>.m X $ A e X 0 >.>.7 X 9 >.>.; X & X j =.>.>.>.` X ",
" O _ >.>.=.c O X X O X < >.>.7 O z >.;.q X X 7 -.>.>.>.X.- ",
" O b -.>.>.' ; . X 9 v 0 ; q e $ X X c $.>.>.=.S O ",
" 9 [ ;.>.;._ $ X X X X X X X X X - _ >.>.>.[ 7 X ",
" $ e ( *.>.:.| c 7 - O X O 7 g _ :.:.{ l ; ",
" X - g C ^ P ^ P ^ ^ C z 0 4 ",
" X X X X X O X X . . ",
" p , : . X X X X % : t p W 3 . ",
" @ J W W W W u # z >.>.c : a W W W W W K # . ",
" K W W W W W % e >.>.i # W W W W W W I : . ",
" u W W W W W W . h >.>.^ . @ I W W W W W W I + ",
" . , R W W W W W W 0 >.>.=.X H W W W W W Y L H . ",
" . G a a Y W W W W o 7 >.>.>.O . F W W W W W K . # t ",
" : J o @ Y W W W W : X g >.>.>.& X p W W W W W I . y : ",
" . L 2 # R W W W W % X k >.>.>.; X r W W W W E I , . s ",
" . , T . + . 2 Y W W . N >.>.>.- r W W W L # . . F 1 ",
" . K a . . . , U W W X ^ >.>.>.- X 2 W W W L # . . . . 1 G ",
" , W : . + F G I W W W X X P >.>.>.; X 1 W W W R Y Y W y + W + ",
" F W o p W W W W W W . X ) :.>.>.w X , W W W W W W W H . W t ",
" U E . J W W W W W U . X $.>.>.>.k o W W W W W W W Y . . ",
" r p . T W W W W W H . X >.>.>.>./ X . W W W W W W W W X ",
" . . W W W W W W a . O >.>.>.>.O. U W W W W W W R 7 S & ",
" ; & . : 3 2 t + X X X X X , t a u r r : . O X.>.; ",
" -.:.7 o . 9 V 9 ",
" ; m x 6 O . @ % % % X X % % X O X $ X X ",
" X X X 5 5 5 5 5 5 5 # 5 5 5 5 5 5 5 r ",
" . . o o o o X @ o @ @ @ @ . ",
" ",
" X & - $ - & ; $ ",
" e >.>.D X ; >.>.>._ O ",
" N >.>.^ X - >.>.>.$.< ",
" X 8 ! Q X l >.>.D X X 4 >.>.>.Z O ; 8 X ",
" d +.#.#.n $ =.>.^ X - >.>.-.X * +.#.~ X ",
" f Q ! M n X & ; $ ; | -.S M #.@.o.= ",
" X X X X X O X X ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "
};

1
assets/sous/fichier Normal file
View file

@ -0,0 +1 @@
contenu

1
assets/sous/sous/fichier Normal file
View file

@ -0,0 +1 @@
i love spaghetti

19
dev/norm.sh Executable file
View file

@ -0,0 +1,19 @@
#!/bin/sh
# Use the norminette but without all these rules that make coding harder.
norminette $* | grep -v \
"INVALID_HEADER
VAR_DECL_START_FUNC
EMPTY_LINE_FUNCTION
TOO_MANY_ARGS
TOO_MANY_FUNCS
TOO_MANY_LINES
PREPROC_CONSTANT
GLOBAL_VAR_DETECTED
WRONG_SCOPE_COMMENT
MULT_DECL_LINE
FORBIDDEN
FBIDDEN
SPACE_EMPTY_LINE
DECL_ASSIGN_LINE"

31
embedassets.sh Executable file
View file

@ -0,0 +1,31 @@
#!/bin/bash
# USED BY MAKEFILE, DO NOT MOVE OR RENAME
# TODO embedassets.sh: docs
ASSETS_FULL_DIR=$1
shift
ASSET_FILES=$@
> __embeddedassets.c echo '// File created by rule __embeddedassets.o'
>> __embeddedassets.c echo '#include <string.h>'
>> __embeddedassets.c echo '#include "mlx3ds.h"'
>> __embeddedassets.c echo 'const t_embeddedasset *mlx3ds_assets_get(const char *name)'
>> __embeddedassets.c echo '{'
>> __embeddedassets.c echo ' static const t_embeddedasset assets[] = {'
for file in $ASSET_FILES
do
if [ ! -f $file ]
then
continue
fi
>> __embeddedassets.c echo -n "{\"$(echo $file | sed -e "s/^${ASSETS_FULL_DIR//\//\\\/}//")\", "
>> __embeddedassets.c echo -n "$(stat --printf=%s $file)"', '
>> __embeddedassets.c echo "\"$(< $file xxd -i | sed -ze 's/[, \n\t\r]\+0x/\\x/g')\"},"
done
>> __embeddedassets.c echo ' {NULL, 0, NULL}};'
>> __embeddedassets.c echo ' for (int i = 0; assets[i].name; i++)'
>> __embeddedassets.c echo ' if (!strcmp(assets[i].name, name))'
>> __embeddedassets.c echo ' return &assets[i];'
>> __embeddedassets.c echo ' return NULL;'
>> __embeddedassets.c echo '}'

41
include/mlx.h Normal file
View file

@ -0,0 +1,41 @@
/**
* mlx.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file and all /include/mlx_*.h files from the root of the
* repository come from the original mlx.h at:
* https://github.com/42Paris/minilibx-linux (commit 7dc5314)
*
* Those files are functionally the same as the original mlx.h file, the changes
* are mostly on the documentation and the organization. This documentation
* explains how to use the library for the 3DS, so some things won't be explain
* since they aren't used in this implementation.
*
* Some arguments are marked as "unused", it means that changing their value
* doesn't do anything. The returned values marked as "unused" are undefined.
* Both are kept as is to stay as compatible as possible with project using the
* original MinilibX implementation.
*/
/**
* This header file includes all the mlx_* functions.
* These are all the functions that already exist in the original MinilibX.
*
* Functions that start with '_' aren't yet implemented.
* TODO Implement _*() functions.
*/
#ifndef MLX_H
# define MLX_H
# include "mlx3ds_typealiases.h"
# include "mlx_init.h"
# include "mlx_window.h"
# include "mlx_put.h"
# include "mlx_image.h"
# include "mlx_hook.h"
# include "mlx_unknown.h"
#endif

19
include/mlx3ds.h Normal file
View file

@ -0,0 +1,19 @@
/**
* mlx3ds.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*/
/**
* This file includes everything that doesn't exist in the original MinilibX
* but can be useful for the 3DS implementation.
*/
#ifndef MLX3DS_H
# define MLX3DS_H
# include "mlx3ds_typealiases.h"
# include "mlx3ds_embeddedassets.h"
#endif

View file

@ -0,0 +1,60 @@
/**
* mlx3ds_embeddedassets.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*/
/**
* This file contains functions to use the assets embedded with the program
* with embedassets.sh.
*/
#ifndef MLX3DS_EMBEDDEDASSETS_H
# define MLX3DS_EMBEDDEDASSETS_H
# include <string.h>
/// @brief Socket to an asset. Equivalent to a file descriptor.
typedef void *t_assetsocket;
/// @brief Represents a file embedded with the program.
typedef struct s_embeddedasset
{
/// @brief Path of the file, relative to the assets directory (`.+(/.+)+`).
const char *name;
/// @brief Size of the file content.
size_t size;
/// @brief Content of the file. NUL-terminated (data[size] is '\0').
const char *data;
} t_embeddedasset;
/// @brief Get an reference to the t_embeddedasset from its name.
///
/// @param name Name of the asset to get.
/// @return A reference to the asset. NULL if the asset doesn't exist.
const t_embeddedasset *mlx3ds_assets_get(const char *name);
/// @brief Create a t_assetsocket from an asset.
///
/// @param name Name of the asset to open.
/// @return A socket to the asset. NULL if error.
t_assetsocket mlx3ds_assets_open(const char *name);
/// @brief Reads up to 'count' bytes of the asset content and write it in 'buf'.
///
/// @param asset The asset to read.
/// @param buf The buffer to write the content to.
/// Its size must be at least 'count' bytes.
/// @param count The number of bytes to read.
/// @return The number of bytes actually read. Can be lower than 'count'.
/// 0 if EOF reached.
size_t mlx3ds_assets_read(
t_assetsocket asset, void *buf, size_t count);
/// @brief Close the asset socket to avoid leaks.
///
/// @param asset Asset to close.
void mlx3ds_assets_close(t_assetsocket asset);
#endif

View file

@ -0,0 +1,25 @@
/**
* mlx3ds_typealiases.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*/
/**
* This file contains different typedefs for void*, to differenciate between
* the different void* used by the MLX functions.
*/
#ifndef MLX3DS_TYPEALIASES_H
# define MLX3DS_TYPEALIASES_H
/// @brief An mlx connection identifier returned by mlx_init().
typedef void *t_mlx;
/// @brief Reference to a window.
typedef void *t_win;
/// @brief Reference to an image in memory.
typedef void *t_image;
#endif

120
include/mlx_events.h Normal file
View file

@ -0,0 +1,120 @@
/**
* mlx_events.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file comes from "X.h".
*/
/**
* This file contains the event and mask values to use with mlx_hook().
* The mask values are here for compatibility, they aren't used for the 3DS.
*/
#ifndef MLX_EVENTS_H
# define MLX_EVENTS_H
// TODO docs mlx_events.h
// TODO add function prototypes.
/// @brief Sent when a key starts to be pressed.
/// Hook prototype: `int keypress_hook(int keycode, void *param);`
# define KeyPress 2
/// @brief Sent when a key ends being pressed.
/// Hook prototype: `int keyrelease_hook(int keycode, void *param);`
# define KeyRelease 3
/// @brief Sent when the window was just created, before all other events.
/// Hook prototype: `int create_hook(void *param);`
# define CreateNotify 16
/// @brief Sent to all the windows when the software is quitting, after all
/// the other events.
/// Hook prototype: `int destroy_hook(void *param);`
# define DestroyNotify 17
# define ButtonPress 4 // Unused, this event will never be sent.
# define ButtonRelease 5 // Unused, this event will never be sent.
# define MotionNotify 6 // Unused, this event will never be sent.
# define EnterNotify 7 // Unused, this event will never be sent.
# define LeaveNotify 8 // Unused, this event will never be sent.
# define FocusIn 9 // Unused, this event will never be sent.
# define FocusOut 10 // Unused, this event will never be sent.
# define KeymapNotify 11 // Unused, this event will never be sent.
# define Expose 12 // Unused, this event will never be sent.
# define GraphicsExpose 13 // Unused, this event will never be sent.
# define NoExpose 14 // Unused, this event will never be sent.
# define VisibilityNotify 15 // Unused, this event will never be sent.
# define UnmapNotify 18 // Unused, this event will never be sent.
# define MapNotify 19 // Unused, this event will never be sent.
# define MapRequest 20 // Unused, this event will never be sent.
# define ReparentNotify 21 // Unused, this event will never be sent.
# define ConfigureNotify 22 // Unused, this event will never be sent.
# define ConfigureRequest 23 // Unused, this event will never be sent.
# define GravityNotify 24 // Unused, this event will never be sent.
# define ResizeRequest 25 // Unused, this event will never be sent.
# define CirculateNotify 26 // Unused, this event will never be sent.
# define CirculateRequest 27 // Unused, this event will never be sent.
# define PropertyNotify 28 // Unused, this event will never be sent.
# define SelectionClear 29 // Unused, this event will never be sent.
# define SelectionRequest 30 // Unused, this event will never be sent.
# define SelectionNotify 31 // Unused, this event will never be sent.
# define ColormapNotify 32 // Unused, this event will never be sent.
# define ClientMessage 33 // Unused, this event will never be sent.
# define MappingNotify 34 // Unused, this event will never be sent.
# define GenericEvent 35 // Unused, this event will never be sent.
# define LASTEvent 36 // A number bigger that all event values.
// Unused, the MinilibX for 3DS doesn't use event masks.
# define NoEventMask 0L
// Unused, the MinilibX for 3DS doesn't use event masks.
# define KeyPressMask (1L<<0)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define KeyReleaseMask (1L<<1)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define ButtonPressMask (1L<<2)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define ButtonReleaseMask (1L<<3)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define EnterWindowMask (1L<<4)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define LeaveWindowMask (1L<<5)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define PointerMotionMask (1L<<6)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define PointerMotionHintMask (1L<<7)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define Button1MotionMask (1L<<8)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define Button2MotionMask (1L<<9)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define Button3MotionMask (1L<<10)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define Button4MotionMask (1L<<11)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define Button5MotionMask (1L<<12)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define ButtonMotionMask (1L<<13)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define KeymapStateMask (1L<<14)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define ExposureMask (1L<<15)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define VisibilityChangeMask (1L<<16)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define StructureNotifyMask (1L<<17)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define ResizeRedirectMask (1L<<18)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define SubstructureNotifyMask (1L<<19)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define SubstructureRedirectMask (1L<<20)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define FocusChangeMask (1L<<21)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define PropertyChangeMask (1L<<22)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define ColormapChangeMask (1L<<23)
// Unused, the MinilibX for 3DS doesn't use event masks.
# define OwnerGrabButtonMask (1L<<24)
#endif

105
include/mlx_hook.h Normal file
View file

@ -0,0 +1,105 @@
/**
* mlx_hook.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file, all /include/mlx_*.h files and /include/mlx.h from
* the root of the repository come from the original mlx.h at:
* https://github.com/42Paris/minilibx-linux (commit 7dc5314)
*
* Those files are functionally the same as the original mlx.h file, the changes
* are mostly on the documentation and the organization. This documentation
* explains how to use the library for the 3DS, so some things won't be explain
* since they aren't used in this implementation.
*
* Some arguments are marked as "unused", it means that changing their value
* doesn't do anything. The returned values marked as "unused" are undefined.
* Both are kept as is to stay as compatible as possible with project using the
* original MinilibX implementation.
*/
/**
* This file contains the functions used to manage window events.
*/
#ifndef MLX_HOOK_H
# define MLX_HOOK_H
# include "mlx3ds_typealiases.h"
# include "mlx_events.h"
/// @brief Doesn't do anything, the 3DS doesn't have a mouse.
///
/// @param win_ptr Unused.
/// @param funct_ptr Unused
/// @param param Unused.
/// @return Unused.
int mlx_mouse_hook(t_win win_ptr, int (*funct_ptr)(), void *param);
/// @brief Assign a function to a key event. When a key is released, the
/// function will be called.
///
/// @param win_ptr Window to affect.
/// @param funct_ptr Function to call when the event occurs. `keycode` is the
/// key pressed (note that they are obviously different than
/// the keyboard ones, use the KEY_* constants from hid.h)).
/// `param` is set as the address given to mlx_key_hook().
/// The return value is unused.
/// @param param Address to pass to the function every time it is called.
/// @return Unused.
int mlx_key_hook(t_win win_ptr,
int (*funct_ptr)(int keycode, void *param), void *param);
/// @brief Assign a function which will be called when the window should be
/// redrawn.
/// TODO is mlx_expose_hook() needed for the 3DS?
///
/// @param win_ptr Window to affect.
/// @param funct_ptr Function to call when the event occurs. `param` is set as
/// the address given to mlx_key_hook(). The return value is
/// unused.
/// @param param Address to pass to the function every time it is called.
/// @return Unused.
int mlx_expose_hook(t_win win_ptr,
int (*funct_ptr)(void *param), void *param);
/// @brief Assign a function which will be called in loop non-stop.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param funct_ptr Function to call when the event occurs. `param` is set as
/// the address given to mlx_key_hook(). The return value is
/// unused.
/// @param param Address to pass to the function every time it is called.
/// @return Unused.
int mlx_loop_hook(t_mlx mlx_ptr,
int (*funct_ptr)(void *param), void *param);
/// @brief Loop indefinitely and wait for events to occurs to call the
/// corresponding functions.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @return This function returns only when the program is quitting or if
/// mlx_loop_end() is used. The return value is unused.
int mlx_loop(t_mlx mlx_ptr);
/// @brief Stop the loop of mlx_loop. Doesn't do anything if mlx_loop isn't
/// running.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @return Unused.
int mlx_loop_end(t_mlx mlx_ptr);
/// @brief Assign a function to a custom event.
///
/// @param win_ptr Window to affect.
/// @param x_event The event to use. "See mlx_events.h".
/// @param x_mask Unused.
/// @param funct Function to call when the event occurs. The prototype depends
/// on the event type, "see mlx_events.h".
/// @param param Address to pass to the function every time it is called.
/// @return Unused.
int mlx_hook(t_mlx win_ptr, int x_event, int x_mask,
int (*funct)(), void *param);
#endif

88
include/mlx_image.h Normal file
View file

@ -0,0 +1,88 @@
/**
* mlx_image.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file, all /include/mlx_*.h files and /include/mlx.h from
* the root of the repository come from the original mlx.h at:
* https://github.com/42Paris/minilibx-linux (commit 7dc5314)
*
* Those files are functionally the same as the original mlx.h file, the changes
* are mostly on the documentation and the organization. This documentation
* explains how to use the library for the 3DS, so some things won't be explain
* since they aren't used in this implementation.
*
* Some arguments are marked as "unused", it means that changing their value
* doesn't do anything. The returned values marked as "unused" are undefined.
* Both are kept as is to stay as compatible as possible with project using the
* original MinilibX implementation.
*/
/**
* This file contains functions to import, create, modify and display images.
*
* When using a x,y couple to define a position, the origin (0,0) is always at
* the top-left corner of the image (despite how the 3ds screen works, for those
* who know).
*/
#ifndef MLX_IMAGE_H
# define MLX_IMAGE_H
# include "mlx3ds_typealiases.h"
/// @brief Create an image in memory.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param width Desired width of the image.
/// @param height Desired height of the image.
/// @return A reference to the image. NULL if failed.
t_image mlx_new_image(void *mlx_ptr, int width, int height);
/// @brief Get an address containing all the pixel values of the image. The user
/// can then modify the image using this pointer directly.
///
/// @param img_ptr Image to use.
/// @param bits_per_pixel Will be filled with the number of bits used for each
/// pixel. Can be NULL, result will always be 24.
/// @param size_line Will be filled with the number of bytes used to store
/// a line of the image, aka 3 * width. Can be NULL.
/// @param endian Will be filled with the endianness of all color values.
/// 1 for big endian, 0 for little endian. Can be NULL, result
/// will always be 1.
/// @return Address to the data of the image.
/// Use `data[y * size_line + x * 3]` to get the first color value (red)
/// of a specific pixel.
char *mlx_get_data_addr(t_image img_ptr, int *bits_per_pixel,
int *size_line, int *endian);
/// @brief Draw an image on the window.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param win_ptr Window to affect.
/// @param img_ptr Image to use.
/// @param x x position of the image to draw.
/// @param y y position of the image to draw.
/// @return Unused.
int mlx_put_image_to_window(t_mlx mlx_ptr, t_win win_ptr, t_image img_ptr,
int x, int y);
// ??? TODO docs xpm_to_image
// width & height CAN be null (check please :3)
t_image mlx_xpm_to_image(t_mlx mlx_ptr, const char **xpm_data,
int *width, int *height);
// ??? TODO docs xpm_file_to_image
// width & height CAN be null (check please :3)
t_image mlx_xpm_file_to_image(t_mlx mlx_ptr, const char *filename,
int *width, int *height);
/// @brief Destroy an image to avoid leaks.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param img_ptr Image to destroy.
/// @return Unused.
int mlx_destroy_image(t_mlx mlx_ptr, t_image img_ptr);
#endif

39
include/mlx_init.h Normal file
View file

@ -0,0 +1,39 @@
/**
* mlx_init.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file, all /include/mlx_*.h files and /include/mlx.h from
* the root of the repository come from the original mlx.h at:
* https://github.com/42Paris/minilibx-linux (commit 7dc5314)
*
* Those files are functionally the same as the original mlx.h file, the changes
* are mostly on the documentation and the organization. This documentation
* explains how to use the library for the 3DS, so some things won't be explain
* since they aren't used in this implementation.
*
* Some arguments are marked as "unused", it means that changing their value
* doesn't do anything. The returned values marked as "unused" are undefined.
* Both are kept as is to stay as compatible as possible with project using the
* original MinilibX implementation.
*/
/**
* Function which initialize everything for the mlx3ds.
*/
#ifndef MLX_INIT_H
# define MLX_INIT_H
# include "mlx3ds_typealiases.h"
/// @brief Call this function before anything else.
///
/// @return The mlx connection identifier to use for all other functions.
/// NULL if failed.
t_mlx mlx_init(void); // TODO should call this before REALLY anything else?
// TODO mlx_end() or something? mlx_destroy_display()? (with C2D_Fini())
#endif

64
include/mlx_put.h Normal file
View file

@ -0,0 +1,64 @@
/**
* mlx_put.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file, all /include/mlx_*.h files and /include/mlx.h from
* the root of the repository come from the original mlx.h at:
* https://github.com/42Paris/minilibx-linux (commit 7dc5314)
*
* Those files are functionally the same as the original mlx.h file, the changes
* are mostly on the documentation and the organization. This documentation
* explains how to use the library for the 3DS, so some things won't be explain
* since they aren't used in this implementation.
*
* Some arguments are marked as "unused", it means that changing their value
* doesn't do anything. The returned values marked as "unused" are undefined.
* Both are kept as is to stay as compatible as possible with project using the
* original MinilibX implementation.
*/
/**
* All the functions to draw specific things on the window.
*
* When using a x,y couple to define a position, the origin (0,0) is always at
* the top-left corner of the image (despite how the 3ds screen works, for those
* who know).
*
* (The function mlx_put_image_to_window() is declared in mlx_image.h)
*/
#ifndef MLX_PUT_H
# define MLX_PUT_H
# include "mlx3ds_typealiases.h"
/// @brief Draws a pixel on the window.
/// @details Way slower than even the original MinilibX.
/// Bad function. Those who use it are condemned to have unexplicable
/// segfaults in exams.
///
/// @param mlx_ptr mlx connectio n identifier returned by mlx_init().
/// @param win_ptr Window to affect.
/// @param x x position of the pixel to set.
/// @param y y position of the pixel to set.
/// @param color Color to use in 0x00RRGGBB format.
/// @return Unused.
int mlx_pixel_put(t_mlx mlx_ptr, t_win win_ptr, int x, int y, int color);
/// @brief Print text on the window.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param win_ptr Window to affect.
/// @param x x position of the text to draw.
/// @param y y position of the text to draw.
/// @param color Color to use in 0x00RRGGBB format.
/// @return Unused.
int _mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color,
char *string);
// TODO docs set_font
void _mlx_set_font(void *mlx_ptr, void *win_ptr, char *name);
#endif

66
include/mlx_unknown.h Normal file
View file

@ -0,0 +1,66 @@
/**
* mlx_unknown.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file, all /include/mlx_*.h files and /include/mlx.h from
* the root of the repository come from the original mlx.h at:
* https://github.com/42Paris/minilibx-linux (commit 7dc5314)
*
* Those files are functionally the same as the original mlx.h file, the changes
* are mostly on the documentation and the organization. This documentation
* explains how to use the library for the 3DS, so some things won't be explain
* since they aren't used in this implementation.
*
* Some arguments are marked as "unused", it means that changing their value
* doesn't do anything. The returned values marked as "unused" are undefined.
* Both are kept as is to stay as compatible as possible with project using the
* original MinilibX implementation.
*/
/**
* Here lies
* all the functions
* that i
* have no idea
* what they does
* so that
* i can't
* yet
* organize
* but
* i shall
* someday
* allow
* myself
* TODO it (organize the unknown functions)
*/
#ifndef MLX_UNKNOWN_H
# define MLX_UNKNOWN_H
# include "mlx3ds_typealiases.h"
// ???
int _mlx_get_color_value(void *mlx_ptr, int color);
// ???
int _mlx_destroy_display(t_mlx mlx_ptr);
// ???
int _mlx_do_sync(t_mlx mlx_ptr);
// ???
int _mlx_mouse_get_pos(void *mlx_ptr, void *win_ptr, int *x, int *y);
// ???
int _mlx_mouse_move(void *mlx_ptr, void *win_ptr, int x, int y);
// ???
int _mlx_mouse_hide(void *mlx_ptr, void *win_ptr);
// ???
int _mlx_mouse_show(void *mlx_ptr, void *win_ptr);
// ???
int _mlx_get_screen_size(void *mlx_ptr, int *sizex, int *sizey);
// ???
int _mlx_do_key_autorepeatoff(t_mlx mlx_ptr);
// ???
int _mlx_do_key_autorepeaton(t_mlx mlx_ptr);
#endif

58
include/mlx_window.h Normal file
View file

@ -0,0 +1,58 @@
/**
* mlx_window.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*
* The content of this file, all /include/mlx_*.h files and /include/mlx.h from
* the root of the repository come from the original mlx.h at:
* https://github.com/42Paris/minilibx-linux (commit 7dc5314)
*
* Those files are functionally the same as the original mlx.h file, the changes
* are mostly on the documentation and the organization. This documentation
* explains how to use the library for the 3DS, so some things won't be explain
* since they aren't used in this implementation.
*
* Some arguments are marked as "unused", it means that changing their value
* doesn't do anything. The returned values marked as "unused" are undefined.
* Both are kept as is to stay as compatible as possible with project using the
* original MinilibX implementation.
*/
/**
* This file contains functions to manage windows.
*/
#ifndef MLX_WINDOW_H
# define MLX_WINDOW_H
# include "mlx3ds_typealiases.h"
/// @brief Create a window. It isn't really a window but a way to draw on the
/// top screen of the 3DS. Only one window can be opened at a time.
///
/// @param mlx_ptr The mlx connection identifier returned by mlx_init().
/// @param size_x Width of the window.
/// Maximum 400 to be able to adapt to the top screen of the 3DS.
/// @param size_y Height of the window.
/// Maximum 240 to be able to adapt to the top screen of the 3DS.
/// @param title The title of the window. Unused in the 3DS.
/// @return A reference to the window. NULL if failed.
t_win mlx_new_window(t_mlx mlx_ptr, int size_x, int size_y,
const char *title);
/// @brief Clear the window in black.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param win_ptr Window to affect.
/// @return Unused.
int mlx_clear_window(t_mlx mlx_ptr, t_win win_ptr);
/// @brief Destroy a window.
///
/// @param mlx_ptr mlx connection identifier returned by mlx_init().
/// @param win_ptr Window to destroy.
/// @return Unused.
int mlx_destroy_window(t_mlx mlx_ptr, t_win win_ptr);
#endif

63
include/utilsconsole.h Normal file
View file

@ -0,0 +1,63 @@
/**
* utilsconsole.h
* by Zy
*/
/**
* utilsconsole.h (uc_*() functions)
* Utility functions for the 3DS console.
*/
#pragma once
#ifdef __cplusplus
extern "C++" {
#include <string>
#include <vector>
using namespace std;
/// @brief To use with uc_menu(): Represent an element of the menu.
typedef struct {
/// @brief Displayed name.
string name;
/// @brief true if this button can be used to change the value of a number.
bool is_number_prompt;
/// @brief Only if is_number_prompt is true: the number to change.
int *value;
/// @brief Only if is_number_prompt is true: the minimum value possible for
/// value.
int min;
/// @brief Only if is_number_prompt is true: the maximum value possible for
/// value.
int max;
} s_uc_menu_element;
/// @brief Display a menu with several items in the console.
/// @details
/// Non-blocking function, must be called in loop.
/// Only one menu can work at the same time. 'elements' must not change in
/// address.
/// @param elements A pointer to a vector of all the elements of the menu.
/// @return The index of the confirmed element. If none, return -1.
int uc_menu(vector<s_uc_menu_element> &elements);
}
#endif
/// @brief Display a menu quickly using only confirm buttons.
/// @details
/// Blocking function. Will return -1 if aptMainLoop() becomes false.
/// @param str Text representing each element. The last parameter must be NULL.
/// @return The index of the confirmed element.
int uc_menu_quick(const char *str, ...);
/// @brief Blocks the program until the user presses A.
/// @details Will also return if aptMainLoop() becomes false.
void uc_pause(void);
/// @brief Show the 3DS keyboard to ask the user for a text.
/// @param def The default text to show the user.
/// @return A freeable address to the text prompted by the user. NULL if error.
char *uc_keyboard(const char *def);

295
source/firsk.xpm Normal file
View file

@ -0,0 +1,295 @@
/* XPM */
static const char *firsk[] = {
/* columns rows colors chars-per-pixel */
"150 150 139 2 ",
" c #000000",
". c #0C0400",
"X c #0A0A00",
"o c #03020B",
"O c #130600",
"+ c #1C0006",
"@ c #160800",
"# c #1B0A00",
"$ c #131300",
"% c #1B1B00",
"& c #010713",
"* c #0C0013",
"= c #000815",
"- c #000A1B",
"; c #10001B",
": c #240007",
"> c #230C00",
", c #2A0F00",
"< c #270008",
"1 c #2C0009",
"2 c #2E1000",
"3 c #331200",
"4 c #3B1500",
"5 c #232300",
"6 c #2C2C00",
"7 c #373700",
"8 c #3C3C00",
"9 c #000D21",
"0 c #030E2B",
"q c #11072D",
"w c #190028",
"e c #00112D",
"r c #1B0232",
"t c #1B063A",
"y c #011435",
"u c #00163B",
"i c #43000D",
"p c #4A000F",
"a c #421700",
"s c #461900",
"d c #4B1A00",
"f c #501C00",
"g c #4A0011",
"h c #540011",
"j c #5C0012",
"k c #610013",
"l c #6B0015",
"z c #750017",
"x c #444400",
"c c #4C4C00",
"v c #545400",
"b c #5A5A00",
"n c #646400",
"m c #6B6B00",
"M c #757500",
"N c #7C7C00",
"B c #130D40",
"V c #001A44",
"C c #001C4A",
"Z c #0A1C5B",
"A c #1B1054",
"S c #2A0045",
"D c #340055",
"F c #34045F",
"G c #38005C",
"H c #002156",
"J c #002258",
"K c #34096B",
"L c #022665",
"P c #0C2068",
"I c #002869",
"U c #002D75",
"Y c #450071",
"T c #84001A",
"R c #8D001C",
"E c #A50021",
"W c #838300",
"Q c #8C8C00",
"! c #929200",
"~ c #9B9B00",
"^ c #A3A300",
"/ c #A9A900",
"( c #B3B300",
") c #BBBB00",
"_ c #C5C500",
"` c #CECE00",
"' c #D5D500",
"] c #D8D800",
"[ c #E0E000",
"{ c #EBEB00",
"} c #F5F500",
"| c yellow",
" . c #003285",
".. c #00358E",
"X. c #003894",
"o. c #003B9A",
"O. c #3C18A0",
"+. c #013DA2",
"@. c #5A039B",
"#. c #61009F",
"$. c #5E0AB2",
"%. c #6A00AD",
"&. c #6704B3",
"*. c #6F00B4",
"=. c #0040AA",
"-. c #3339EA",
";. c #7E00CE",
":. c #6414D9",
">. c #6C1EFF",
",. c #7A15FF",
"<. c #731AFF",
"1. c #412DE1",
"2. c #542DFF",
"3. c #4735FF",
"4. c #4E31FF",
"5. c #4139FF",
"6. c #5030FF",
"7. c #6125FF",
"8. c #6821FF",
"9. c #004CC6",
"0. c #0052D7",
"q. c #0055E0",
"w. c #0754EB",
"e. c #005DF5",
"r. c #045FFF",
"t. c #095BFF",
"y. c #1752FF",
"u. c #1B51FF",
"i. c #2D45FF",
"p. c #204DFF",
"a. c #0061FF",
"s. c #8B00E2",
"d. c #850FFF",
"f. c #8D0BFF",
"g. c #9700F5",
"h. c #9406FF",
"j. c #9C00FF",
"k. c #8210FF",
"l. c white",
/* pixels */
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" . O # # 2 2 2 , # . . # ",
" X O 2 a f f f f f f f f f f f f f a # ",
" . 2 d d f f f f f f f f f f f f f f f f d 4 O ",
" . , d f d f f f f f f f f f f f f f f f f f f f d , . ",
" > d f f f f f f f f f f f f f f f f f f f f f f f f f 4 . ",
" 3 f f f f f f f f f f f f f f f f f f f f f f f f f f f f d . ",
" . 3 f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f s ",
" , d f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f , ",
" . d f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f d O ",
" 3 f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f 4 ",
" O f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f O ",
" 2 f f f f f f d f f d f f f f f f f f f f f f f f f f f f f f f f f f f f 4 ",
" O f f f f f f d > . O , f f f f f f f f f f f f f f f f f f f f f f f f f a ",
" 4 f f f f f d @ , s > X . 3 d f f 3 # . O a f f f f f f f f f f . ",
" d f f f f f # 6 n % . . 3 a @ X X X X d f f f f f f f f f , ",
" O f f f f f , 8 { | _ > X 6 M X X b x X @ , # a f f f f f f d , ",
" 3 f f f f 3 6 ` | | | ( 7 6 N | | ^ % X X % Q | } v . f f f f f f d a ",
" f f f f 3 $ _ | | | | | | | | | | | [ W N ` | | | | { x X X @ d f f f f f f . ",
" O f f f . $ ^ | | | | | | | | | | | | | | | | | | | | | | ' ' 5 3 f f f f f f . ",
" # f f 4 X ^ | | M 6 % 5 % 8 ~ | | | | | | | ' m x x m W ^ ` | ! % d f f f f f @ ",
" , f f , X ` | | | 8 X X X 8 | | | | | | | / X X X X X x | } ( $ # d f f f f @ ",
" 4 f f @ > | | | | ~ b c n 8 x M | | | | | | | | c % $ % X X x | | } v X X > d f @ ",
" d f f @ % | | | | | | | | | | | | | | | | | | | | | | | | | | | | | { x X X 2 f @ ",
" f f f , X { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | { ( W X . d @ ",
" f f f 4 X ^ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ^ . f @ ",
" f f f f . 7 } | | | | | | | | | | | | | | | | | | | | | | | | | | | | | { 5 3 f O ",
" f f f f 2 X ^ | | | | | | | | | ' ^ Q Q Q ~ ` | | | | | | | | | } x 6 N x X 2 f f . ",
" s f f f d % { | | | | | | | | n X X X X X x | | | | | | | | | ( X X . O f f f ",
" 2 f f f f 3 X 8 ` | | | | | | | m X X X X $ n | | | | | | | | ` $ @ a f f f ",
" @ f f f f f , X 6 _ | | | | | | | | | | | | | | | | | | | | ) 5 . 3 f f f f f f 3 ",
" . f f f f f d # $ Q } | | | | | | | | | | | | | | | } ~ 6 X 3 f f f f s 4 4 # ",
" f f f f f f f > X 8 ( | | | | | | | | | | | | | ( $ . 3 d f f f 4 @ ",
" a f d > . . > s 3 . X $ 8 W Q _ } | } ) ! N x % X > s 4 3 4 f a . ",
" > 3 O X X X X X > # # . ",
" o o o o o o o - V y ",
" o U .+.0.a.q.=.o.0.a.a.a.a.a.a.o.& ",
" o .e.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.q.C ",
" o O.i.w.=.=.a.a.a.a.a.a.a.a.a.a.a.a.a.t.u.5.:.* ",
" S j.j.S * r ,.>.2.4.3.i.y.i.3.6.7.,.k.@.Y %.j.*. . i . ",
" o ;.j.Y o . D j.j.j.j.j.j.j.j.j.j.j.j.j.G * w s.j.G o O l k ",
" q d.&.o S j.j.j.j.j.j.j.j.j.j.j.j.j.j.#.o F >.-.0 + R E 1 o . ",
" o o.e.y o & 1.>.,.f.h.h.h.j.j.j.h.h.f.k.8.6.Z o o 9.a...o . g E E R . ",
" - e.+.o .a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.0.o J a.e.C + z E E E : ",
" o V a.e & e.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.y & a.a.0.o o < T E E E g ",
" o +.0.o o K 8.2.5.p.a.a.a.a.a.a.a.a.a.a.t.i.3.8.$.o 0.e. . g E l j R g . ",
" 0.X.o o ;.j.j.j.j.j.j.j.j.h.h.h.h.j.j.j.j.j.j.g.o H y o . h E p . O ",
" o & * j.j.j.j.j.j.j.j.j.j.j.j.j.j.j.j.j.j.j.j.; o . + z k + ",
" X X t ,.f.h.h.j.j.j.j.j.j.j.j.j.j.j.j.j.h.f.<.B < R 1 ",
" n ` X A r.r.a.a.a.a.a.p.i.6.4.6.3.i.a.a.a.a.a.a.L i O ",
" X Q | X P t.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.V ",
" n | C a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.o ",
" 5 _ X o .a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.& ",
" X X % =.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.9.U o ",
" X X % o o - e u V C L U X.X... .I V V 9 = o ",
" X o X o o o o o X ",
" X % 8 5 % $ $ $ % 6 8 ",
" X Q | | | ^ X X 6 | | | | Q X | ",
" X X X 5 ) | | | M X X 7 | | | | / $ $ | X ",
" X % / } | | | v X $ x | | | | [ $ X ",
" 5 _ | | | | x $ 8 | | | | | ] $ ",
" ) | | | | | M $ X % ) { | | | | ! X ",
" X X X X X X X X X % % X X X X ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "
};

View file

@ -1,25 +1,687 @@
#include <3ds.h>
#include <stdio.h>
int main(int argc, char **argv) {
gfxInitDefault();
consoleInit(GFX_TOP, NULL);
printf("Test Code::Blocks project!");
printf("\x1b[20;15HPress Start to exit.");
while(aptMainLoop()) {
gspWaitForVBlank();
hidScanInput();
if(hidKeysDown() & KEY_START)
break;
gfxFlushBuffers();
gfxSwapBuffers();
extern "C" {
#include "mlx.h"
#include "3ds.h"
#include "mlx3ds.h"
#include "utilsconsole.h"
}
#include <iostream>
#include "firsk.xpm"
#include <string.h>
#include <sys/dirent.h>
#include <fcntl.h>
#include <unistd.h>
using namespace std;
static void draw_rainbow_image(t_mlx mlx, t_win win, int x, int y)
{
cout << "Draw rainbow image at (" << x << "," << y << ")..." << endl;
uc_pause();
{
static const u32 red = 0xFF0000;
static const u32 green = 0x00FF00;
static const u32 blue = 0x0000FF;
t_image img = mlx_new_image(mlx, 30, 30);
char *img_data = mlx_get_data_addr(img, NULL, NULL, NULL);
for (int x = 0; x < 30; x++)
{
for (int y = 0; y < 20; y++)
{
if (x < 10)
memcpy(img_data + 3 * (y * 30 + x), &red, 3);
else if (x < 20)
memcpy(img_data + 3 * (y * 30 + x), &green, 3);
else
memcpy(img_data + 3 * (y * 30 + x), &blue, 3);
}
}
mlx_put_image_to_window(mlx, win, img, x, y);
mlx_destroy_image(mlx, img);
}
}
static int keydown_hook(int keycode, void *param)
{
(void)param;
cout << "[D" << keycode << "] (B to continue)" << endl;
return (0);
};
static int create_hook(void *param) {
(void)param;
cout << "create_hook() called" << endl;
int file = open("__tmp_heya.txt", O_RDONLY);
if (!file)
cout << "can't open file __tmp_heya.txt" << endl;
else {
static char buf[100];
if (read(file, buf, 100) < 0)
cout << "can't read file" << endl;
else
cout << "buf :\"" << buf << "\"" << endl;
}
close(file);
cout
<< "quit software to create file:" << endl
<< " __tmp_heya.txt" << endl;
return (0);
};
static int destroy_hook(void **ptrs) {
int file = open("__tmp_heya.txt", O_WRONLY | O_CREAT);
if (!file) {
cout << "can't create file" << endl;
return (0);
}
write(file, "spaghetti :3\n", 13);
if (!file)
cout << "can't write on file" << endl;
close(file);
mlx_loop_end(ptrs[0]);
return (0);
};
int main(void) {
void *const mlx = mlx_init();
void *win;
// MENU
{
switch (uc_menu_quick("pixels", "images", "xpm", "files",
"navigate", "assets", "xpm files", "events", "quit", NULL))
{
case 0:
goto pixels;
break;
case 1:
goto images;
break;
case 2:
goto xpm;
break;
case 3:
goto files;
break;
case 4:
goto navigate;
break;
case 5:
goto assets;
break;
case 6:
goto xpm_files;
break;
case 7:
goto events;
break;
}
goto end;
}
pixels:
cout << "create window..." << endl;
uc_pause();
win = mlx_new_window(mlx, 400, 240, "hey");
cout << "clear window..." << endl;
uc_pause();
mlx_clear_window(mlx, win);
cout
<< "Put pixels for red green and blue" << endl
<< "at the top-left corner..." << endl;
uc_pause();
{
int block_y = 20;
for (
int block_x = 20, color = 0xFF0000;
block_x <= 60;
block_x += 20, color = color >> 8
)
for (int x = 0; x < 10; x++)
for (int y = 0; y < 10; y++)
mlx_pixel_put(mlx, win, block_x + x, block_y + y, color);
}
cout << "clear window..." << endl;
uc_pause();
mlx_clear_window(mlx, win);
cout << "destroy window..." << endl;
uc_pause();
mlx_destroy_window(mlx, win);
goto end;
images:
cout << "create window..." << endl;
uc_pause();
win = mlx_new_window(mlx, 400, 240, "hoi");
cout << "clear window..." << endl;
uc_pause();
mlx_clear_window(mlx, win);
draw_rainbow_image(mlx, win, 185, 110);
draw_rainbow_image(mlx, win, -15, 100);
draw_rainbow_image(mlx, win, 385, 120);
draw_rainbow_image(mlx, win, 170, -10);
draw_rainbow_image(mlx, win, 200, 230);
draw_rainbow_image(mlx, win, -15, -10);
draw_rainbow_image(mlx, win, 385, -10);
draw_rainbow_image(mlx, win, -15, 230);
draw_rainbow_image(mlx, win, 385, 230);
cout << "Draw RG image at (20,10)..." << endl;
uc_pause();
{
t_image img = mlx_new_image(mlx, 30, 20);
char *img_data = mlx_get_data_addr(img, NULL, NULL, NULL);
for (int x = 0; x < 30; x++)
{
for (int y = 0; y < 20; y++)
{
u32 color =
((0xFF0000 * x / 30) & 0xFF0000)
| ((0x00FF00 * y / 20) & 0x00FF00);
memcpy(img_data + 3 * (y * 30 + x), &color, 3);
}
}
mlx_put_image_to_window(mlx, win, img, 20, 10);
mlx_destroy_image(mlx, img);
}
cout << "Draw GB image at (50,0)..." << endl;
uc_pause();
{
t_image img = mlx_new_image(mlx, 10, 50);
char *img_data = mlx_get_data_addr(img, NULL, NULL, NULL);
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 50; y++)
{
u32 color =
((0x00FF00 * x / 10) & 0x00FF00)
| ((0x0000FF * y / 50) & 0x0000FF);
memcpy(img_data + 3 * (y * 10 + x), &color, 3);
}
}
mlx_put_image_to_window(mlx, win, img, 50, 0);
mlx_destroy_image(mlx, img);
}
cout << "Draw BR image at (200,100)..." << endl;
uc_pause();
{
t_image img = mlx_new_image(mlx, 100, 100);
char *img_data = mlx_get_data_addr(img, NULL, NULL, NULL);
for (int x = 0; x < 100; x++)
{
for (int y = 0; y < 100; y++)
{
u32 color =
((0x0000FF * x / 100) & 0x0000FF)
| ((0xFF0000 * y / 100) & 0xFF0000);
memcpy(img_data + 3 * (y * 100 + x), &color, 3);
}
}
mlx_put_image_to_window(mlx, win, img, 200, 100);
mlx_destroy_image(mlx, img);
}
cout << "clear window..." << endl;
uc_pause();
mlx_clear_window(mlx, win);
cout << "destroy window..." << endl;
uc_pause();
mlx_destroy_window(mlx, win);
goto end;
xpm:
cout << "create window..." << endl;
uc_pause();
win = mlx_new_window(mlx, 400, 240, "hey");
cout << "Show XPM image..." << endl;
uc_pause();
{
static const char *xpm[] = {
"4 3 3 2",
"r c red",
"g c green",
"b c blue",
"r g b r ",
"g b r g ",
"b r g b ",
};
t_image img = mlx_xpm_to_image(mlx, xpm, NULL, NULL);
if (img)
mlx_put_image_to_window(mlx, win, img, 10, 10);
else
cout << "error :(" << endl;
}
cout << "Show bigger XPM image..." << endl;
uc_pause();
{
/* XPM */
static const char *xpm[] = {
/* plaid pixmap
* width height ncolors chars_per_pixel */
"22 22 4 2",
/* colors */
"r c red",
"Y c green",
"+ c yellow",
"x c black",
/* pixels */
"x r x r x x x r x r x x x x x x + x x x x x ",
"r x r x r x r x r x r x x x x x x x x x x x ",
"x r x r x x x r x r x x x x x x + x x x x x ",
"r x r x r x r x r x r x x x x x x x x x x x ",
"x r x r x x x r x r x x x x x x + x x x x x ",
"Y Y Y Y Y x Y Y Y Y Y + x + x + x + x + x + ",
"x r x r x x x r x r x x x x x x + x x x x x ",
"r x r x r x r x r x r x x x x x x x x x x x ",
"x r x r x x x r x r x x x x x x + x x x x x ",
"r x r x r x r x r x r x x x x x x x x x x x ",
"x r x r x x x r x r x x x x x x + x x x x x ",
"r r r r r x r r r r r x r x r x Y x r x r x ",
"r r r r r x r r r r r r x r x r Y r x r x r ",
"r r r r r x r r r r r x r x r x Y x r x r x ",
"r r r r r x r r r r r r x r x r Y r x r x r ",
"r r r r r x r r r r r x r x r x Y x r x r x ",
"x x x x x x x x x x x x x x x x x x x x x x ",
"r r r r r x r r r r r x r x r x Y x r x r x ",
"r r r r r x r r r r r r x r x r Y r x r x r ",
"r r r r r x r r r r r x r x r x Y x r x r x ",
"r r r r r x r r r r r r x r x r Y r x r x r ",
"r r r r r x r r r r r x r x r x Y x r x r x "
};
t_image img = mlx_xpm_to_image(mlx, xpm, NULL, NULL);
if (img)
mlx_put_image_to_window(mlx, win, img, 20, 10);
else
cout << "error :(" << endl;
}
cout << "Show firsk..." << endl;
uc_pause();
{
t_image img = mlx_xpm_to_image(mlx, firsk, NULL, NULL);
if (img)
mlx_put_image_to_window(mlx, win, img, 100, 10);
else
cout << "error :(" << endl;
}
cout << "destroy window..." << endl;
uc_pause();
mlx_destroy_window(mlx, win);
goto end;
files:
cout << "Current working directory: " << getcwd(NULL, 0) << endl;
uc_pause();
cout << "List of files in /:" << endl;
{
DIR *dir = opendir("/");
dirent *dir_in;
do
{
dir_in = readdir(dir);
if (!dir_in)
break;
cout << "> " << dir_in->d_name << endl;
} while (dir_in);
closedir(dir);
}
uc_pause();
cout << "Read file abc.txt..." << endl;
{
int f = 0;
f = open("/abc.txt", O_RDONLY);
if (!f)
{
cout << "open() error :(" << endl;
goto file_read_end;
}
char buf[1000];
{
cout << "file content:" << endl << "\"";
int n = 1;
while (n)
{
n = read(f, buf, 1000);
if (n < 0)
{
cout << "read() error :(" << endl;
goto file_read_end;
}
if (n > 0)
write(1, buf, n);
}
cout << "\"" << endl;
}
file_read_end:
if (f)
close(f);
}
uc_pause();
cout << "Write \"hello :3\" in abc.txt..." << endl;
{
int f = 0;
f = open("/abc.txt", O_WRONLY | O_CREAT);
if (!f)
{
cout << "open() error :(" << endl;
goto file_write_end;
}
if (write(f, "hello :3", 8) < 0)
cout << "write() error :(" << endl;
else
cout << "write() success :)" << endl;
file_write_end:
if (f)
close(f);
}
uc_pause();
cout << "Read file abc.txt again..." << endl;
{
int f = 0;
f = open("/abc.txt", O_RDONLY);
if (!f)
{
cout << "open() error :(" << endl;
goto file_read2_end;
}
char buf[1000];
{
cout << "file content:" << endl << "\"";
int n = 1;
while (n)
{
n = read(f, buf, 1000);
if (n < 0)
{
cout << "read() error :(" << endl;
goto file_read2_end;
}
if (n > 0)
write(1, buf, n);
}
cout << "\"" << endl;
}
file_read2_end:
if (f)
close(f);
}
uc_pause();
goto end;
navigate:
{
char *last = new char[2];
last[0] = '/';
last[1] = '\n';
while (true)
{
cout << "Write a file path or a directory path toshow it." << endl;
cout << "Put an empty text to return." << endl;
uc_pause();
char *name = NULL;
if (aptMainLoop())
name = uc_keyboard(last);
if (!name || !strcmp(name, ""))
break;
cout << "\e[7m" << name << "\e[0m" << endl;
cout << "Try to open as directory..." << endl;
DIR *dir = opendir(name);
if (dir)
{
cout << "Directory opened!" << endl;
uc_pause();
cout << "Files:" << endl;
dirent *dir_in;
do {
dir_in = readdir(dir);
if (dir_in)
cout << "> " << dir_in->d_name << endl;
} while (dir_in);
closedir(dir);
}
else {
cout << "Can't open as directory." << endl;
cout << "Try to open as file..." << endl;
int file = open(name, O_RDONLY);
if (file)
{
cout << "File opened!" << endl;
uc_pause();
cout << "Content:" << endl;
int n = 1;
char buf[1000];
while (n > 0)
{
n = read(file, buf, 1000);
if (n < 0)
cout << "read() error :(" << endl;
else if (n > 0)
write(1, buf, n);
}
cout << "[EOF]" << endl;
close(file);
}
else
{
cout << "Can't either." << endl;
cout << "Seems nothing works." << endl;
cout << "That is sad." << endl;
cout << "Anyway," << endl;
}
}
delete [] last;
last = name;
uc_pause();
}
delete [] last;
}
goto end;
assets:
{
const t_embeddedasset *asset;
cout << "Read asset \"hello\"..." << endl;
asset = mlx3ds_assets_get("hello");
if (asset)
cout << "Content (" << asset->size << "): \""
<< asset->data << "\"" << endl;
else
cout << "No asset" << endl;
uc_pause();
cout << "Read asset \"bonjour\"..." << endl;
asset = mlx3ds_assets_get("bonjour");
if (asset)
cout << "Content (" << asset->size << "): \""
<< asset->data << "\"" << endl;
else
cout << "No asset" << endl;
uc_pause();
cout << "Read asset \"hola\"..." << endl;
asset = mlx3ds_assets_get("hola");
if (asset)
cout << "Content (" << asset->size << "): \""
<< asset->data << "\"" << endl;
else
cout << "No asset" << endl;
uc_pause();
cout << "Read asset \"sous/fichier\"..." << endl;
asset = mlx3ds_assets_get("sous/fichier");
if (asset)
cout << "Content (" << asset->size << "): \""
<< asset->data << "\"" << endl;
else
cout << "No asset" << endl;
uc_pause();
cout << "Read asset \"sous/sous/fichier\"..." << endl;
asset = mlx3ds_assets_get("sous/sous/fichier");
if (asset)
cout << "Content (" << asset->size << "): \""
<< asset->data << "\"" << endl;
else
cout << "No asset" << endl;
uc_pause();
{
char buf[10];
cout
<< "Read asset \"sous/sous/fichier\"" << endl
<< "from mlx3ds_assets_open()..." << endl
<< "(buf[10])" << endl;
t_assetsocket asset = mlx3ds_assets_open("sous/sous/fichier");
if (!asset)
cout << "Error" << endl;
else {
cout << "Content: \"";
int n;
do {
n = mlx3ds_assets_read(asset, buf, 10);
if (n < 0) {
cout << "read error :/" << endl;
break;
}
if (n > 0)
write(1, buf, n);
} while (n);
cout << "\"" << endl;
mlx3ds_assets_close(asset);
}
}
uc_pause();
{
char buf[100];
cout
<< "Read asset \"sous/sous/fichier\"" << endl
<< "from mlx3ds_assets_open()..." << endl
<< "(buf[100])" << endl;
t_assetsocket asset = mlx3ds_assets_open("sous/sous/fichier");
if (!asset)
cout << "Error" << endl;
else {
cout << "Content: \"";
int n;
do {
n = mlx3ds_assets_read(asset, buf, 100);
if (n < 0) {
cout << "read error :/" << endl;
break;
}
if (n > 0)
write(1, buf, n);
} while (n);
cout << "\"" << endl;
mlx3ds_assets_close(asset);
}
}
uc_pause();
}
goto end;
xpm_files:
{
cout
<< "Display snas.xpm from" << endl
<< "mlx_xpm_file_to_image()..." << endl;
uc_pause();
{
win = mlx_new_window(mlx, 400, 240, NULL);
if (!win) {
cout << "mlx_new_window() error :/" << endl;
goto xpm_files_end;
}
int w, h;
t_image img = mlx_xpm_file_to_image(mlx, "snas.xpm", &w, &h);
if (!img) {
cout << "Image not found :/" << endl;
goto xpm_files_end;
}
cout << "width: " << w << ", height: " << h << endl;
mlx_put_image_to_window(mlx, win, img, 100, 100);
}
xpm_files_end:
cout << "DONE! (i hope)" << endl;
uc_pause();
}
goto end;
events:
{
win = mlx_new_window(mlx, 400, 240, NULL);
const static auto loop_hook = [](void *param) -> int {
(void)param;
cout << "hi from loop_hook (B to continue)" << endl;
hidScanInput();
if (hidKeysDown() & KEY_B)
mlx_loop_end(param);
return (0);
};
mlx_loop_hook(mlx, loop_hook, mlx);
mlx_loop(mlx);
cout << "mlx_loop() returned." << endl;
mlx_destroy_window(mlx, win);
mlx_loop_hook(mlx, NULL, NULL);
uc_pause();
}
{
win = mlx_new_window(mlx, 400, 240, NULL);
const static auto key_hook = [](int keycode, void *param) -> int {
cout << "[U" << keycode << "] (B to continue)" << endl;
if (keycode == KEY_B)
mlx_loop_end(param);
return (0);
};
mlx_key_hook(win, key_hook, mlx);
mlx_hook(win, KeyPress, 0, (int (*)())(void *)&keydown_hook, mlx);
mlx_loop(mlx);
cout << "mlx_loop() returned." << endl;
mlx_destroy_window(mlx, win);
uc_pause();
}
{
win = mlx_new_window(mlx, 400, 240, NULL);
void *ptrs[2];
ptrs[0] = mlx;
ptrs[1] = win;
mlx_hook(win, CreateNotify, 0, (int (*)())(void *)&create_hook, NULL);
mlx_hook(win, DestroyNotify, 0, (int (*)())(void *)&destroy_hook, &ptrs);
mlx_loop(mlx);
cout << "mlx_loop() returned." << endl;
mlx_destroy_window(mlx, win);
uc_pause();
}
goto end;
end:
cout << "Exit..." << endl;
uc_pause();
gfxExit();
return 0;
}

View file

@ -0,0 +1,55 @@
/**
* mlx3ds_embeddedassets.c
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*/
#include "mlx3ds_embeddedassets.h"
#include <unistd.h>
#include <stdlib.h>
/// @brief Internal of a t_assetsocket.
typedef struct s_in_assetsocket
{
/// @brief Asset used.
const t_embeddedasset *asset;
/// @brief Index of the cursor.
size_t i;
} t_in_assetsocket;
// This function is implemented in embedassets.sh
const t_embeddedasset *mlx3ds_assets_get(const char *name);
t_assetsocket mlx3ds_assets_open(const char *name)
{
const t_embeddedasset *asset;
t_in_assetsocket *r;
asset = mlx3ds_assets_get(name);
if (!asset)
return (NULL);
r = malloc(sizeof(t_in_assetsocket));
if (!r)
return (NULL);
r->asset = asset;
r->i = 0;
return (r);
}
size_t mlx3ds_assets_read(t_assetsocket asset, void *buf, size_t count)
{
t_in_assetsocket *asset_ = asset;
if (count > asset_->asset->size - asset_->i)
count = asset_->asset->size - asset_->i;
memcpy(buf, asset_->asset->data + asset_->i, count);
asset_->i += count;
return (count);
}
void mlx3ds_assets_close(t_assetsocket asset)
{
free(asset);
}

135
source/mlx_hook.c Normal file
View file

@ -0,0 +1,135 @@
/**
* mlx_hook.c
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*/
#include "mlx_hook.h"
#include "mlx_internal.h"
int mlx_mouse_hook(t_win win_ptr, int (*funct_ptr)(), void *param)
{
(void)win_ptr;
(void)funct_ptr;
(void)param;
// ╮(︶▽︶)╭
return (0);
}
int mlx_key_hook(t_win win_ptr,
int (*funct_ptr)(int keycode, void *param), void *param)
{
((t_internal_win *)win_ptr)->hooks[KeyRelease].hook = funct_ptr;
((t_internal_win *)win_ptr)->hooks[KeyRelease].param = param;
return (0);
}
int mlx_expose_hook(t_win win_ptr,
int (*funct_ptr)(void *param), void *param)
{
// TODO use expose hook?
((t_internal_win *)win_ptr)->hooks[Expose].hook = funct_ptr;
((t_internal_win *)win_ptr)->hooks[Expose].param = param;
return (0);
}
#include <stdlib.h> // remove debug TODO
#include <stdio.h>
#include "utilsconsole.h"
int mlx_loop_hook(t_mlx mlx_ptr,
int (*funct_ptr)(void *param), void *param)
{
((t_internal_mlx *)mlx_ptr)->hook_loop_function = funct_ptr;
((t_internal_mlx *)mlx_ptr)->hook_loop_param = param;
return (0);
}
int mlx_hook(t_win win_ptr, int x_event, int x_mask,
int (*funct)(), void *param)
{
(void)x_mask;
((t_internal_win *)win_ptr)->hooks[x_event].hook = funct;
((t_internal_win *)win_ptr)->hooks[x_event].param = param;
return (0);
}
typedef struct
{
u32 held;
u32 down;
u32 up;
} t_keys_status;
static t_keys_status keys_events(void)
{
static u32 last_held;
static u32 real_last_held;
t_keys_status r;
u32 real_held = hidKeysHeld();
hidScanInput();
r.held = real_held | real_last_held;
r.up = last_held & ~r.held;
r.down = ~last_held & r.held;
last_held = r.held;
real_last_held = real_held;
return (r);
}
static void call_events(t_internal_win *win, t_keys_status keys)
{
if (win->hooks[KeyRelease].hook && keys.up)
for (int i = 0; i < 32; i++)
if ((keys.up >> i) & 1)
win->hooks[KeyRelease].hook(
1 << i, win->hooks[KeyRelease].param);
if (win->hooks[KeyPress].hook && keys.down)
for (int i = 0; i < 32; i++)
if ((keys.down >> i) & 1)
win->hooks[KeyPress].hook(
1 << i, win->hooks[KeyPress].param);
}
static void call_start_events(t_internal_win *win)
{
if (win->hooks[CreateNotify].hook)
win->hooks[CreateNotify].hook(win->hooks[CreateNotify].param);
}
static void call_end_events(t_internal_win *win)
{
if (win->hooks[DestroyNotify].hook)
win->hooks[DestroyNotify].hook(win->hooks[DestroyNotify].param);
}
int mlx_loop(t_mlx mlx_ptr)
{
t_internal_mlx *mlx = mlx_ptr;
mlx->loop = true;
if (mlx->top_window)
call_start_events(mlx->top_window);
while (aptMainLoop() && mlx->loop)
{
t_keys_status keys = keys_events();
if (mlx->top_window)
call_events(mlx->top_window, keys);
if (mlx->hook_loop_function)
mlx->hook_loop_function(mlx->hook_loop_param);
gfxFlushBuffers(); // aptMainLoop() doesn't work without that
}
if (!aptMainLoop())
if (mlx->top_window)
call_end_events(mlx->top_window);
mlx->loop = false;
return (0);
}
int mlx_loop_end(t_mlx mlx_ptr)
{
((t_internal_mlx *)mlx_ptr)->loop = false;
return (0);
}

124
source/mlx_image.c Normal file
View file

@ -0,0 +1,124 @@
/**
* mlx_image.c
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*/
#include "mlx_image.h"
#include <stdlib.h>
#include "mlx_internal.h"
#include "mlx_inline.c"
t_image mlx_new_image(void *mlx_ptr, int width, int height)
{
t_internal_image *r;
(void)mlx_ptr;
r = NULL;
r = malloc(sizeof(t_internal_image));
if (!r)
goto error;
r->data = NULL;
r->data = malloc(width * height * 3 * sizeof(u8));
if (!r->data)
goto error;
r->width = width;
r->height = height;
return (r);
error:
free(r);
return (NULL);
}
int mlx_destroy_image(t_mlx mlx_ptr, t_image img_ptr)
{
(void)mlx_ptr;
if (img_ptr)
free(((t_internal_image *)img_ptr)->data);
free(img_ptr);
return (0);
}
char *mlx_get_data_addr(t_image img_ptr, int *bits_per_pixel,
int *size_line, int *endian)
{
if (bits_per_pixel)
*bits_per_pixel = 24;
if (size_line)
*size_line = 3 * ((t_internal_image *)img_ptr)->width;
if (endian)
*endian = 1;
return ((char *)((t_internal_image *)img_ptr)->data);
}
/// @brief Return the minimum between a and b.
/// @param a Number a.
/// @param b Number b.
/// @return The result.
static inline int min(int a, int b)
{
return (a < b ? a : b);
}
/// @brief Return the maximum between a and b.
/// @param a Number a.
/// @param b Number b.
/// @return The result.
static inline int max(int a, int b)
{
return (a > b ? a : b);
}
int mlx_put_image_to_window(t_mlx mlx_ptr, t_win win_ptr, t_image img_ptr,
int x, int y)
{
// buffers
u8 *frame_data, *img_data;
int // dimensions
frame_width, frame_height, img_width, img_height,
// interval of pixels to draw, to avoid drawing outside of the buffer
min_x_on_screen, max_x_on_screen, min_y_on_screen, max_y_on_screen,
// position relative to frame
x_on_screen, y_on_screen;
// variables that contain results of constant expressions
int a, b;
u8 *c, *d, *e, *f;
mlx3ds_internal_drawstart(mlx_ptr, win_ptr);
frame_data = ((t_internal_win *)win_ptr)->framebuffer;
frame_width = ((t_internal_win *)win_ptr)->framebuffer_width;
frame_height = ((t_internal_win *)win_ptr)->framebuffer_height;
img_data = ((t_internal_image *)img_ptr)->data;
img_width = ((t_internal_image *)img_ptr)->width;
img_height = ((t_internal_image *)img_ptr)->height;
min_x_on_screen = max(x, 0);
max_x_on_screen = min(x + img_width, frame_width);
min_y_on_screen = max(y, 0);
max_y_on_screen = min(y + img_height, frame_height);
a = 3 * img_width;
b = 3 * frame_height;
c = img_data - 3 * x - a * y;
d = frame_data - 3 + b;
x_on_screen = min_x_on_screen;
while (x_on_screen < max_x_on_screen)
{
e = c + 3 * x_on_screen;
f = d + b * x_on_screen;
y_on_screen = min_y_on_screen;
while (y_on_screen < max_y_on_screen)
{
mlx_inline_drawcolor(
f - 3 * y_on_screen,
e + a * y_on_screen);
y_on_screen++;
}
x_on_screen++;
}
mlx3ds_internal_drawend(mlx_ptr, win_ptr);
return (0);
}

27
source/mlx_init.c Normal file
View file

@ -0,0 +1,27 @@
/**
* mlx_init.c
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*/
#include "mlx_init.h"
#include "mlx_internal.h"
#include <stdlib.h>
#include "3ds.h"
#include <citro2d.h>
static t_internal_mlx g_internal_mlx;
t_mlx mlx_init(void)
{
if (g_internal_mlx.is_init_called)
mlx3ds_internal_fatalerror("mlx_init() must be called only once");
g_internal_mlx.is_init_called = true;
gfxInit(FRAMEBUFFER_FORMAT, FRAMEBUFFER_FORMAT, false);
consoleInit(GFX_BOTTOM, NULL);
C2D_Init(SIZE_MAX); // TODO C2D use SIZE_MAX?
C2D_Prepare(); // TODO C2D overrides gfxInit??
return (&g_internal_mlx);
}

39
source/mlx_inline.c Normal file
View file

@ -0,0 +1,39 @@
/**
* mlx_inline.c
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*/
/**
* This file contains some internal functions that have to be inline for
* optimization purposes.
*
* Yes, I do include this file directly even if it's a .c file.
* What the norminette doesn't know can't hurt it.
*/
#include "3ds.h"
/// @brief Write a color at a specific location of the memory,
/// the 3 color values will be in the same order.
/// It's basically a memcpy of 3 bytes.
/// @param dest Address to the first color value of the destination.
/// @param src Address to the first color value of the source.
inline void mlx_inline_drawcolor(u8 *dest, u8 *src)
{
dest[0] = src[0];
dest[1] = src[1];
dest[2] = src[2];
}
/// @brief Write a color at a specific location of the memory,
/// the 3 color values will be in opposite order.
/// @param dest Address to the first color value of the destination.
/// @param src Address to the first color value of the source.
inline void mlx_inline_drawcolor_invert(u8 *dest, u8 *src)
{
dest[2] = src[0];
dest[1] = src[1];
dest[0] = src[2];
}

38
source/mlx_internal.c Normal file
View file

@ -0,0 +1,38 @@
/**
* mlx_internal.c
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*/
// TODO mlx_internal.c: embed uc_pause()
#include "utilsconsole.h"
#include "mlx_internal.h"
#include "3ds.h"
#include <stdio.h>
void mlx3ds_internal_fatalerror(const char *msg)
{
consoleInit(GFX_BOTTOM, NULL);
printf("\e[0;31m[mlx3ds] Fatal error:\e[0m\n%s\n", msg);
uc_pause();
}
void mlx3ds_internal_drawstart(
t_internal_mlx *mlx_ptr, t_internal_win *win_ptr)
{
(void)mlx_ptr;
win_ptr->framebuffer = gfxGetFramebuffer(GFX_TOP, GFX_LEFT,
&win_ptr->framebuffer_height, &win_ptr->framebuffer_width);
gspWaitForVBlank();
}
void mlx3ds_internal_drawend(
t_internal_mlx *mlx_ptr, t_internal_win *win_ptr)
{
(void)mlx_ptr;
(void)win_ptr;
gfxFlushBuffers();
gfxSwapBuffers();
}

96
source/mlx_internal.h Normal file
View file

@ -0,0 +1,96 @@
/**
* mlx_internal.h
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*/
/**
* This file contains internal utils.
*/
#ifndef MLX_INTERNAL_H
# define MLX_INTERNAL_H
# include <stdbool.h>
# include "3ds.h"
# include "mlx_events.h"
# define FRAMEBUFFER_FORMAT GSP_RGBA8_OES // GSPGPU_FramebufferFormat
# define FRAMEBUFFER_BPP 32 // must be coherent with above
# define FRAMEBUFFER_ENDIAN 0 // ??? // must be coherent with above
/// @brief Write an error message and exit the program.
///
/// @param msg Message to write. Must use less than 38 colons.
void mlx3ds_internal_fatalerror(const char *msg);
struct s_internal_win;
/// @brief Content of the mlx connection identifier.
typedef struct s_internal_mlx
{
/// @brief is true after mlx_init() was called, is false before.
bool is_init_called;
/// @brief Window displayed on the top screen.
struct s_internal_win *top_window;
/// @brief Function called in loop by mlx_loop().
int (*hook_loop_function)(void *param);
/// @brief Parameter given to hook_loop_function.
void *hook_loop_param;
/// @brief Set to false to break the loop of mlx_loop().
bool loop;
} t_internal_mlx;
// TODO docs
typedef struct s_internal_win_hook
{
int (*hook)();
void *param;
} t_internal_win_hook;
/// @brief Represents a window.
typedef struct s_internal_win
{
/// @brief mlx connection identifier
t_internal_mlx *mlx;
/// @brief Width of the window
int width;
/// @brief Height of the window
int height;
/// @brief Buffer of the screen.
u8 *framebuffer;
/// @brief Width of the screen (on x).
u16 framebuffer_width;
/// @brief Height of the screen (on y).
u16 framebuffer_height;
// TODO docs
t_internal_win_hook hooks[LASTEvent];
} t_internal_win;
/// @brief Represents an image in memory.
typedef struct s_internal_image
{
/// @brief Width of the image
int width;
/// @brief Height of the image
int height;
/// @brief Address of the image data. Returned by mlx_get_data_addr().
u8 *data;
} t_internal_image;
/// @brief To call before drawing. Init winptr->framebuffer.
///
/// @param mlx_ptr mlx connection identifier
/// @param win_ptr Reference to the window to draw on.
void mlx3ds_internal_drawstart(
t_internal_mlx *mlx_ptr, t_internal_win *win_ptr);
/// @brief To call when finish drawing. Flush and swap buffers.
///
/// @param mlx_ptr mlx connection identifier
/// @param win_ptr Reference to the window to draw on.
void mlx3ds_internal_drawend(
t_internal_mlx *mlx_ptr, t_internal_win *win_ptr);
#endif

32
source/mlx_put.c Normal file
View file

@ -0,0 +1,32 @@
/**
* mlx_put.c
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*/
#include "mlx_put.h"
#include "mlx_internal.h"
#include "mlx_inline.c"
int mlx_pixel_put(t_mlx mlx_ptr, t_win win_ptr, int x, int y, int color)
{
u8 *frame;
mlx3ds_internal_drawstart(mlx_ptr, win_ptr);
if (x < 0 || x >= ((t_internal_win *)win_ptr)->framebuffer_width
|| y < 0 || y >= ((t_internal_win *)win_ptr)->framebuffer_height)
return (0);
frame = ((t_internal_win *)win_ptr)->framebuffer;
mlx_inline_drawcolor(
frame + 3 * (
(x + 1) * ((t_internal_win *)win_ptr)->framebuffer_height - y - 1
),
(u8 *)&color);
mlx3ds_internal_drawend(mlx_ptr, win_ptr);
return (0);
}

54
source/mlx_window.c Normal file
View file

@ -0,0 +1,54 @@
/**
* mlx_window.c
* for the project "MinilibX for 3DS"
* by Zy
* at https://github.com/frzysk/mlx3ds
*/
#include "mlx_window.h"
#include "3ds.h"
#include "mlx_internal.h"
#include <stdlib.h>
#include <strings.h>
t_win mlx_new_window(t_mlx mlx_ptr, int size_x, int size_y, const char *title)
{
t_internal_win *r;
(void)title;
if (size_x > GSP_SCREEN_HEIGHT_TOP || size_y > GSP_SCREEN_WIDTH)
mlx3ds_internal_fatalerror("Window too big for the screen");
r = malloc(sizeof(t_internal_win));
if (!r)
return (NULL);
bzero(r, sizeof(t_internal_win));
r->mlx = mlx_ptr;
r->mlx->top_window = r;
r->width = size_x;
r->height = size_y;
return (r);
}
int mlx_clear_window(t_mlx mlx_ptr, t_win win_ptr)
{
u8 *frame_i;
u8 *frame;
mlx3ds_internal_drawstart(mlx_ptr, win_ptr);
frame = ((t_internal_win *)win_ptr)->framebuffer;
frame_i = frame
+ 3 * ((t_internal_win *)win_ptr)->framebuffer_width
* ((t_internal_win *)win_ptr)->framebuffer_height;
while (--frame_i >= frame)
*frame_i = 0x00;
mlx3ds_internal_drawend(mlx_ptr, win_ptr);
return (0);
}
int mlx_destroy_window(t_mlx mlx_ptr, t_win win_ptr)
{
((t_internal_mlx *)mlx_ptr)->top_window = NULL;
free(win_ptr);
return (0);
}

115
source/utilsconsole.cpp Normal file
View file

@ -0,0 +1,115 @@
/**
* utilsconsole.cpp
* by Zy
*/
#include <iostream>
#include <cstring>
extern "C" {
#include "utilsconsole.h"
#include <3ds.h>
#include <stdarg.h>
}
using namespace std;
int uc_menu(vector<s_uc_menu_element> &elements) {
static void *lastElements = NULL;
static size_t selected = 0;
bool confirmed = false;
if (&elements != lastElements) {
// init if new menu
consoleClear();
lastElements = &elements;
selected = 0;
}
else {
// read inputs
hidScanInput();
if (hidKeysDown() & KEY_UP) {
if (selected-- == 0)
selected += elements.size();
}
else if (hidKeysDown() & KEY_DOWN) {
if (++selected >= elements.size())
selected -= elements.size();
}
else if (!elements[selected].is_number_prompt) {
if (hidKeysDown() & KEY_A) {
confirmed = true;
lastElements = NULL;
}
}
else {
if (hidKeysDown() & KEY_LEFT)
if (*elements[selected].value > elements[selected].min)
(*elements[selected].value)--;
if (hidKeysDown() & KEY_RIGHT)
if (*elements[selected].value < elements[selected].max)
(*elements[selected].value)++;
}
}
// display
cout << "\e[H\e[0m";
for (size_t i = 0; i < elements.size(); i++) {
cout << (i == selected && !confirmed ? "\e[7m" : "")
<< elements[i].name << "\e[0m";
if (elements[i].is_number_prompt)
cout
<< ((*(elements[i].value) == elements[i].min) ? " " : " <")
<< *(elements[i].value)
<< ((*(elements[i].value) == elements[i].max) ? " " : ">");
cout << "\e[0K" << endl;
}
if (!confirmed)
cout << "\e[2m" << "[Up/Down] Move / "
<< (elements[selected].is_number_prompt ?
"[Left/Right] Modify" : "(A) Confirm") << "\e[0K" << endl;
else
cout << "\e[2mOK.\e[0K\e[0m" << endl;
return confirmed ? selected : -1;
}
extern "C" {
int uc_menu_quick(const char *str, ...) {
va_list arguments;
auto elements = vector<s_uc_menu_element>();
for (va_start(arguments, str); str; str = va_arg(arguments, const char *))
elements.push_back({str, false, NULL, 0, 0});
int r = -1;
while (r < 0 && aptMainLoop())
r = uc_menu(elements);
return r;
}
void uc_pause(void) {
cout << "\e[0;2mPress (A) to continue...\e[0m" << endl;
while (aptMainLoop()) {
hidScanInput();
if (hidKeysDown() & KEY_A)
break;
gfxFlushBuffers();
}
}
char *uc_keyboard(const char *def)
{
char *buf;
SwkbdState swkbd;
buf = new char[1000];
if (!buf)
return (NULL);
swkbdInit(&swkbd, SWKBD_TYPE_NORMAL, 1, -1);
swkbdSetInitialText(&swkbd, def);
swkbdInputText(&swkbd, buf, 1000);
return (buf);
}
}

137
source/xpm_mlx_int.h Normal file
View file

@ -0,0 +1,137 @@
/*
** mlx_int.h for mlx in
**
** Made by Charlie Root
** Login <ol@epitech.net>
**
** Started on Mon Jul 31 16:45:48 2000 Charlie Root
** Last update Wed May 25 16:44:16 2011 Olivier Crouzet
*/
/*
** Internal settings for MiniLibX
*/
/**
* Modified by Zy to work with the MinilibX For 3DS project
* (at https://github.com/frzysk/mlx3ds).
*/
#ifndef MLX_INT_H
# define MLX_INT_H
# include <stdlib.h>
# include <stdio.h>
# include <string.h>
# include <unistd.h>
# include <fcntl.h>
# define MLX_TYPE_SHM_PIXMAP 3
# define MLX_TYPE_SHM 2
# define MLX_TYPE_XIMAGE 1
# define MLX_MAX_EVENT LASTEvent
# define ENV_DISPLAY "DISPLAY"
# define LOCALHOST "localhost"
# define ERR_NO_TRUECOLOR "MinilibX Error : No TrueColor Visual available.\n"
# define WARN_SHM_ATTACH "MinilibX Warning : X server can't attach shared memory.\n"
typedef struct s_xpm_col
{
int name;
int col;
} t_xpm_col;
struct s_col_name
{
char *name;
int color;
};
typedef struct s_event_list
{
int mask;
int (*hook)();
void *param;
} t_event_list;
// typedef struct s_win_list
// {
// Window window;
// GC gc;
// struct s_win_list *next;
// int (*mouse_hook)();
// int (*key_hook)();
// int (*expose_hook)();
// void *mouse_param;
// void *key_param;
// void *expose_param;
// t_event_list hooks[MLX_MAX_EVENT];
// } t_win_list;
// typedef struct s_img
// {
// XImage *image;
// Pixmap pix;
// GC gc;
// int size_line;
// int bpp;
// int width;
// int height;
// int type;
// int format;
// char *data;
// XShmSegmentInfo shm;
// } t_img;
// typedef struct s_xvar
// {
// Display *display;
// Window root;
// int screen;
// int depth;
// Visual *visual;
// Colormap cmap;
// int private_cmap;
// t_win_list *win_list;
// int (*loop_hook)();
// void *loop_param;
// int use_xshm;
// int pshm_format;
// int do_flush;
// int decrgb[6];
// Atom wm_delete_window;
// Atom wm_protocols;
// int end_loop;
// } t_xvar;
int mlx_int_do_nothing();
int mlx_get_color_value();
int mlx_int_get_good_color();
int mlx_int_find_in_pcm();
int mlx_int_anti_resize_win();
int mlx_int_wait_first_expose();
int mlx_int_rgb_conversion();
int mlx_int_deal_shm();
void *mlx_int_new_xshm_image();
char **mlx_int_str_to_wordtab();
void *mlx_new_image();
int shm_att_pb();
// int mlx_int_get_visual(t_xvar *xvar);
// int mlx_int_set_win_event_mask(t_xvar *xvar);
int mlx_int_str_str_cote(char *str,char *find,int len);
int mlx_int_str_str(char *str,char *find,int len);
#endif

View file

@ -0,0 +1,117 @@
/*
** mlx_int_str_to_wordtab.c for MinilibX in
**
** Made by Charlie Root
** Login <ol@epitech.net>
**
** Started on Wed Sep 13 11:36:09 2000 Charlie Root
** Last update Fri Dec 14 11:02:09 2001 Charlie Root
*/
/**
* Modified by Zy to work with the MinilibX For 3DS project
* (at https://github.com/frzysk/mlx3ds).
*/
#include "xpm_mlx_int.h"
int mlx_int_str_str(char *str,char *find,int len)
{
int len_f;
int pos;
char *s;
char *f;
len_f = strlen(find);
if (len_f>len)
return (-1);
pos = 0;
while (*(str+len_f-1))
{
s = str;
f = find;
while (*(f++) == *(s++))
if (!*f)
return (pos);
str ++;
pos ++;
}
return (-1);
}
int mlx_int_str_str_cote(char *str,char *find,int len)
{
int len_f;
int pos;
char *s;
char *f;
int cote;
len_f = strlen(find);
if (len_f>len)
return (-1);
cote = 0;
pos = 0;
while (*(str+len_f-1))
{
if (*str=='"')
cote = 1-cote;
if (!cote)
{
s = str;
f = find;
while (*(f++) == *(s++))
if (!*f)
return (pos);
}
str ++;
pos ++;
}
return (-1);
}
char **mlx_int_str_to_wordtab(char *str)
{
char **tab;
int pos;
int nb_word;
int len;
len = strlen(str);
nb_word = 0;
pos = 0;
while (pos<len)
{
while (*(str+pos)==' ' || *(str+pos)=='\t')
pos ++;
if (*(str+pos))
nb_word ++;
while (*(str+pos) && *(str+pos)!=' ' && *(str+pos)!='\t')
pos ++;
}
if (!(tab = malloc((1+nb_word)*sizeof(*tab))))
return ((char **)0);
nb_word = 0;
pos = 0;
while (pos<len)
{
while (*(str+pos)==' ' || *(str+pos)=='\t')
{
*(str+pos) = 0;
pos ++;
}
if (*(str+pos))
{
tab[nb_word] = str+pos;
nb_word ++;
}
while (*(str+pos) && *(str+pos)!=' ' && *(str+pos)!='\t')
pos ++;
}
tab[nb_word] = 0;
return (tab);
}

769
source/xpm_mlx_rgb.c Normal file
View file

@ -0,0 +1,769 @@
/*
** This is a generated file with rgb2c.pl and rgb.txt from
** the XFree86 distribution.
*/
/**
* Modified by Zy to work with the MinilibX For 3DS project
* (at https://github.com/frzysk/mlx3ds).
*/
#include "xpm_mlx_int.h"
struct s_col_name mlx_col_name[] =
{
{ "snow" , 0xfffafa },
{ "ghost white" , 0xf8f8ff },
{ "ghostwhite" , 0xf8f8ff },
{ "white smoke" , 0xf5f5f5 },
{ "whitesmoke" , 0xf5f5f5 },
{ "gainsboro" , 0xdcdcdc },
{ "floral white" , 0xfffaf0 },
{ "floralwhite" , 0xfffaf0 },
{ "old lace" , 0xfdf5e6 },
{ "oldlace" , 0xfdf5e6 },
{ "linen" , 0xfaf0e6 },
{ "antique white" , 0xfaebd7 },
{ "antiquewhite" , 0xfaebd7 },
{ "papaya whip" , 0xffefd5 },
{ "papayawhip" , 0xffefd5 },
{ "blanched almond" , 0xffebcd },
{ "blanchedalmond" , 0xffebcd },
{ "bisque" , 0xffe4c4 },
{ "peach puff" , 0xffdab9 },
{ "peachpuff" , 0xffdab9 },
{ "navajo white" , 0xffdead },
{ "navajowhite" , 0xffdead },
{ "moccasin" , 0xffe4b5 },
{ "cornsilk" , 0xfff8dc },
{ "ivory" , 0xfffff0 },
{ "lemon chiffon" , 0xfffacd },
{ "lemonchiffon" , 0xfffacd },
{ "seashell" , 0xfff5ee },
{ "honeydew" , 0xf0fff0 },
{ "mint cream" , 0xf5fffa },
{ "mintcream" , 0xf5fffa },
{ "azure" , 0xf0ffff },
{ "alice blue" , 0xf0f8ff },
{ "aliceblue" , 0xf0f8ff },
{ "lavender" , 0xe6e6fa },
{ "lavender blush" , 0xfff0f5 },
{ "lavenderblush" , 0xfff0f5 },
{ "misty rose" , 0xffe4e1 },
{ "mistyrose" , 0xffe4e1 },
{ "white" , 0xffffff },
{ "black" , 0x0 },
{ "dark slate" , 0x2f4f4f },
{ "darkslategray" , 0x2f4f4f },
{ "dark slate" , 0x2f4f4f },
{ "darkslategrey" , 0x2f4f4f },
{ "dim gray" , 0x696969 },
{ "dimgray" , 0x696969 },
{ "dim grey" , 0x696969 },
{ "dimgrey" , 0x696969 },
{ "slate gray" , 0x708090 },
{ "slategray" , 0x708090 },
{ "slate grey" , 0x708090 },
{ "slategrey" , 0x708090 },
{ "light slate" , 0x778899 },
{ "lightslategray" , 0x778899 },
{ "light slate" , 0x778899 },
{ "lightslategrey" , 0x778899 },
{ "gray" , 0xbebebe },
{ "grey" , 0xbebebe },
{ "light grey" , 0xd3d3d3 },
{ "lightgrey" , 0xd3d3d3 },
{ "light gray" , 0xd3d3d3 },
{ "lightgray" , 0xd3d3d3 },
{ "midnight blue" , 0x191970 },
{ "midnightblue" , 0x191970 },
{ "navy" , 0x80 },
{ "navy blue" , 0x80 },
{ "navyblue" , 0x80 },
{ "cornflower blue" , 0x6495ed },
{ "cornflowerblue" , 0x6495ed },
{ "dark slate" , 0x483d8b },
{ "darkslateblue" , 0x483d8b },
{ "slate blue" , 0x6a5acd },
{ "slateblue" , 0x6a5acd },
{ "medium slate" , 0x7b68ee },
{ "mediumslateblue" , 0x7b68ee },
{ "light slate" , 0x8470ff },
{ "lightslateblue" , 0x8470ff },
{ "medium blue" , 0xcd },
{ "mediumblue" , 0xcd },
{ "royal blue" , 0x4169e1 },
{ "royalblue" , 0x4169e1 },
{ "blue" , 0xff },
{ "dodger blue" , 0x1e90ff },
{ "dodgerblue" , 0x1e90ff },
{ "deep sky" , 0xbfff },
{ "deepskyblue" , 0xbfff },
{ "sky blue" , 0x87ceeb },
{ "skyblue" , 0x87ceeb },
{ "light sky" , 0x87cefa },
{ "lightskyblue" , 0x87cefa },
{ "steel blue" , 0x4682b4 },
{ "steelblue" , 0x4682b4 },
{ "light steel" , 0xb0c4de },
{ "lightsteelblue" , 0xb0c4de },
{ "light blue" , 0xadd8e6 },
{ "lightblue" , 0xadd8e6 },
{ "powder blue" , 0xb0e0e6 },
{ "powderblue" , 0xb0e0e6 },
{ "pale turquoise" , 0xafeeee },
{ "paleturquoise" , 0xafeeee },
{ "dark turquoise" , 0xced1 },
{ "darkturquoise" , 0xced1 },
{ "medium turquoise" , 0x48d1cc },
{ "mediumturquoise" , 0x48d1cc },
{ "turquoise" , 0x40e0d0 },
{ "cyan" , 0xffff },
{ "light cyan" , 0xe0ffff },
{ "lightcyan" , 0xe0ffff },
{ "cadet blue" , 0x5f9ea0 },
{ "cadetblue" , 0x5f9ea0 },
{ "medium aquamarine" , 0x66cdaa },
{ "mediumaquamarine" , 0x66cdaa },
{ "aquamarine" , 0x7fffd4 },
{ "dark green" , 0x6400 },
{ "darkgreen" , 0x6400 },
{ "dark olive" , 0x556b2f },
{ "darkolivegreen" , 0x556b2f },
{ "dark sea" , 0x8fbc8f },
{ "darkseagreen" , 0x8fbc8f },
{ "sea green" , 0x2e8b57 },
{ "seagreen" , 0x2e8b57 },
{ "medium sea" , 0x3cb371 },
{ "mediumseagreen" , 0x3cb371 },
{ "light sea" , 0x20b2aa },
{ "lightseagreen" , 0x20b2aa },
{ "pale green" , 0x98fb98 },
{ "palegreen" , 0x98fb98 },
{ "spring green" , 0xff7f },
{ "springgreen" , 0xff7f },
{ "lawn green" , 0x7cfc00 },
{ "lawngreen" , 0x7cfc00 },
{ "green" , 0xff00 },
{ "chartreuse" , 0x7fff00 },
{ "medium spring" , 0xfa9a },
{ "mediumspringgreen" , 0xfa9a },
{ "green yellow" , 0xadff2f },
{ "greenyellow" , 0xadff2f },
{ "lime green" , 0x32cd32 },
{ "limegreen" , 0x32cd32 },
{ "yellow green" , 0x9acd32 },
{ "yellowgreen" , 0x9acd32 },
{ "forest green" , 0x228b22 },
{ "forestgreen" , 0x228b22 },
{ "olive drab" , 0x6b8e23 },
{ "olivedrab" , 0x6b8e23 },
{ "dark khaki" , 0xbdb76b },
{ "darkkhaki" , 0xbdb76b },
{ "khaki" , 0xf0e68c },
{ "pale goldenrod" , 0xeee8aa },
{ "palegoldenrod" , 0xeee8aa },
{ "light goldenrod" , 0xfafad2 },
{ "lightgoldenrodyellow" , 0xfafad2 },
{ "light yellow" , 0xffffe0 },
{ "lightyellow" , 0xffffe0 },
{ "yellow" , 0xffff00 },
{ "gold" , 0xffd700 },
{ "light goldenrod" , 0xeedd82 },
{ "lightgoldenrod" , 0xeedd82 },
{ "goldenrod" , 0xdaa520 },
{ "dark goldenrod" , 0xb8860b },
{ "darkgoldenrod" , 0xb8860b },
{ "rosy brown" , 0xbc8f8f },
{ "rosybrown" , 0xbc8f8f },
{ "indian red" , 0xcd5c5c },
{ "indianred" , 0xcd5c5c },
{ "saddle brown" , 0x8b4513 },
{ "saddlebrown" , 0x8b4513 },
{ "sienna" , 0xa0522d },
{ "peru" , 0xcd853f },
{ "burlywood" , 0xdeb887 },
{ "beige" , 0xf5f5dc },
{ "wheat" , 0xf5deb3 },
{ "sandy brown" , 0xf4a460 },
{ "sandybrown" , 0xf4a460 },
{ "tan" , 0xd2b48c },
{ "chocolate" , 0xd2691e },
{ "firebrick" , 0xb22222 },
{ "brown" , 0xa52a2a },
{ "dark salmon" , 0xe9967a },
{ "darksalmon" , 0xe9967a },
{ "salmon" , 0xfa8072 },
{ "light salmon" , 0xffa07a },
{ "lightsalmon" , 0xffa07a },
{ "orange" , 0xffa500 },
{ "dark orange" , 0xff8c00 },
{ "darkorange" , 0xff8c00 },
{ "coral" , 0xff7f50 },
{ "light coral" , 0xf08080 },
{ "lightcoral" , 0xf08080 },
{ "tomato" , 0xff6347 },
{ "orange red" , 0xff4500 },
{ "orangered" , 0xff4500 },
{ "red" , 0xff0000 },
{ "hot pink" , 0xff69b4 },
{ "hotpink" , 0xff69b4 },
{ "deep pink" , 0xff1493 },
{ "deeppink" , 0xff1493 },
{ "pink" , 0xffc0cb },
{ "light pink" , 0xffb6c1 },
{ "lightpink" , 0xffb6c1 },
{ "pale violet" , 0xdb7093 },
{ "palevioletred" , 0xdb7093 },
{ "maroon" , 0xb03060 },
{ "medium violet" , 0xc71585 },
{ "mediumvioletred" , 0xc71585 },
{ "violet red" , 0xd02090 },
{ "violetred" , 0xd02090 },
{ "magenta" , 0xff00ff },
{ "violet" , 0xee82ee },
{ "plum" , 0xdda0dd },
{ "orchid" , 0xda70d6 },
{ "medium orchid" , 0xba55d3 },
{ "mediumorchid" , 0xba55d3 },
{ "dark orchid" , 0x9932cc },
{ "darkorchid" , 0x9932cc },
{ "dark violet" , 0x9400d3 },
{ "darkviolet" , 0x9400d3 },
{ "blue violet" , 0x8a2be2 },
{ "blueviolet" , 0x8a2be2 },
{ "purple" , 0xa020f0 },
{ "medium purple" , 0x9370db },
{ "mediumpurple" , 0x9370db },
{ "thistle" , 0xd8bfd8 },
{ "snow1" , 0xfffafa },
{ "snow2" , 0xeee9e9 },
{ "snow3" , 0xcdc9c9 },
{ "snow4" , 0x8b8989 },
{ "seashell1" , 0xfff5ee },
{ "seashell2" , 0xeee5de },
{ "seashell3" , 0xcdc5bf },
{ "seashell4" , 0x8b8682 },
{ "antiquewhite1" , 0xffefdb },
{ "antiquewhite2" , 0xeedfcc },
{ "antiquewhite3" , 0xcdc0b0 },
{ "antiquewhite4" , 0x8b8378 },
{ "bisque1" , 0xffe4c4 },
{ "bisque2" , 0xeed5b7 },
{ "bisque3" , 0xcdb79e },
{ "bisque4" , 0x8b7d6b },
{ "peachpuff1" , 0xffdab9 },
{ "peachpuff2" , 0xeecbad },
{ "peachpuff3" , 0xcdaf95 },
{ "peachpuff4" , 0x8b7765 },
{ "navajowhite1" , 0xffdead },
{ "navajowhite2" , 0xeecfa1 },
{ "navajowhite3" , 0xcdb38b },
{ "navajowhite4" , 0x8b795e },
{ "lemonchiffon1" , 0xfffacd },
{ "lemonchiffon2" , 0xeee9bf },
{ "lemonchiffon3" , 0xcdc9a5 },
{ "lemonchiffon4" , 0x8b8970 },
{ "cornsilk1" , 0xfff8dc },
{ "cornsilk2" , 0xeee8cd },
{ "cornsilk3" , 0xcdc8b1 },
{ "cornsilk4" , 0x8b8878 },
{ "ivory1" , 0xfffff0 },
{ "ivory2" , 0xeeeee0 },
{ "ivory3" , 0xcdcdc1 },
{ "ivory4" , 0x8b8b83 },
{ "honeydew1" , 0xf0fff0 },
{ "honeydew2" , 0xe0eee0 },
{ "honeydew3" , 0xc1cdc1 },
{ "honeydew4" , 0x838b83 },
{ "lavenderblush1" , 0xfff0f5 },
{ "lavenderblush2" , 0xeee0e5 },
{ "lavenderblush3" , 0xcdc1c5 },
{ "lavenderblush4" , 0x8b8386 },
{ "mistyrose1" , 0xffe4e1 },
{ "mistyrose2" , 0xeed5d2 },
{ "mistyrose3" , 0xcdb7b5 },
{ "mistyrose4" , 0x8b7d7b },
{ "azure1" , 0xf0ffff },
{ "azure2" , 0xe0eeee },
{ "azure3" , 0xc1cdcd },
{ "azure4" , 0x838b8b },
{ "slateblue1" , 0x836fff },
{ "slateblue2" , 0x7a67ee },
{ "slateblue3" , 0x6959cd },
{ "slateblue4" , 0x473c8b },
{ "royalblue1" , 0x4876ff },
{ "royalblue2" , 0x436eee },
{ "royalblue3" , 0x3a5fcd },
{ "royalblue4" , 0x27408b },
{ "blue1" , 0xff },
{ "blue2" , 0xee },
{ "blue3" , 0xcd },
{ "blue4" , 0x8b },
{ "dodgerblue1" , 0x1e90ff },
{ "dodgerblue2" , 0x1c86ee },
{ "dodgerblue3" , 0x1874cd },
{ "dodgerblue4" , 0x104e8b },
{ "steelblue1" , 0x63b8ff },
{ "steelblue2" , 0x5cacee },
{ "steelblue3" , 0x4f94cd },
{ "steelblue4" , 0x36648b },
{ "deepskyblue1" , 0xbfff },
{ "deepskyblue2" , 0xb2ee },
{ "deepskyblue3" , 0x9acd },
{ "deepskyblue4" , 0x688b },
{ "skyblue1" , 0x87ceff },
{ "skyblue2" , 0x7ec0ee },
{ "skyblue3" , 0x6ca6cd },
{ "skyblue4" , 0x4a708b },
{ "lightskyblue1" , 0xb0e2ff },
{ "lightskyblue2" , 0xa4d3ee },
{ "lightskyblue3" , 0x8db6cd },
{ "lightskyblue4" , 0x607b8b },
{ "slategray1" , 0xc6e2ff },
{ "slategray2" , 0xb9d3ee },
{ "slategray3" , 0x9fb6cd },
{ "slategray4" , 0x6c7b8b },
{ "lightsteelblue1" , 0xcae1ff },
{ "lightsteelblue2" , 0xbcd2ee },
{ "lightsteelblue3" , 0xa2b5cd },
{ "lightsteelblue4" , 0x6e7b8b },
{ "lightblue1" , 0xbfefff },
{ "lightblue2" , 0xb2dfee },
{ "lightblue3" , 0x9ac0cd },
{ "lightblue4" , 0x68838b },
{ "lightcyan1" , 0xe0ffff },
{ "lightcyan2" , 0xd1eeee },
{ "lightcyan3" , 0xb4cdcd },
{ "lightcyan4" , 0x7a8b8b },
{ "paleturquoise1" , 0xbbffff },
{ "paleturquoise2" , 0xaeeeee },
{ "paleturquoise3" , 0x96cdcd },
{ "paleturquoise4" , 0x668b8b },
{ "cadetblue1" , 0x98f5ff },
{ "cadetblue2" , 0x8ee5ee },
{ "cadetblue3" , 0x7ac5cd },
{ "cadetblue4" , 0x53868b },
{ "turquoise1" , 0xf5ff },
{ "turquoise2" , 0xe5ee },
{ "turquoise3" , 0xc5cd },
{ "turquoise4" , 0x868b },
{ "cyan1" , 0xffff },
{ "cyan2" , 0xeeee },
{ "cyan3" , 0xcdcd },
{ "cyan4" , 0x8b8b },
{ "darkslategray1" , 0x97ffff },
{ "darkslategray2" , 0x8deeee },
{ "darkslategray3" , 0x79cdcd },
{ "darkslategray4" , 0x528b8b },
{ "aquamarine1" , 0x7fffd4 },
{ "aquamarine2" , 0x76eec6 },
{ "aquamarine3" , 0x66cdaa },
{ "aquamarine4" , 0x458b74 },
{ "darkseagreen1" , 0xc1ffc1 },
{ "darkseagreen2" , 0xb4eeb4 },
{ "darkseagreen3" , 0x9bcd9b },
{ "darkseagreen4" , 0x698b69 },
{ "seagreen1" , 0x54ff9f },
{ "seagreen2" , 0x4eee94 },
{ "seagreen3" , 0x43cd80 },
{ "seagreen4" , 0x2e8b57 },
{ "palegreen1" , 0x9aff9a },
{ "palegreen2" , 0x90ee90 },
{ "palegreen3" , 0x7ccd7c },
{ "palegreen4" , 0x548b54 },
{ "springgreen1" , 0xff7f },
{ "springgreen2" , 0xee76 },
{ "springgreen3" , 0xcd66 },
{ "springgreen4" , 0x8b45 },
{ "green1" , 0xff00 },
{ "green2" , 0xee00 },
{ "green3" , 0xcd00 },
{ "green4" , 0x8b00 },
{ "chartreuse1" , 0x7fff00 },
{ "chartreuse2" , 0x76ee00 },
{ "chartreuse3" , 0x66cd00 },
{ "chartreuse4" , 0x458b00 },
{ "olivedrab1" , 0xc0ff3e },
{ "olivedrab2" , 0xb3ee3a },
{ "olivedrab3" , 0x9acd32 },
{ "olivedrab4" , 0x698b22 },
{ "darkolivegreen1" , 0xcaff70 },
{ "darkolivegreen2" , 0xbcee68 },
{ "darkolivegreen3" , 0xa2cd5a },
{ "darkolivegreen4" , 0x6e8b3d },
{ "khaki1" , 0xfff68f },
{ "khaki2" , 0xeee685 },
{ "khaki3" , 0xcdc673 },
{ "khaki4" , 0x8b864e },
{ "lightgoldenrod1" , 0xffec8b },
{ "lightgoldenrod2" , 0xeedc82 },
{ "lightgoldenrod3" , 0xcdbe70 },
{ "lightgoldenrod4" , 0x8b814c },
{ "lightyellow1" , 0xffffe0 },
{ "lightyellow2" , 0xeeeed1 },
{ "lightyellow3" , 0xcdcdb4 },
{ "lightyellow4" , 0x8b8b7a },
{ "yellow1" , 0xffff00 },
{ "yellow2" , 0xeeee00 },
{ "yellow3" , 0xcdcd00 },
{ "yellow4" , 0x8b8b00 },
{ "gold1" , 0xffd700 },
{ "gold2" , 0xeec900 },
{ "gold3" , 0xcdad00 },
{ "gold4" , 0x8b7500 },
{ "goldenrod1" , 0xffc125 },
{ "goldenrod2" , 0xeeb422 },
{ "goldenrod3" , 0xcd9b1d },
{ "goldenrod4" , 0x8b6914 },
{ "darkgoldenrod1" , 0xffb90f },
{ "darkgoldenrod2" , 0xeead0e },
{ "darkgoldenrod3" , 0xcd950c },
{ "darkgoldenrod4" , 0x8b6508 },
{ "rosybrown1" , 0xffc1c1 },
{ "rosybrown2" , 0xeeb4b4 },
{ "rosybrown3" , 0xcd9b9b },
{ "rosybrown4" , 0x8b6969 },
{ "indianred1" , 0xff6a6a },
{ "indianred2" , 0xee6363 },
{ "indianred3" , 0xcd5555 },
{ "indianred4" , 0x8b3a3a },
{ "sienna1" , 0xff8247 },
{ "sienna2" , 0xee7942 },
{ "sienna3" , 0xcd6839 },
{ "sienna4" , 0x8b4726 },
{ "burlywood1" , 0xffd39b },
{ "burlywood2" , 0xeec591 },
{ "burlywood3" , 0xcdaa7d },
{ "burlywood4" , 0x8b7355 },
{ "wheat1" , 0xffe7ba },
{ "wheat2" , 0xeed8ae },
{ "wheat3" , 0xcdba96 },
{ "wheat4" , 0x8b7e66 },
{ "tan1" , 0xffa54f },
{ "tan2" , 0xee9a49 },
{ "tan3" , 0xcd853f },
{ "tan4" , 0x8b5a2b },
{ "chocolate1" , 0xff7f24 },
{ "chocolate2" , 0xee7621 },
{ "chocolate3" , 0xcd661d },
{ "chocolate4" , 0x8b4513 },
{ "firebrick1" , 0xff3030 },
{ "firebrick2" , 0xee2c2c },
{ "firebrick3" , 0xcd2626 },
{ "firebrick4" , 0x8b1a1a },
{ "brown1" , 0xff4040 },
{ "brown2" , 0xee3b3b },
{ "brown3" , 0xcd3333 },
{ "brown4" , 0x8b2323 },
{ "salmon1" , 0xff8c69 },
{ "salmon2" , 0xee8262 },
{ "salmon3" , 0xcd7054 },
{ "salmon4" , 0x8b4c39 },
{ "lightsalmon1" , 0xffa07a },
{ "lightsalmon2" , 0xee9572 },
{ "lightsalmon3" , 0xcd8162 },
{ "lightsalmon4" , 0x8b5742 },
{ "orange1" , 0xffa500 },
{ "orange2" , 0xee9a00 },
{ "orange3" , 0xcd8500 },
{ "orange4" , 0x8b5a00 },
{ "darkorange1" , 0xff7f00 },
{ "darkorange2" , 0xee7600 },
{ "darkorange3" , 0xcd6600 },
{ "darkorange4" , 0x8b4500 },
{ "coral1" , 0xff7256 },
{ "coral2" , 0xee6a50 },
{ "coral3" , 0xcd5b45 },
{ "coral4" , 0x8b3e2f },
{ "tomato1" , 0xff6347 },
{ "tomato2" , 0xee5c42 },
{ "tomato3" , 0xcd4f39 },
{ "tomato4" , 0x8b3626 },
{ "orangered1" , 0xff4500 },
{ "orangered2" , 0xee4000 },
{ "orangered3" , 0xcd3700 },
{ "orangered4" , 0x8b2500 },
{ "red1" , 0xff0000 },
{ "red2" , 0xee0000 },
{ "red3" , 0xcd0000 },
{ "red4" , 0x8b0000 },
{ "deeppink1" , 0xff1493 },
{ "deeppink2" , 0xee1289 },
{ "deeppink3" , 0xcd1076 },
{ "deeppink4" , 0x8b0a50 },
{ "hotpink1" , 0xff6eb4 },
{ "hotpink2" , 0xee6aa7 },
{ "hotpink3" , 0xcd6090 },
{ "hotpink4" , 0x8b3a62 },
{ "pink1" , 0xffb5c5 },
{ "pink2" , 0xeea9b8 },
{ "pink3" , 0xcd919e },
{ "pink4" , 0x8b636c },
{ "lightpink1" , 0xffaeb9 },
{ "lightpink2" , 0xeea2ad },
{ "lightpink3" , 0xcd8c95 },
{ "lightpink4" , 0x8b5f65 },
{ "palevioletred1" , 0xff82ab },
{ "palevioletred2" , 0xee799f },
{ "palevioletred3" , 0xcd6889 },
{ "palevioletred4" , 0x8b475d },
{ "maroon1" , 0xff34b3 },
{ "maroon2" , 0xee30a7 },
{ "maroon3" , 0xcd2990 },
{ "maroon4" , 0x8b1c62 },
{ "violetred1" , 0xff3e96 },
{ "violetred2" , 0xee3a8c },
{ "violetred3" , 0xcd3278 },
{ "violetred4" , 0x8b2252 },
{ "magenta1" , 0xff00ff },
{ "magenta2" , 0xee00ee },
{ "magenta3" , 0xcd00cd },
{ "magenta4" , 0x8b008b },
{ "orchid1" , 0xff83fa },
{ "orchid2" , 0xee7ae9 },
{ "orchid3" , 0xcd69c9 },
{ "orchid4" , 0x8b4789 },
{ "plum1" , 0xffbbff },
{ "plum2" , 0xeeaeee },
{ "plum3" , 0xcd96cd },
{ "plum4" , 0x8b668b },
{ "mediumorchid1" , 0xe066ff },
{ "mediumorchid2" , 0xd15fee },
{ "mediumorchid3" , 0xb452cd },
{ "mediumorchid4" , 0x7a378b },
{ "darkorchid1" , 0xbf3eff },
{ "darkorchid2" , 0xb23aee },
{ "darkorchid3" , 0x9a32cd },
{ "darkorchid4" , 0x68228b },
{ "purple1" , 0x9b30ff },
{ "purple2" , 0x912cee },
{ "purple3" , 0x7d26cd },
{ "purple4" , 0x551a8b },
{ "mediumpurple1" , 0xab82ff },
{ "mediumpurple2" , 0x9f79ee },
{ "mediumpurple3" , 0x8968cd },
{ "mediumpurple4" , 0x5d478b },
{ "thistle1" , 0xffe1ff },
{ "thistle2" , 0xeed2ee },
{ "thistle3" , 0xcdb5cd },
{ "thistle4" , 0x8b7b8b },
{ "gray0" , 0x0 },
{ "grey0" , 0x0 },
{ "gray1" , 0x30303 },
{ "grey1" , 0x30303 },
{ "gray2" , 0x50505 },
{ "grey2" , 0x50505 },
{ "gray3" , 0x80808 },
{ "grey3" , 0x80808 },
{ "gray4" , 0xa0a0a },
{ "grey4" , 0xa0a0a },
{ "gray5" , 0xd0d0d },
{ "grey5" , 0xd0d0d },
{ "gray6" , 0xf0f0f },
{ "grey6" , 0xf0f0f },
{ "gray7" , 0x121212 },
{ "grey7" , 0x121212 },
{ "gray8" , 0x141414 },
{ "grey8" , 0x141414 },
{ "gray9" , 0x171717 },
{ "grey9" , 0x171717 },
{ "gray10" , 0x1a1a1a },
{ "grey10" , 0x1a1a1a },
{ "gray11" , 0x1c1c1c },
{ "grey11" , 0x1c1c1c },
{ "gray12" , 0x1f1f1f },
{ "grey12" , 0x1f1f1f },
{ "gray13" , 0x212121 },
{ "grey13" , 0x212121 },
{ "gray14" , 0x242424 },
{ "grey14" , 0x242424 },
{ "gray15" , 0x262626 },
{ "grey15" , 0x262626 },
{ "gray16" , 0x292929 },
{ "grey16" , 0x292929 },
{ "gray17" , 0x2b2b2b },
{ "grey17" , 0x2b2b2b },
{ "gray18" , 0x2e2e2e },
{ "grey18" , 0x2e2e2e },
{ "gray19" , 0x303030 },
{ "grey19" , 0x303030 },
{ "gray20" , 0x333333 },
{ "grey20" , 0x333333 },
{ "gray21" , 0x363636 },
{ "grey21" , 0x363636 },
{ "gray22" , 0x383838 },
{ "grey22" , 0x383838 },
{ "gray23" , 0x3b3b3b },
{ "grey23" , 0x3b3b3b },
{ "gray24" , 0x3d3d3d },
{ "grey24" , 0x3d3d3d },
{ "gray25" , 0x404040 },
{ "grey25" , 0x404040 },
{ "gray26" , 0x424242 },
{ "grey26" , 0x424242 },
{ "gray27" , 0x454545 },
{ "grey27" , 0x454545 },
{ "gray28" , 0x474747 },
{ "grey28" , 0x474747 },
{ "gray29" , 0x4a4a4a },
{ "grey29" , 0x4a4a4a },
{ "gray30" , 0x4d4d4d },
{ "grey30" , 0x4d4d4d },
{ "gray31" , 0x4f4f4f },
{ "grey31" , 0x4f4f4f },
{ "gray32" , 0x525252 },
{ "grey32" , 0x525252 },
{ "gray33" , 0x545454 },
{ "grey33" , 0x545454 },
{ "gray34" , 0x575757 },
{ "grey34" , 0x575757 },
{ "gray35" , 0x595959 },
{ "grey35" , 0x595959 },
{ "gray36" , 0x5c5c5c },
{ "grey36" , 0x5c5c5c },
{ "gray37" , 0x5e5e5e },
{ "grey37" , 0x5e5e5e },
{ "gray38" , 0x616161 },
{ "grey38" , 0x616161 },
{ "gray39" , 0x636363 },
{ "grey39" , 0x636363 },
{ "gray40" , 0x666666 },
{ "grey40" , 0x666666 },
{ "gray41" , 0x696969 },
{ "grey41" , 0x696969 },
{ "gray42" , 0x6b6b6b },
{ "grey42" , 0x6b6b6b },
{ "gray43" , 0x6e6e6e },
{ "grey43" , 0x6e6e6e },
{ "gray44" , 0x707070 },
{ "grey44" , 0x707070 },
{ "gray45" , 0x737373 },
{ "grey45" , 0x737373 },
{ "gray46" , 0x757575 },
{ "grey46" , 0x757575 },
{ "gray47" , 0x787878 },
{ "grey47" , 0x787878 },
{ "gray48" , 0x7a7a7a },
{ "grey48" , 0x7a7a7a },
{ "gray49" , 0x7d7d7d },
{ "grey49" , 0x7d7d7d },
{ "gray50" , 0x7f7f7f },
{ "grey50" , 0x7f7f7f },
{ "gray51" , 0x828282 },
{ "grey51" , 0x828282 },
{ "gray52" , 0x858585 },
{ "grey52" , 0x858585 },
{ "gray53" , 0x878787 },
{ "grey53" , 0x878787 },
{ "gray54" , 0x8a8a8a },
{ "grey54" , 0x8a8a8a },
{ "gray55" , 0x8c8c8c },
{ "grey55" , 0x8c8c8c },
{ "gray56" , 0x8f8f8f },
{ "grey56" , 0x8f8f8f },
{ "gray57" , 0x919191 },
{ "grey57" , 0x919191 },
{ "gray58" , 0x949494 },
{ "grey58" , 0x949494 },
{ "gray59" , 0x969696 },
{ "grey59" , 0x969696 },
{ "gray60" , 0x999999 },
{ "grey60" , 0x999999 },
{ "gray61" , 0x9c9c9c },
{ "grey61" , 0x9c9c9c },
{ "gray62" , 0x9e9e9e },
{ "grey62" , 0x9e9e9e },
{ "gray63" , 0xa1a1a1 },
{ "grey63" , 0xa1a1a1 },
{ "gray64" , 0xa3a3a3 },
{ "grey64" , 0xa3a3a3 },
{ "gray65" , 0xa6a6a6 },
{ "grey65" , 0xa6a6a6 },
{ "gray66" , 0xa8a8a8 },
{ "grey66" , 0xa8a8a8 },
{ "gray67" , 0xababab },
{ "grey67" , 0xababab },
{ "gray68" , 0xadadad },
{ "grey68" , 0xadadad },
{ "gray69" , 0xb0b0b0 },
{ "grey69" , 0xb0b0b0 },
{ "gray70" , 0xb3b3b3 },
{ "grey70" , 0xb3b3b3 },
{ "gray71" , 0xb5b5b5 },
{ "grey71" , 0xb5b5b5 },
{ "gray72" , 0xb8b8b8 },
{ "grey72" , 0xb8b8b8 },
{ "gray73" , 0xbababa },
{ "grey73" , 0xbababa },
{ "gray74" , 0xbdbdbd },
{ "grey74" , 0xbdbdbd },
{ "gray75" , 0xbfbfbf },
{ "grey75" , 0xbfbfbf },
{ "gray76" , 0xc2c2c2 },
{ "grey76" , 0xc2c2c2 },
{ "gray77" , 0xc4c4c4 },
{ "grey77" , 0xc4c4c4 },
{ "gray78" , 0xc7c7c7 },
{ "grey78" , 0xc7c7c7 },
{ "gray79" , 0xc9c9c9 },
{ "grey79" , 0xc9c9c9 },
{ "gray80" , 0xcccccc },
{ "grey80" , 0xcccccc },
{ "gray81" , 0xcfcfcf },
{ "grey81" , 0xcfcfcf },
{ "gray82" , 0xd1d1d1 },
{ "grey82" , 0xd1d1d1 },
{ "gray83" , 0xd4d4d4 },
{ "grey83" , 0xd4d4d4 },
{ "gray84" , 0xd6d6d6 },
{ "grey84" , 0xd6d6d6 },
{ "gray85" , 0xd9d9d9 },
{ "grey85" , 0xd9d9d9 },
{ "gray86" , 0xdbdbdb },
{ "grey86" , 0xdbdbdb },
{ "gray87" , 0xdedede },
{ "grey87" , 0xdedede },
{ "gray88" , 0xe0e0e0 },
{ "grey88" , 0xe0e0e0 },
{ "gray89" , 0xe3e3e3 },
{ "grey89" , 0xe3e3e3 },
{ "gray90" , 0xe5e5e5 },
{ "grey90" , 0xe5e5e5 },
{ "gray91" , 0xe8e8e8 },
{ "grey91" , 0xe8e8e8 },
{ "gray92" , 0xebebeb },
{ "grey92" , 0xebebeb },
{ "gray93" , 0xededed },
{ "grey93" , 0xededed },
{ "gray94" , 0xf0f0f0 },
{ "grey94" , 0xf0f0f0 },
{ "gray95" , 0xf2f2f2 },
{ "grey95" , 0xf2f2f2 },
{ "gray96" , 0xf5f5f5 },
{ "grey96" , 0xf5f5f5 },
{ "gray97" , 0xf7f7f7 },
{ "grey97" , 0xf7f7f7 },
{ "gray98" , 0xfafafa },
{ "grey98" , 0xfafafa },
{ "gray99" , 0xfcfcfc },
{ "grey99" , 0xfcfcfc },
{ "gray100" , 0xffffff },
{ "grey100" , 0xffffff },
{ "dark grey" , 0xa9a9a9 },
{ "darkgrey" , 0xa9a9a9 },
{ "dark gray" , 0xa9a9a9 },
{ "darkgray" , 0xa9a9a9 },
{ "dark blue" , 0x8b },
{ "darkblue" , 0x8b },
{ "dark cyan" , 0x8b8b },
{ "darkcyan" , 0x8b8b },
{ "dark magenta" , 0x8b008b },
{ "darkmagenta" , 0x8b008b },
{ "dark red" , 0x8b0000 },
{ "darkred" , 0x8b0000 },
{ "light green" , 0x90ee90 },
{ "lightgreen" , 0x90ee90 },
{ "none", -1 },
{ 0, 0 }
};

354
source/xpm_mlx_xpm.c Normal file
View file

@ -0,0 +1,354 @@
/*
** xpm-read.c for MinilibX in
**
** Made by Charlie Root
** Login <ol@epitech.net>
**
** Started on Tue Dec 11 15:25:27 2001 olivier crouzet
** Last update Sat Oct 1 14:56:13 2005 Olivier Crouzet
*/
/**
* Modified by Zy to work with the MinilibX For 3DS project
* (at https://github.com/frzysk/mlx3ds).
*/
#include "xpm_mlx_int.h"
#include "mlx.h"
#include "mlx_internal.h"
#include "mlx3ds.h"
extern struct s_col_name mlx_col_name[];
#define RETURN { if (colors) free(colors); if (tab) free(tab); \
tab = (void *)0; if (colors_direct) free(colors_direct); \
if (img) free(img); \
return ((void *)0);}
char *mlx_int_get_line(char *ptr,int *pos,int size)
{
int pos2;
int pos3;
int pos4;
if ((pos2 = mlx_int_str_str(ptr+*pos,"\"",size-*pos))==-1)
return ((char *)0);
if ((pos3 = mlx_int_str_str(ptr+*pos+pos2+1,"\"",size-*pos-pos2-1))==-1)
return ((char *)0);
*(ptr+*pos+pos2) = 0;
*(ptr+*pos+pos2+1+pos3) = 0;
pos4 = *pos+pos2+1;
*pos += pos2+pos3+2;
return (ptr+pos4);
}
unsigned int strlcpy_is_not_posix(char *dest, char *src, unsigned int size)
{
unsigned count;
unsigned i;
count = 0;
while (src[count] != '\0')
++count;
i = 0;
while (src[i] != '\0' && i < (size - 1))
{
dest[i] = src[i];
++i;
}
dest[i] = '\0';
return (count);
}
char *mlx_int_static_line(char **xpm_data,int *pos,int size)
{
static char *copy = 0;
static int len = 0;
int len2;
char *str;
(void)size;
str = xpm_data[(*pos)++];
if ((len2 = strlen(str))>len)
{
if (copy)
free(copy);
if (!(copy = malloc(len2+1)))
return ((char *)0);
len = len2;
}
strlcpy_is_not_posix(copy, str, len2 + 1);
return (copy);
}
int mlx_int_get_col_name(char *str,int size)
{
int result;
result = 0;
while (size--)
result = (result<<8)+*(str++);
return (result);
}
int mlx_int_get_text_rgb(char *name, char *end)
{
int i;
char buff[64];
if (*name == '#')
return (strtol(name+1,0,16));
if (end)
{
snprintf(buff, 64, "%s %s", name, end);
name = buff;
}
i = 0;
while (mlx_col_name[i].name)
{
if (!strcasecmp(mlx_col_name[i].name, name))
return (mlx_col_name[i].color);
i ++;
}
return (0);
}
int mlx_int_xpm_set_pixel(t_internal_image *img, u8 *data, int opp, int col, int x)
{
int dec;
(void)img;
dec = opp;
while (dec--)
{
const bool byte_order = false; // apparently works lol
if (byte_order)
*(data+x*opp+dec) = col&0xFF;
else
*(data+x*opp+opp-dec-1) = col&0xFF;
col >>= 8;
}
return (0);
}
void *mlx_int_parse_xpm(t_mlx mlx_ptr,void *info,int info_size,char *(*f)())
{
int pos;
char *line;
char **tab;
u8 *data;
int nc;
int cpp;
int col;
int rgb_col;
int col_name;
int method;
int x;
int i;
int j;
t_internal_image *img;
t_xpm_col *colors;
int *colors_direct;
int width;
int height;
colors = 0;
colors_direct = 0;
img = 0;
tab = 0;
pos = 0;
if (!(line = f(info,&pos,info_size)) ||
!(tab = mlx_int_str_to_wordtab(line)) || !(width = atoi(tab[0])) ||
!(height = atoi(tab[1])) || !(nc = atoi(tab[2])) ||
!(cpp = atoi(tab[3])) )
RETURN;
free(tab);
tab = 0;
method = 0;
if (cpp<=2)
{
method = 1;
if (!(colors_direct = malloc((cpp==2?65536:256)*sizeof(int))))
RETURN;
}
else
if (!(colors = malloc(nc*sizeof(*colors))))
RETURN;
i = nc;
while (i--)
{
if (!(line = f(info,&pos,info_size)) ||
!(tab = mlx_int_str_to_wordtab(line+cpp)) )
RETURN;
j = 0;
while (tab[j] && strcmp(tab[j++],"c"));
if (!tab[j])
RETURN;
rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]);
/*
if ((rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]))==-1)
{
if (!(clip_data = malloc(4*width*height)) || ok, nice size ..
!(clip_img = XCreateImage(xvar->display, xvar->visual,
1, XYPixmap, 0, clip_data,
width, height, 8, (width+7)/8)) )
RETURN;
memset(clip_data, 0xFF, 4*width*height);
}
*/
if (method)
colors_direct[mlx_int_get_col_name(line,cpp)] = rgb_col;
// rgb_col>=0?mlx_get_color_value(xvar, rgb_col):rgb_col;
else
{
colors[i].name = mlx_int_get_col_name(line,cpp);
colors[i].col = rgb_col; //rgb_col>=0?mlx_get_color_value(xvar,rgb_col):rgb_col;
}
free(tab);
tab = (void *)0;
}
if (!(img = mlx_new_image(mlx_ptr,width,height)))
RETURN;
i = height;
data = img->data;
while (i--)
{
if (!(line = f(info,&pos,info_size)))
RETURN;
x = 0;
while (x<width)
{
col = 0;
col_name = mlx_int_get_col_name(line+cpp*x,cpp);
if (method)
col = colors_direct[col_name];
else
{
j = nc;
while (j--)
if (colors[j].name==col_name)
{
col = colors[j].col;
j = 0;
}
}
/*
if (col==-1)
XPutPixel(clip_img, x, height-1-i, 0);
else
mlx_int_xpm_set_pixel(img, data, opp, col, x);
x ++;
*/
if (col==-1)
col = 0xFF000000;
mlx_int_xpm_set_pixel(img, data, 3, col, x);
++x;
}
data += img->width * 3;
}
/*
if (clip_data)
{
if (!(clip_pix = XCreatePixmap(xvar->display, xvar->root,
width, height, 1)) )
RETURN;
img->gc = XCreateGC(xvar->display, clip_pix, 0, &xgcv);
XPutImage(xvar->display, clip_pix, img->gc, clip_img,
0, 0, 0, 0, width, height);
XFreeGC(xvar->display, img->gc);
xgcv.clip_mask = clip_pix;
xgcv.function = GXcopy;
xgcv.plane_mask = AllPlanes;
img->gc = XCreateGC(xvar->display, xvar->root, GCClipMask|GCFunction|
GCPlaneMask, &xgcv);
XSync(xvar->display, False);
XDestroyImage(clip_img);
}
*/
if (colors)
free(colors);
if (colors_direct)
free(colors_direct);
return (img);
}
int mlx_int_file_get_rid_comment(char *ptr, int size)
{
int com_begin;
int com_end;
while ((com_begin = mlx_int_str_str_cote(ptr,"/*",size))!=-1)
{
com_end = mlx_int_str_str(ptr+com_begin+2,"*/",size-com_begin-2);
memset(ptr+com_begin,' ',com_end+4);
}
while ((com_begin = mlx_int_str_str_cote(ptr,"//",size))!=-1)
{
com_end = mlx_int_str_str(ptr+com_begin+2,"\n",size-com_begin-2);
memset(ptr+com_begin,' ',com_end+3);
}
return (0);
}
t_image mlx_xpm_file_to_image(t_mlx xvar, const char *file,int *width,int *height)
{
const t_embeddedasset *asset;
char *ptr;
t_internal_image *img;
// fd = -1;
// if ((fd = open(file,O_RDONLY))==-1 || (size = lseek(fd,0,SEEK_END))==-1 ||
// (ptr = mmap(0,size,PROT_WRITE|PROT_READ,MAP_PRIVATE,fd,0))==
// (void *)MAP_FAILED)
// {
// if (fd>=0)
// close(fd);
// return ((void *)0);
// }
asset = mlx3ds_assets_get(file);
if (!asset)
return (NULL);
ptr = strdup(asset->data);
mlx_int_file_get_rid_comment(ptr, asset->size);
img = mlx_int_parse_xpm(xvar,ptr,asset->size,mlx_int_get_line);
if (img)
{
*width = img->width;
*height = img->height;
}
return (img);
}
t_image mlx_xpm_to_image(t_mlx mlx_ptr, const char **xpm_data,int *width,int *height)
{
t_internal_image *img;
img = mlx_int_parse_xpm(mlx_ptr, xpm_data,0,mlx_int_static_line);
if (img)
{
if (width)
*width = img->width;
if (height)
*height = img->height;
}
return (img);
}

10
wiki/BASICS.mc Normal file
View file

@ -0,0 +1,10 @@
TODO file
How to change a original MinilibX project to a 3DS one:
- manage files and Makefile (include the 3ds mlx.h)
- change screen dimensions
- main must be main(void)
- new inputs
- use assets instead of files
- change big malloc/free to linearAlloc/linearFree
- change color format and adapt everything