Explorar o código

Upload files to 'Paint'

Yeung Alan %!s(int64=5) %!d(string=hai) anos
pai
achega
ccbd9a9db0
Modificáronse 5 ficheiros con 401 adicións e 0 borrados
  1. 1 0
      Paint/README.txt
  2. 1 0
      Paint/description.txt
  3. 190 0
      Paint/index.php
  4. 199 0
      Paint/index.php_old
  5. 10 0
      Paint/save.php

+ 1 - 0
Paint/README.txt

@@ -0,0 +1 @@
+This is a demo module of ArOZ Online Beta System for dummy / experimental purpose.

+ 1 - 0
Paint/description.txt

@@ -0,0 +1 @@
+Dummy module for experimental purpose. Do whatever you like with this folder.

+ 190 - 0
Paint/index.php

@@ -0,0 +1,190 @@
+<html>
+<head>
+<!-- Tocas UI:CSS 與元件 -->
+<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocas-ui/2.3.3/tocas.css">
+<!-- Tocas JS:模塊與 JavaScript 函式 -->
+<script src="https://cdnjs.cloudflare.com/ajax/libs/tocas-ui/2.3.3/tocas.js"></script>
+<script src="../script/jquery.min.js"></script>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/pressure/2.1.2/jquery.pressure.min.js"></script>
+<script src="../script/ao_module.js"></script>
+<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
+</head>
+<body>
+<div class="ts menu" style="position: absolute;width: 100vw;z-index: 2;">
+    <a class="item" onclick="save();">Save</a>
+    <a class="item" onclick="importimg();">Import</a>
+	<a class="item" id="mode" onclick="chgmode()">Normal</a>
+</div>
+
+<canvas id="paintArea" width="100" height="100"></canvas>
+
+<div style="position: fixed;bottom: 0;right: 0;">
+	<div style="bottom: 5px;right: 5px;display: block;float: left;" id="colorselector">
+		<div class="ts slider" style="margin-right: 10px;float: right;">
+			<input id="width" type="range">
+		</div>
+	</div>
+</div>
+<div class="ts bottom right snackbar">
+		<div class="content"></div>
+	</div>
+</body>
+<script type="text/javascript">
+var canvas = document.getElementById("paintArea");
+var ctx = canvas.getContext('2d');
+var clicking = false;
+
+var width = 0;
+ts('.ts.slider').slider();
+
+var currHeight = window.innerWidth;
+var currWidth = window.innerHeight;
+$("#paintArea")[0].width = window.innerWidth;
+$("#paintArea")[0].height = window.innerHeight;
+
+var color = ['#ff0000', '#ff8c00', '#fff600', '#00ff6e', '#00ffae', '#3b00ff', '#ae00ff', '#000000'];
+color.forEach(function(element) {
+  $("#colorselector").prepend('<div class="cp" style="background-color: ' + element + ';width: 30px;height: 30px;border-radius: 50%;float: right;margin-right: 4px;" data-color="' + element + '" onclick="chgcolor(this)"></div>');
+});
+$( ".cp[data-color~='#000000']" ).html('<i style="margin-left: 24%;margin-top: 24%;" class="checkmark icon"></i>');
+function chgcolor(element){
+	ctx.strokeStyle = $(element).attr("data-color");
+	$(".cp").html("");
+	$(element).html('<i style="margin-left: 24%;margin-top: 24%;" class="checkmark icon"></i>');
+}
+
+var pmode = false;
+function chgmode(){
+	if(pmode){
+		pmode = false;
+		$("#mode").html("Normal");
+	}else{
+		pmode = true;
+		$("#mode").html("Pressure");
+	}
+}
+$('#paintArea').pressure({
+  change: function(f, event){
+		if(pmode){
+			width = f * 10;
+			$("#width").attr("style","background-image: -webkit-gradient(linear, 0% 0%, 100% 0%, color-stop(" + width/10 + ", rgb(150, 150, 150)), color-stop(" + width/10 + ", rgb(233, 233, 233)));");
+			$("#width").val(width * 10);
+			console.log(width);
+		}
+  },
+});
+
+
+$(window).on('resize', function () {
+	var currImg = ctx.getImageData(0, 0, currWidth, currHeight);	
+	currWidth = window.innerWidth;
+	currHeight = window.innerHeight;		
+	$("#paintArea")[0].width = window.innerWidth;
+	$("#paintArea")[0].height = window.innerHeight;
+	ctx.putImageData(currImg, 0, 0);
+});
+
+var prevX = 0;
+var prevY = 0;
+$( "#paintArea" ).on('mousedown touchstart',function(e) {
+    console.log(e.pageX, e.pageY);
+	clicking = true;
+	if(!pmode){
+		ctx.beginPath();
+		ctx.moveTo(e.pageX,e.pageY);
+	}
+	prevX = e.pageX;
+	prevY = e.pageY;
+});
+
+$( "#paintArea" ).on('mousemove touchmove',function(e) {
+	if(clicking){
+		if(pmode){
+			ctx.beginPath();
+			ctx.moveTo(prevX,prevY);
+		}
+		ctx.lineWidth = width;
+		console.log(e.pageX, e.pageY);
+		ctx.lineTo(e.pageX,e.pageY);
+		ctx.stroke();
+		
+		prevX = e.pageX;
+		prevY = e.pageY;
+	}
+});
+
+$( "#paintArea" ).on('mouseup touchend',function(e) {
+	clicking = false;
+});
+
+$("#width").on('change', function () {
+	width = $("#width").val() / 10;
+});
+
+function save(){
+	if (ao_module_virtualDesktop){
+		ao_module_openFileSelector(Math.round(Math.random()*100,0),"setPathBySelector",undefined,undefined,false,"folder");
+	}else{
+		ao_module_openFileSelectorTab(Math.round(Math.random()*100,0),"../",false,"folder",setPathBySelector);
+	}
+}
+
+function importimg(){
+	if (ao_module_virtualDesktop){
+		ao_module_openFileSelector(Math.round(Math.random()*100,0),"importselector",undefined,undefined,false,"file");
+	}else{
+		ao_module_openFileSelectorTab(Math.round(Math.random()*100,0),"../",false,"file",importselector);
+	}	
+}
+
+function importselector(object){
+	var files = JSON.parse(object);
+	console.log(files);
+	var img = new Image();
+	img.onload = function() {
+		var ctx = document.getElementById('paintArea').getContext('2d');
+		ctx.drawImage(img, 0, 0);
+		msgbox("Imported /AOR/" + files[0].filepath);
+	}
+	img.src = "../" + files[0].filepath;
+}
+
+function setPathBySelector(object){
+	var files = JSON.parse(object);
+	console.log(files);
+	$.post("save.php", { b64: $("#paintArea")[0].toDataURL('image/png'), path: files[0].filepath},
+	   function(data){
+		 msgbox("Saved as " + data);
+   });
+}
+
+function msgbox(content){
+	ts('.snackbar').snackbar({
+		content: content,
+		onAction: () => {
+			$(".snackbar").removeAttr("style");
+		}
+	});
+}
+
+  function preventPullToRefresh(element) {
+    var prevent = false;
+
+    document.querySelector(element).addEventListener('touchstart', function(e){
+      if (e.touches.length !== 1) { return; }
+
+      var scrollY = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
+      prevent = (scrollY === 0);
+    });
+
+    document.querySelector(element).addEventListener('touchmove', function(e){
+      if (prevent) {
+        prevent = false;
+        e.preventDefault();
+      }
+    });
+  }
+
+  preventPullToRefresh('#paintArea') // pass #id or html tag into the method
+</script>
+</html>

