Compare commits
4 Commits
724592ec67
...
dab7a96ec2
| Author | SHA1 | Date | |
|---|---|---|---|
| dab7a96ec2 | |||
| 584b65041c | |||
| 0a92e29aa3 | |||
| 58f4845746 |
@@ -11,7 +11,12 @@ function _update()
|
||||
end
|
||||
|
||||
function normal_update()
|
||||
view()
|
||||
|
||||
cls(20)
|
||||
view(10,10,140,100)
|
||||
cls(3)
|
||||
prnt("HOLA",0,0)
|
||||
prnt(text,x,60)
|
||||
if btnp(keyRight) then x=x+1 end
|
||||
if btnp(keyLeft) then x=x-1 end
|
||||
|
||||
28
lua.cpp
28
lua.cpp
@@ -259,11 +259,15 @@ extern "C" {
|
||||
}
|
||||
|
||||
static int cpp_clip(lua_State *L) {
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
int w = luaL_checknumber(L, 3);
|
||||
int h = luaL_checknumber(L, 4);
|
||||
clip(x, y, w, h);
|
||||
if (lua_gettop(L) == 0) {
|
||||
clip();
|
||||
} else {
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
int w = luaL_checknumber(L, 3);
|
||||
int h = luaL_checknumber(L, 4);
|
||||
clip(x, y, w, h);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -274,6 +278,19 @@ extern "C" {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_view(lua_State *L) {
|
||||
if (lua_gettop(L) == 0) {
|
||||
view();
|
||||
} else {
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
int w = luaL_checknumber(L, 3);
|
||||
int h = luaL_checknumber(L, 4);
|
||||
view(x, y, w, h);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_circ(lua_State *L) {
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
@@ -837,6 +854,7 @@ void push_lua_funcs() {
|
||||
lua_pushcfunction(L,cpp_print); lua_setglobal(L, "prnt");
|
||||
lua_pushcfunction(L,cpp_clip); lua_setglobal(L, "clip");
|
||||
lua_pushcfunction(L,cpp_camera); lua_setglobal(L, "camera");
|
||||
lua_pushcfunction(L,cpp_view); lua_setglobal(L, "view");
|
||||
lua_pushcfunction(L,cpp_circ); lua_setglobal(L, "circ");
|
||||
lua_pushcfunction(L,cpp_circfill); lua_setglobal(L, "circfill");
|
||||
lua_pushcfunction(L,cpp_oval); lua_setglobal(L, "oval");
|
||||
|
||||
57
mini.cpp
57
mini.cpp
@@ -28,6 +28,9 @@ uint8_t screen_zoom = 4;
|
||||
bool screen_fullscreen = false;
|
||||
bool screen_cursor = true;
|
||||
|
||||
int windowpos_x = SDL_WINDOWPOS_UNDEFINED;
|
||||
int windowpos_y = SDL_WINDOWPOS_UNDEFINED;
|
||||
|
||||
surface_t surfaces[10];
|
||||
surface_t *screen_surface = &surfaces[0];
|
||||
surface_t *dest_surface = screen_surface;
|
||||
@@ -60,6 +63,7 @@ bool should_quit = false;
|
||||
SDL_Window *mini_win;
|
||||
SDL_Renderer *mini_ren;
|
||||
SDL_Texture *mini_bak;
|
||||
Uint32 windowID;
|
||||
Uint32 *pixels;
|
||||
int pitch;
|
||||
|
||||
@@ -200,12 +204,14 @@ void setmap(uint8_t surface) {
|
||||
}
|
||||
|
||||
void createDisplay() {
|
||||
mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width*screen_zoom, screen_height*screen_zoom, screen_fullscreen?SDL_WINDOW_FULLSCREEN_DESKTOP:SDL_WINDOW_SHOWN);
|
||||
mini_win = SDL_CreateWindow(window_title, windowpos_x, windowpos_y, screen_width*screen_zoom, screen_height*screen_zoom, screen_fullscreen?SDL_WINDOW_FULLSCREEN_DESKTOP:SDL_WINDOW_SHOWN);
|
||||
windowID = SDL_GetWindowID(mini_win);
|
||||
mini_ren = SDL_CreateRenderer(mini_win, -1, 0);
|
||||
//SDL_CreateWindowAndRenderer(512,512,0,&mini_win,&mini_ren);
|
||||
SDL_RenderSetLogicalSize(mini_ren, screen_width, screen_height);
|
||||
SDL_ShowCursor(screen_cursor?SDL_ENABLE:SDL_DISABLE);
|
||||
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
||||
SDL_GetWindowPosition(mini_win, &windowpos_x, &windowpos_y);
|
||||
}
|
||||
|
||||
void destroyDisplay() {
|
||||
@@ -326,6 +332,13 @@ int main(int argc,char*argv[]){
|
||||
if (mini_eve.type == SDL_CONTROLLERBUTTONDOWN) {
|
||||
pad_just_pressed = mini_eve.cbutton.button;
|
||||
}
|
||||
if ( (mini_eve.type == SDL_WINDOWEVENT) &&
|
||||
(mini_eve.window.windowID == windowID) &&
|
||||
(mini_eve.window.event == SDL_WINDOWEVENT_MOVED) ) {
|
||||
windowpos_x = mini_eve.window.data1-4;
|
||||
windowpos_y = mini_eve.window.data2-36;
|
||||
//SDL_GetWindowPosition(mini_win, &windowpos_x, &windowpos_y);
|
||||
}
|
||||
}
|
||||
keys = SDL_GetKeyboardState(NULL);
|
||||
mouse_buttons = SDL_GetMouseState(&mouse_x, &mouse_y);
|
||||
@@ -364,8 +377,19 @@ int main(int argc,char*argv[]){
|
||||
return 0;
|
||||
}
|
||||
|
||||
void simple_pset(int x, int y, uint8_t color) {
|
||||
x -= ds::cam[0]; y -= ds::cam[1];
|
||||
if (x < ds::clip[0] || x >= ds::clip[2] || y < ds::clip[1] || y >= ds::clip[3]) return;
|
||||
DEST(x, y) = color;
|
||||
}
|
||||
|
||||
void cls(uint8_t color) {
|
||||
SDL_memset(dest_surface->p, color, dest_surface->size);
|
||||
for (int y=ds::clip[1]+ds::cam[1]; y<ds::clip[3]+ds::cam[1];++y) {
|
||||
for (int x=ds::clip[0]+ds::cam[0]; x<ds::clip[2]+ds::cam[0];++x) {
|
||||
simple_pset(x,y,color);
|
||||
}
|
||||
}
|
||||
//SDL_memset(dest_surface->p, color, dest_surface->size);
|
||||
}
|
||||
|
||||
void color(uint8_t color) {
|
||||
@@ -442,15 +466,9 @@ void palt(uint8_t col, bool t) {
|
||||
}
|
||||
*/
|
||||
|
||||
void simple_pset(int x, int y, uint8_t color) {
|
||||
x -= ds::cam[0]; y -= ds::cam[1];
|
||||
if (x < ds::clp[0] || x > ds::clp[2] || y < ds::clp[1] || y > ds::clp[3]) return;
|
||||
DEST(x, y) = color;
|
||||
}
|
||||
|
||||
void pset(int x, int y) {
|
||||
x -= ds::cam[0]; y -= ds::cam[1];
|
||||
if (x < ds::clp[0] || x > ds::clp[2] || y < ds::clp[1] || y > ds::clp[3]) return;
|
||||
if (x < ds::clip[0] || x >= ds::clip[2] || y < ds::clip[1] || y >= ds::clip[3]) return;
|
||||
if (ds::trans != ds::pen_color) DEST(x, y) = ds::pen_color;
|
||||
}
|
||||
|
||||
@@ -473,7 +491,8 @@ void pset(int x, int y, uint8_t color) {
|
||||
|
||||
uint8_t pget(int x, int y) {
|
||||
x -= ds::cam[0]; y -= ds::cam[1];
|
||||
if (x < 0 || x > (dest_surface->w-1) || y < 0 || y > (dest_surface->h-1)) return 0;
|
||||
//if (x < 0 || x > (dest_surface->w-1) || y < 0 || y > (dest_surface->h-1)) return 0;
|
||||
if (x < ds::clip[0] || x >= ds::clip[2] || y < ds::clip[1] || y >= ds::clip[3]) return 0;
|
||||
return DEST(x, y);
|
||||
}
|
||||
|
||||
@@ -629,11 +648,29 @@ void clip(int x, int y, int w, int h) {
|
||||
ds::clp[0] = x; ds::clp[1] = y; ds::clp[2] = w-x-1; ds::clp[3] = h-y-1;
|
||||
}
|
||||
|
||||
void clip() {
|
||||
ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = screen_width; ds::clip[3] = screen_height;
|
||||
ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = screen_width-1; ds::clp[3] = screen_height-1;
|
||||
}
|
||||
|
||||
void camera(int x, int y) {
|
||||
ds::cam[0] = x;
|
||||
ds::cam[1] = y;
|
||||
}
|
||||
|
||||
void view(int x, int y, int w, int h) {
|
||||
ds::cam[0] = -x;
|
||||
ds::cam[1] = -y;
|
||||
ds::clip[0] = x; ds::clip[1] = y; ds::clip[2] = w+x; ds::clip[3] = h+y;
|
||||
ds::clp[0] = x; ds::clp[1] = y; ds::clp[2] = w-1; ds::clp[3] = h-1;
|
||||
}
|
||||
|
||||
void view() {
|
||||
ds::cam[0] = ds::cam[1] = 0;
|
||||
ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = screen_width; ds::clip[3] = screen_height;
|
||||
ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = screen_width-1; ds::clp[3] = screen_height-1;
|
||||
}
|
||||
|
||||
void _drawcirc(int xc, int yc, int x, int y) {
|
||||
pset(xc+x, yc+y);
|
||||
pset(xc-x, yc+y);
|
||||
|
||||
3
mini.h
3
mini.h
@@ -166,7 +166,10 @@ void print(const char *str, int x, int y);
|
||||
void print(const char *str, int x, int y, uint8_t color);
|
||||
|
||||
void clip(int x, int y, int w, int h);
|
||||
void clip();
|
||||
void camera(int x, int y);
|
||||
void view(int x, int y, int w, int h);
|
||||
void view();
|
||||
|
||||
void circ(int x, int y, uint8_t r = 4);
|
||||
void circ(int x, int y, uint8_t r, uint8_t color);
|
||||
|
||||
Reference in New Issue
Block a user