enabled intersecting ribbon crop modes...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-11-16 02:21:07 +04:00
parent 40349ac968
commit 995e279927
4 changed files with 56 additions and 25 deletions

View File

@ -28,9 +28,13 @@ function getAllData(){
// NOTE: this will not update .current state...
// NOTE: when keep_ribbons is set, this may generate empty ribbons...
// NOTE: this requieres all data to be present, if currently viewing
// server-side data, then cropping is a server-side operation...
// XXX another way to go here is to save the crop method and take
// it into account when loading new sections of data...
//
// XXX should this set the .current to anything but null or the first elem???
function makeCroppedData(gids, keep_ribbons){
function makeCroppedData(gids, keep_ribbons, keep_unloaded_gids){
var res = {
varsion: '2.0',
current: null,
@ -38,6 +42,18 @@ function makeCroppedData(gids, keep_ribbons){
order: DATA.order.slice(),
}
// remove any gid that is not in IMAGES or is not loaded...
if(!keep_unloaded_gids){
var loaded = []
$.each(DATA.ribbons, function(i, e){ loaded = loaded.concat(e) })
// NOTE: if IMAGES contains only part of the data loadable this will
// be wrong...
gids = gids.filter(function(e){
return e in IMAGES && loaded.indexOf(e) >= 0
})
}
// flat single ribbon crop...
if(!keep_ribbons){
res.ribbons[0] = gids
@ -59,12 +75,12 @@ function makeCroppedData(gids, keep_ribbons){
// NOTE: if keep_ribbons is not set this will ALWAYS build a single ribbon
// data-set...
function cropDataTo(gids, keep_ribbons){
function cropDataTo(gids, keep_ribbons, keep_unloaded_gids){
var prev_state = DATA
var cur = DATA.current
var r = getRibbonIndex()
var new_data = makeCroppedData(gids, keep_ribbons)
var new_data = makeCroppedData(gids, keep_ribbons, keep_unloaded_gids)
// do nothing if there is no change...
// XXX is there a better way to compare states???
@ -139,11 +155,14 @@ function showAllData(){
// uncropLastState(...)
// NOTE: crop modes are exclusive -- it is not possible to enter one crop
// mode from a different crop mode
//
// XXX add "exclusive" crop option -- prevent other crop modes to enter...
function makeCropModeToggler(cls, crop){
var res = createCSSClassToggler(
'.viewer',
//cls + ' cropped-mode',
cls,
/* XXX make this an option...
function(action){
// prevent mixing marked-only and single-ribbon modes...
if(action == 'on'
@ -152,6 +171,7 @@ function makeCropModeToggler(cls, crop){
return false
}
},
*/
function(action){
if(action == 'on'){
showStatusQ('Cropping current ribbon...')

View File

@ -16,25 +16,12 @@
// NOTE: MARKED may contain both gids that are not loaded and that do
// not exist, as there is no way to distinguish between the two
// situations the cleanup is optional...
function cropMarkedImages(cmp, no_cleanout_marks){
function cropMarkedImages(cmp, keep_ribbons, no_cleanout_marks){
cmp = cmp == null ? imageOrderCmp : cmp
var cur = DATA.current
var marked = MARKED.slice().sort(cmp)
if(!no_cleanout_marks){
// build all loaded images cache...
var loaded = []
$.each(DATA.ribbons, function(i, e){ loaded = loaded.concat(e) })
// ignore any gid in marks that is not in IMAGES...
// NOTE: if IMAGES contains only part of the data loadable this will
// be wrong...
var marked = marked.filter(function(e){
return e in IMAGES && loaded.indexOf(e) >= 0
})
}
cropDataTo(marked)
cropDataTo(marked, keep_ribbons, no_cleanout_marks)
return DATA
}
@ -51,6 +38,13 @@ var toggleMarkedOnlyView = makeCropModeToggler(
cropMarkedImages)
var toggleMarkedOnlyWithRibbonsView = makeCropModeToggler(
'marked-only-view',
function(){
cropMarkedImages(null, true)
})
// XXX shifting images and unmarking in this mode do not work correctly...
var toggleMarkesView = createCSSClassToggler(
'.viewer',

View File

@ -180,6 +180,24 @@ var toggleSingleRibbonMode = makeCropModeToggler(
})
var toggleCurrenAndAboveRibbonsMode = makeCropModeToggler(
'current-and-above-ribbons-mode',
function(){
var gids = []
var c = getRibbonIndex()
var ribbons = DATA.ribbons
// merge the ribbons...
for(var i=0; i <= c; i++){
gids = gids.concat(ribbons[i])
}
gids.sort(imageOrderCmp)
// do the crop...
cropDataTo(gids)
})
// TODO transitions...
// TODO a real setup UI (instead of prompt)
var toggleSlideShowMode = createCSSClassToggler(

View File

@ -1055,15 +1055,11 @@ function cropImagesDialog(){
updateStatus('Crop...').show()
var alg = 'Crop:|'+
'Use Esc and Shift-Esc to exit crop modes.'+
'\n\n'+
'NOTE: currently mixing crop modes is not supported,\n'+
'thus, if you are in a particular crop mode, you can\n'+
'only use that mode to crop again.\n'+
'...This restriction will be removed later.'
'Use Esc and Shift-Esc to exit crop modes.'
cfg = {}
cfg[alg] = [
'Marked images (single ribbon)',
'Marked images',
'Current ribbon',
'Current ribbon and above'
@ -1076,9 +1072,12 @@ function cropImagesDialog(){
.done(function(res){
res = res[alg]
if(/Marked/i.test(res)){
if(/Marked.*single ribbon/i.test(res)){
var method = toggleMarkedOnlyView
} else if(/Marked/i.test(res)){
var method = toggleMarkedOnlyWithRibbonsView
} else if(/Current ribbon/i.test(res)){
var method = toggleSingleRibbonMode