示例#1
0
void ImageArea::onChangeMode( void )
{
    if( _enlarge_timer.isActive() ) return;

    if ( _front_viewer )
    {
        _old_viewers.append(_front_viewer);
        _front_viewer = NULL;
        update();
        _image_viewer.onSettingsChanged();
        _dir_viewer.onSettingsChanged();
        return;
    }

    // start animation
    if ( _dir_view )
    {
        _image_viewer.changeFromOtherViewer( &_dir_viewer );
        _dir_view = false;
        if ( g_config.disable_animations )
        {
            _enlarge_parameter = 1.0;
            enlargeImage();
        } else {
            _thumb_pos = _dir_viewer.currentItemPosition();
            _image_viewer.setZoom(_thumb_zoom);
            _image_viewer.setView(_thumb_pos);
            _enlarge_timer.start(20);
        }
    } else {
        if ( g_config.disable_animations )
        {
            _enlarge_parameter = 0.0;
            reduceImage();
        } else {
            _enlarge_parameter = 1.0;
            _thumb_pos = _dir_viewer.currentItemPosition();
            _start_pos = _image_viewer.getView();
            _start_zoom = _image_viewer.getZoom();
            _start_angle = _image_viewer.getRotation();
            _reduce_timer.start(15);
        }
    }
}
示例#2
0
ImageArea::ImageArea(QWidget *parent)
    : QWidget(parent)
    , _front_viewer(nullptr)
    , _dir_view(false)
    , _hide_cursor_timer(0)
    , _enlarge_timer(this)
    , _reduce_timer(this)
    , _fit_timer(this)
    , _enlarge_parameter(0.01)
    , _start_zoom(1.0)
    , _start_pos(0,0)
    , _thumb_zoom(0.05)
{

    setAttribute(Qt::WA_StaticContents);

    _connectSignals( &_image_viewer );
    _image_viewer.setSize( width(), height() );

    _connectSignals( &_dir_viewer );
    _dir_viewer.setSize( width(), height() );

    connect( &_timer, SIGNAL(timeout()), this, SLOT(onTimer()));
    _timer.start( g_config.timer_duration );
    if ( g_config.multitouch )
    {
        setAttribute(Qt::WA_AcceptTouchEvents);
        setMouseTracking(true);
    } else {
        setMouseTracking(true);
    }
    setAcceptDrops(true);

    connect( &_enlarge_timer, SIGNAL(timeout()), this, SLOT(enlargeImage()) );
    connect( &_reduce_timer, SIGNAL(timeout()),this, SLOT(reduceImage()) );
    connect( &_fit_timer, SIGNAL(timeout()), this, SLOT(fitImage()));

    connect( &_image_viewer, SIGNAL(fitImage()), this, SLOT(onFitImage()));
}
示例#3
0
void generate_optimal_paletteapply(Fl_Widget*,void*s){
	struct settings*set=(struct settings*)s;
	uint8_t * image;
	uint32_t w,h;
	if(set->sprite){
		unsigned msprt=curSpritemeta;
		w=currentProject->ms->sps[msprt].width(curSpritegroup);
		h=currentProject->ms->sps[msprt].height(curSpritegroup);
	}else{
		w=currentProject->tms->maps[currentProject->curPlane].mapSizeW;
		h=currentProject->tms->maps[currentProject->curPlane].mapSizeHA;
		w*=currentProject->tileC->sizew;
		h*=currentProject->tileC->sizeh;
	}

	unsigned maxRows,firstRow;
	int spRow=currentProject->fixedSpirtePalRow();
	if(spRow>=0&&set->sprite){
		maxRows=spRow+1;
		firstRow=spRow;
		if(!set->useRow[firstRow]){
			fl_alert("No rows specified");
			return;
		}
	}else{
		maxRows=currentProject->pal->getMaxRows(set->sprite);
		for(firstRow=0;(firstRow<maxRows)&&(!set->useRow[firstRow]);++firstRow);
		if(firstRow>=maxRows){
			fl_alert("No rows specified");
			return;
		}
	}
	unsigned rows=0;
	for(unsigned i=firstRow;i<maxRows;++i){
		if(set->useRow[i])
			++rows;
	}
	printf("First row: %u\n",firstRow);
	uint8_t found_colors[768];
	int rowAuto;
	if((rows==1)&&(!set->sprite))
		rowAuto = set->rowAuto;
	else if(!set->sprite){
		rowAuto = set->rowAuto;
		if(rowAuto<0)
			return;
	}else{
		puts("rowAuto forced to zero");
		rowAuto=0;
	}
	pushPaletteAll();//Save the old palette
	Fl_Window *win=0;
	Fl_Progress *progress=0;
	mkProgress(&win,&progress);
	image = (uint8_t *)malloc(w*h*3);
	if (rows==1){
		if (rowAuto)
			currentProject->tms->maps[currentProject->curPlane].allRowSet(firstRow);
		if(set->sprite){
			unsigned off=set->off[firstRow]+(firstRow*currentProject->pal->perRow);
			if(currentProject->gameSystem==NES)
				off+=16;
			reduceImage(image,found_colors,-1,off,progress,win,set->perRow[firstRow],set->colSpace,set->alg,true);
		}else
			reduceImage(image,found_colors,-1,firstRow*currentProject->pal->perRow+set->off[firstRow],progress,win,set->perRow[firstRow],set->colSpace,set->alg);
		if(window){
			window->damage(FL_DAMAGE_USER1);
			Fl::check();
		}
	}else{
		if(rowAuto==2){
			unsigned coltarget=0;
			for(unsigned i=0;i<currentProject->pal->getMaxRows(set->sprite);++i)
				coltarget+=set->perRow[i];	
			reduceImage(image,found_colors,-1,0,progress,win,coltarget,set->colSpace,set->alg);
			currentProject->tms->maps[currentProject->curPlane].pickRowDelta(true,progress,set->rowAutoEx[0],set->rowAutoEx[1]);
			if(window){
				window->damage(FL_DAMAGE_USER1);
				Fl::check();
			}
		}else{
			if (rowAuto==1)
				currentProject->tms->maps[currentProject->curPlane].pickRow(maxRows-firstRow,set->rowAutoEx[0],set->rowAutoEx[1]);
			else if(rowAuto==3)
				currentProject->tms->maps[currentProject->curPlane].pickTileRowQuantChoice(maxRows-firstRow);
			for (unsigned i=firstRow;i<maxRows;++i){
				if(set->useRow[i]){
					reduceImage(image,found_colors,i,(i*currentProject->pal->perRow)+set->off[i],progress,win,set->perRow[i],set->colSpace,set->alg);
					if(window){
						window->damage(FL_DAMAGE_USER1);
						Fl::check();
					}
				}
			}
		}
	}
	free(image);
	if(progress){
		win->remove(progress);// remove progress bar from window
		delete(progress);// deallocate it
	}
	if(win)
		delete win;
	palBar.updateSliders();
	if(set->ditherAfter){
		if(set->sprite){
			ditherSpriteAsImage(window->metaspritesel->value(),curSpritegroup);
		}else{
			pushTilesAll(tTypeTile);
			currentProject->tms->maps[currentProject->curPlane].ditherAsImage(set->entireRow);
		}
	}
	if(window){
		window->redraw();
		Fl::check();
	}
}