Skip to content

Commit 2fdf1f3

Browse files
authored
Merge pull request #2028 from error414/layout_copy
Copy/Paste of elements in OSD layout
2 parents a7634fb + ba4fe59 commit 2fdf1f3

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed

_locales/en/messages.json

+18
Original file line numberDiff line numberDiff line change
@@ -4841,6 +4841,15 @@
48414841
"save": {
48424842
"message": "Save"
48434843
},
4844+
"copy": {
4845+
"message": "Copy"
4846+
},
4847+
"paste": {
4848+
"message": "Paste"
4849+
},
4850+
"clear": {
4851+
"message": "Clear"
4852+
},
48444853
"active": {
48454854
"message": "Active"
48464855
},
@@ -5634,6 +5643,15 @@
56345643
"osdSettingsSaved": {
56355644
"message": "OSD settings saved"
56365645
},
5646+
"osdLayoutInsertedIntoClipboard": {
5647+
"message": "Layout has been saved to clipboard"
5648+
},
5649+
"osdLayoutPasteFromClipboard": {
5650+
"message": "Layout has been restored from clipboard"
5651+
},
5652+
"osdClearLayout": {
5653+
"message": "Layout has been cleared"
5654+
},
56375655
"failedToOpenSerialPort": {
56385656
"message": "<span style=\"color: red\">Failed</span> to open serial port"
56395657
},

src/css/tabs/osd.css

+30
Original file line numberDiff line numberDiff line change
@@ -733,4 +733,34 @@ button {
733733

734734
.osdCustomElement_main_table select, .osdCustomElement_main_table input{
735735
width: 100% !important;
736+
}
737+
738+
.settings .btn a{
739+
margin-top: 0;
740+
margin-bottom: 0;
741+
border-radius: 3px;
742+
color: #fff;
743+
font-family: 'open_sansbold', Arial, serif;
744+
font-size: 12px;
745+
text-shadow: 0 1px rgba(0, 0, 0, 0.25);
746+
cursor: pointer;
747+
transition: all ease 0.2s;
748+
padding: 0 9px;
749+
line-height: 22px;
750+
}
751+
752+
.settings .btn_blue a{
753+
background-color: #37a8db;
754+
border: 1px solid #3394b5;
755+
}
756+
757+
.settings .btn_danger a{
758+
background-color: #e2a2a2;
759+
border: 1px solid #e58383;
760+
}
761+
762+
763+
.settings .btn a:hover {
764+
background-color: #3394b5;
765+
transition: all ease 0.2s;
736766
}

tabs/osd.html

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ <h1 class="tab_title" data-i18n="tabOSD"></h1>
1010
<div class="settings spacer_right">
1111
<select class="osd_layouts">
1212
</select>
13+
<span class="btn btn_blue">
14+
<a class="active osd_copy" href="#" data-i18n="copy"></a>
15+
</span>
16+
<span class="btn btn_blue">
17+
<a class="active osd_paste" href="#" data-i18n="paste"></a>
18+
</span>
19+
<span class="btn btn_danger">
20+
<a class="active osd_clear" href="#" data-i18n="clear"></a>
21+
</span>
1322
<input class="osd_search" placeholder="Search...">
1423
</div>
1524
<div class="spacer_right">

tabs/osd.js

+59
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ var video_type = null;
138138
var isGuidesChecked = false;
139139
var FONT = FONT || {};
140140

141+
var layout_clipboard = {layout: [], filled: false};
142+
141143
var FONT = FONT || {};
142144
FONT.initData = function () {
143145
if (FONT.data) {
@@ -3106,6 +3108,9 @@ OSD.GUI.updateAll = function() {
31063108
return;
31073109
}
31083110
var layouts = $('.osd_layouts');
3111+
var copy = $('.osd_copy');
3112+
var paste = $('.osd_paste').hide();
3113+
var clear = $('.osd_clear');
31093114
if (OSD.data.layout_count > 1) {
31103115
layouts.empty();
31113116
for (var ii = 0; ii < OSD.data.layout_count; ii++) {
@@ -3121,9 +3126,63 @@ OSD.GUI.updateAll = function() {
31213126
OSD.GUI.updateDjiView($('#djiUnsupportedElements').find('input').is(':checked'));
31223127
OSD.GUI.updatePreviews();
31233128
});
3129+
3130+
copy.on('click', function() {
3131+
if(OSD.data.selected_layout >= 0 && OSD.data.selected_layout < OSD.data.layout_count){
3132+
layout_clipboard = {layout: JSON.parse(JSON.stringify(OSD.data.layouts[OSD.data.selected_layout])), filled: true};
3133+
paste.show();
3134+
GUI.log(chrome.i18n.getMessage('osdLayoutInsertedIntoClipboard'));
3135+
}
3136+
});
3137+
3138+
paste.on('click', function() {
3139+
if(layout_clipboard.filled == true){
3140+
3141+
var oldLayout = JSON.parse(JSON.stringify(OSD.data.layouts[OSD.data.selected_layout]))
3142+
OSD.data.layouts[OSD.data.selected_layout] = JSON.parse(JSON.stringify(layout_clipboard.layout));
3143+
layouts.trigger('change');
3144+
OSD.data.layouts[OSD.data.selected_layout].forEach(function(item, index){
3145+
if(!(item.isVisible === false && oldLayout[index].isVisible === false) && (oldLayout[index].x !== item.x || oldLayout[index].y !== item.y || oldLayout[index].position !== item.position || oldLayout[index].isVisible !== item.isVisible)){
3146+
OSD.saveItem({id: index});
3147+
}
3148+
});
3149+
GUI.log(chrome.i18n.getMessage('osdLayoutPasteFromClipboard'));
3150+
}
3151+
});
3152+
3153+
clear.on('click', function() {
3154+
var oldLayout = JSON.parse(JSON.stringify(OSD.data.layouts[OSD.data.selected_layout]));
3155+
3156+
var clearedLayout = [];
3157+
oldLayout.forEach(function(item, index){
3158+
var itemCopy = JSON.parse(JSON.stringify(item));
3159+
itemCopy.isVisible = false;
3160+
clearedLayout[index] = itemCopy;
3161+
})
3162+
3163+
OSD.data.layouts[OSD.data.selected_layout] = clearedLayout;
3164+
layouts.trigger('change');
3165+
OSD.data.layouts[OSD.data.selected_layout].forEach(function(item, index){
3166+
if(oldLayout[index].isVisible === true){
3167+
OSD.saveItem({id: index});
3168+
}
3169+
});
3170+
GUI.log(chrome.i18n.getMessage('osdClearLayout'));
3171+
});
3172+
3173+
31243174
} else {
31253175
layouts.hide();
31263176
layouts.off('change');
3177+
3178+
copy.hide();
3179+
copy.off('change');
3180+
3181+
paste.hide();
3182+
paste.off('change');
3183+
3184+
clear.hide();
3185+
clear.off('change');
31273186
}
31283187

31293188
$('.osd_search').on('input', function() {

0 commit comments

Comments
 (0)