mirror of
https://github.com/MeexReay/poshlostios.git
synced 2025-06-24 02:22:58 +03:00
add scroll to zterm
This commit is contained in:
parent
cede5caa21
commit
44869b61ed
@ -257,11 +257,25 @@ async function onMouseMove(ctx, x, y) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function onMouseWheel(ctx, x, y, z) {
|
||||||
|
for (let window of listWindows()) {
|
||||||
|
if (isMouseInside(window)) {
|
||||||
|
selected_window = window["wid"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selected_window != null) {
|
||||||
|
let window = getWindow(selected_window)
|
||||||
|
window.onmousewheel(y,x,z)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function main(args) {
|
async function main(args) {
|
||||||
let ctx = null
|
let ctx = null
|
||||||
|
|
||||||
enableGraphics({
|
enableGraphics({
|
||||||
"onmousemove": (x, y) => onMouseMove(ctx, x, y),
|
"onmousemove": (x, y) => onMouseMove(ctx, x, y),
|
||||||
|
"onmousewheel": (x, y, z) => onMouseWheel(ctx, x, y, z),
|
||||||
"onmousedown": (btn) => onMouseDown(ctx, btn),
|
"onmousedown": (btn) => onMouseDown(ctx, btn),
|
||||||
"onmouseup": (btn) => onMouseUp(ctx, btn),
|
"onmouseup": (btn) => onMouseUp(ctx, btn),
|
||||||
"onkeydown": (key) => onKeyDown(ctx, key),
|
"onkeydown": (key) => onKeyDown(ctx, key),
|
||||||
|
@ -25,6 +25,7 @@ function createWindow(options) {
|
|||||||
"onmouseup": options["onmouseup"] || (o => {}),
|
"onmouseup": options["onmouseup"] || (o => {}),
|
||||||
"onmousemove": options["onmousemove"] || ((x,y) => {}),
|
"onmousemove": options["onmousemove"] || ((x,y) => {}),
|
||||||
"onresize": options["onresize"] || ((x,y) => {}),
|
"onresize": options["onresize"] || ((x,y) => {}),
|
||||||
|
"onmousewheel": options["onmousewheel"] || options["onwheel"] || options["onscroll"] || ((y,x,z) => {}),
|
||||||
"onupdate": options["onupdate"] || (() => {}),
|
"onupdate": options["onupdate"] || (() => {}),
|
||||||
"decorated": "decorated" in options ? options["decorated"] : true,
|
"decorated": "decorated" in options ? options["decorated"] : true,
|
||||||
"selectable": "selectable" in options ? options["selectable"] : true,
|
"selectable": "selectable" in options ? options["selectable"] : true,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "zterm",
|
"name": "zterm",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"description": "Zcom Terminal Emulator",
|
"description": "Zcom Terminal Emulator",
|
||||||
"author": "MeexReay",
|
"author": "MeexReay",
|
||||||
"apps": [ "zterm.js" ]
|
"apps": [ "zterm.js" ]
|
||||||
|
@ -7,8 +7,11 @@ let stdin_disable = true
|
|||||||
let ctx = null
|
let ctx = null
|
||||||
let wid = null
|
let wid = null
|
||||||
|
|
||||||
const CHAR_WIDTH = 7
|
let char_width = 7
|
||||||
const CHAR_HEIGHT = 14
|
let char_height = 14
|
||||||
|
|
||||||
|
let text_scroll = 0
|
||||||
|
|
||||||
const TERMINAL_COLORS = [
|
const TERMINAL_COLORS = [
|
||||||
"BLACK",
|
"BLACK",
|
||||||
"DARK_BLUE", "DARK_GREEN", "DARK_CYAN", "DARK_RED", "DARK_MAGENTA", "DARK_YELLOW", "DARK_WHITE",
|
"DARK_BLUE", "DARK_GREEN", "DARK_CYAN", "DARK_RED", "DARK_MAGENTA", "DARK_YELLOW", "DARK_WHITE",
|
||||||
@ -24,11 +27,11 @@ async function draw() {
|
|||||||
ctx.fillStyle = "black"
|
ctx.fillStyle = "black"
|
||||||
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height)
|
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height)
|
||||||
|
|
||||||
ctx.font = "14px terminus";
|
ctx.font = char_height+"px terminus";
|
||||||
ctx.textBaseline = "middle";
|
ctx.textBaseline = "middle";
|
||||||
ctx.textAlign = "left";
|
ctx.textAlign = "left";
|
||||||
|
|
||||||
let y = ctx.canvas.height - 12
|
let y = ctx.canvas.height - char_height / 2 - 5 + text_scroll
|
||||||
for (let line of text.split("\n").reverse()) {
|
for (let line of text.split("\n").reverse()) {
|
||||||
let x = 5
|
let x = 5
|
||||||
let buffer = ""
|
let buffer = ""
|
||||||
@ -70,7 +73,7 @@ async function draw() {
|
|||||||
ctx.fillStyle = color_before;
|
ctx.fillStyle = color_before;
|
||||||
ctx.fillText(buffer, x, y);
|
ctx.fillText(buffer, x, y);
|
||||||
color_before = color
|
color_before = color
|
||||||
x += buffer.length * CHAR_WIDTH
|
x += buffer.length * char_width
|
||||||
buffer = ""
|
buffer = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +83,7 @@ async function draw() {
|
|||||||
ctx.fillStyle = color_before;
|
ctx.fillStyle = color_before;
|
||||||
ctx.fillText(buffer, x, y);
|
ctx.fillText(buffer, x, y);
|
||||||
|
|
||||||
y -= CHAR_HEIGHT
|
y -= char_height
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,6 +212,7 @@ let ctrlKey = false
|
|||||||
let shiftKey = false
|
let shiftKey = false
|
||||||
|
|
||||||
async function onKeyDown(key) {
|
async function onKeyDown(key) {
|
||||||
|
text_scroll = 0
|
||||||
if (!stdin_disable) {
|
if (!stdin_disable) {
|
||||||
if (key == "Enter") {
|
if (key == "Enter") {
|
||||||
stdin_text += "\n"
|
stdin_text += "\n"
|
||||||
@ -234,6 +238,23 @@ async function onKeyDown(key) {
|
|||||||
draw()
|
draw()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function onMouseWheel(y) {
|
||||||
|
console.log(y)
|
||||||
|
if (ctrlKey) {
|
||||||
|
if (y < 0) {
|
||||||
|
char_height *= 1.05
|
||||||
|
char_width *= 1.05
|
||||||
|
} else {
|
||||||
|
char_height /= 1.05
|
||||||
|
char_width /= 1.05
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
text_scroll -= y * 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
draw()
|
||||||
|
}
|
||||||
|
|
||||||
async function onKeyUp(key) {
|
async function onKeyUp(key) {
|
||||||
if (key == "Alt") {
|
if (key == "Alt") {
|
||||||
altKey = false
|
altKey = false
|
||||||
@ -256,6 +277,7 @@ async function main(args) {
|
|||||||
"y": 50,
|
"y": 50,
|
||||||
"onkeydown": onKeyDown,
|
"onkeydown": onKeyDown,
|
||||||
"onkeyup": onKeyUp,
|
"onkeyup": onKeyUp,
|
||||||
|
"onmousewheel": onMouseWheel,
|
||||||
"onresize": (w,h) => draw(),
|
"onresize": (w,h) => draw(),
|
||||||
"onsignal": (s) => {
|
"onsignal": (s) => {
|
||||||
if (s == 9) {
|
if (s == 9) {
|
||||||
|
@ -19,6 +19,15 @@ function enableGraphics(options={}) {
|
|||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if ("onmousewheel" in options) {
|
||||||
|
graphics_canvas.onwheel = e => {
|
||||||
|
options.onmousewheel(e.deltaX, e.deltaY, e.deltaZ)
|
||||||
|
if (e.ctrlKey == true) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ("onmousemove" in options) {
|
if ("onmousemove" in options) {
|
||||||
graphics_canvas.onmousemove = e => {
|
graphics_canvas.onmousemove = e => {
|
||||||
options.onmousemove(e.x, e.y)
|
options.onmousemove(e.x, e.y)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user