最初コミット
このコミットが含まれているのは:
コミット
0685ca320b
|
@ -0,0 +1,2 @@
|
|||
sprite.tga
|
||||
pixed
|
|
@ -0,0 +1,2 @@
|
|||
# 0.1.0
|
||||
* 開始
|
|
@ -0,0 +1,14 @@
|
|||
Copyright © 2004-2011 by Internet Systems Consortium, Inc. ("ISC")
|
||||
Copyright © 2018-2024 by 076.moe
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
|
||||
TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
SOFTWARE.
|
|
@ -0,0 +1,32 @@
|
|||
NAME=pixed
|
||||
VERSION=0.1.0
|
||||
PREFIX=/usr/local
|
||||
CC=cc
|
||||
FILES=main.c src/*.c
|
||||
CFLAGS=-Wall -Wextra -g
|
||||
LIBS=-lSDL2
|
||||
LDFLAGS=-L${PREFIX}/lib
|
||||
CPPFLAGS=-I${PREFIX}/include
|
||||
|
||||
all:
|
||||
${CC} ${CFLAGS} ${CPPFLAGS} -o ${NAME} ${FILES} ${LDFLAGS} ${LIBS}
|
||||
|
||||
clean:
|
||||
rm -f ${NAME}
|
||||
|
||||
dist: clean
|
||||
mkdir -p ${NAME}-${VERSION}
|
||||
cp -R LICENSE.txt Makefile README.md CHANGELOG.md\
|
||||
*.c src ${NAME}-${VERSION}
|
||||
tar zcfv ${NAME}-${VERSION}.tar.gz ${NAME}-${VERSION}
|
||||
rm -rf ${NAME}-${VERSION}
|
||||
|
||||
install: all
|
||||
mkdir -p ${DESTDIR}${PREFIX}/bin
|
||||
cp -f ${NAME} ${DESTDIR}${PREFIX}/bin
|
||||
chmod 755 ${DESTDIR}${PREFIX}/bin/${NAME}
|
||||
|
||||
uninstall:
|
||||
rm -f ${DESTDIR}${PREFIX}/bin/${NAME}
|
||||
|
||||
.PHONY: all clean install uninstall
|
|
@ -0,0 +1,53 @@
|
|||
# pixed
|
||||
シンプルなピクセルアート編集ツール
|
||||
|
||||
# インストールする方法
|
||||
|
||||
## OpenBSD
|
||||
```sh
|
||||
doas pkg_add sdl2
|
||||
make
|
||||
doas make install
|
||||
```
|
||||
|
||||
## FreeBSD
|
||||
```sh
|
||||
doas pkg install sdl2
|
||||
make
|
||||
doas make install
|
||||
```
|
||||
|
||||
## NetBSD
|
||||
```sh
|
||||
doas pkgin install SDL2-2.28.5
|
||||
make PREFIX=/usr/pkg
|
||||
doas make install PREFIX=/usr/pkg
|
||||
```
|
||||
|
||||
## CRUX
|
||||
```sh
|
||||
doas prt-get depinst libsdl2
|
||||
make PREFIX=/usr
|
||||
doas make install PREFIX=/usr
|
||||
```
|
||||
|
||||
## Void Linux
|
||||
```sh
|
||||
doas xbps-install -S SDL2
|
||||
make PREFIX=/usr
|
||||
doas make install PREFIX=/usr
|
||||
```
|
||||
|
||||
## Artix Linux
|
||||
```sh
|
||||
doas pacman -S sdl2
|
||||
make PREFIX=/usr
|
||||
doas make install PREFIX=/usr
|
||||
```
|
||||
|
||||
## Devuan GNU/Linux
|
||||
```sh
|
||||
doas apt install libsdl2-dev
|
||||
make PREFIX=/usr
|
||||
doas make install PREFIX=/usr
|
||||
```
|
|
@ -0,0 +1,35 @@
|
|||
#include <SDL2/SDL.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "src/export.h"
|
||||
#include "src/input.h"
|
||||
#include "src/draw.h"
|
||||
#include "src/global.h"
|
||||
|
||||
void initSDL() {
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
window = SDL_CreateWindow(
|
||||
"pixed",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT,
|
||||
SDL_WINDOW_SHOWN
|
||||
);
|
||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
initSDL();
|
||||
|
||||
while (1) {
|
||||
handleInput();
|
||||
drawGrid();
|
||||
SDL_Delay(16);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "global.h"
|
||||
|
||||
void doDrawGrid(int x, int y) {
|
||||
SDL_Rect pixelRect = {
|
||||
x * PIXEL_SIZE,
|
||||
y * PIXEL_SIZE,
|
||||
PIXEL_SIZE,
|
||||
PIXEL_SIZE
|
||||
};
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
|
||||
if (grid[x][y] == 0) {
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
} else if (grid[x][y] == 1) {
|
||||
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
||||
} else if (grid[x][y] == 2) {
|
||||
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
|
||||
} else if (grid[x][y] == 3) {
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
|
||||
} else {
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
}
|
||||
|
||||
SDL_RenderFillRect(renderer, &pixelRect);
|
||||
}
|
||||
|
||||
void drawPicker() {
|
||||
SDL_Rect pickerRect = {
|
||||
FRAME_WIDTH,
|
||||
0,
|
||||
COLOR_PICKER_WIDTH,
|
||||
SCREEN_HEIGHT
|
||||
};
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 200, 200, 200, 255);
|
||||
SDL_RenderFillRect(renderer, &pickerRect);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
SDL_Rect colorRect = {
|
||||
FRAME_WIDTH + PIXEL_SIZE,
|
||||
i * (COLOR_PICKER_WIDTH / 4),
|
||||
COLOR_PICKER_WIDTH - (PIXEL_SIZE * 2),
|
||||
COLOR_PICKER_WIDTH / 4 - PIXEL_SIZE
|
||||
};
|
||||
if (i == 0) {
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
} else if (i == 1) {
|
||||
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
||||
} else if (i == 2) {
|
||||
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
|
||||
} else if (i == 3) {
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
|
||||
} else {
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
}
|
||||
|
||||
SDL_RenderFillRect(renderer, &colorRect);
|
||||
}
|
||||
}
|
||||
|
||||
void drawGrid() {
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
for (int x = 0; x < FRAME_WIDTH / PIXEL_SIZE; x++) {
|
||||
for (int y = 0; y < FRAME_HEIGHT / PIXEL_SIZE; y++) {
|
||||
doDrawGrid(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
drawPicker();
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef DRAW_H
|
||||
#define DRAW_H
|
||||
|
||||
void drawGrid();
|
||||
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "global.h"
|
||||
|
||||
void saveTGA() {
|
||||
FILE *file = fopen("sprite.tga", "wb");
|
||||
if (!file) {
|
||||
puts("ファイルの作成に失敗。\n");
|
||||
return;
|
||||
}
|
||||
|
||||
fputc(0, file); // ID長さ
|
||||
fputc(0, file); // 色マップ類
|
||||
fputc(2, file);
|
||||
for (int i = 0; i < 5; i++) fputc(0, file);
|
||||
for (int i = 0; i < 4; i++) fputc(0, file);
|
||||
fputc(FRAME_WIDTH & 0xFF, file);
|
||||
fputc((FRAME_WIDTH >> 8) & 0xFF, file);
|
||||
fputc(FRAME_HEIGHT & 0xFF, file);
|
||||
fputc((FRAME_HEIGHT >> 8) & 0xFF, file);
|
||||
fputc(24, file);
|
||||
|
||||
for (int y = FRAME_HEIGHT / PIXEL_SIZE - 1; y >= 0; y--) {
|
||||
for (int x = 0; x < FRAME_WIDTH / PIXEL_SIZE; x++) {
|
||||
int color = grid[x][y];
|
||||
if (color == 0) {
|
||||
fputc(0, file);
|
||||
fputc(0, file);
|
||||
fputc(0, file);
|
||||
} else if (color == 1) {
|
||||
fputc(255, file);
|
||||
fputc(0, file);
|
||||
fputc(0, file);
|
||||
} else if (color == 2) {
|
||||
fputc(0, file);
|
||||
fputc(255, file);
|
||||
fputc(0, file);
|
||||
} else if (color == 3) {
|
||||
fputc(0, file);
|
||||
fputc(0, file);
|
||||
fputc(255, file);
|
||||
} else {
|
||||
fputc(255, file);
|
||||
fputc(255, file);
|
||||
fputc(255, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
puts("ファイルを保存しました。");
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXPORT_H
|
||||
#define EXPORT_H
|
||||
|
||||
void saveTGA();
|
||||
|
||||
#endif
|
|
@ -0,0 +1,6 @@
|
|||
#include "global.h"
|
||||
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *renderer = NULL;
|
||||
int grid[FRAME_WIDTH / PIXEL_SIZE][FRAME_HEIGHT / PIXEL_SIZE];
|
||||
int currentColor = 0;
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef GLOBAL_H
|
||||
#define GLOBAL_H
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#define SCREEN_WIDTH 800
|
||||
#define SCREEN_HEIGHT 600
|
||||
#define FRAME_WIDTH 600
|
||||
#define FRAME_HEIGHT 600
|
||||
#define COLOR_PICKER_WIDTH 200
|
||||
#define PIXEL_SIZE 10
|
||||
|
||||
extern SDL_Window *window;
|
||||
extern SDL_Renderer *renderer;
|
||||
extern int grid[FRAME_WIDTH / PIXEL_SIZE][FRAME_HEIGHT / PIXEL_SIZE];
|
||||
extern int currentColor;
|
||||
|
||||
#endif
|
|
@ -0,0 +1,43 @@
|
|||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "export.h"
|
||||
#include "global.h"
|
||||
|
||||
void doHandleInput(SDL_Event event) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
exit(0);
|
||||
} else if (event.type == SDL_KEYDOWN) {
|
||||
if (event.key.keysym.sym == SDLK_w && SDL_GetModState() & KMOD_CTRL) {
|
||||
saveTGA();
|
||||
}
|
||||
} else if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||
int x = event.button.x;
|
||||
int y = event.button.y;
|
||||
if (x < FRAME_WIDTH && y < FRAME_HEIGHT) {
|
||||
int gridX = x / PIXEL_SIZE;
|
||||
int gridY = y / PIXEL_SIZE;
|
||||
grid[gridX][gridY] = currentColor;
|
||||
} else if (x >= FRAME_WIDTH && x < SCREEN_WIDTH && y < COLOR_PICKER_WIDTH) {
|
||||
int colorIndex = (y / (COLOR_PICKER_WIDTH / 4)) % 4;
|
||||
currentColor = colorIndex;
|
||||
}
|
||||
}
|
||||
} else if (event.type == SDL_MOUSEMOTION) {
|
||||
if (event.motion.state & SDL_BUTTON_LMASK) {
|
||||
int x = event.motion.x;
|
||||
int y = event.motion.y;
|
||||
if (x > FRAME_WIDTH || y > FRAME_HEIGHT) return;
|
||||
int gridX = x / PIXEL_SIZE;
|
||||
int gridY = y / PIXEL_SIZE;
|
||||
grid[gridX][gridY] = currentColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void handleInput() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
doHandleInput(event);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
|
||||
void handleInput();
|
||||
|
||||
#endif
|
読み込み中…
新しいイシューから参照