2
#include "dlgbankrange.h"
7
#include <supportfuncs.h>
14
extern int PletterMain( int dataSize, unsigned char *pData, string destfilename );
17
const int CScreenW::PAL_ALL = 100;
25
void CScreenW::Initialize()
34
m_pLblScreen = new CLabelBtn( m_pFrmScreen, 32*16, 24*16 );
35
m_pLblScreen->setGeometry( 3, 3, 32*16, 24*16 );
36
m_pLblScreen->setMouseTracking( true );
39
m_pLblSelection = new CLabelBtn( m_pFrmScreen, 0, 0 );
40
m_pLblSelection->setGeometry( 0, 0, 0, 0 );
41
m_pLblSelection->setFrameShape( QFrame::Box );
42
m_pLblSelection->setFrameShadow( QFrame::Raised );
43
pal = m_pLblSelection->palette();
44
pal.setColor( QPalette::Dark, Qt::green );
45
m_pLblSelection->setPalette( pal );
49
connect( m_pLblScreen, SIGNAL( onClickedLeft( int, int ) ), this, SLOT( OnScreenClickLeft( int, int ) ) );
50
connect( m_pLblScreen, SIGNAL( onReleasedLeft( int, int ) ), this, SLOT( OnScreenReleaseLeft( int, int ) ) );
51
connect( m_pLblScreen, SIGNAL( onReleasedRight( int, int ) ), this, SLOT( OnScreenReleaseRight( int, int ) ) );
52
connect( m_pLblScreen, SIGNAL( onMouseMoveEvent( int, int ) ), this, SLOT( OnScreenMouseMoveEvent( int, int ) ) );
55
m_pTabBank = new QTabWidget( this );
56
m_pTabBank->setGeometry( QRect( 5, 420, 596, 184 ) );
58
for( i = 0; i < 3; i++ )
61
m_pTabBank->addTab( pTab, QString());
63
m_pTabBank->setTabText( m_pTabBank->indexOf( pTab), QString( "Bank %1" ).arg( i ) );
65
m_pFrmBank[i] = new QFrame( pTab );
66
m_pFrmBank[i]->setGeometry( QRect( 5, 10, 591, 194) );
67
m_pFrmBank[i]->setFrameShape( QFrame::StyledPanel );
68
m_pFrmBank[i]->setFrameShadow( QFrame::Raised );
70
m_pLblBank[i] = new CLabelBtn( m_pFrmBank[i], 32*18, 8*18 );
71
m_pLblBank[i]->setGeometry( 0, 0, m_pFrmBank[i]->width(), m_pFrmBank[i]->height() );
73
m_pLblBank[i]->show();
76
connect( m_pTabBank, SIGNAL( currentChanged( int ) ), this, SLOT( OnBankChanged( int ) ) );
77
connect( m_pLblBank[0], SIGNAL( onClickedLeft( int, int ) ), this, SLOT( OnBank0Click( int, int ) ) );
78
connect( m_pLblBank[1], SIGNAL( onClickedLeft( int, int ) ), this, SLOT( OnBank1Click( int, int ) ) );
79
connect( m_pLblBank[2], SIGNAL( onClickedLeft( int, int ) ), this, SLOT( OnBank2Click( int, int ) ) );
81
m_pLblBank[0]->setMouseTracking( true );
82
m_pLblBank[1]->setMouseTracking( true );
83
m_pLblBank[2]->setMouseTracking( true );
85
connect( m_pLblBank[0], SIGNAL( onReleasedLeft( int, int ) ), this, SLOT( OnBankReleaseLeft( int, int ) ) );
86
connect( m_pLblBank[1], SIGNAL( onReleasedLeft( int, int ) ), this, SLOT( OnBankReleaseLeft( int, int ) ) );
87
connect( m_pLblBank[2], SIGNAL( onReleasedLeft( int, int ) ), this, SLOT( OnBankReleaseLeft( int, int ) ) );
89
connect( m_pLblBank[0], SIGNAL( onDoubleClickedLeft( int, int ) ), this, SLOT( OnBank0DoubleClick( int, int ) ) );
90
connect( m_pLblBank[1], SIGNAL( onDoubleClickedLeft( int, int ) ), this, SLOT( OnBank1DoubleClick( int, int ) ) );
91
connect( m_pLblBank[2], SIGNAL( onDoubleClickedLeft( int, int ) ), this, SLOT( OnBank2DoubleClick( int, int ) ) );
93
connect( m_pGrOneBank, SIGNAL( clicked() ), this, SLOT( OnOneBank() ) );
95
m_pLblPalette = new CLabelBtn( m_pFrmPalette, 40, 96 );
96
m_pLblPalette->setGeometry( 0, 0, m_pFrmPalette->width(), m_pFrmPalette->height() );
98
connect( m_pLblPalette, SIGNAL( onClickedLeft( int, int ) ), this, SLOT( OnPaletteClick( int, int ) ) );
100
m_pLblPalBack = new CLabelBtn( m_pFrmDesigner, 16, 10 );
101
m_pLblPalBack->setGeometry( m_pLblPalBackC->x(), m_pLblPalBackC->y() + 25, 16, 10 );
103
m_pLblPalFore = new CLabelBtn( m_pFrmDesigner, 16, 10 );
104
m_pLblPalFore->setGeometry( m_pLblPalForeC->x(), m_pLblPalForeC->y() + 25, 16, 10 );
106
connect( m_pLblPalBack, SIGNAL( onClickedLeft( int, int ) ), this, SLOT( OnPalBackClick( int, int ) ) );
107
connect( m_pLblPalFore, SIGNAL( onClickedLeft( int, int ) ), this, SLOT( OnPalForeClick( int, int ) ) );
109
m_pLblTile = new CLabelBtn( m_pFrmTile, 96, 96 );
110
m_pLblTile->setGeometry( 2, 2, m_pFrmTile->width(), m_pFrmTile->height() );
112
connect( m_pLblTile, SIGNAL( onClickedLeft( int, int ) ), this, SLOT( OnTileClickLeft( int, int ) ) );
113
connect( m_pLblTile, SIGNAL( onClickedRight( int, int ) ), this, SLOT( OnTileClickRight( int, int ) ) );
115
m_pLblColors = new CLabelBtn( m_pFrmColors, 96, 12 );
116
m_pLblColors->setGeometry( 3, 3, 12*16, 16 );
118
image = QImage( m_pLblColors->width(), m_pLblColors->height(), QImage::Format_RGB32 );
120
for( x = 0; x < 16; x++ ) CSupportFuncs::SetPixelRect( &image, x*12, 0, CSupportFuncs::COLORS_TABLE[x], 12, 16 );
122
m_pLblColors->put_Image( image );
124
connect( m_pLblColors, SIGNAL( onClickedLeft( int, int ) ), this, SLOT( OnColorsClick( int, int ) ) );
126
connect( m_pBtnFromBank, SIGNAL( clicked() ), this, SLOT( OnFromBank() ) );
127
connect( m_pBtnToBank, SIGNAL( clicked() ), this, SLOT( OnToBank() ) );
129
connect( m_pRadBack, SIGNAL( clicked() ), this, SLOT( OnRadBack() ) );
130
connect( m_pRadFore, SIGNAL( clicked() ), this, SLOT( OnRadFore() ) );
132
m_SelColor = QPoint( 1, 0 );
134
for( x = 0; x < 256*3; x++ ) m_Screen[x] = 0;
135
for( y = 0; y < 3; y++ ) for( x = 0; x < 256; x++ ) m_TilesBank[x][y] = CTile();
137
m_pRadFore->setChecked( true );
139
connect( m_pGrTileClear, SIGNAL( clicked() ), this, SLOT( OnTileClear() ) );
140
connect( m_pGrTileReorder, SIGNAL( clicked() ), this, SLOT( OnTileReorder() ) );
141
connect( m_pGrTileShiftDown, SIGNAL( clicked() ), this, SLOT( OnTileShiftDown() ) );
142
connect( m_pGrTileShiftUp, SIGNAL( clicked() ), this, SLOT( OnTileShiftUp() ) );
143
connect( m_pGrTileShiftLeft, SIGNAL( clicked() ), this, SLOT( OnTileShiftLeft() ) );
144
connect( m_pGrTileShiftRight, SIGNAL( clicked() ), this, SLOT( OnTileShiftRight() ) );
145
connect( m_pGrTileFlipHorizontal, SIGNAL( clicked() ), this, SLOT( OnTileFlipHorizontal() ) );
146
connect( m_pGrTileFlipVertical, SIGNAL( clicked() ), this, SLOT( OnTileFlipVertical() ) );
147
connect( m_pGrTileInvertColors, SIGNAL( clicked() ), this, SLOT( OnTileInvertColors() ) );
148
connect( m_pGrTileRotate, SIGNAL( clicked() ), this, SLOT( OnTileRotate() ) );
150
setMouseTracking( true );
152
for( x = 0; x < 32; x++ )
154
m_pColsLabels[x] = new QLabel( QString( "%1" ).arg( x ), this );
155
m_pColsLabels[x]->setGeometry( 16*x+26, 5, 16, 16 );
156
m_pColsLabels[x]->setAlignment( Qt::AlignCenter );
157
m_pColsLabels[x]->setFrameShape(QFrame::Box);
158
m_pColsLabels[x]->setFrameShadow(QFrame::Raised);
161
for( x = 0; x < 24; x++ )
163
m_pRowsLabels[x] = new QLabel( QString( "%1" ).arg( x%8 ), this );
164
m_pRowsLabels[x]->setGeometry( 6, 16*x+26, 16, 16 );
165
m_pRowsLabels[x]->setAlignment( Qt::AlignCenter );
166
m_pRowsLabels[x]->setFrameShape(QFrame::Box);
167
m_pRowsLabels[x]->setFrameShadow(QFrame::Raised);
170
m_LastGridValue = QPoint( 0, 0 );
173
m_CursorImage = QImage( 16, 16, QImage::Format_RGB32 ); //TODO - 1 No membre
174
CSupportFuncs::SetPixelRect( &m_CursorImage, 0, 0, CSupportFuncs::COLORS_TABLE[15], 16, 16 );
175
m_pLblCursor[0] = new CLabelBtn( m_pFrmScreen, 15, 1 );
176
m_pLblCursor[0]->setGeometry( 0, 0, 0, 0 );
177
m_pLblCursor[0]->put_Image( m_CursorImage );
179
m_pLblCursor[1] = new CLabelBtn( m_pFrmScreen, 1, 15 );
180
m_pLblCursor[1]->setGeometry( 0, 0, 0, 0 );
181
m_pLblCursor[1]->put_Image( m_CursorImage );
183
m_pLblCursor[2] = new CLabelBtn( m_pFrmScreen, 15, 11 );
184
m_pLblCursor[2]->setGeometry( 0, 0, 0, 0 );
185
m_pLblCursor[2]->put_Image( m_CursorImage );
187
m_pLblCursor[3] = new CLabelBtn( m_pFrmScreen, 1, 15 );
188
m_pLblCursor[3]->setGeometry( 0, 0, 0, 0 );
189
m_pLblCursor[3]->put_Image( m_CursorImage );
191
for( i = 0; i < 256; i++ )
193
m_pGrBackgroundTiles0->addItem( QString( "%1" ).arg( i ) );
194
m_pGrBackgroundTiles1->addItem( QString( "%1" ).arg( i ) );
195
m_pGrBackgroundTiles2->addItem( QString( "%1" ).arg( i ) );
199
m_pLblBankTile = new CLabelBtn( this, 16, 16 );
200
m_pLblBankTile->setGeometry( 0, 0, 16, 16 );
201
m_pLblBankTile->setPixmap( QPixmap( 16, 16 ) );
202
// m_pLblBankTile->setMouseTracking( true );
203
m_pLblBankTile->setVisible( false );
204
//m_pLblBankTile->show();
207
connect( m_pLblBankTile, SIGNAL( onMouseMoveEvent( int, int ) ), this, SLOT( OnBankTileMouseMoveEvent( int, int ) ) );
208
connect( m_pLblBankTile, SIGNAL( onReleasedLeft( int, int ) ), this, SLOT( OnBankTileReleaseLeft( int, int ) ) );
209
connect( m_pLblBankTile, SIGNAL( onClickedLeft( int, int ) ), this, SLOT( OnBankTileClickLeft( int, int ) ) );
210
connect( m_pLblBankTile, SIGNAL( onDoubleClickedLeft( int, int ) ), this, SLOT( OnBankTileDoubleClickLeft( int, int ) ) );
211
m_LastBankTilePos = QPoint( -1, -1 );
216
// m_DragDrop = false;
220
m_SelectionRect = QRect( 0, 0, 0, 0 );
221
m_LastClickPos = QPoint( -1, -1 );
223
m_LastTilesBlockW = m_pGrTilesBlockW->text().toLongLong();
224
m_LastTilesBlockH = m_pGrTilesBlockH->text().toLongLong();
226
m_pFrmBackgroundTiles->setVisible( false );
231
void CScreenW::UpdateBank( int tile, int bank, bool updateScreen )
233
PaintTile( &m_BankImages[bank], m_TilesBank[tile][bank], (tile%32)*18+1, (tile/32)*18+1, 2 );
235
m_pLblBank[bank]->put_Image( m_BankImages[bank] );
237
if( updateScreen ) UpdateScreen();
240
void CScreenW::InitBanks()
245
for( j = 0; j < 3; j++ )
247
m_BankImages[j] = m_pLblBank[j]->pixmap()->toImage();
249
PaintGrid( &m_BankImages[j], 16, 16 );
251
for( i = 0; i < 256; i++ )
253
PaintTile( &m_BankImages[j], m_TilesBank[i][j], (i%32)*18+1, (i/32)*18+1, 2 );
256
m_pLblBank[j]->put_Image( m_BankImages[j] );
261
OnBank0Click( 1, 1 );
264
void CScreenW::UpdateScreen()
271
image = QImage( 32*16, 24*16, QImage::Format_RGB32 );
273
for( i = 0; i < 3; i++ )
275
for( row = 0; row < 8; row++ )
277
for( col = 0; col < 32; col++ )
279
PaintTile( &image, m_TilesBank[ m_Screen[(i*8+row)*32+col] ][ i ], col*16, (i*8+row)*16, 2 );
283
m_pLblScreen->put_Image( image );
287
void CScreenW::CopyTile()
289
if( m_ScreenSelection.size() ) m_ScreenSelectionCopy = m_ScreenSelection;
292
m_CopyTile = m_TilesBank[m_SelTile.x()][m_SelTile.y()];
293
m_ScreenSelectionCopy.clear();
297
void CScreenW::PasteTile()
305
if( m_ScreenSelectionCopy.size() )
310
if( m_ScreenSelectionCopy.size() == m_SelectionRect.height() && m_ScreenSelectionCopy.at( 0 ).size() == m_SelectionRect.width() )
312
for( i = 0; i < m_ScreenSelectionCopy.size(); i++ )
314
s = m_ScreenSelectionCopy.at( i );
316
if( ( i + y ) > 23 ) break;
318
for( j = 0, x = xI; j < s.size(); j++ )
320
if( ( j + x ) > 31 ) break;
322
m_Screen[(i+y)*32+j+x] = s.at( j );
328
for( y = m_SelectionRect.top(), j = 0; y <= m_SelectionRect.bottom(); y++, j++ )
330
if( j == m_ScreenSelectionCopy.size() ) j = 0;
332
s = m_ScreenSelectionCopy.at( j );
334
for( x = m_SelectionRect.left(), i = 0; x <= m_SelectionRect.right(); x++, i++ )
336
if( i == m_ScreenSelectionCopy.at( j ).size() ) i = 0;
338
m_Screen[y*32+x] = s.at( i );
346
if( m_ScreenSelection.size() )
348
for( y = m_SelectionRect.top(); y <= m_SelectionRect.bottom(); y++ )
350
for( x = m_SelectionRect.left(); x <= m_SelectionRect.right(); x++ )
352
m_Screen[y*32+x] = m_SelTile.x();
359
m_TilesBank[m_SelTile.x()][m_SelTile.y()] = m_CopyTile;
360
UpdateBank( m_SelTile.x(), m_SelTile.y() );
365
void CScreenW::PasteTileColors()
370
for( y = 0; y < 8; y++ )
372
m_TilesBank[m_SelTile.x()][m_SelTile.y()].SetForeColor( y, m_CopyTile.GetForeColor( y ) );
373
m_TilesBank[m_SelTile.x()][m_SelTile.y()].SetBackColor( y, m_CopyTile.GetBgColor( y ) );
375
UpdateBank( m_SelTile.x(), m_SelTile.y() );
378
void CScreenW::OnBank0DoubleClick( int x, int y )
380
OnBankDoubleClick( x, y, 0 );
383
void CScreenW::OnBank1DoubleClick( int x, int y )
385
OnBankDoubleClick( x, y, 1 );
388
void CScreenW::OnBank2DoubleClick( int x, int y )
390
OnBankDoubleClick( x, y, 2 );
393
void CScreenW::OnBankDoubleClick( int /*x*/, int /*y*/, int /*bank*/ )
395
m_pLblSelection->setGeometry( 0, 0, 0, 0 ); //TODO - 1 Class CSelection
396
m_ScreenSelection.clear();
402
void CScreenW::OnBankTileDoubleClickLeft( int x, int y )
407
void CScreenW::OnBankTileClickLeft( int x, int y )
413
// mX = m_pLblBankTile->x() - m_pTabBank->x() - m_pFrmBank[0]->x() - 4;
414
// mY = m_pLblBankTile->y() - m_pTabBank->y() - m_pFrmBank[0]->y() - 25;
416
qDebug()<<"CScreenW::OnBankTileClickedLEft currentTab="<<m_pTabBank->currentIndex();
418
OnBankClick( mX, mY, m_pTabBank->currentIndex() );
421
void CScreenW::OnBank0Click( int x, int y )
423
OnBankClick( x, y, 0 );
426
void CScreenW::OnBank1Click( int x, int y )
428
OnBankClick( x, y, 1 );
431
void CScreenW::OnBank2Click( int x, int y )
433
OnBankClick( x, y, 2 );
436
void CScreenW::OnBankClick( int x, int y, int bank )
438
m_pLblSelection->setGeometry( 0, 0, 0, 0 );
439
m_ScreenSelection.clear();
441
CSupportFuncs::SetBorderImage( &m_BankImages[m_SelTile.y()], (m_SelTile.x()%32)*18 + 1, (m_SelTile.x()/32)*18 + 1, 18*m_LastTilesBlockW-1, 18*m_LastTilesBlockH-1, 0xC0C0C0 );
442
m_pLblBank[m_SelTile.y()]->put_Image( m_BankImages[m_SelTile.y()] );
444
m_SelTile = QPoint( (y/18)*32+(x/18), bank );
445
CSupportFuncs::SetBorderImage( &m_BankImages[bank], (m_SelTile.x()%32)*18 + 1, (m_SelTile.x()/32)*18 + 1, 18*m_pGrTilesBlockW->text().toLongLong()-1, 18*m_pGrTilesBlockH->text().toLongLong()-1, 0xffff00 );
447
m_LastTilesBlockW = m_pGrTilesBlockW->text().toLongLong();
448
m_LastTilesBlockH = m_pGrTilesBlockH->text().toLongLong();
450
m_pLblBank[bank]->put_Image( m_BankImages[bank] );//TODO - 1 Serveix?
452
m_pLblShowTile->setText( QString( "%1" ).arg( m_SelTile.x() ) );
455
void CScreenW::OnPaletteClick( int x, int y )
457
m_SelColor = QPoint( x/(int)20, y/(int)12 );
459
if( m_SelColor.x() == 0 ) m_pRadBack->click();
460
else m_pRadFore->click();
463
void CScreenW::OnPalBackClick( int, int )
465
m_SelColor = QPoint( 0, PAL_ALL );
469
void CScreenW::OnPalForeClick( int, int )
471
m_SelColor = QPoint( 1, PAL_ALL );
476
void CScreenW::OnColorsClick( int x, int /*y*/ )
484
if( m_SelColor.x() == 0 )
486
if( m_SelColor.y() != PAL_ALL ) m_TileDesign.SetBackColor( m_SelColor.y(), c );
487
else for( i = 0; i < 8; i++ ) m_TileDesign.SetBackColor( i, c );
491
if( m_SelColor.y() != PAL_ALL ) m_TileDesign.SetForeColor( m_SelColor.y(), c );
492
else for( i = 0; i < 8; i++ ) m_TileDesign.SetForeColor( i, c );
498
void CScreenW::OnTileClickLeft( int x, int y )
503
if( m_pRadBack->isChecked() )
505
m_TileDesign.SetBackPixel( x, y );
506
m_SelColor = QPoint( 0, y );
510
m_TileDesign.SetForePixel( x, y );
511
m_SelColor = QPoint( 1, y );
517
void CScreenW::OnTileClickRight( int x, int y )
522
if( !m_pRadBack->isChecked() ) m_TileDesign.SetBackPixel( x, y );
523
else m_TileDesign.SetForePixel( x, y );
528
void CScreenW::OnFromBank()
530
CopyToTileDesign( m_SelTile.x(), m_SelTile.y() );
532
//TODO - 1 class CUndo
533
void CScreenW::Undo()
535
if( m_Undo.size() == 0 ) return;
537
if( m_Undo.at( 0 ) == "TOBANK" )
539
if( m_Undo.at( 1 ) == "ALLBANKS" )
541
m_TilesBank[ m_Undo.at( 2 ).toLongLong() ] [ 0 ] = m_UndoTile;
542
m_TilesBank[ m_Undo.at( 2 ).toLongLong() ] [ 1 ] = m_UndoTile;
543
m_TilesBank[ m_Undo.at( 2 ).toLongLong() ] [ 2 ] = m_UndoTile;
544
UpdateBank( m_Undo.at( 2 ).toLongLong(), 0 );
546
else if( m_Undo.at( 1 ) == "ONEBANK" )
548
m_TilesBank[ m_Undo.at( 2 ).toLongLong() ] [ m_Undo.at( 3 ).toLongLong() ] = m_UndoTile;
549
UpdateBank( m_Undo.at( 2 ).toLongLong(), m_Undo.at( 3 ).toLongLong() );
551
else Q_ASSERT( false );
555
else if( m_Undo.at( 0 ) == "SCREENCLICK" )
557
m_Screen[ m_Undo.at( 2 ).toLongLong() *32 + m_Undo.at( 1 ).toLongLong() ] = m_Undo.at( 3 ).toLongLong();
569
void CScreenW::OnToBank()
571
if( m_pGrOneBank->isChecked() )
574
m_Undo<<"TOBANK"<<"ALLBANKS"<<m_SelTile.x();
575
m_UndoTile = m_TilesBank[ m_SelTile.x() ] [0 ];
577
m_TilesBank[ m_SelTile.x() ][ 0 ] = m_TileDesign;
578
m_TilesBank[ m_SelTile.x() ][ 1 ] = m_TileDesign;
579
m_TilesBank[ m_SelTile.x() ][ 2 ] = m_TileDesign;
580
UpdateBank( m_SelTile.x(), 0 );
585
m_Undo<<"TOBANK"<<"ONEBANK"<<m_SelTile.x()<<m_SelTile.y();
586
m_UndoTile = m_TilesBank[ m_SelTile.x() ] [ m_SelTile.y() ];
588
m_TilesBank[ m_SelTile.x() ][ m_SelTile.y() ] = m_TileDesign;
589
UpdateBank( m_SelTile.x(), m_SelTile.y() );
593
void CScreenW::OnScreenReleaseRight( int x, int y )
595
m_pLblSelection->setGeometry( 0, 0, 0, 0 );
596
m_ScreenSelection.clear();
602
m_Undo<<"SCREENCLICK"<<x<<y<<m_Screen[y*32+x];
604
m_Screen[y*32 + x] = GetBackgroundTile( y/8 );
608
//TODO - 1 Deshabilitat. Per mes endavant.
609
int CScreenW::GetBackgroundTile( int y )
611
if( m_pGrOneBank->isChecked() ) return m_pGrBackgroundTiles0->currentText().toLongLong();
615
case 0: return m_pGrBackgroundTiles0->currentText().toLongLong();
616
case 1: return m_pGrBackgroundTiles1->currentText().toLongLong();
617
case 2: return m_pGrBackgroundTiles2->currentText().toLongLong();
618
default: Q_ASSERT( false ); return 0;
622
void CScreenW::OnScreenClickLeft( int x, int y )
624
m_ScreenSelection.clear();
628
m_pLblCursor[0]->setVisible( false );
629
m_pLblCursor[1]->setVisible( false );
630
m_pLblCursor[2]->setVisible( false );
631
m_pLblCursor[3]->setVisible( false );
633
m_LastClickPos = QPoint( x, y );
636
void CScreenW::OnScreenReleaseLeft( int x, int y )
646
m_ScreenSelection.clear();
647
//TODO - 1 xI<xE yI < yE
648
if( m_LastClickPos.x() >= 0 && ( abs( m_LastClickPos.x() - x ) >= 8 || abs( m_LastClickPos.y() - y ) >= 8 ) )
650
xI = m_LastClickPos.x() / 16 * 16;
651
yI = m_LastClickPos.y() / 16 * 16;
652
xE = ( x / 16 * 16 );
653
yE = ( y / 16 * 16 );
668
m_pLblSelection->setGeometry( xI + 3, yI + 2, abs( xI - xE ), abs( yI - yE ) );
669
m_pLblSelection->show();
676
m_SelectionRect = QRect( xI, yI, xE - xI, yE - yI );
678
for( i = yI; i < yE; i++ )
682
for( j = xI; j < xE; j++ )
687
m_ScreenSelection<<r;
693
m_pLblSelection->setVisible( false );
698
if( ( y / 8 ) != m_SelTile.y() && !m_pGrOneBank->isChecked() ) return;
701
m_Undo<<"SCREENCLICK"<<x<<y<<m_Screen[y*32+x];
703
for( i = 0; i < m_pGrTilesBlockH->text().toLongLong(); i++ )
705
for( j = 0; j < m_pGrTilesBlockW->text().toLongLong(); j++ )
707
if( ( m_SelTile.x() + (i*32) + j ) < 256 ) m_Screen[(y+i)*32+x+j] = m_SelTile.x()+(i*32)+j;
708
else Q_ASSERT( false );
715
void CScreenW::OnBankChanged( int index )
717
OnBankClick( ( m_SelTile.x() % 32 )*18, ( m_SelTile.x() / 32 )*18, index );
720
void CScreenW::CopyToTileDesign( int index, int bank )
722
m_TileDesign = m_TilesBank[index][bank];
726
void CScreenW::SetTileDesign()
732
image = QImage( 96, 96, QImage::Format_RGB32 );
734
PaintTile( &image, m_TileDesign, 0, 0, 12 );
736
m_pLblTile->put_Image( image );
738
image = QImage( 42, 98, QImage::Format_RGB32 );
740
for( y = 0; y < 8; y++ )
742
CSupportFuncs::SetPixelRect( &image, 0, y*12, CSupportFuncs::COLORS_TABLE[m_TileDesign.GetBgColor( y )], 20, 12 );
743
CSupportFuncs::SetPixelRect( &image, 20, y*12, CSupportFuncs::COLORS_TABLE[m_TileDesign.GetForeColor( y )], 20, 12 );
745
CSupportFuncs::SetBorderImage( &image, 0, y*12, 20, 12, 0xC0C0C0 );
746
CSupportFuncs::SetBorderImage( &image, 20, y*12, 20, 12, 0xC0C0C0 );
748
m_pLblPalette->put_Image( image );
752
void CScreenW::PaintTile( QImage *pImage, CTile &tile, int posX, int posY, int dotSize )
757
for( y = 0; y < 8; y++ )
759
for( x = 0; x < 8; x++ )
761
CSupportFuncs::SetPixelRect( pImage, posX + x*dotSize, posY + y*dotSize, CSupportFuncs::COLORS_TABLE[tile.GetPixelColor( x, y )], dotSize, dotSize );
766
void CScreenW::PaintGrid( QImage *pImage, int gridWidth, int gridHeight )
771
for( i = 1; i < pImage->height(); i+= ( gridHeight+ 2 ) )
773
for( j = 0; j < pImage->width(); j++ )
775
pImage->setPixel( j, i-1, 0xC0C0C0 );
776
pImage->setPixel( j, i+gridHeight, 0xC0C0C0 );
780
for( i = 1; i < pImage->width(); i+= ( gridWidth + 2 ) )
782
for( j = 0; j < pImage->height(); j++ )
784
pImage->setPixel( i-1, j, 0xC0C0C0 );
785
pImage->setPixel( i+gridWidth, j, 0xC0C0C0 );
792
void CScreenW::OnRadBack()
794
m_SelColor = QPoint( 0, m_SelColor.y() );
797
void CScreenW::OnRadFore()
799
m_SelColor = QPoint( 1, m_SelColor.y() );
802
void CScreenW::OnTileClear()
804
m_TileDesign.Reset();
808
void CScreenW::OnTileReorder()
810
m_TileDesign.Reorder();
814
void CScreenW::OnTileRotate()
816
m_TileDesign.Rotate();
820
void CScreenW::OnTileInvertColors()
824
for( i = 0; i < 8; i++ ) m_TileDesign.InvertRow( i );
828
void CScreenW::OnTileShiftDown()
830
m_TileDesign.ShiftDown();
834
void CScreenW::OnTileShiftUp()
836
m_TileDesign.ShiftUp();
840
void CScreenW::OnTileShiftLeft()
842
m_TileDesign.ShiftLeft();
846
void CScreenW::OnTileShiftRight()
848
m_TileDesign.ShiftRight();
852
void CScreenW::OnTileFlipHorizontal()
854
m_TileDesign.FlipHorizontal();
858
void CScreenW::OnTileFlipVertical()
860
m_TileDesign.FlipVertical();
864
void CScreenW::OnBankReleaseLeft( int, int )
869
void CScreenW::OnBankTileMouseMoveEvent( int x, int y )
877
difX = m_LastBankTilePos.x() - x;
878
difY = m_LastBankTilePos.y() - y;
880
m_pLblBankTile->setGeometry( m_pLblBankTile->x() - difX, m_pLblBankTile->y() - difY, m_pLblBankTile->width(), m_pLblBankTile->height() );
882
m_LastBankTilePos = QPoint( x + difX, y + difY );
884
OnScreenMouseMoveEvent( m_pLblBankTile->x() - m_pFrmScreen->x(), m_pLblBankTile->y() - m_pFrmScreen->y() );
888
void CScreenW::OnBank0MouseMoveEvent( int x, int y )
890
OnBankMouseMoveEvent( x, y, 0 );
893
void CScreenW::OnBank1MouseMoveEvent( int x, int y )
895
OnBankMouseMoveEvent( x, y, 1 );
898
void CScreenW::OnBank2MouseMoveEvent( int x, int y )
900
OnBankMouseMoveEvent( x, y, 2 );
903
void CScreenW::OnBankMouseMoveEvent( int x, int y, int bank )
909
bX = mX = ( x / 18 ) * 18;
910
mX += ( m_pTabBank->x() + m_pFrmBank[bank]->x() + 4 ); //4 Bordes
912
bY = mY = ( y / 18 ) * 18;
913
mY += ( m_pTabBank->y() + m_pFrmBank[bank]->y() + 25 ); //25 Pestanyes
915
m_pLblBankTile->setGeometry( mX, mY, 17, 17 );
917
m_pLblBankTile->put_Image( m_BankImages[bank].copy( bX, bY, 17, 17 ) );
918
m_pLblBankTile->setVisible( true );
921
void CScreenW::OnScreenMouseMoveEvent( int x, int y )
926
if( x < 0 || y < 0 ) return;
934
if( x > 31 || y >23 ) return;
936
if( m_LastGridValue.x() != x || m_LastGridValue.y() != y )
938
pal = m_pColsLabels[m_LastGridValue.x()]->palette();
939
pal.setColor( QPalette::Dark, Qt::gray );
940
m_pColsLabels[m_LastGridValue.x()]->setPalette( pal );
941
pal.setColor( QPalette::Dark, Qt::green );
942
m_pColsLabels[x]->setPalette( pal );
944
Q_ASSERT( m_pRowsLabels[m_LastGridValue.y()] );
945
pal = m_pRowsLabels[m_LastGridValue.y()]->palette();
946
pal.setColor( QPalette::Dark, Qt::gray );
947
m_pRowsLabels[m_LastGridValue.y()]->setPalette( pal );
948
pal.setColor( QPalette::Dark, Qt::green );
949
Q_ASSERT( m_pRowsLabels[y] );
950
m_pRowsLabels[y]->setPalette( pal );
951
m_LastGridValue = QPoint( x, y );
953
m_pLblShowTileBank->setText( QString( "%1" ).arg( m_Screen[ y*32+x] ) );
958
if( m_LastClickPos.x() > m_MouseX) ox = m_MouseX;
959
else ox = m_LastClickPos.x();
961
if( m_LastClickPos.y() > m_MouseY ) oy = m_MouseY;
962
else oy = m_LastClickPos.y();
964
m_pLblSelection->setGeometry( ox, oy, abs( m_MouseX - m_LastClickPos.x() ), abs( m_MouseY - m_LastClickPos.y() ) );
965
m_pLblSelection->setVisible( true );
969
m_pLblCursor[0]->setGeometry( x*16+1 + 3, y*16+1, 14, 1 );
970
m_pLblCursor[1]->setGeometry( x*16+20, y*16+1 + 2, 1, 16 );
971
m_pLblCursor[2]->setGeometry( x*16+1 + 3, y*16+21, 14, 1 );
972
m_pLblCursor[3]->setGeometry( x*16+1, y*16+1 + 2, 1, 16 );
974
m_pLblCursor[0]->setVisible( true );
975
m_pLblCursor[1]->setVisible( true );
976
m_pLblCursor[2]->setVisible( true );
977
m_pLblCursor[3]->setVisible( true );
981
void CScreenW::NewScreen()
985
for( i = 0; i < 32*24; i++ ) m_Screen[i] = 0;
990
bool CScreenW::LoadScreen( QString fileName )
997
hFile.setFileName( fileName );
998
hFile.open( QIODevice::ReadOnly );
999
QTextStream str( &hFile );
1007
line = str.readLine();
1009
if( line != "SCREEN" )
1015
for( i = 0; i < 32*24; i++ )
1017
line = str.readLine();
1018
m_Screen[i] = line.toInt();
1028
bool CScreenW::SaveScreen( QString fileName )
1034
hFile.setFileName( fileName );
1035
hFile.open( QIODevice::WriteOnly );
1037
QTextStream str( &hFile );
1039
str<<"SCREEN"<<endl;
1041
for( i = 0; i < 32*24; i++ ) str<<m_Screen[i]<<endl;
1049
bool CScreenW::ExportScreenBin( QString fileName, int initX, int initY, int w, int h )
1057
hFile.setFileName( fileName );
1058
hFile.open( QIODevice::WriteOnly );
1060
QDataStream str( &hFile );
1062
addX = m_pGrTilesBlockW->text().toLongLong();
1063
addY = m_pGrTilesBlockH->text().toLongLong();
1066
if( wi > 32 ) wi = 32;
1069
if( he > 24 ) he = 24;
1071
for( y = initY; y < he; )
1074
for( x = initX; x < wi; )
1076
str<<(unsigned char)m_Screen[y*32+x];
1088
bool CScreenW::ExportScreenPNG( QString fileName )
1098
image = QImage( 256, 192, QImage::Format_RGB32 );
1100
for( yT = 0, i = -1; yT < 192; yT+=8 )
1102
for( xT = 0; xT < 256; xT+=8 )
1105
tileId = m_Screen[i];
1106
for( y = 0, tile = m_TilesBank[tileId%256][i/256]; y < 8; y++ )
1108
for( x = 0; x < 8; x++ )
1110
image.setPixel( xT + x, yT + y, CSupportFuncs::COLORS_TABLE[tile.GetPixelColor(x, y)]);
1117
image.save( fileName );
1121
bool CScreenW::ExportScreenBinPletter( QString fileName, int initX, int initY, int w, int h )
1127
unsigned char buffer[256*3];
1129
addX = m_pGrTilesBlockW->text().toLongLong();
1130
addY = m_pGrTilesBlockH->text().toLongLong();
1134
if( wi > 32 ) wi = 32;
1137
if( he > 24 ) he = 24;
1139
for( y = initY; y < he; )
1141
for( x = initX; x < wi; )
1143
buffer[s] = (unsigned char)m_Screen[y*32+x];
1150
PletterMain( s, buffer, fileName.toStdString() );
1152
return true; //TODO - 2
1155
bool CScreenW::ExportScreenData( QString fileName, bool hexa, int initX, int initY, int w, int h )
1164
hFile.setFileName( fileName );
1165
hFile.open( QIODevice::WriteOnly );
1167
QTextStream str( &hFile );
1169
str<<"SCREEN:"<<"\r\n"<<"db ";
1171
addX = m_pGrTilesBlockW->text().toLongLong();
1172
addY = m_pGrTilesBlockH->text().toLongLong();
1175
if( wi > 32 ) wi = 32;
1178
if( he > 24 ) he = 24;
1180
for( y = initY; y < he; )
1182
for( x = initX; x < wi; )
1184
if( hexa ) str<<QString( "0x%1" ).arg( m_Screen[y*32+x], 0, 16 ).rightJustified( 4, ' ' );
1185
else str<<QString( "%1" ).arg( m_Screen[y*32+x] ).rightJustified( 3, ' ' );
1187
if( (y*32+x+1)%32 == 0 || x == ( wi - 1 ) )
1190
if( (y*32+x+1) != 256*3 && !( y == (he-1) && x == (wi-1) )) str<<"db ";
1192
else if( !( x == (wi - 1) && y == (he - 1) ) ) str<<",";
1208
void CScreenW::NewTiles()
1212
for( b = 0; b < 3; b++ )
1214
for( i = 0; i < 256; i++ ) m_TilesBank[i][b] = CTile();
1219
bool CScreenW::LoadTiles( QString fileName )
1227
hFile.setFileName( fileName );
1228
hFile.open( QIODevice::ReadOnly );
1229
QTextStream str( &hFile );
1237
if( str.readLine() != "TILES" )
1243
for( b = 0; b < 3; b++ )
1245
line = str.readLine();
1247
if( line != QString( "BANK%1" ).arg( b ) )
1252
for( i = 0; i < 256; i++ )
1254
for( y = 0; y < 8; y++ ) m_TilesBank[i][b].put_BgColor( y, str.readLine().toInt() );
1256
for( y = 0; y < 8; y++ ) m_TilesBank[i][b].put_ForeColor( y, str.readLine().toInt() );
1258
for( y = 0; y < 8; y++ )
1260
for( x = 0; x < 8; x++ ) m_TilesBank[i][b].put_Pixel( x, y, str.readLine().toInt() );
1272
bool CScreenW::LoadTilesLibrary( QString fileName, int bankOr, int xOr, int yOr, int width, int height, int bankDest, int xDest, int yDest )
1282
hFile.setFileName( fileName );
1283
hFile.open( QIODevice::ReadOnly );
1284
QTextStream str( &hFile );
1286
//TODO - 1 Indicar error
1293
if( str.readLine() != "TILES" )
1299
for( b = 0; b < 3; b++ )
1301
line = str.readLine();
1303
if( line != QString( "BANK%1" ).arg( b ) )
1309
for( i = 0; i < 256; i++ )
1314
dX = vX - xOr + xDest;
1315
dY = vY - yOr + yDest;
1317
if( vX >= xOr && vX < ( xOr + width ) && vY >= yOr && vY < ( yOr + height ) && bankOr == b && dX >= 0 && dX < 32 && dY >=0 && dY < 8 )
1319
qDebug()<<"CScreenW::LoadTilesLibrary dX="<<dX<<" dY="<<dY;
1320
for( y = 0; y < 8; y++ ) m_TilesBank[dY*32+dX][bankDest].put_BgColor( y, str.readLine().toInt() );
1322
for( y = 0; y < 8; y++ ) m_TilesBank[dY*32+dX][bankDest].put_ForeColor( y, str.readLine().toInt() );
1324
for( y = 0; y < 8; y++ )
1326
for( x = 0; x < 8; x++ ) m_TilesBank[dY*32+dX][bankDest].put_Pixel( x, y, str.readLine().toInt() );
1331
for( y = 0; y < 8*2; y++ ) str.readLine();
1332
for( y = 0; y < 8*8; y++ ) str.readLine();
1345
bool CScreenW::SaveTiles( QString fileName )
1352
hFile.setFileName( fileName );
1353
hFile.open( QIODevice::WriteOnly );
1355
QTextStream str( &hFile );
1359
for( b = 0; b < 3; b++ )
1361
str<<"BANK"<<b<<endl;
1363
for( i = 0; i < 256; i++ )
1365
for( x = 0; x < 8; x++ ) str<<m_TilesBank[i][b].get_BgColor(x)<<endl;
1366
for( x = 0; x < 8; x++ ) str<<m_TilesBank[i][b].get_ForeColor(x)<<endl;
1367
for( y = 0; y < 8; y++ )
1369
for( x = 0; x < 8; x++ ) str<<m_TilesBank[i][b].get_Pixel( x, y )<<endl;
1380
void CScreenW::GroupTiles()
1385
CTile groupBank[256];
1388
for( b = 0; b < 3; b++ )
1390
for( i = 0; i < 256; i++ ) groupBank[b] = CTile();
1392
for( i = 0, index = 0, blacked = false; i < 256; i++ )
1394
if( !m_TilesBank[i][b].IsBlack() || !blacked )
1396
if( m_TilesBank[i][b].IsBlack() ) blacked = true;
1398
groupBank[index] = m_TilesBank[i][b];
1400
for( j = 0; j < 256; j++ ) if( m_Screen[j+256*b] == i ) m_Screen[j+256*b] = index;
1406
for( i = 0; i < 256; i++ ) m_TilesBank[i][b] = groupBank[i];
1413
void CScreenW::ExportTilesPNG( QString fileName )
1422
if( m_pGrOneBank->isChecked() ) h = 64;
1425
image = QImage( 256, h, QImage::Format_RGB32 );
1427
for( yT = 0, i = -1; yT < h; yT+=8 )
1429
for( xT = 0; xT < 256; xT+=8 )
1432
for( y = 0, tile = m_TilesBank[i%256][i/256]; y < 8; y++ )
1434
for( x = 0; x < 8; x++ )
1436
image.setPixel( xT + x, yT + y, CSupportFuncs::COLORS_TABLE[tile.GetPixelColor(x, y)]);
1443
image.save( fileName );
1447
bool CScreenW::ExportTilesBin( QString fileName )
1453
CDlgBankRange dlgBankRange;
1456
dlgBankRange.exec();
1458
if( dlgBankRange.result() == 0 ) //TODO - 1 MsgBox
1463
hFile.setFileName( fileName + QString( ".til" ) );
1464
hFile.open( QIODevice::WriteOnly );
1466
if( m_pGrOneBank->isChecked() ) nLoops = 1;
1469
QDataStream str( &hFile );
1471
for( b = 0; b < nLoops; b++ )
1473
for( j = dlgBankRange.get_FromTile(); j < dlgBankRange.get_ToTile() + 1; j++ )
1475
if( dlgBankRange.get_BankOption() == 0 || dlgBankRange.get_BankOption() == (b + 1) )
1477
for( i = 0; i < 8; i++ )
1480
str<<(unsigned char)m_TilesBank[j][b].GetRowPattern( i );
1489
hFile.setFileName( fileName + QString( ".col" ) );
1490
hFile.open( QIODevice::WriteOnly );
1492
QDataStream strCol( &hFile );
1494
for( b = 0; b < nLoops; b++ )
1496
for( j = dlgBankRange.get_FromTile(); j < dlgBankRange.get_ToTile() + 1; j++ )
1498
if( dlgBankRange.get_BankOption() == 0 || dlgBankRange.get_BankOption() == (b + 1) )
1500
for( i = 0; i < 8; i++ )
1502
strCol<<(unsigned char)m_TilesBank[j][b].GetRowColor( i );
1514
void CScreenW::ExportTilesBinPletter( QString fileName )
1519
unsigned char buffer[256*3*8];
1520
CDlgBankRange dlgBankRange;
1523
dlgBankRange.exec();
1525
if( dlgBankRange.result() == 0 ) //TODO - 1 MsgBox
1530
if( m_pGrOneBank->isChecked() ) nLoops = 1;
1534
for( b = 0, sz = 0; b < nLoops; b++ )
1536
for( j = dlgBankRange.get_FromTile(); j < dlgBankRange.get_ToTile() + 1; j++ )
1538
if( dlgBankRange.get_BankOption() == 0 || dlgBankRange.get_BankOption() == (b + 1) )
1540
//for( i = 0; i < 8; i++ ) buffer[b*256*8+j*8+i] = m_TilesBank[j][b].GetRowPattern( i );
1541
for( i = 0; i < 8; i++, sz++ ) buffer[sz] = m_TilesBank[j][b].GetRowPattern( i );
1546
PletterMain( sz/*b*256*8*/, buffer, QString( fileName + QString( ".til" ) ).toStdString() );
1548
for( b = 0, sz = 0; b < nLoops; b++ )
1550
for( j = dlgBankRange.get_FromTile(); j < dlgBankRange.get_ToTile() + 1; j++ )
1552
if( dlgBankRange.get_BankOption() == 0 || dlgBankRange.get_BankOption() == (b + 1) )
1554
for( i = 0; i < 8; i++, sz++ ) buffer[sz] = m_TilesBank[j][b].GetRowColor( i );
1559
PletterMain( sz/*b*256*8*/, buffer, QString( fileName + QString( ".col" ) ).toStdString() );
1562
bool CScreenW::ExportTilesData( QString fileName, bool hexa )
1569
hFile.setFileName( fileName );
1570
hFile.open( QIODevice::WriteOnly );
1572
QTextStream str( &hFile );
1574
for( b = 0; b < 3; b++ )
1576
str<<QString( "BANK_PATTERN_%1:").arg( b )<<endl;
1578
for( j = 0; j < 256; j++ )
1582
for( i = 0; i < 8; i++ )
1584
if( hexa ) str<<QString( "0x%1" ).arg( m_TilesBank[j][b].GetRowPattern( i ), 0, 16 );
1585
else str<<m_TilesBank[j][b].GetRowPattern( i );
1587
if( i != 7 ) str<<", ";
1595
for( b = 0; b < 3; b++ )
1597
str<<QString( "BANK_COLOR_%1:").arg( b )<<endl;
1599
for( j = 0; j < 256; j++ )
1602
for( i = 0; i < 8; i++ )
1604
if( hexa ) str<<QString( "0x%1" ).arg( m_TilesBank[j][b].GetRowColor( i ), 0, 16 );
1605
else str<<m_TilesBank[j][b].GetRowColor( i );
1607
if( i != 7 ) str<<", ";
1619
bool CScreenW::DeduceColorPalette( unsigned int color, unsigned int palette[16] ) {
1622
unsigned int paltmp[3];
1625
if( color >= 9000000 && color <= 17000000 ) { //RED 6, 8, 9
1627
paltmp[0] = palette[6];
1628
paltmp[1] = palette[8];
1629
paltmp[2] = palette[9];
1631
for( i = 2; i >=0; i-- ) {
1632
if( color == paltmp[i] ) break;
1634
if( color > paltmp[i] ) {
1642
palette[6] = paltmp[0];
1643
palette[8] = paltmp[1];
1644
palette[9] = paltmp[2];
1647
return true; //TODO - -1 treure true
1651
bool CScreenW::ImportTilesPNGAdv( QString fileName ) {
1655
unsigned int rawColor;
1657
unsigned int palette[16];
1659
//Llegir fitxer i muntar paleta
1660
if( !image.load( fileName ) ) return false;
1661
for( i = 0; i < 16; i++ ) palette[i] = 0;
1663
for( y = 0; y < image.height(); y++ ) {
1665
for( x = 0; x < image.width(); x++) {
1666
color = image.pixel( x, y );
1667
if( color > 0xff000000 ) color -= 0xff000000; //Treu transparencia si hi ha
1669
DeduceColorPalette( color, palette );
1674
if( !image.load( fileName ) ) return false;
1676
if( image.width() < 256 || image.height() < 64 ) return false;
1678
for( b = 0; b < 3; b++ )
1680
if( b > 0 && image.height() <= 64 ) break;
1682
for( y = 0; y < 8*8; y++ )
1684
for( x = 0; x < 32; x++ )
1688
for( i = 0; i < 8; i++ )
1690
rawColor = image.pixel( x*8+i, y+b*64 );
1691
if( rawColor > 0xff000000 ) rawColor -= 0xff000000; //Treu transparencia si hi ha
1693
color = GetColor( rawColor, palette );
1698
m_TilesBank[(y/8)*32+x][b].put_ForeColor( y%8, fore );
1699
m_TilesBank[(y/8)*32+x][b].put_Pixel( i, y%8, 1 );
1701
else if( fore == color )
1703
m_TilesBank[(y/8)*32+x][b].put_Pixel( i, y%8, 1 );
1705
else if( back == -1 )
1708
m_TilesBank[(y/8)*32+x][b].put_BgColor( y%8, back );
1709
m_TilesBank[(y/8)*32+x][b].put_Pixel( i, y%8, 0 );
1711
else if( back == color )
1713
m_TilesBank[(y/8)*32+x][b].put_Pixel( i, y%8, 0 );
1715
else //Three colors on a row!
1717
m_TilesBank[(y/8)*32+x][b].put_ForeColor( y%8, fore );
1729
bool CScreenW::ImportTiles( QString fileName, QString paletteFileName )
1736
unsigned int palette[16];
1739
if( paletteFileName == "" ) //Palette used by nMSXtiles
1741
for( i = 0; i < 16; i++ ) palette[i] = CSupportFuncs::COLORS_TABLE[i];
1745
if( !image.load( paletteFileName ) ) return false;
1747
if( image.width() < 16 ) return false;
1749
for( i = 0; i < 16; i++ ) palette[i] = (unsigned int )image.pixel( i, 0 );
1752
if( !image.load( fileName ) ) return false;
1754
if( image.width() < 256 || image.height() < 64 ) return false;
1756
for( b = 0; b < 3; b++ )
1758
if( b > 0 && image.height() <= 64 ) break;
1760
for( y = 0; y < 8*8; y++ )
1762
for( x = 0; x < 32; x++ )
1766
for( i = 0; i < 8; i++ )
1768
color = GetColor( image.pixel( x*8+i, y+b*64 ), palette );
1773
m_TilesBank[(y/8)*32+x][b].put_ForeColor( y%8, fore );
1774
m_TilesBank[(y/8)*32+x][b].put_Pixel( i, y%8, 1 );
1776
else if( fore == color )
1778
m_TilesBank[(y/8)*32+x][b].put_Pixel( i, y%8, 1 );
1780
else if( back == -1 )
1783
m_TilesBank[(y/8)*32+x][b].put_BgColor( y%8, back );
1784
m_TilesBank[(y/8)*32+x][b].put_Pixel( i, y%8, 0 );
1786
else if( back == color )
1788
m_TilesBank[(y/8)*32+x][b].put_Pixel( i, y%8, 0 );
1790
else //Three colors on a row!
1792
m_TilesBank[(y/8)*32+x][b].put_ForeColor( y%8, fore );
1804
bool CScreenW::ImportPolkaTiles( QString fileName )
1812
unsigned char buffer[256*8];
1813
ifstream myFile( qPrintable( fileName ), ios::in | ios::binary );
1818
myFile.read ((char*)buffer, 7);
1819
if (!myFile) return false;
1821
myFile.read( (char*)buffer, 2048 );
1823
for( i = 0; i < 256; i++ )
1825
for( y = 0; y < 8; y++ )
1827
for( x = 0; x < 8; x++ )
1829
value = ( buffer[ i*8 + y ] >> x ) & 0x1;
1830
m_TilesBank[i][0].put_Pixel( x, y, value );
1835
myFile.read( (char*)buffer, 2048 );
1837
for( i = 0; i < 256; i++ )
1839
for( y = 0; y < 8; y++ )
1841
m_TilesBank[i][0].put_BgColor( y, ( buffer[i*8 + y] >> 4 ) & 0xF );
1842
m_TilesBank[i][0].put_ForeColor( y, ( buffer[i*8 + y] ) & 0xF );
1846
for( b = 0; b < 3; b++ ) for( i = 0; i < 32*8; i++ ) m_Screen[i+b*32*8]=i;
1853
bool CScreenW::ExportPolkaTiles( QString fileName )
1857
unsigned char buffer[256*8];
1860
if( !( pFile = fopen( qPrintable( fileName ), "wb" ) ) ) return false;
1862
sprintf( (char*)buffer, "%s", "POLKA" );
1865
fwrite( buffer, sizeof( unsigned char ), 7, pFile );
1867
for( i = 0; i < 256; i++ )
1869
for( y = 0; y < 8; y++ )
1871
buffer[ i*8 + y ] = 0;
1873
for( x = 0; x < 8; x++ )
1875
buffer[ i*8 + y ] |= ( m_TilesBank[i][0].get_Pixel( x, y )<<x );
1880
fwrite( buffer, sizeof( unsigned char ), 2048, pFile );
1882
for( i = 0; i < 256; i++ )
1884
for( y = 0; y < 8; y++ )
1886
buffer[i*8+y] = ( (m_TilesBank[i][0].get_BgColor(y )<<4 ) | (m_TilesBank[i][0].get_ForeColor(y) ) );
1890
fwrite( buffer, sizeof( unsigned char), 2048, pFile );
1892
buffer[0] = 0; //Num of Palettes
1894
fwrite( buffer, sizeof( unsigned char ), 1, pFile );
1899
//[97][1][39][6][113][1]
1901
//[100][6][17][4][101][2][85][5][119][7]
1902
buffer[ 0] = buffer[1] = buffer[2] = buffer[3] = 0;
1903
buffer[ 4] = 17; buffer[ 5] = 6;
1904
buffer[ 6] = 51; buffer[ 7] = 7;
1905
buffer[ 8] = 23; buffer[ 9] = 1;
1906
buffer[10] = 39; buffer[11] = 3;
1907
buffer[12] = 97; buffer[13] = 1;
1908
buffer[14] = 39; buffer[15] = 6;
1909
buffer[16] =113; buffer[17] = 1;
1910
buffer[18] =115; buffer[19] = 3;
1911
buffer[20] = 97; buffer[21] = 6;
1912
buffer[22] =100; buffer[23] = 6;
1913
buffer[24] = 17; buffer[25] = 4;
1914
buffer[26] =101; buffer[27] = 2;
1915
buffer[28] = 85; buffer[29] = 5;
1916
buffer[30] =119; buffer[31] = 7;
1918
fwrite( buffer, sizeof( unsigned char ), 32, pFile );
1920
for( i = 0; i < 256; i++ ) buffer[i] = 1;
1922
fwrite( buffer, sizeof( unsigned char ), 256, pFile );
1929
void CScreenW::Fill1to255()
1935
for( b = 0; b < 3; b++ ) for( i = 0; i < 32*8; i++ ) m_Screen[i+b*32*8]=i;
1939
int CScreenW::GetColor( unsigned int color, unsigned int palette[] )
1943
for( i = 0; i < 16; i++ )
1945
if( color == palette[i] ) return i;
1947
//Color not in palette
1951
void CScreenW::Close()
1957
void CScreenW::closeEvent( QCloseEvent *pEvent )
1959
if( m_Close ) pEvent->accept();
1960
else pEvent->ignore();
1963
void CScreenW::OnOneBank()
1968
m_pTabBank->setCurrentIndex( 0 );
1970
for( i = 0; i < 256; i++ )
1972
m_TilesBank[i][1] = m_TilesBank[i][0];
1973
m_TilesBank[i][2] = m_TilesBank[i][0];
1976
m_pTabBank->setTabEnabled( 1, !m_pGrOneBank->isChecked() );
1977
m_pTabBank->setTabEnabled( 2, !m_pGrOneBank->isChecked() );
1979
m_pGrBackgroundTiles1->setVisible( !m_pGrOneBank->isChecked() );
1980
m_pGrBackgroundTiles2->setVisible( !m_pGrOneBank->isChecked() );
1981
m_pGrLblBackgroundTiles1->setVisible( !m_pGrOneBank->isChecked() );
1982
m_pGrLblBackgroundTiles2->setVisible( !m_pGrOneBank->isChecked() );
1988
void CScreenW::SetOneBank( bool value )
1990
m_pGrOneBank->setChecked( value );
1991
if( value ) OnOneBank();
1994
bool CScreenW::GetOneBank()
1996
return m_pGrOneBank->isChecked();