+ 199 - 0
Paint/index.php_old

@@ -0,0 +1,199 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<title>小畫家</title>
+		<link rel="stylesheet" href="../script/jquery-ui-1.10.3.custom.min.css" />
+		<style>
+			body {
+				font-size: 9pt;
+				margin: 0;
+				padding: 0;
+			}
+			
+			#line {
+				clear: both;
+			}
+			
+			#paintarea {
+				position: fixed;
+				top: 0;
+				left: 0;
+				z-index: -99;
+			}
+			
+			#controls {
+				position: fixed;
+				width: auto;
+				display: inline-block;
+				padding: 1em;
+				top: 1em;
+				left: 1em;
+			}
+			
+			.option {
+				float: left;
+				width: 20px;
+				height: 20px;
+				margin-right: 4px;
+				margin-bottom: 4px;
+				box-shadow: 0 0 4px #aaa;
+			}
+			
+			.paint_controls {
+			    background-color: #fff;
+			    box-shadow: 0 0 15px #ccc;
+			}
+			
+			.active {
+				box-shadow: 0 0 4px #000;
+			}
+			
+			#paint {
+				cursor: arrow;
+			}
+		</style>
+		<script src="../script/jquery.min.js" type="text/javascript"></script>
+		<script src="../../js/jquery.ui.min.js"></script>
+		<script>
+			$(function () {
+				var p_width, p_color;
+				var colors = ['#F00', '#0F0', '#00F', '#FF0', '#0FF', '#F0F', '#F90', '#FFF'];
+				$.each(colors, function (i) {
+					$("<div class='option' style='background-color:" + colors[i] + "'></div>").appendTo('#pallete');
+				});
+
+				for(var i = 1; i <= 9; i++) {
+					$('<div class="option"><div></div></div>')
+					.find('div')
+                    .css({
+                        'margin-top': 10 - i / 2,
+                        'margin-left': 10 - i / 2,
+                        width: i,
+                        height: i
+                    })
+					.end()
+					.appendTo('#line');
+				}
+
+				var cBlock = $("#pallete .option");
+				var lBlock = $("#line .option");
+
+				cBlock
+					.click(function () {
+						cBlock.removeClass("active");
+						$(this).addClass("active");
+						
+						p_color = $(this).css('background-color');
+						
+						lBlock
+                            .children("div")
+                            .css("background-color", p_color);
+					})
+					.first()
+					.click();
+
+				lBlock
+					.click(function () {
+						lBlock.removeClass("active");
+						$(this).addClass("active");
+						p_width = $(this)
+                            .children("div")
+                            .css("width")
+                            .replace("px", "");
+					})
+					.eq(3)
+					.click();
+
+				var $canvas = $("#paint");
+				var ctx = $canvas[0].getContext("2d");
+
+				$canvas[0].width = window.innerWidth;
+				$canvas[0].height = window.innerHeight;
+
+				$(window).on('resize', function () {
+					var state = ctx.getImageData(0, 0, $canvas[0].width, $canvas[0].height);
+					
+					$canvas[0].width = window.innerWidth;
+					$canvas[0].height = window.innerHeight;
+					
+					ctx.putImageData(state, 0, 0);
+				});
+
+				ctx.lineCap = "butt";
+				ctx.fillStyle = "white";
+				ctx.fillRect(0, 0, $canvas.width(), $canvas.height());
+				var mousedown = false;
+
+				$canvas
+					.on('mousedown touchstart', function (e) {
+						ctx.beginPath();
+						ctx.strokeStyle = p_color;
+						ctx.lineWidth = p_width;
+
+						var posX = (e.pageX || e.originalEvent.targetTouches[0].pageX);
+						var posY = (e.pageY || e.originalEvent.targetTouches[0].pageY);
+
+						ctx.moveTo(posX, posY);
+						mousedown = true;
+					})
+					.on('mousemove touchmove', function (e) {
+						if(mousedown) {
+							var posX = (e.pageX || e.originalEvent.targetTouches[0].pageX);
+							var posY = (e.pageY || e.originalEvent.targetTouches[0].pageY);
+
+							ctx.lineTo(posX, posY);
+							ctx.stroke();
+						}
+					})
+					.on('mouseup touchend', function (e) {
+						mousedown = false;
+					});
+
+				$("#saveImg").button().click(function () {
+					var data = escape($canvas[0].toDataURL('image/png').split(',')[1]);
+					var xhr = new XMLHttpRequest();
+
+					xhr.onreadystatechange = function () {
+						if(xhr.status === 200 && xhr.readyState == 4) {
+							$("#output").dialog("open");
+						}
+					};
+
+					xhr.open("POST", "./save.php", true);
+					xhr.send(data);
+				});
+
+				$("#output").dialog({
+					autoOpen: false,
+					modal: true
+				});
+
+				$("#controls").draggable({
+					containment: "parent",
+					scroll: false,
+					start: function(){
+                        $(this).animate({
+                            opacity: 1
+                        }, 500);
+					},
+					stop: function(){
+                        $(this).animate({
+                            opacity: 0.5
+                        }, 500);
+					}
+				});
+			});
+		</script>
+	</head>
+	<body>
+		<div class="paint_controls ui-corner-all ui-helper-clearfix" id="controls">
+			<div id="pallete"></div>
+			<div id="line"></div>
+			<input type="button" id="saveImg" value="儲存圖片" />
+		</div>
+		<div id="paintarea">
+			<canvas id="paint" width="100%" height="600" />
+		</div>
+		<div id="output" title="完成">儲存完成!</div>
+	</body>
+</html>

+ 10 - 0
Paint/save.php

@@ -0,0 +1,10 @@
+<?php
+$dt = new DateTime();
+
+$data = $_POST["b64"];
+list($type, $data) = explode(';', $data);
+list(, $data)      = explode(',', $data);
+$data = base64_decode($data);
+file_put_contents("../".$_POST["path"].'/paint_'. $dt->format('YmdHis').'.png', $data);
+echo "/AOR/".$_POST["path"].'/paint_'. $dt->format('YmdHis').'.png';
+?>