Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fit vertically 2x2 as expected #2590

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions motioneye/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,22 @@ div.page-container.four-columns div.camera-frame {
width: 25%;
}

div.page-container.one-row div.camera-frame {
height: 100%
}

div.page-container.two-rows div.camera-frame {
height: 50%
}

div.page-container.three-rows div.camera-frame {
height: 33.3333%
}

div.page-container.four-rows div.camera-frame {
height: 25%
}

div.page-container div.camera-frame.full-screen-hidden {
width: 0 !important;
height: 0 !important;
Expand Down Expand Up @@ -1263,14 +1279,18 @@ div.camera-action-button.preset9:BEFORE {
div.camera-container {
position: relative;
padding: 0;
height: 100%;
}

img.camera {
position: relative;
width: 100%;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
height: inherit;
display: block;
transition: opacity 0.2s ease;
opacity: 1;
transition: opacity .2s ease;
opacity: 1
}

img.camera.error,
Expand Down
129 changes: 78 additions & 51 deletions motioneye/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,62 +1099,89 @@ function setLayoutColumns(columns) {
updateLayout();
}

Array.prototype.reshape = function(rows, cols) {
var copy = [];

for (var r = 0; r < rows; r++) {
var row = [];
for (var c = 0; c < cols; c++) {
var i = r * cols + c;
if (i < this.length) {
row.push(this[i]);
}
}
copy.push(row);
}
return copy;
};

function updateLayout() {

if (fitFramesVertically) {

/* make sure the height of each camera
* is smaller than the height of the screen
* divided by the number of layout rows */

/* find the max height/width ratio */
var frames = getCameraFrames();
var maxRatio = 0;

frames.each(function () {
var cameraId = this.id.substring(6);
var ratio = cameraFrameRatios[cameraId];
if (ratio > maxRatio) {
maxRatio = ratio;
}
});

if (!maxRatio) {
return; /* no camera frames */
}

var pageContainer = getPageContainer();
var windowWidth = $(window).width();

var columns = layoutColumns;
if (isSingleView() || fullScreenMode || windowWidth <= 1200) {
columns = 1; /* always 1 column when in full screen or mobile */
}


var heightOffset = 5; /* some padding */
if (!fullScreenMode && !isSingleView()) {
heightOffset += 50; /* top bar */
}

var windowHeight = $(window).height() - heightOffset;
var maxWidth = windowWidth;

var width = windowHeight / maxRatio * columns;
if (pageContainer.hasClass('stretched') && windowWidth > 1200) {
maxWidth *= 0.6; /* opened settings panel occupies 40% of the window width */
}

if (width < 100) {
width = 100; /* absolute minimum width for a frame */
// 2D array representing rows/cols of the layout
var cameraDimensions = getCameraFrames().map(function () {
return { height: this.img._naturalHeight, width: this.img._naturalWidth };
}).toArray().reshape(layoutRows, layoutColumns);

// Take max cam height for each row, add them together
var combinedHeight = cameraDimensions.map(function(row) {
return row.length ? Math.max(...row.map(function(cam) {
return cam.height;
})) : 0
}).reduce(function(a,b) {
return a+b;
}, 0);

// Take max cam width for each col, add them together
var combinedWidth = [...Array(layoutColumns).keys()].map(function(col) {
return cameraDimensions.map(function(row) {
return row[col];
})
}).map(function(col) {
return col ? Math.max(...col.map(function(cam) {
return cam ? cam.width : 0;
})) : 0
}).reduce(function(a,b) {
return a+b;
}, 0);

var combinedRatio = combinedWidth/combinedHeight;

var windowWidth = $(window).width();
if (getPageContainer().hasClass('stretched') && windowWidth > 1200) {
windowWidth *= 0.6; /* opened settings panel occupies 40% of the window width */
}

if (width > maxWidth) {
getPageContainer().css('width', '');
return; /* page container width already at its maximum */
var windowRatio = windowWidth/windowHeight;
if( windowRatio > combinedRatio ) {
getPageContainer().css('height', windowHeight);
getPageContainer().css('width', windowHeight*combinedRatio);
}

getPageContainer().css('width', width);
}
else {
getPageContainer().css('width', '');
else {
getPageContainer().css('height', windowWidth/combinedRatio);
getPageContainer().css('width', windowWidth);
}

var cssClasses = {
1: 'one-row',
2: 'two-rows',
3: 'three-rows',
4: 'four-rows'
};

getPageContainer().removeClass(Object.values(cssClasses).join(' '));
getPageContainer().addClass(cssClasses[layoutRows]);
}
}

Expand Down Expand Up @@ -1459,8 +1486,8 @@ function closeSettings() {
$('div.settings-top-bar').removeClass('open').addClass('closed');

if (isSingleView()) {
pageContainer.removeClass('single-cam-edit');
$('div.header').addClass('single-cam');
pageContainer.removeClass('single-cam-edit');
$('div.header').addClass('single-cam');
}

updateLayout();
Expand Down Expand Up @@ -3579,18 +3606,18 @@ function runLoginDialog(retry) {
'</tr>' +
'<tr>' +
'<td class="dialog-item-label"><span class="dialog-item-label">'
+i18n.gettext("Uzantnomo") + '</span></td>' +
+i18n.gettext("Uzantnomo") + '</span></td>' +
'<td class="dialog-item-value"><input type="text" name="username" class="styled" id="usernameEntry" autofocus></td>' +
'</tr>' +
'<tr>' +
'<td class="dialog-item-label"><span class="dialog-item-label">'
+i18n.gettext("Pasvorto") + '</span></td>' +
+i18n.gettext("Pasvorto") + '</span></td>' +
'<td class="dialog-item-value"><input type="password" name="password" class="styled" id="passwordEntry"></td>' +
'<input type="submit" style="display: none;" name="login" value="login">' +
'</tr>' +
'<tr>' +
'<td class="dialog-item-label"><span class="dialog-item-label">'
+i18n.gettext("Memoru min")+'</span></td>' +
+i18n.gettext("Memoru min")+'</span></td>' +
'<td class="dialog-item-value"><input type="checkbox" name="remember" class="styled" id="rememberCheck"></td>' +
'</tr>' +
'</table></form>');
Expand Down Expand Up @@ -3941,12 +3968,12 @@ function runAddCameraDialog() {

content.find('tr.netcam').css('display', 'table-row');
addCameraInfo.html(
i18n.gettext("Retaj kameraoj (aŭ IP-kameraoj) estas aparatoj, kiuj denaske fluas RTSP/RTMP aŭ MJPEG-filmetojn aŭ simplajn JPEG-bildojn. Konsultu la manlibron de via aparato por ekscii la ĝustan URL RTSP, RTMP, MJPEG aŭ JPEG."));
i18n.gettext("Retaj kameraoj (aŭ IP-kameraoj) estas aparatoj, kiuj denaske fluas RTSP/RTMP aŭ MJPEG-filmetojn aŭ simplajn JPEG-bildojn. Konsultu la manlibron de via aparato por ekscii la ĝustan URL RTSP, RTMP, MJPEG aŭ JPEG."));
}
else if (typeSelect.val() == 'mmal') {
content.find('tr.mmal').css('display', 'table-row');
addCameraInfo.html(
i18n.gettext("Lokaj MMAL-kameraoj estas aparatoj konektitaj rekte al via motionEye-sistemo. Ĉi tiuj estas kutime kart-specifaj kameraoj."));
i18n.gettext("Lokaj MMAL-kameraoj estas aparatoj konektitaj rekte al via motionEye-sistemo. Ĉi tiuj estas kutime kart-specifaj kameraoj."));
}
else if (typeSelect.val() == 'mjpeg') {
usernameEntry.removeAttr('readonly');
Expand All @@ -3961,7 +3988,7 @@ function runAddCameraDialog() {

content.find('tr.mjpeg').css('display', 'table-row');
addCameraInfo.html(
i18n.gettext("Aldonante vian aparaton kiel simplan MJPEG-kameraon anstataŭ kiel retan kameraon plibonigos la fotografaĵon, sed neniu moviĝo-detekto, bilda kaptado aŭ registrado de filmoj estos disponebla por ĝi. La kamerao devas esti alirebla por via servilo kaj via retumilo. Ĉi tiu tipo de kamerao ne kongruas kun Internet Explorer."));
i18n.gettext("Aldonante vian aparaton kiel simplan MJPEG-kameraon anstataŭ kiel retan kameraon plibonigos la fotografaĵon, sed neniu moviĝo-detekto, bilda kaptado aŭ registrado de filmoj estos disponebla por ĝi. La kamerao devas esti alirebla por via servilo kaj via retumilo. Ĉi tiu tipo de kamerao ne kongruas kun Internet Explorer."));
}
else { /* assuming v4l2 */
content.find('tr.v4l2').css('display', 'table-row');
Expand Down