Initial commit
This commit is contained in:
commit
92399f7ef1
|
@ -0,0 +1,9 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2023
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,20 @@
|
|||
# me.fier.draw
|
||||
A dead-simple crappy drawing program that I may or may not expand at a later date.
|
||||
|
||||
## Quirks
|
||||
* If you resize the window, your image is gone.
|
||||
* There is no erase.
|
||||
|
||||
## Tweaking
|
||||
If you look in `user/modules/me/fier/draw/main.py`, you can change several things like background color, brush color, brush smoothing (`brushSpeed`) and framerate.
|
||||
|
||||
## Prerequisites
|
||||
### Python 3.4 or up
|
||||
* **Windows:** [python.org](https://www.python.org/downloads/) ([3.4.4](https://www.python.org/downloads/release/python-344/) on XP, [3.8.10](https://www.python.org/downloads/release/python-3810/) on 7)
|
||||
* **Debian:** `apt install python3`
|
||||
### PySDL2
|
||||
* **Windows:** `py -m pip install PySDL2`
|
||||
* **Debian:** `apt install python3-sdl2`
|
||||
### toml
|
||||
* **Windows:** `py -m pip install toml`
|
||||
* **Debian:** `apt install python3-toml`
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env python3
|
||||
# App launcher
|
||||
def init():
|
||||
import sys
|
||||
sys.dont_write_bytecode = True
|
||||
|
||||
import os
|
||||
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
|
||||
s = os.path.realpath(sys.executable)
|
||||
else:
|
||||
s = os.path.realpath(__file__)
|
||||
|
||||
sys.path.insert(0,os.path.join(os.path.dirname(s),"user","modules"))
|
||||
global app
|
||||
import app
|
||||
app.init(s,"me.fier.draw") # Change the second argument to your app name, I recommend using your domain if you have one. For example, If you own "example.com", and the program is called "app", then you should name it com.example.app.
|
||||
init()
|
||||
app.main.main()
|
|
@ -0,0 +1,2 @@
|
|||
engine = "$DISTRO.engine.sdl2"
|
||||
main = "$DISTRO.main"
|
|
@ -0,0 +1,64 @@
|
|||
import sys
|
||||
import os
|
||||
|
||||
def initConfigDirs():
|
||||
for i in configDirs:
|
||||
fi = os.path.join(i,"modules")
|
||||
try:
|
||||
del sys.path[sys.path.index(fi)]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
for i in reversed(configDirs):
|
||||
sys.path.insert(0,os.path.join(i,"modules"))
|
||||
|
||||
def configFindFile(name):
|
||||
for i in configDirs:
|
||||
fi = os.path.join(i,name)
|
||||
if os.path.isfile(fi): yield fi
|
||||
|
||||
def init(scp,dist):
|
||||
global distro,p,s,sd,configDirs
|
||||
distro = dist
|
||||
p = os.path.join
|
||||
s = scp
|
||||
sd = os.path.dirname(s)
|
||||
configDirs = [
|
||||
p(os.environ.get("HOME",os.environ.get("USERPROFILE",None)),".config",distro),
|
||||
p(sd,"user")
|
||||
]
|
||||
|
||||
initConfigDirs()
|
||||
modules = {}
|
||||
import toml
|
||||
for file in configFindFile("modules.toml"):
|
||||
tbl = toml.loads(open(file).read())
|
||||
for i in tbl:
|
||||
if not i in modules:
|
||||
modules[i] = tbl[i]
|
||||
|
||||
length = len(sys.argv)
|
||||
index = 1
|
||||
while index < length:
|
||||
arg = sys.argv[index]
|
||||
if arg.startswith("--app:module"):
|
||||
arg = arg.split("--app:module:",1)[1].split("=",1)
|
||||
modules[arg[0]] = arg[1].replace("$DISTRO",distro)
|
||||
del sys.argv[index]
|
||||
length -= 1
|
||||
continue
|
||||
index += 1
|
||||
|
||||
import importlib
|
||||
glb = globals()
|
||||
for module in modules:
|
||||
modules[module] = modules[module].replace("$DISTRO",distro)
|
||||
print("* Importing '" +modules[module]+ "' -> '" +module+ "' ...")
|
||||
glb[module] = importlib.import_module(modules[module])
|
||||
|
||||
for module in modules:
|
||||
if hasattr(glb[module],"appInit"):
|
||||
print("* Initializing '" +module+ "' ...")
|
||||
glb[module].appInit()
|
||||
|
||||
print("* Running app.")
|
|
@ -0,0 +1,15 @@
|
|||
import app
|
||||
|
||||
nullDict = {}
|
||||
def null(*args,**kwargs): return nullDict
|
||||
for i in [
|
||||
"createWindow",
|
||||
"setColor",
|
||||
"drawPixel",
|
||||
"clear",
|
||||
"sleep",
|
||||
"getEvents",
|
||||
"render",
|
||||
"quit"
|
||||
]:
|
||||
globals()[i] = null
|
|
@ -0,0 +1,59 @@
|
|||
import app
|
||||
from sdl2 import *
|
||||
import sdl2.ext as s2ext
|
||||
|
||||
def createWindow(title,w,h):
|
||||
global window, renderer, width, height
|
||||
width = w
|
||||
height = h
|
||||
SDL_Init(SDL_INIT_VIDEO)
|
||||
window = SDL_CreateWindow(title.encode("utf-8"),SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,w,h,SDL_WINDOW_RESIZABLE)
|
||||
renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED)
|
||||
|
||||
def setColor(r,g,b,a):
|
||||
SDL_SetRenderDrawColor(renderer,r,g,b,a)
|
||||
|
||||
def drawPixel(x,y):
|
||||
SDL_RenderDrawPoint(renderer,x,y)
|
||||
|
||||
def clear():
|
||||
SDL_RenderClear(renderer)
|
||||
|
||||
def sleep(t):
|
||||
SDL_Delay(t)
|
||||
|
||||
def getEvents():
|
||||
events = s2ext.get_events()
|
||||
for event in events:
|
||||
if event.type == SDL_QUIT:
|
||||
yield "quit",[],{}
|
||||
continue
|
||||
|
||||
if event.type == SDL_MOUSEMOTION:
|
||||
yield "mouse.move",[event.motion.x,event.motion.y],{}
|
||||
continue
|
||||
|
||||
if event.type in [SDL_MOUSEBUTTONDOWN,SDL_MOUSEBUTTONUP]:
|
||||
button = event.button.button
|
||||
if button == 1: button = "left"
|
||||
if button == 2: button = "middle"
|
||||
if button == 3: button = "right"
|
||||
|
||||
if event.type == SDL_MOUSEBUTTONDOWN:
|
||||
yield "mouse.down",[button],{}
|
||||
continue
|
||||
|
||||
if event.type == SDL_MOUSEBUTTONUP:
|
||||
yield "mouse.up",[button],{}
|
||||
continue
|
||||
|
||||
if event.window.event == SDL_WINDOWEVENT_RESIZED:
|
||||
yield "resized",[width,height],{}
|
||||
continue
|
||||
|
||||
def render():
|
||||
global renderer
|
||||
SDL_RenderPresent(renderer)
|
||||
|
||||
def quit():
|
||||
SDL_Quit()
|
|
@ -0,0 +1,49 @@
|
|||
def main():
|
||||
import app
|
||||
import sys
|
||||
|
||||
app.engine.createWindow(app.distro,640,480)
|
||||
app.engine.setColor(0,0,0,255)
|
||||
app.engine.clear()
|
||||
app.engine.setColor(255,0,0,255)
|
||||
mouseHeld = False
|
||||
mouseX = 0
|
||||
mouseY = 0
|
||||
mousePrevX = 0
|
||||
mousePrevY = 0
|
||||
brushX = -1
|
||||
brushY = -1
|
||||
brushSpeed = 0.05
|
||||
while True:
|
||||
for event,args,kwargs in app.engine.getEvents():
|
||||
if event == "mouse.move":
|
||||
mousePrevX = mouseX
|
||||
mousePrevY = mouseY
|
||||
mouseX = args[0]
|
||||
mouseY = args[1]
|
||||
brushX = brushX + ((mouseX - brushX) * brushSpeed)
|
||||
brushY = brushY + ((mouseY - brushY) * brushSpeed)
|
||||
|
||||
if mouseHeld:
|
||||
app.engine.drawPixel(int(brushX),int(brushY))
|
||||
|
||||
continue
|
||||
|
||||
if event == "mouse.down":
|
||||
brushX = mouseX
|
||||
brushY = mouseY
|
||||
mouseHeld = True
|
||||
continue
|
||||
|
||||
if event == "mouse.up":
|
||||
brushX = mouseX
|
||||
brushY = mouseY
|
||||
mouseHeld = False
|
||||
continue
|
||||
|
||||
if event == "quit":
|
||||
app.engine.quit()
|
||||
sys.exit(0)
|
||||
|
||||
app.engine.render()
|
||||
app.engine.sleep(33)
|
Loading…
Reference in New Issue