//--------------------------------------------------------------------------- #include #pragma hdrstop #include "TextureArrange.h" #include "TPUtils.hpp" #include "Exception.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- // TTextureArrange //--------------------------------------------------------------------------- __fastcall TTextureArrange::TTextureArrange() { for(int i = 0; i < MAX_TEXTURE; i++) { Array[i].sx = 0; Array[i].number = 0; Array[i].cut = 0; } bFinish = false; page = 0; } //--------------------------------------------------------------------------- TPException __fastcall TTextureArrange::LoadFromFile(AnsiString fn) { HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwRead; int i, j, offset; TTexVersion ver; TPException ec = EC_NONE; if ((hFile = CreateFile(fn.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_OPEN; goto fail; } FileName = fn; if (!ReadFile(hFile, &ver, sizeof(TTexVersion), &dwRead, NULL)) goto fail; if (ver.Texpia == 'P') { if (ver.Method == 'T' && ver.Number >= 100) { // Windows Version if (!ReadFile(hFile, &Count, sizeof(Byte), &dwRead, NULL)) goto fail; for (i = 0; i < Count; i++) { if (!ReadFile(hFile, &Array[i].sx, sizeof(char), &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &Array[i].number, sizeof(char), &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &Array[i].cut, sizeof(WORD), &dwRead, NULL)) goto fail; for (j = 0; j < Array[i].number; j++) { if (!ReadFile(hFile, &Array[i].Data[j], sizeof(TPointElement), &dwRead, NULL)) goto fail; } } } } CloseHandle(hFile); return EC_NONE; fail: if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_READ; return ec; } //--------------------------------------------------------------------------- TPException __fastcall TTextureArrange::SaveToFile(AnsiString fn) { HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwWrite; int i, j; TTexVersion ver = { 'P', 'T', 100 }; TPException ec = EC_NONE; if ((hFile = CreateFile(fn.c_str(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_CREATE; goto fail; } if (!WriteFile(hFile, &ver, sizeof(TTexVersion), &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &Count, sizeof(Byte), &dwWrite, NULL)) goto fail; for (i = 0; i < Count; i++) { if (!WriteFile(hFile, &Array[i].sx, sizeof(char), &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &Array[i].number, sizeof(char), &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &Array[i].cut, sizeof(WORD), &dwWrite, NULL)) goto fail; for (j = 0; j < Array[i].number; j++) { if (!WriteFile(hFile, &Array[i].Data[j], sizeof(TPointElement), &dwWrite, NULL)) goto fail; } } CloseHandle(hFile); return EC_NONE; fail: if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_WRITE; return ec; } //--------------------------------------------------------------------------- void __fastcall TTextureArrange::Copy(TTextureArrange *ta) { int i, j; FileName = ta->FileName; bFinish = ta->bFinish; Count = ta->Count; for (i = 0; i < MAX_TEXTURE; i++) { Array[i].sx = ta->Array[i].sx; Array[i].number = ta->Array[i].number; Array[i].cut = ta->Array[i].cut; for (j = 0; j < NUM_POINT; j++) { Array[i].Data[j].Pass = ta->Array[i].Data[j].Pass; Array[i].Data[j].DX = ta->Array[i].Data[j].DX; Array[i].Data[j].DY = ta->Array[i].Data[j].DY; } } } //--------------------------------------------------------------------------- void __fastcall TTextureArrange::PartCopy(TTextureArrange *ta) { int i, j; Array[page].sx = ta->Array[ta->page].sx; Array[page].number = ta->Array[ta->page].number; for (j = 0; j < NUM_POINT; j++) { Array[page].Data[j].Pass = ta->Array[ta->page].Data[j].Pass; Array[page].Data[j].DX = ta->Array[ta->page].Data[j].DX; Array[page].Data[j].DY = ta->Array[ta->page].Data[j].DY; } } //--------------------------------------------------------------------------- void __fastcall TTextureArrange::Draw(TCanvas *cv, POINT sp, SIZE view, int p, int Item) { int sx, sy, ex, ey, i; sx = sp.x + 2 * (PTMAP_COL - Array[p].sx); sp.y = sp.y + view.cy - 2; sy = sp.y; for (i = 0; i < Array[p].number; i++) { ex = sx; ey = sy; sx = sp.x + 2 * (PTMAP_COL - Array[p].Data[i].DX); sy = sp.y - 2 * Array[p].Data[i].DY; if (Array[p].Data[i].Pass == PT_EXIST) { cv->Pen->Color = clBlack; cv->MoveTo(sx, sy); cv->LineTo(sx, ey); cv->MoveTo(sx+1, sy); cv->LineTo(sx+1, ey); } else { cv->Pen->Color = clRed; if (Item) { //Tricot cv->MoveTo(ex, ey); cv->LineTo(sx, sy); } else { // DNB cv->MoveTo(ex, ey); cv->LineTo(ex, sy); cv->MoveTo(ex, sy); cv->LineTo(sx, sy); } } } } //--------------------------------------------------------------------------- TPException __fastcall TTextureArrange::LoadFromFile(HANDLE fh, TTexVersion &v) { DWORD dwRead; int i, offset, fver, k; TPException ec = EC_NONE; if (v.Texpia == 'P') { if (v.Method != 'T') { if (v.Number < 303) fver = 0; //First----->Dos else fver = 1; //Second---->Dos } else { if (v.Number < 200) fver = 1; //Second---->Dos else fver = 2; //Last-->Windows } } if (!ReadFile(fh, &Count, sizeof(Byte), &dwRead, NULL)) goto fail; switch(fver) { case 0: for (i=0; i