Selaa lähdekoodia

refactor(FilmStrip): calculateThumbnailSizeFromAvailable

j8
hristoterezov 8 vuotta sitten
vanhempi
commit
a65fca851c
2 muutettua tiedostoa jossa 62 lisäystä ja 65 poistoa
  1. 3
    5
      interface_config.js
  2. 59
    60
      modules/UI/videolayout/FilmStrip.js

+ 3
- 5
interface_config.js Näytä tiedosto

@@ -41,10 +41,6 @@ var interfaceConfig = { // eslint-disable-line no-unused-vars
41 41
     RANDOM_AVATAR_URL_PREFIX: false,
42 42
     RANDOM_AVATAR_URL_SUFFIX: false,
43 43
     FILM_STRIP_MAX_HEIGHT: 120,
44
-    LOCAL_THUMBNAIL_RATIO_WIDTH: 16,
45
-    LOCAL_THUMBNAIL_RATIO_HEIGHT: 9,
46
-    REMOTE_THUMBNAIL_RATIO_WIDTH: 1,
47
-    REMOTE_THUMBNAIL_RATIO_HEIGHT: 1,
48 44
     // Enables feedback star animation.
49 45
     ENABLE_FEEDBACK_ANIMATION: false,
50 46
     DISABLE_FOCUS_INDICATOR: false,
@@ -52,5 +48,7 @@ var interfaceConfig = { // eslint-disable-line no-unused-vars
52 48
     // disables the ringing sound when the RingOverlay is shown.
53 49
     DISABLE_RINGING: false,
54 50
     AUDIO_LEVEL_PRIMARY_COLOR: "rgba(255,255,255,0.7)",
55
-    AUDIO_LEVEL_SECONDARY_COLOR: "rgba(255,255,255,0.4)"
51
+    AUDIO_LEVEL_SECONDARY_COLOR: "rgba(255,255,255,0.4)",
52
+    LOCAL_THUMBNAIL_RATIO: 16/9, //16:9
53
+    REMOTE_THUMBNAIL_RATIO: 1, //1:1
56 54
 };

+ 59
- 60
modules/UI/videolayout/FilmStrip.js Näytä tiedosto

@@ -72,40 +72,6 @@ const FilmStrip = {
72 72
         return this.calculateThumbnailSizeFromAvailable(width, height);
73 73
     },
74 74
 
75
-    /**
76
-     * Normalizes local and remote thumbnail ratios
77
-     */
78
-    normalizeThumbnailRatio () {
79
-        let remoteHeightRatio = interfaceConfig.REMOTE_THUMBNAIL_RATIO_HEIGHT;
80
-        let remoteWidthRatio = interfaceConfig.REMOTE_THUMBNAIL_RATIO_WIDTH;
81
-
82
-        let localHeightRatio = interfaceConfig.LOCAL_THUMBNAIL_RATIO_HEIGHT;
83
-        let localWidthRatio = interfaceConfig.LOCAL_THUMBNAIL_RATIO_WIDTH;
84
-
85
-        let commonHeightRatio = remoteHeightRatio * localHeightRatio;
86
-
87
-        let localRatioCoefficient = localWidthRatio / localHeightRatio;
88
-        let remoteRatioCoefficient = remoteWidthRatio / remoteHeightRatio;
89
-
90
-        remoteWidthRatio = commonHeightRatio * remoteRatioCoefficient;
91
-        remoteHeightRatio = commonHeightRatio;
92
-
93
-        localWidthRatio = commonHeightRatio * localRatioCoefficient;
94
-        localHeightRatio = commonHeightRatio;
95
-
96
-        let localRatio = {
97
-            widthRatio: localWidthRatio,
98
-            heightRatio: localHeightRatio
99
-        };
100
-
101
-        let remoteRatio = {
102
-            widthRatio: remoteWidthRatio,
103
-            heightRatio: remoteHeightRatio
104
-        };
105
-
106
-        return { localRatio, remoteRatio };
107
-    },
108
-
109 75
     calculateAvailableSize() {
110 76
         let availableHeight = interfaceConfig.FILM_STRIP_MAX_HEIGHT;
111 77
         let thumbs = this.getThumbs(true);
@@ -181,34 +147,67 @@ const FilmStrip = {
181 147
         return { availableWidth, availableHeight };
182 148
     },
183 149
 
150
+    /**
151
+     * Calculate the thumbnail size in order to fit all the thumnails in passed
152
+     * dimensions.
153
+     * NOTE: Here we assume that the remote and local thumbnails are with the
154
+     * same height.
155
+     * @param {int} availableWidth the maximum width for all thumbnails
156
+     * @param {int} availableHeight the maximum height for all thumbnails
157
+     */
184 158
     calculateThumbnailSizeFromAvailable(availableWidth, availableHeight) {
185
-        let { localRatio, remoteRatio } = this.normalizeThumbnailRatio();
186
-        let { remoteThumbs } = this.getThumbs(true);
187
-        let remoteProportion = remoteRatio.widthRatio * remoteThumbs.length;
188
-        let widthProportion = remoteProportion + localRatio.widthRatio;
189
-
190
-        let heightUnit = availableHeight / localRatio.heightRatio;
191
-        let widthUnit = availableWidth / widthProportion;
159
+        /**
160
+         * Let:
161
+         * lW - width of the local thumbnail
162
+         * rW - width of the remote thumbnail
163
+         * h - the height of the thumbnails
164
+         * remoteRatio - width:height for the remote thumbnail
165
+         * localRatio - width:height for the local thumbnail
166
+         * numberRemoteThumbs - number of remote thumbnails (we have only one
167
+         * local thumbnail)
168
+         *
169
+         * Since the height for local thumbnail = height for remote thumbnail
170
+         * and we know the ratio (width:height) for the local and for the
171
+         * remote thumbnail we can find rW/lW:
172
+         * rW / remoteRatio = lW / localRatio then -
173
+         * remoteLocalWidthRatio = rW / lW = remoteRatio / localRatio
174
+         * and rW = lW * remoteRatio / localRatio = lW * remoteLocalWidthRatio
175
+         * And the total width for the thumbnails is:
176
+         * totalWidth = rW * numberRemoteThumbs + lW
177
+         * = lW * remoteLocalWidthRatio * numberRemoteThumbs + lW =
178
+         * lW * (remoteLocalWidthRatio * numberRemoteThumbs + 1)
179
+         * and the h = lW/localRatio
180
+         *
181
+         * In order to fit all the thumbails in the area defined by
182
+         * availableWidth * availableHeight we should check one of the
183
+         * following options:
184
+         * 1) if availableHeight == h - totalWidth should be less than
185
+         * availableWidth
186
+         * 2) if availableWidth ==  totalWidth - h should be less than
187
+         * availableHeight
188
+         *
189
+         * 1) or 2) will be true and we are going to use it to calculate all
190
+         * sizes.
191
+         *
192
+         * if 1) is true that means that
193
+         * availableHeight/h > availableWidth/totalWidth otherwise 2) is true
194
+         */
192 195
 
193
-        if (heightUnit < widthUnit) {
194
-            widthUnit = heightUnit;
195
-        }
196
-        else
197
-            heightUnit = widthUnit;
198
-
199
-        let localVideo = {
200
-            thumbWidth: widthUnit * localRatio.widthRatio,
201
-            thumbHeight: heightUnit * localRatio.heightRatio
202
-        };
203
-        let remoteVideo = {
204
-            thumbWidth: widthUnit * remoteRatio.widthRatio,
205
-            thumbHeight: widthUnit * remoteRatio.heightRatio
206
-        };
207
-
208
-        return {
209
-            localVideo,
210
-            remoteVideo
211
-        };
196
+        const numberRemoteThumbs = this.getThumbs(true).remoteThumbs.length;
197
+        const remoteLocalWidthRatio = interfaceConfig.REMOTE_THUMBNAIL_RATIO /
198
+            interfaceConfig.LOCAL_THUMBNAIL_RATIO;
199
+        const lW = Math.min(availableWidth /
200
+            (remoteLocalWidthRatio * numberRemoteThumbs + 1), availableHeight *
201
+            interfaceConfig.LOCAL_THUMBNAIL_RATIO);
202
+        const h = lW / interfaceConfig.LOCAL_THUMBNAIL_RATIO;
203
+        return { localVideo:{
204
+                        thumbWidth: lW,
205
+                        thumbHeight: h
206
+                    }, remoteVideo: {
207
+                        thumbWidth: lW * remoteLocalWidthRatio,
208
+                        thumbHeight: h
209
+                    }
210
+                };
212 211
     },
213 212
 
214 213
     resizeThumbnails (local, remote,

Loading…
Peruuta
Tallenna