You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. glob_dev_fns.getTileViewGridDimensions = function(numberOfParticipants,state,maxColumns){
  2. // return
  3. if (glob_dev_fns.ret0){return}
  4. clog("getTileViewGridDimensions....")
  5. const rui = state['features/base/responsive-ui'];
  6. const clientHeight = rui.clientHeight
  7. const clientWidth = rui.clientWidth
  8. // var clo = calc_layout_heper(clientWidth,clientHeight,numberOfParticipants)
  9. // const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  10. // {
  11. // var aspect = 16/9
  12. var aspect = TILE_ASPECT_RATIO
  13. const topBottomPadding = 200;
  14. const sideMargins = 30 * 2;
  15. // var thumbs_count = Thumbs.remoteThumbs.length + Thumbs.localThumb.length
  16. var viewWidth = clientWidth - sideMargins
  17. var viewHeight = clientHeight - topBottomPadding
  18. clog("",view_width,viewHeight)
  19. // const r1 = avail_width/avail_height
  20. const viewAspectRatio = viewWidth/viewHeight
  21. // var clo = calc_layout2(1/((avail_width/avail_height)/aspect),numberOfParticipants)
  22. var clo = calc_layout2(TILE_ASPECT_RATIO/viewAspectRatio,numberOfParticipants)
  23. // }
  24. var r = clo.r
  25. var c = clo.c
  26. // c = clo.r
  27. // r = clo.c
  28. // you only need to check
  29. // if (Math.min(c,r) >= )
  30. if (r <= clo.n - numberOfParticipants){
  31. // c -= 1
  32. clog("cl_trc dec")
  33. }
  34. clog("GTVGD",clo,{r,c})
  35. // return 3
  36. return c
  37. }
  38. glob_dev_fns.getTileViewGridDimensions = function(state,maxColumns){
  39. // return
  40. // const { iAmRecorder } = state['features/base/config'];
  41. const iAmRecorder = state['features/base/config'].iAmRecorder;
  42. const numberOfParticipants = state['features/base/participants'].length - (iAmRecorder ? 1 : 0);
  43. if (glob_dev_fns.ret0){return}
  44. clog("getTileViewGridDimensions....")
  45. const rui = state['features/base/responsive-ui'];
  46. const clientHeight = rui.clientHeight
  47. const clientWidth = rui.clientWidth
  48. // var clo = calc_layout_heper(clientWidth,clientHeight,numberOfParticipants)
  49. // const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  50. // {
  51. var aspect = 16/9
  52. var TILE_ASPECT_RATIO = aspect
  53. // var aspect = TILE_ASPECT_RATIO
  54. const topBottomPadding = 200;
  55. const sideMargins = 30 * 2;
  56. var viewWidth = clientWidth - sideMargins
  57. var viewHeight = clientHeight - topBottomPadding
  58. clog("",viewWidth,viewHeight)
  59. // const r1 = avail_width/avail_height
  60. const viewAspectRatio = viewWidth/viewHeight
  61. // var clo = calc_layout2(1/((avail_width/avail_height)/aspect),numberOfParticipants)
  62. var clo = calc_layout2(TILE_ASPECT_RATIO/viewAspectRatio,numberOfParticipants)
  63. // }
  64. var r = clo.r
  65. var c = clo.c
  66. // c = clo.r
  67. // r = clo.c
  68. // you only need to check
  69. // if (Math.min(c,r) >= )
  70. clog("GTVGD0",clo,{r,c})
  71. if (r <= clo.n - numberOfParticipants){
  72. // Math.floor()
  73. var xtra_space = clo.n - numberOfParticipants
  74. Math.floor(xtra_space/r)
  75. clog("cl_trc_ dec",{r,c,f:Math.floor(xtra_space/r),rl:xtra_space/r,"x":clo.n - numberOfParticipants,numberOfParticipants,clo})
  76. // c -= 1
  77. // c -= Math.floor(xtra_space/r)
  78. }
  79. if (r <= (r * c) - numberOfParticipants){
  80. c -= 1
  81. clog("cl_trc dec2")
  82. }
  83. clog("GTVGD",clo,{r,c})
  84. // return 3
  85. const columnsToMaintainASquare = c
  86. // const columns = Math.min(columnsToMaintainASquare, maxColumns);
  87. const columns = Math.min(columnsToMaintainASquare, 100);
  88. const rows = Math.ceil(numberOfParticipants / columns);
  89. // const visibleRows = Math.min(maxColumns, rows);
  90. const visibleRows = rows;
  91. clog("GTVGD2",{visibleRows,columns})
  92. return {
  93. columns,
  94. visibleRows
  95. };
  96. // return c
  97. }
  98. function calcTileGrid(a,ni){
  99. var dflt = {
  100. r:1,
  101. c:1,
  102. n:1,
  103. ni:1,
  104. }
  105. if (!ni){
  106. clog("calcTileGrid TILES MAY NOT BE 0")
  107. // return dflt
  108. }
  109. var mcnt=100
  110. var cnt=0
  111. if (ni < 1){
  112. clog("calcTileGrid TILES MAY 0",ni)
  113. }
  114. var r = 1
  115. var c = 1
  116. var n = 1
  117. clog("mx cl_trc",ni,a)
  118. while (1){
  119. cnt += 1
  120. if (mcnt < cnt ){
  121. clog("calcTileGrid ILOOP",cnt)
  122. return dflt
  123. }
  124. if (r * c < n){
  125. if ( (c + 1) * a < r + 1 ) {
  126. c++
  127. } else {
  128. r++
  129. }
  130. }
  131. clog("cl_trc",{r,c,n,nn:r*c})
  132. n=r*c
  133. if (n >= ni){
  134. break
  135. }
  136. n=n+1
  137. }
  138. clog("CL",ni,r,c,n)
  139. return {
  140. r:r,
  141. c:c,
  142. n:n,
  143. ni:ni,
  144. }
  145. }
  146. function calcTileGrid(ratio,tiles){
  147. var dflt = {
  148. r:1,
  149. c:1,
  150. n:1,
  151. ni:1,
  152. }
  153. if (!tiles){
  154. clog("calcTileGrid TILES MAY NOT BE 0")
  155. // return dflt
  156. }
  157. var mcnt=1000000000
  158. var mcntt=100000000
  159. var mcnttx=mcntt
  160. var cnt=0
  161. if (tiles < 1){
  162. clog("calcTileGrid TILES MAY 0",tiles)
  163. }
  164. // avail_tiles
  165. var rows = 1
  166. var columns = 1
  167. var avail_tiles = 0
  168. // this can become an infinite loop for large numbers due to loss of precision
  169. if (tiles > 2147483648) {tiles = 1}
  170. clog("mx cl_trc",tiles,ratio)
  171. while (avail_tiles < tiles){
  172. avail_tiles=avail_tiles+1
  173. cnt += 1
  174. if (mcnt < cnt ){
  175. clog("calcTileGrid ILOOP",{rows,columns,avail_tiles,tiles},cnt)
  176. return dflt
  177. }
  178. if (mcnttx < cnt ){
  179. clog(".calcTileGrid ILOOP.",avail_tiles,avail_tiles+1,{rows,columns,avail_tiles,tiles},jc({rows,columns,avail_tiles,tiles}),cnt)
  180. mcnttx += mcntt
  181. // return dflt
  182. }
  183. if (rows * columns < avail_tiles){
  184. if ( (columns + 1) * ratio < rows + 1 ) {
  185. columns++
  186. } else {
  187. rows++
  188. }
  189. }
  190. // clog("cl_trc",{r,c,n,nn:r*c})
  191. avail_tiles=rows*columns
  192. // if (n >= tiles){
  193. if (!(avail_tiles < tiles)){
  194. // break
  195. }
  196. }
  197. // clog("CL",tiles,r,c,n,cnt)
  198. return {
  199. r:rows,
  200. c:columns,
  201. n:avail_tiles,
  202. ni:tiles,
  203. }
  204. }
  205. glob_dev_fns.getTileViewGridDimensions_cc = function(numberOfParticipants,state,maxColumns){
  206. // return
  207. if (glob_dev_fns.ret0){return}
  208. clog("getTileViewGridDimensions....")
  209. const rui = state['features/base/responsive-ui'];
  210. const clientHeight = rui.clientHeight
  211. const clientWidth = rui.clientWidth
  212. // const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  213. var clo = calc_layout_heper(clientWidth,clientHeight,numberOfParticipants)
  214. var r = clo.r
  215. var c = clo.c
  216. // c = clo.r
  217. // r = clo.c
  218. // you only need to check
  219. // if (Math.min(c,r) >= )
  220. if (r <= clo.n - numberOfParticipants){
  221. // c -= 1
  222. clog("cl_trc dec")
  223. }
  224. clog("GTVGD",clo,{r,c})
  225. // return 3
  226. return c
  227. }
  228. glob_dev_fns.getTileViewGridDimensions_sq = function(numberOfParticipants,state,maxColumns){
  229. // return
  230. if (glob_dev_fns.ret0){return}
  231. clog("getTileViewGridDimensions....")
  232. const rui = state['features/base/responsive-ui'];
  233. const clientHeight = rui.clientHeight
  234. const clientWidth = rui.clientWidth
  235. // var clo = calc_layout_heper(clientWidth,clientHeight,numberOfParticipants)
  236. // const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  237. // {
  238. var aspect = 16/9
  239. var TILE_ASPECT_RATIO = aspect
  240. // var aspect = TILE_ASPECT_RATIO
  241. const topBottomPadding = 200;
  242. const sideMargins = 30 * 2;
  243. var viewWidth = clientWidth - sideMargins
  244. var viewHeight = clientHeight - topBottomPadding
  245. clog("",viewWidth,viewHeight)
  246. // const r1 = avail_width/avail_height
  247. const viewAspectRatio = viewWidth/viewHeight
  248. // var clo = calc_layout2(1/((avail_width/avail_height)/aspect),numberOfParticipants)
  249. var clo = calc_layout2(TILE_ASPECT_RATIO/viewAspectRatio,numberOfParticipants)
  250. // }
  251. var r = clo.r
  252. var c = clo.c
  253. // c = clo.r
  254. // r = clo.c
  255. // you only need to check
  256. // if (Math.min(c,r) >= )
  257. if (r <= clo.n - numberOfParticipants){
  258. // c -= 1
  259. clog("cl_trc dec")
  260. }
  261. clog("GTVGD",clo,{r,c})
  262. // return 3
  263. return c
  264. }
  265. // function calc_layout_heper(avail_width,avail_height,thumbs_count){
  266. function calc_layout_heper(clientWidth,clientHeight,numberOfParticipants){
  267. var aspect = 16/9
  268. // Thumbs = glob_react.Filmstrip._getThumbs()
  269. const topBottomPadding = 200;
  270. const sideMargins = 30 * 2;
  271. // var thumbs_count = Thumbs.remoteThumbs.length + Thumbs.localThumb.length
  272. var avail_width = clientWidth - sideMargins
  273. var avail_height = clientHeight - topBottomPadding
  274. clog("",avail_width,avail_height)
  275. const r1 = avail_width/avail_height
  276. const r0 = aspect
  277. clo = calc_layout2(1/((avail_width/avail_height)/aspect),numberOfParticipants)
  278. return clo
  279. }
  280. glob_dev_fns.setTileViewDimensions_x = function(o,dimensions,windowSize,that){
  281. // console.trace("STV")
  282. // SET_TILE_VIEW_DIMENSIONS
  283. windowSize = o.args[1]
  284. dimensions = o.args[0]
  285. clog("glob_dev_fns.setTileViewDimensions",arguments)
  286. var aspect = 16/9
  287. Thumbs = glob_react.Filmstrip._getThumbs()
  288. const topBottomPadding = 200;
  289. const sideMargins = 30 * 2;
  290. var thumbs_count = Thumbs.remoteThumbs.length + Thumbs.localThumb.length
  291. var avail_width = windowSize.clientWidth - sideMargins
  292. var avail_height = windowSize.clientHeight - topBottomPadding
  293. clog("",avail_width,avail_height)
  294. const r1 = avail_width/avail_height
  295. const r0 = aspect
  296. var clo = calc_layout2((avail_width/avail_height)/aspect,thumbs_count)
  297. // calc_layout2
  298. clog(windowSize,dimensions)
  299. var bw = avail_width
  300. var w2,width
  301. // clog(xgrp,xgrp.length,clo)
  302. if ((r1/r0) * (clo.c / clo.r) > 1) {
  303. w2 = bw / ((r1/r0) * clo.c)
  304. } else {
  305. w2 = bw / ( clo.r)
  306. }
  307. // width = 310
  308. // w2 =w2 - 12
  309. w2 =w2 - (10 * aspect)
  310. // w2 =w2 - 15
  311. // w2 =w2 - 16
  312. // width = Math.round(w2)
  313. width = Math.floor(w2)
  314. var height = Math.floor(width / (aspect))
  315. clog(clo)
  316. var avail_width2 = avail_width
  317. // if (clo.ni < clo.n){
  318. // r and c are misnamed!
  319. var col,max_width
  320. if (clo.c == 2){
  321. col = Math.ceil(clo.ni / 2)
  322. max_width = (col + .5) * width
  323. clog("MX...",col ,avail_width2,max_width)
  324. if (max_width < avail_width2){
  325. clog("MX",avail_width2,max_width)
  326. avail_width2 = max_width
  327. }
  328. }
  329. if (clo.ni <= clo.n + clo.c){
  330. // avail_width2 = Math.round(width * clo.)
  331. // avail_width2 = Math.round(avail_width2 - width/2)
  332. }
  333. // return
  334. const SET_TILE_VIEW_DIMENSIONS = "SET_TILE_VIEW_DIMENSIONS"
  335. return {ret:{
  336. type: SET_TILE_VIEW_DIMENSIONS,
  337. dimensions: {
  338. gridDimensions: {columns:clo.c,visibleRows:clo.r,},
  339. xtra:"xtra_val2",
  340. thumbnailSize:{height,width},
  341. filmstripWidth:avail_width2
  342. }
  343. }};
  344. /*
  345. return {
  346. dimensions:{
  347. columns:cl.c,
  348. visibleRows:cl.r,
  349. }
  350. }
  351. */
  352. return {ret:{
  353. type: SET_TILE_VIEW_DIMENSIONS,
  354. dimensions: {
  355. gridDimensions: dimensions,
  356. xtra:"xtra_val",
  357. thumbnailSize,
  358. filmstripWidth
  359. }
  360. }};
  361. }
  362. // ["Filmstrip", "fs", "rf_filmstrip"]
  363. // Calculates the most efficient grid for tiling rectangles of the same size and aspect ratio in a rectangular container
  364. // This function does NOT take into account margins between tiles. so in practice our result will not be
  365. // Calculates an efficient grid for tiling rectangles of the same size and aspect ratio in a rectangular container
  366. // takes as arguments
  367. function calcTileGrid0(ratio,tiles){
  368. var dflt = {
  369. r:1,
  370. c:1,
  371. n:1,
  372. ni:1,
  373. }
  374. if (!tiles){
  375. clog("calcTileGrid TILES MAY NOT BE 0")
  376. // return dflt
  377. }
  378. var mcnt=100
  379. var cnt=0
  380. if (tiles < 1){
  381. clog("calcTileGrid TILES MAY 0",tiles)
  382. }
  383. var r = 1
  384. var c = 1
  385. var n = 1
  386. clog("mx cl_trc",tiles,ratio)
  387. while (1){
  388. cnt += 1
  389. if (mcnt < cnt ){
  390. clog("calcTileGrid ILOOP",cnt)
  391. return dflt
  392. }
  393. if (r * c < n){
  394. if ( (c + 1) * ratio < r + 1 ) {
  395. c++
  396. } else {
  397. r++
  398. }
  399. }
  400. clog("cl_trc",{r,c,n,nn:r*c})
  401. n=r*c
  402. // if (n >= tiles){
  403. if (!(n < tiles)){
  404. break
  405. }
  406. n=n+1
  407. }
  408. clog("CL",tiles,r,c,n,cnt)
  409. return {
  410. r:r,
  411. c:c,
  412. n:n,
  413. ni:tiles,
  414. }
  415. }