From cab7206a244f2b57a744a5cd42d8b3dfe7859cf0 Mon Sep 17 00:00:00 2001 From: Eason010212 <1371033826@qq.com> Date: Sat, 6 Apr 2024 22:58:53 +0800 Subject: [PATCH] new-widget --- css/widgets.css | 3 ++ icons/database.svg | 2 +- js/lang.js | 35 ++++++++++++++++++++--- js/projects.js | 7 ++++- js/widgets.js | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 6 deletions(-) diff --git a/css/widgets.css b/css/widgets.css index a119a41..fe086d1 100644 --- a/css/widgets.css +++ b/css/widgets.css @@ -237,6 +237,9 @@ font-size: 1rem; border-radius:10px; border:solid gray 2px; + display: flex; + align-items: center; + justify-content: center; } .bulb0{ width: 46px; diff --git a/icons/database.svg b/icons/database.svg index 237d56f..2907422 100644 --- a/icons/database.svg +++ b/icons/database.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/js/lang.js b/js/lang.js index 8ee4ea7..a4b07bd 100644 --- a/js/lang.js +++ b/js/lang.js @@ -1,5 +1,14 @@ var JSLang = { "zh": { + "tensorAI": "- 人工智能 Tensorflow.js -", + "imageNet": "ImageNet 图像分类", + "cocoSSD": "CocoSSD 对象检测", + "deepLab": "DeepLab 图像分割", + "blazeFace": "BlazeFace 人脸检测", + "mediaPipe": "MediaPipe 手势检测", + "MoveNet": "MoveNet 关节点识别", + "Bert": "BERT 文本问答", + "SpeechCMD": "SpeechCMD 语音指令", "syncInterval": "自动更新频率", "sendInterval": "自动发送频率", "never": "从不", @@ -210,12 +219,21 @@ var JSLang = { "platformList": "已登录平台", "deviceList": "已连接设备", "camera": "摄像头", - "mic": "麦克风", - "tinydb": "数据库", + "mic": "语音识别", + "tinydb": "下拉选项", "resolution": "分辨率", "fps": "帧率" }, "tw": { + "tensorAI": "- AI·Tensorflow.js -", + "imageNet": "ImageNet", + "cocoSSD": "CocoSSD", + "deepLab": "DeepLab", + "blazeFace": "BlazeFace", + "mediaPipe": "MediaPipe", + "MoveNet": "MoveNet", + "Bert": "BERT", + "SpeechCMD": "SpeechCMD", "syncInterval": "自動更新頻率", "sendInterval": "自動發送頻率", "never": "從不", @@ -427,11 +445,20 @@ var JSLang = { "deviceList": "已連接設備", "camera": "攝像頭", "mic": "麥克風", - "tinydb": "數據庫", + "tinydb": "下拉選項", "resolution": "分辨率", "fps": "幀率" }, "en": { + "tensorAI": "- AI·Tensorflow.js -", + "imageNet": "ImageNet", + "cocoSSD": "CocoSSD", + "deepLab": "DeepLab", + "blazeFace": "BlazeFace", + "mediaPipe": "MediaPipe", + "MoveNet": "MoveNet", + "Bert": "BERT", + "SpeechCMD": "SpeechCMD", "syncInterval": "Auto-sync", "sendInterval": "Auto-send", "never": "Never", @@ -643,7 +670,7 @@ var JSLang = { "deviceList": "Devices", "camera": "Camera", "mic": "Microphone", - "tinydb": "Database", + "tinydb": "Options", "resolution": "Resolution", "fps": "FPS" } diff --git a/js/projects.js b/js/projects.js index 8604278..d759e48 100644 --- a/js/projects.js +++ b/js/projects.js @@ -847,7 +847,7 @@ function view_project(projectName, projectType) { keyName = userName.slice(1) userName = 'MixIO_public' } - client = mqtt.connect((location.protocol == 'https:' ? 'wss://' : 'ws://') + window.location.host.split(":")[0] + (location.protocol == 'https:' ? (':'+MIXIO_WSS_PORT) : (':'+MIXIO_WS_PORT)), { + client = mqtt.connect((location.protocol == 'https:' ? 'wss://' : 'ws://') + window.location.host.split(":")[0] + (location.protocol == 'https:' ? ':8084' : ':8083'), { 'clientId': randomClientID, 'username': userName, 'password': projectPass, @@ -1740,6 +1740,11 @@ function add_widget() { widget_list.append(decorate_pic_add) var magic_add = $("
" + JSLang[lang].magic + "
") widget_list.append(magic_add) + /* + widget_list.append($("
" + JSLang[lang].tensorAI + "
")) + var imageNet_add = $("
" + JSLang[lang].imageNet + "
") + widget_list.append(imageNet_add) + */ ble_add.children("a").click(function() { d.close().remove() var editForm = $('
') diff --git a/js/widgets.js b/js/widgets.js index e5f4c91..2f58930 100644 --- a/js/widgets.js +++ b/js/widgets.js @@ -42,20 +42,79 @@ function add_block(width, height, contents, attrs) { else grid.prepend(itemdiv[0]) }) + itemdiv.draggable({ onStopDrag: function() { var stdLeft = parseInt(itemdiv.css('left')) - (parseInt(itemdiv.css('left')) % 20) + (parseInt(itemdiv.css('left')) % 20 > 10 ? 1 : 0) * 20 var stdTop = parseInt(itemdiv.css('top')) - (parseInt(itemdiv.css('top')) % 20) + (parseInt(itemdiv.css('top')) % 20 > 10 ? 1 : 0) * 20 itemdiv.css('left', stdLeft + 'px') itemdiv.css('top', stdTop + 'px') + // 对于tmpInnerItems中的所有item,也进行同样的处理 + if(itemdiv.attr('user-type') == 'magic') + { + for(var i=0;i 10 ? 1 : 0) * 20 + var top = parseInt(item.css('top')) - (parseInt(item.css('top')) % 20) + (parseInt(item.css('top')) % 20 > 10 ? 1 : 0) * 20 + item.css('left', left + 'px') + item.css('top', top + 'px') + } + } + tmpInnerItems = [] }, onStartDrag: function(event) { lastDragX = event.pageX lastDragY = event.pageY + if(itemdiv.attr('user-type') == 'magic') + { + + // 包围在块内部的所有item + tmpInnerItems = [] + // magic块的边界坐标 + var magicLeft = parseInt(itemdiv.css('left')) + var magicTop = parseInt(itemdiv.css('top')) + var magicRight = magicLeft + parseInt(itemdiv.css('width')) + var magicBottom = magicTop + parseInt(itemdiv.css('height')) + // 遍历所有.item + var items = $(".item") + tmpOriHeight = parseInt(itemdiv.css('height')) + tmpOriWidth = parseInt(itemdiv.css('width')) + for(var i=0;i= magicLeft && right-5 <= magicRight && top+5 >= magicTop && bottom-5 <= magicBottom) + tmpInnerItems.push(i) + } + } + console.log(tmpInnerItems) + } }, onDrag: function(event) { + var dx = event.pageX - lastDragX + var dy = event.pageY - lastDragY lastDragX = event.pageX lastDragY = event.pageY + + var items = $(".item") + if(itemdiv.attr('user-type') == 'magic') + { + if(tmpOriWidth==parseInt(itemdiv.css('width')) && tmpOriHeight==parseInt(itemdiv.css('height'))) + for(var i=0;i") textDiv.html(stringendecoder.decodeHtml(user_content)) + var minFontSize = 1 + var fontSize = 3 - user_content.length / 3 + if (fontSize < minFontSize) + fontSize = minFontSize + textDiv.css('font-size', fontSize + 'rem') textDiv.attr('class', 'mid_screen') contents.push(textDiv) attrs = [ @@ -3787,6 +3851,11 @@ function add_text(user_title, user_topic, user_content, user_style, title_style) textDiv.empty() // set innerHTML textDiv.html(stringendecoder.decodeHtml(String(message1))) + var minFontSize = 1 + var fontSize = 3 - String(message1).length / 3 + if (fontSize < minFontSize) + fontSize = minFontSize + textDiv.css('font-size', fontSize + 'rem') title.parent().parent().attr('user-content', stringendecoder.encodeHtml(String(message1))) itemdiv.trigger(MixIO.eventTags.TEXT_SCREEN_CHANGED, [String(message1)]) }