Advertisement
xiahanlu

Untitled

May 25th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 91.88 KB | None | 0 0
  1.  
  2. # include "precompiled.h"
  3. # include <stdint.h>
  4. # include <assert.h>
  5.  
  6. // shared global struct .
  7. class cs_mainFrame;
  8. class cs_ViewStatus;
  9. class cs_ViewGlobalZoom;
  10. class cs_ViewRootTexture;
  11. class cs_ViewClaySet;
  12. class cs_ViewPixel;
  13. class cs_PageTile;
  14. class cs_ClayTile;
  15.  
  16. class shared_cs {
  17.  
  18. public:
  19.   class cs_mainFrame *cs_mainFrame_;
  20.   class cs_ViewStatus *cs_ViewStatus_;
  21.   class cs_ViewGlobalZoom *cs_ViewGlobalZoom_;
  22.   class cs_ViewRootTexture *cs_ViewRootTexture_;
  23.   class cs_ViewClaySet *cs_ViewClaySet_;
  24.   class cs_ViewPixel *cs_ViewPixel_;
  25.   class cs_PageTile *cs_PageTile_;
  26.   class cs_ClayTile *cs_ClayTile_;
  27.  
  28. public:
  29.   shared_cs () {
  30.     cs_mainFrame_ = nullptr;
  31.     cs_ViewStatus_ = nullptr;
  32.     cs_ViewGlobalZoom_ = nullptr;
  33.     cs_ViewRootTexture_ = nullptr;
  34.     cs_ViewClaySet_ = nullptr;
  35.     cs_ViewPixel_ = nullptr;
  36.     cs_PageTile_ = nullptr;
  37.     cs_ClayTile_ = nullptr;
  38.   }
  39.  ~shared_cs () {
  40.     cs_mainFrame_ = nullptr;
  41.     cs_ViewStatus_ = nullptr;
  42.     cs_ViewGlobalZoom_ = nullptr;
  43.     cs_ViewRootTexture_ = nullptr;
  44.     cs_ViewClaySet_ = nullptr;
  45.     cs_ViewPixel_ = nullptr;
  46.     cs_PageTile_ = nullptr;
  47.     cs_ClayTile_ = nullptr;
  48.   }
  49. };
  50.  
  51. namespace common {
  52.   static void fillImg (wxImage &c, char r, char g, char b) {
  53.     wxSize s = c.GetSize ();
  54.     for (int y = 0; y != s.y; y++)  {
  55.       for (int x = 0; x != s.x; x++)  {
  56.         c.SetRGB (x, y, r, g, b);
  57.       }
  58.     }
  59.   }
  60.   static void fillImg (wxImage &c, wxColour &s) {
  61.     fillImg (c, (char )s.Red(), (char )s.Green(), (char )s.Blue());
  62.   }
  63.   static void getMousePos (wxWindow *wd, wxPoint & pts)  {
  64.     wxPoint pt = wxGetMousePosition ();
  65.     pts.x = pt.x - wd->GetScreenPosition ().x;
  66.     pts.y = pt.y - wd->GetScreenPosition ().y;
  67.   }
  68.   static void getAbsRect2 (wxRect &pe, wxPoint &p1, wxPoint &p2)  {
  69.  
  70.     int pBigger = p2.x;
  71.     int pSmaller = p1.x;
  72.  
  73.     if (p1.x > p2.x) {
  74.       pBigger = p1.x;
  75.       pSmaller = p2.x;
  76.     }
  77.     pe.x = pSmaller &-8;
  78.     pe.width = ( pBigger+ 7) & -8; // XXX: stop around 8.
  79.     pe.width = pe.width - pe.x;
  80.  
  81.     pBigger = p2.y;
  82.     pSmaller = p1.y;
  83.  
  84.     if (p1.y > p2.y) {
  85.       pBigger = p1.y;
  86.       pSmaller = p2.y;
  87.     }
  88.     pe.y = pSmaller &-8;
  89.     pe.height = ( pBigger+ 7) & -8; // XXX: stop around 8.
  90.     pe.height = pe.height - pe.y;
  91.   }
  92.   static void limitBoard (wxPoint & pt) {
  93.     pt.x &= -8;
  94.     pt.y &= -8;
  95.   }
  96.   static void getRound (wxPoint & pt) {
  97.     pt.x >>= 3;
  98.     pt.y >>= 3;
  99.   }
  100.   static void getRound (wxSize & se) {
  101.     se.x >>= 3;
  102.     se.y >>= 3;
  103.   }
  104.    static void setExpand (wxPoint & pt) {
  105.     pt.x <<= 3;
  106.     pt.y <<= 3;
  107.   }
  108.     static void getMiniOffset (wxPoint & pt) {
  109.     pt.x &= 7;
  110.     pt.y &= 7;
  111.   }
  112.   static void limitBoard (wxRect & pt) {
  113.     pt.x &= -8;
  114.     pt.y &= -8;
  115.   }
  116.   static void getRound (wxRect & pt) {
  117.     pt.x >>= 3;
  118.     pt.y >>= 3;
  119.   }
  120.   static void setExpand (wxRect & pt) {
  121.     pt.x <<= 3;
  122.     pt.y <<= 3;
  123.   }
  124.   static void getMiniOffset (wxRect & pt) {
  125.     pt.x &= 7;
  126.     pt.y &= 7;
  127.   }
  128. };
  129.  
  130. struct imgSlot {
  131.   bool enable;
  132.   wxString *strPath;
  133.   wxBitmap *img;
  134.   wxImage *img2;
  135.   wxUint8 id;
  136.  
  137.   imgSlot () {
  138.     init ();
  139.   }
  140.   void init () {
  141.     enable = false;
  142.     strPath = nullptr;
  143.     img2 = nullptr;
  144.     img = nullptr;
  145.     id = 0xFF;
  146.   }
  147.   void uninit () {
  148.     if (strPath != nullptr) delete strPath;
  149.     if (img != nullptr) delete img;
  150.     if (img2 != nullptr) delete img2;
  151.     enable = false;
  152.     id = 0xFF;
  153.     strPath = nullptr;
  154.     img = nullptr;
  155.     img2 = nullptr;
  156.   }
  157.   ~imgSlot() {
  158.     uninit ();
  159.   }
  160.   static const int image_size_w = 128;
  161.   static const int image_size_h = 128;
  162. };
  163.  
  164. struct tileChunk {
  165.   bool enable;
  166.   struct imgSlot *slot;
  167.   wxUint8 idInSlot;
  168.  
  169.   tileChunk () {
  170.     init ();
  171.   }
  172.   void init () {
  173.     enable = false;
  174.     slot = nullptr;
  175.     idInSlot = 0xFF;
  176.   }
  177. };
  178.  
  179. struct tileChunkMap {
  180.   struct tileChunk map[32*32];
  181.   class wxString *desc ;
  182.   char Rbg;
  183.   char Gbg;
  184.   char Bbg;
  185.   tileChunkMap () {
  186.     init ();
  187.   }
  188.   ~ tileChunkMap () {
  189.     if (desc != nullptr) delete desc;
  190.     desc = nullptr;
  191.   }
  192.   void init () {
  193.     wxUint16 id;
  194.     for (id = 0; id != sizeof (map)/ sizeof (map[0]); id++)
  195.     { map[id].init(); desc = nullptr; }
  196.   }
  197.   void copy (struct tileChunkMap & t)  {
  198.     wxUint16 id;
  199.     for (id = 0; id != sizeof (map)/ sizeof (map[0]); id++)
  200.     { map[id].enable  = t.map[id].enable;
  201.       map[id].idInSlot  = t.map[id].idInSlot;
  202.       map[id].slot  = t.map[id].slot;
  203.     }
  204.   }
  205.   void copy (struct tileChunkMap & t, imgSlot *p, wxUint8 land)  {
  206.     wxUint16 id;
  207.     for (id = 0; id != sizeof (map)/ sizeof (map[0]); id++)
  208.     { map[id].enable  = (p == nullptr) ? false : p->enable;
  209.     map[id].idInSlot  = land;
  210.     map[id].slot  = p;
  211.     }
  212.   }
  213. };
  214.  
  215. class cs_mainFrame : public wxFrame {
  216.    
  217. public:
  218.   enum wxRESID {
  219.     wxID_LOAD_TEXTURE = 1005,
  220.     wxID_LOAD_SETTINGS,
  221.     wxID_SAVE_SETTINGS,
  222.     wxID_PAGE_SETTINGS,
  223.     wxID_PAGE_NEW,
  224.     wxID_PAGE_CLOSE,
  225.     wxID_PAGE_SAVE,
  226.     wxID_CLAY_ADD,
  227.     wxID_GVIEW,
  228.     wxID_BTEXTURE,
  229.     wxID_CLAY,
  230.     wxID_STATUS_OUTPUT,
  231.     wxID_PIXEL,
  232.     wxID_ABOUT_WXWIDGETS,
  233.     wxID_ABOUT_EDITORS
  234.   };
  235.  
  236. public:
  237.  
  238.   cs_mainFrame (wxWindow* parent);
  239.   ~cs_mainFrame()
  240.   {
  241.     // deinitialize the frame manager
  242.     aui_Manager.UnInit();
  243.   }
  244.  
  245. public:
  246.   // event mapper .
  247.   void OnFile_LoadImage (class wxCommandEvent& event);
  248.   void OnFile_ClayAdd (class wxCommandEvent& event);
  249.   void OnFile_PageNew  (class wxCommandEvent& event);
  250.   void OnFile_PageSettings  (class wxCommandEvent& event);
  251.   void OnFile_LoadSettings  (class wxCommandEvent& event);
  252.   void OnFile_SaveSettings  (class wxCommandEvent& event);
  253.   void OnFile_PageSave  (class wxCommandEvent& event);
  254.  
  255.   void OnAbout_wxWidgets (class wxCommandEvent& event);  
  256.   void OnAbout_TileMap (class wxCommandEvent& event);
  257.  
  258.   void OnView_StatusOutput  (class wxCommandEvent& event);
  259.   void OnView_Close  (wxAuiManagerEvent& event);
  260.   void OnView_BTexture  (class wxCommandEvent& event);
  261.   void OnView_Clay  (class wxCommandEvent& event);
  262.  
  263.   void StatusShowText ();
  264.   void StatusOut (wxString & content);
  265.   void StatusShowClearAppendBaseTextSetTemp (wxString &s);
  266.   void StatusOutWrap (wxString & content);
  267.   void StatusOutWrapShow (wxString & content);
  268.  
  269.   // manger solt.
  270.   // on pattern panel. only adjust. bank.
  271.   struct imgSlot imgSlot_[256];
  272.   std::list <tileChunkMap *> fmset;
  273.   struct tileChunkMap tps;
  274. public:
  275.   class shared_cs share_cs_;
  276.   class shared_cs & attach;
  277.   class cs_PageTileTab *ctab;
  278.  
  279.   wxWindow *fd_mainFrame_;
  280.   wxWindow *fd_ViewStatus_;
  281.   wxWindow *fd_ViewGlobalZoom_;
  282.   wxAuiNotebook *fd_ViewRootTexture_;
  283.   wxAuiNotebook *fd_ViewClaySet_;
  284.   wxWindow *fd_ViewPixel_;
  285.  
  286.   wxAuiManager aui_Manager;
  287.   wxAuiNotebook *note_tab2;
  288.  
  289.   wxString statOut;
  290.   struct tile_action_rt *umlink ;
  291.   struct tile_translat *tefcopy;
  292.  
  293.   wxDECLARE_EVENT_TABLE();
  294. public:
  295.   struct imgSlot *getSlotByID (wxUint8 id_)  {
  296.     for (int id= 0; id != sizeof (imgSlot_)/ sizeof (imgSlot_[0]); id++)  {
  297.       if (imgSlot_[id].enable != false)  {
  298.         if  (imgSlot_[id].id == id_)
  299.           return & imgSlot_[id];
  300.         else ;
  301.       }
  302.     }
  303.     return nullptr  ;
  304.   }
  305. };
  306.  
  307. wxBEGIN_EVENT_TABLE (cs_mainFrame, wxFrame)  
  308.   EVT_MENU (cs_mainFrame::wxID_LOAD_TEXTURE, cs_mainFrame::OnFile_LoadImage)
  309.   EVT_MENU (cs_mainFrame::wxID_CLAY_ADD, cs_mainFrame::OnFile_ClayAdd)
  310.   EVT_MENU (cs_mainFrame::wxID_PAGE_SETTINGS, cs_mainFrame::OnFile_PageSettings)
  311.   EVT_MENU (cs_mainFrame::wxID_LOAD_SETTINGS, cs_mainFrame::OnFile_LoadSettings)
  312.   EVT_MENU (cs_mainFrame::wxID_SAVE_SETTINGS, cs_mainFrame::OnFile_SaveSettings)
  313.   EVT_MENU (cs_mainFrame::wxID_PAGE_SAVE, cs_mainFrame::OnFile_PageSave)
  314.   EVT_MENU (cs_mainFrame::wxID_CLAY, cs_mainFrame::OnView_Clay)
  315.   EVT_MENU (cs_mainFrame::wxID_ABOUT_WXWIDGETS, cs_mainFrame::OnAbout_wxWidgets)  
  316.   EVT_MENU (cs_mainFrame::wxID_ABOUT_EDITORS, cs_mainFrame::OnAbout_TileMap)
  317.   EVT_MENU (cs_mainFrame::wxID_PAGE_NEW, cs_mainFrame::OnFile_PageNew)
  318.   EVT_MENU (cs_mainFrame::wxID_STATUS_OUTPUT, cs_mainFrame::OnView_StatusOutput)
  319.   EVT_MENU (cs_mainFrame::wxID_BTEXTURE, cs_mainFrame::OnView_BTexture)
  320.   EVT_AUI_PANE_CLOSE (cs_mainFrame::OnView_Close)
  321. wxEND_EVENT_TABLE ()
  322.  
  323. struct tileChunkSet {
  324.   wxUint8 hnums;
  325.   wxUint8 vnums;
  326.   struct tileChunkMap *tcm;
  327.   class wxString desc;
  328. };
  329.  
  330. /* namespace*/
  331. struct tile_file {
  332.   struct dummyroot {
  333.     char rgroup[imgSlot::image_size_w*imgSlot::image_size_h];
  334.     char ggroup[imgSlot::image_size_w*imgSlot::image_size_h];
  335.     char bgroup[imgSlot::image_size_w*imgSlot::image_size_h];
  336.     char unused[imgSlot::image_size_w*imgSlot::image_size_h];
  337.   };
  338.   struct std_infos {
  339.     wxUint8 mg[4];
  340.     wxUint16 imgSlot_nums;
  341.     wxUint16 claySet_nums;
  342.     wxUint16 pageSet_nums;
  343.     wxUint32 claySetDesc_Offset; // offset base byte. not ch encode.
  344.     wxUint32 claySetChunk_Offset;
  345.     wxUint32 pageSetDesc_Offset; // offset base byte. not ch encode.
  346.     wxUint32 pageSetChunk_Offset;
  347.   };
  348.   struct RVA_uv_chunk {
  349.     wxUint32 offset;
  350.     wxUint32 length;
  351.   };
  352.   struct RVA_np_chunk {
  353.     wxUint32 ch_offset;
  354.     wxUint32 ch_length;
  355.     wxUint32 pg_Width;
  356.     wxUint32 pg_Height;
  357.   };
  358.   struct RVA_kc_chunk {
  359.     wxUint8 enable;
  360.     wxUint8 page;
  361.     wxUint8 land;
  362.   };
  363.   struct RVA_as_chunk {
  364.     struct RVA_kc_chunk kcset[32*32];
  365.   };
  366.   static void maptoas (RVA_as_chunk &as, tileChunkMap &cm) {
  367.     for (int y = 0; y != 32; y++)  {
  368.       for  (int x = 0; x != 32; x++) {
  369.         int k = x+y*32;
  370.         as.kcset[k].enable = cm.map[k].enable;
  371.         if  (as.kcset[k].enable  != false)  {
  372.           as.kcset[k].page = cm.map[k].slot->id;
  373.           as.kcset[k].land = cm.map[k].idInSlot;
  374.         }
  375.       }
  376.     }
  377.   }
  378.  
  379.   static void astomap (tileChunkMap &cm, RVA_as_chunk &as, class cs_mainFrame &csm) {
  380.     for (int y = 0; y != 32; y++)  {
  381.       for (int x = 0; x != 32; x++)  {
  382.         int k = y*32+x;
  383.         cm.map[k].enable = !! as.kcset[k].enable;
  384.         if  (cm.map[k].enable != false) {
  385.           cm.map[k].idInSlot = as.kcset[k].land;
  386.           cm.map[k].slot = csm. getSlotByID (as.kcset[k].page);
  387.         }
  388.       }
  389.     }
  390.   }
  391.   // -------------------------------------------------------
  392.   // file struct desc .
  393.   //
  394.   // dword    magic number. assert file vailed.
  395.   // word     imgSlot nums. [max : 256]
  396.   // word     clayset nums  [max : word max ]
  397.   // word     page set nums
  398.   // dword    clay desc ch heap offset
  399.   // dword    clay chunk heap offset
  400.   // dword    page desc ch heap offset
  401.   // dword    page chunk heap offset  
  402.   // -------------------------------------------------------
  403.   // byte*?     vailed id count[imgSlot nums]
  404.   // dummyroot*? imgSlot RGB pixel set [imgSlot nums]
  405.   // -------------------------------------------------------
  406.   // RVA_uv_chunk*?     desc struct [clayset nums]
  407.   // ucs-2 buffer    clay desc set
  408.   // RVA_as_chunk*?      as chunk set [clayset nums]
  409.   // -------------------------------------------------------
  410.   // RVA_np_chunk*?     desc struct [page nums]
  411.   // ucs-2 buffer    page desc set
  412.   // RVA_as_chunk* *?      as chunk set [page nums]
  413.   // -------------------------------------------------------
  414. };
  415.  
  416. // AUI-WINDOW status output.
  417. class  cs_ViewStatus : public wxTextCtrl {
  418.  
  419. public:
  420.   cs_ViewStatus (class shared_cs &attach_, class wxWindow *parent, wxWindowID id,
  421.     const wxString &title,
  422.     const wxPoint &point,
  423.     const wxSize &size,
  424.     long style ) : wxTextCtrl (parent, id, title, point, size, style), attach (attach_)
  425.   { attach.cs_ViewStatus_ = this; }
  426.  
  427.   class shared_cs & attach;
  428. };
  429.  
  430.  
  431.  
  432. // read edit
  433. struct tile_action_rt {
  434.   bool collect;
  435.   bool stop;
  436.   void set_discard () {
  437.     collect = false;
  438.     stop = false;
  439.   }
  440.   void init () {
  441.     set_discard ();
  442.   }
  443.   bool cando () {
  444.     return ((collect == false) && (stop == true));
  445.   }
  446.   bool canselectOrpt () {
  447.     return ((collect != false) || (stop != false));
  448.   }
  449. };
  450.  
  451. struct tile_translat {
  452.  
  453.   enum CBG_fromtype {
  454.     CBG_FROM_UNSET = -1,
  455.     CBG_FROM_ROOTTEXTURE = 0,
  456.     CBG_FROM_CLAY,
  457.     CBG_FROM_PPSET
  458.   };
  459.   struct tileChunkSet *pSet;
  460.   enum CBG_fromtype type;
  461.   class wxRect mapRect;
  462.   union  {
  463.     struct imgSlot *slot_;
  464.     struct tileChunkMap *map_;
  465.   };
  466. };
  467.  
  468. // <CLAY-TILE> =====================================================================
  469. class cs_ClayTile : public wxAuiNotebook {
  470.  
  471. public:
  472.   cs_ClayTile (class shared_cs & attach_, wxWindow *parent)
  473.     : wxAuiNotebook (parent), attach (attach_)
  474.   { attach.cs_ClayTile_ = this; }
  475.  
  476.   class shared_cs & attach;
  477. };
  478.  
  479. class cs_ClayTileTab : public wxNotebookPage {
  480.  
  481. public:
  482.   cs_ClayTileTab (class shared_cs & attach_, wxWindow *parent, wxWindowID id, int vnums, int hnums, wxString & caption)
  483.     : wxNotebookPage (parent, id), attach (attach_) {}
  484. public:
  485.   class shared_cs & attach;
  486.   tileChunkSet *chunkset;
  487. };
  488.  
  489. // <PAGE-TILE> =====================================================================
  490. class cs_PageTile : public wxAuiNotebook {
  491.  
  492. public:
  493.   cs_PageTile (class shared_cs & attach_, wxWindow *parent)
  494.     : wxAuiNotebook (parent), attach (attach_)
  495.   {
  496.     attach.cs_PageTile_ = this;
  497.     this->Connect (wxEVT_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler (cs_PageTile::OnAui_page_changed));
  498.     this->Connect (wxEVT_AUINOTEBOOK_PAGE_CLOSED, wxAuiNotebookEventHandler (cs_PageTile::OnAui_page_closed));
  499.   }
  500.   void cs_PageTile::OnAui_page_changed (wxAuiNotebookEvent &event)  {
  501.     attach.cs_mainFrame_->ctab = (class cs_PageTileTab *) this->GetPage(event.GetSelection ());
  502.   }
  503.   void cs_PageTile::OnAui_page_closed (wxAuiNotebookEvent &event)  {
  504.  
  505.     attach.cs_mainFrame_->ctab = (class cs_PageTileTab *) this->GetCurrentPage ();
  506.   }
  507.  
  508. public:
  509.   class shared_cs & attach;
  510. };
  511.  
  512. // main tab.
  513. class cs_PageTileTab : public wxNotebookPage {
  514.  
  515. public:
  516.   cs_PageTileTab (class shared_cs & attach_, wxWindow *parent, wxWindowID id, int hnums, int vnums, wxString & caption, tileChunkSet * pp = nullptr)
  517.     : wxNotebookPage (parent, id), attach (attach_)
  518.   {
  519.     // create notepage
  520.     if  (pp == nullptr)  {
  521.       chunkset.hnums = hnums;
  522.       chunkset.vnums = vnums;
  523.       chunkset.tcm = new tileChunkMap [hnums * vnums];
  524.       chunkset.desc = caption.size () > 0 ? caption : wxT ("noname");
  525.     } else {
  526.       chunkset.hnums = pp->hnums;
  527.       chunkset.vnums = pp->vnums;
  528.       chunkset.tcm = new tileChunkMap [pp->hnums * pp->vnums];
  529.       chunkset.desc = pp->desc;
  530.       for (int y = 0; y != chunkset.vnums; y++)  {
  531.         for (int x = 0; x != chunkset.hnums; x++)  {
  532.           int c = y*chunkset.hnums+x;
  533.           chunkset.tcm[c].copy(pp->tcm[c]);
  534.         }
  535.       }
  536.     }
  537.     XorBgColor (chunkset);
  538.    
  539.     this->SetBackgroundColour ( wxColour (0xd8b166));
  540.  
  541.     wxAuiNotebook *bk = (wxAuiNotebook *) parent;
  542.     bk->AddPage (this, chunkset.desc);
  543.     int switchbank = 0;
  544.  
  545.     // set scrolls.
  546.     vScr = new wxScrollBar (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL);
  547.     hScr = new wxScrollBar (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSB_HORIZONTAL);
  548.  
  549.     dgs.init ();
  550.     SetScrFitSize ();
  551.     SetThumbSize ();
  552.  
  553.     ptStart.x =
  554.     ptStart.y =
  555.     ptPoll.x =
  556.     ptPoll.y = 0;
  557.  
  558.     // link message map.
  559.     this->Connect (wxEVT_SIZE, wxSizeEventHandler (cs_PageTileTab::OnSize_Event));
  560.     this->Connect (wxEVT_PAINT, wxPaintEventHandler (cs_PageTileTab::OnPaint_Event));
  561.     this->Connect (wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler (cs_PageTileTab::OnThumbTrackOrRelease_Event));
  562.     this->Connect (wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler (cs_PageTileTab::OnThumbTrackOrRelease_Event));
  563.  
  564.     this->Connect (wxEVT_MOTION, wxMouseEventHandler (cs_PageTileTab::OnMotion_Event));
  565.     this->Connect (wxEVT_LEFT_DOWN, wxMouseEventHandler (cs_PageTileTab::OnMouseLButtonDown_Event));
  566.     this->Connect (wxEVT_RIGHT_UP, wxMouseEventHandler (cs_PageTileTab::OnMouseRButtonUp_Event));
  567.     this->Connect (wxEVT_RIGHT_DOWN, wxMouseEventHandler (cs_PageTileTab::OnMouseRButtonDown_Event));
  568.   }
  569.  
  570.   void XorBgColor (tileChunkSet &cs) {
  571.     for ( wxUint16 y = 0; y != cs.vnums; y++)  {
  572.       for ( wxUint16 x = 0; x != cs.hnums; x++)  {
  573.         int n = y;
  574.         int c = x;
  575.         int s = x+y*cs.hnums;
  576.         n &= 1;
  577.         c &= 1;
  578.         c ^= n;
  579.         if (c == 0) {
  580.           cs.tcm[s].Rbg = (char )0x00;
  581.           cs.tcm[s].Gbg = (char )0xC6;
  582.           cs.tcm[s].Bbg = (char )0xFF;
  583.         } else  {
  584.           cs.tcm[s].Rbg = (char )0xFF;
  585.           cs.tcm[s].Gbg = (char )0xAF;
  586.           cs.tcm[s].Bbg = (char )0x02;
  587.         }
  588.       }    
  589.     }
  590.   }
  591.   void XorBgColor () {
  592.     XorBgColor (chunkset);
  593.   }
  594.   void OnThumbTrackOrRelease_Event (wxScrollEvent& event) {
  595.     int curid = event.GetId ();
  596.     outputBaseInfos ();
  597.     if  (curid == vScr->GetId ())  {
  598.       ptStart.y = vScr->GetThumbPosition();
  599.       this->Refresh ();
  600.     } else if (curid == hScr->GetId ())  {
  601.       ptStart.x = hScr->GetThumbPosition();
  602.       this->Refresh ();
  603.     } else  {
  604.       event.Skip ();
  605.     }
  606.   }
  607.  
  608.   void SetThumbSize () {
  609.     wxSize u;
  610.     wxSize v;
  611.     if ( GetClientSize2(u) != false)  {
  612.       GetLogicSize2(v);
  613.       hScr->SetRange (v.x);
  614.       hScr->SetThumbSize (u.x);
  615.       vScr->SetRange (v.y);
  616.       vScr->SetThumbSize (u.y);
  617.     }
  618.   }
  619.  
  620.   void SetScrFitSize () {
  621.  
  622.     wxRect mvRect = this->GetClientRect();
  623.     wxRect vdRect (mvRect);
  624.     int q = vdRect.GetRight ();
  625.     int q2 = q - 20;
  626.     int q3 = vdRect.GetBottom ();
  627.     int q4 = q3 - 20;
  628.     vdRect.SetLeft (q2);
  629.     vdRect.SetRight (q);
  630.     vdRect.SetBottom (q4);
  631.     vScr->SetSize (vdRect);
  632.  
  633.     wxRect hdRect (mvRect);
  634.     q = hdRect.GetBottom ();
  635.     q2 = q - 20;
  636.     q3 = hdRect.GetRight ();
  637.     q4 = q3 - 20;
  638.     hdRect.SetTop (q2);
  639.     hdRect.SetBottom (q);
  640.     hdRect.SetRight (q4);
  641.     hScr->SetSize (hdRect);
  642.   }
  643.  
  644.   inline
  645.   struct tileChunk *getTileChunk (int hnumsInList, int vnumsInList, struct tileChunkMap **pp = nullptr)  {
  646.     // chunkset.hnums;
  647.     // 32 32
  648.     //  get vpos.
  649.     int b = vnumsInList >> 5;
  650.     int p = vnumsInList & 31;
  651.     int q = hnumsInList >> 5;
  652.     int d = hnumsInList & 31;
  653.     if (hnumsInList >= (chunkset.hnums <<5)) return nullptr;
  654.     if (vnumsInList >= (chunkset.vnums <<5)) return nullptr;
  655.     struct tileChunkMap * c = & chunkset.tcm[b *chunkset.hnums+q];
  656.     if (pp != nullptr) * pp = c;
  657.     return & c->map[ (p <<5)+d];
  658.   }
  659.  
  660.   void OnMouseLButtonDown_Event (wxMouseEvent &event) {
  661.    
  662.     wxPoint pe  = wxGetMousePosition ();
  663.     wxSize es;
  664.     common :: getMousePos (this, pe);
  665.     GetClientSize2 (es);
  666.  
  667.     if (pe.x >= 0
  668.       && (pe.y >= 0)
  669.       && (pe.x < es.x)
  670.       && (pe.y < es.y))
  671.     {
  672.       wxPoint pg = pe;
  673.       common ::getMiniOffset (pg);
  674.  
  675.       // fill rect.
  676.       tile_translat *tf = attach.cs_mainFrame_->tefcopy;
  677.       common :: limitBoard (pe);
  678.  
  679.       if (tf != nullptr)  {
  680.        
  681.         wxPoint sp (tf->mapRect.width, tf->mapRect.height);
  682.         wxPoint ap (tf->mapRect.x, tf->mapRect.y);
  683.         common :: getRound (pe);
  684.         common :: limitBoard (ap);
  685.         common :: getRound (ap);
  686.         common :: getRound (sp);
  687.         wxPoint cc ( hScr->GetThumbPosition () + 8* !! (ptStart.x & 7),
  688.                      vScr->GetThumbPosition () + 8* !! (ptStart.y & 7)  ); // XXX:mini offset incorrent.
  689.         common :: getRound (cc);
  690.         cc += pe;
  691.         for ( int y = 0; y < sp.y; y++)  {
  692.           for (int x = 0; x < sp.x; x++)  {
  693.             if  (tf->type == tile_translat:: CBG_FROM_ROOTTEXTURE)  {
  694.               // to cachemap.
  695.               imgSlot *pq = tf->slot_;
  696.               if (pq->enable == false)
  697.                 continue  ;
  698.               wxPoint st (x, y);
  699.               st += cc;
  700.               struct tileChunk *j = getTileChunk (st.x, st.y);
  701.               // tileChunk *p = & map2->map[xq+pe.x+(yq+pe.y)*32];
  702.               if (j != nullptr)  {
  703.                 j->slot = pq;
  704.                 j->enable = true;
  705.                 j->idInSlot = ap.x + x;
  706.                 j->idInSlot += ( ap.y + y) * 16;
  707.               }
  708.             } else if (tf->type == tile_translat::CBG_FROM_CLAY)  {
  709.               wxPoint st2 (x, y);
  710.               st2 += ap;
  711.               int sc = st2.x+st2.y*32;
  712.               imgSlot *pq = attach.cs_mainFrame_->tps.map[sc].slot;
  713.               if (pq == nullptr)
  714.                 continue  ;
  715.               if (pq->enable == false)
  716.                 continue  ;
  717.               wxPoint st (x, y);
  718.               st += cc;
  719.               struct tileChunk *j = getTileChunk (st.x, st.y);
  720.               // tileChunk *p = & map2->map[xq+pe.x+(yq+pe.y)*32];
  721.               if (j != nullptr)  {
  722.                 j->slot = pq;
  723.                 j->enable = true;
  724.                 j->idInSlot = attach.cs_mainFrame_->tps.map[sc].idInSlot;
  725.               }
  726.             }
  727.           }
  728.         }
  729.         this->Refresh ();
  730.       }
  731.     }
  732.   }
  733.  
  734.   void outputBaseInfos ()  {
  735.  
  736.     wxPoint s;
  737.     wxSize s2;
  738.     wxString rc;
  739.     common ::getMousePos (this, s);
  740.     GetClientSize2 (s2);
  741.  
  742.     rc.Printf (  
  743.       wxT ("M-(x:%d y:%d)|(b8x:%d b8y:%d)|(m8x:%d m8y:%d)")
  744.       wxT (" W-(w:%d h:%d)|(b8w:%d b8h:%d)|(m8w:%d m8h:%d)")
  745.       wxT (" H-(total:%d pos:%d size:%d)")
  746.       wxT (" V-(total:%d pos:%d size:%d)"),
  747.       // mouse
  748.       s.x, s.y,
  749.       s.x >> 3, s.y >> 3,
  750.       s.x % 8, s.y % 8,
  751.       // window
  752.       s2.x, s2.y,
  753.       s2.x >> 3, s2.y >> 3,
  754.       s2.x % 8, s2.y % 8,
  755.       // sh.
  756.       hScr->GetRange (),
  757.       hScr->GetThumbPosition(),
  758.       hScr->GetThumbSize (),
  759.       // sv.
  760.       vScr->GetRange (),
  761.       vScr->GetThumbPosition(),
  762.       vScr->GetThumbSize () );
  763.  
  764.     attach.cs_mainFrame_->GetStatusBar ()->SetLabelText (rc);
  765.   }
  766.  
  767.   void OnMouseRButtonDown_Event (wxMouseEvent &event) { event.Skip (); }
  768.   void OnMouseRButtonUp_Event (wxMouseEvent &event) { event.Skip (); }
  769.  
  770.   void OnMotion_Event (wxMouseEvent &event) {
  771.     common ::getMousePos (this, ptPoll);
  772.     outputBaseInfos ();
  773.     this->Refresh ();
  774.   }
  775.   void OnSize_Event (wxSizeEvent &event) {
  776.  
  777.     SetScrFitSize ();
  778.     SetThumbSize ();
  779.     outputBaseInfos ();
  780.     ptStart.y = vScr->GetThumbPosition();
  781.     ptStart.x = hScr->GetThumbPosition();
  782.     this->Refresh();
  783.   }
  784.  
  785.   void OnPaint_Event (wxPaintEvent &event) {
  786.  
  787.     // try scan.
  788.     // first scan current'size tile base scroll's offset and client size.
  789.    
  790.     class wxPoint s = ptStart;
  791.     class wxPoint s2 = s;
  792.     class wxSize e;
  793.  
  794.     GetClientSize2 (e);
  795.     common :: getMiniOffset (s2);
  796.  
  797.     if (e.x <= 0 || e.y <= 0)
  798.       return ;
  799.     else ;
  800.  
  801.     int needScanHoriNums = e.x / 8 + !! (e.x % 8);
  802.     int nessScanVertNums = e.y / 8 + !! (e.y % 8);
  803.  
  804.     // check more scan base scroll..
  805.     if (s2.x != 0)   {
  806.       //  exist remain.
  807.       if  (((8 - s2.x) & -8) < ((e.x) & 7)) needScanHoriNums ++;
  808.     }
  809.     if (s2.y != 0)   {
  810.       //  exist remain.
  811.       if  (((8 - s2.y) & -8) < ((e.y) & 7)) nessScanVertNums ++;
  812.     }
  813.     int q = s.x >> 3;
  814.     int g = s.y >> 3;
  815.     q = q + !! s2.x;
  816.     g = g + !! s2.y;
  817.  
  818.     // dummy draw buffer.
  819.     class wxImage img (needScanHoriNums * 8, nessScanVertNums * 8);
  820.     common :: fillImg(img, 0xFF, 0xFF, 0xFF);
  821.     // img.Clear ();
  822.  
  823.     // scan base image.
  824.     for (int y = 0; y != nessScanVertNums; y++)  {
  825.       for (int x = 0; x != needScanHoriNums; x++)  {
  826.         tileChunkMap *pp;
  827.         tileChunk *p = getTileChunk (x+q, y+g, & pp);
  828.         if (p == nullptr)
  829.           continue  ;
  830.         if ( p->enable == false)
  831.           goto LL  ;
  832.         imgSlot *k = p->slot;
  833.         if (k == nullptr)
  834.           goto LL  ;
  835.         if (k->enable == false)
  836.           goto LL  ;
  837.         int xs = p->idInSlot & 15;
  838.         int ys = p->idInSlot >> 4;
  839.         xs *= 8;
  840.         ys *= 8;
  841.         for (int u = 0; u != 8; u++)  {
  842.           for  (int v = 0; v != 8; v++)  {
  843.             char R = k->img2->GetRed (xs+v, ys+u);
  844.             char G = k->img2->GetGreen (xs+v, ys+u);
  845.             char B = k->img2->GetBlue (xs+v, ys+u);
  846.             img.SetRGB (x*8+v, y*8+u, R, G, B );
  847.           }
  848.         }
  849.         continue  ;
  850. LL:    
  851.         for (int u = 0; u != 8; u++)  {
  852.           for  (int v = 0; v != 8; v++)  { // 5514fb
  853.             img.SetRGB (x*8+v, y*8+u, pp->Rbg, pp->Gbg, pp->Bbg );
  854.           }
  855.         }
  856.       }
  857.     }
  858.  
  859.     // alpha rect.
  860.     if ( attach.cs_mainFrame_->tefcopy != nullptr)  {
  861.       if (attach.cs_mainFrame_->umlink != nullptr) {
  862.         if (attach.cs_mainFrame_->umlink->cando() != false)  {
  863.           // check range.
  864.           wxPoint pe;
  865.           common :: getMousePos (this, pe);
  866.           // if (inRange (pe) != false)  {
  867.           if (  1 ) {
  868.             // switch
  869.             tile_translat *m = attach.cs_mainFrame_->tefcopy;
  870.             //   alpha select rect/.
  871.             switch (m->type)  {
  872.             case  tile_translat::CBG_FROM_CLAY:
  873.               {
  874.                 //   iterater.
  875.                 for  (int y = 0; y < m->mapRect.height; y+=8)  {
  876.                   for  (int x = 0; x < m->mapRect.width; x+=8)  {
  877.                     //   pick imgSlot .
  878.                     int xm = m->mapRect.x & -8;
  879.                     int xd = xm + x;
  880.                     int ym = m->mapRect.y & -8;
  881.                     int yd = ym + y;
  882.                     xd >>= 3;
  883.                     yd >>= 3;
  884.                     tileChunk *p = & attach.cs_mainFrame_->tps.map[xd+yd*32];
  885.                     imgSlot *pq = p->slot;
  886.                     if (p->enable == false)
  887.                       continue  ;
  888.                     if (pq->enable == false)
  889.                       continue  ;
  890.                     common :: limitBoard (pe);
  891.                     int fx = x + pe.x;
  892.                     int fy = y + pe.y;
  893.                     int tx = p->idInSlot & 0x0F;
  894.                     int ty = p->idInSlot >> 4;
  895.                     tx <<= 3;
  896.                     ty <<= 3;
  897.                     for (int y1 = 0; y1 != 8; y1++)  {
  898.                       for  (int x1 = 0; x1 != 8; x1++)  {
  899.                         // fetch source.
  900.                         int q = tx + x1;
  901.                         int b = ty + y1;
  902.                         int p = fx + x1;
  903.                         int d = fy + y1;
  904.                         if (p >= 0 && (p < e.x)
  905.                           && (d >= 0 && (d < e.y))
  906.                           && (q >= 0 && (q <= 127))
  907.                           && (b >= 0 && (b <= 127)) )
  908.                         {
  909.                           char r = pq->img2->GetRed (q, b);
  910.                           char g = pq->img2->GetGreen (q, b);
  911.                           char b2 = pq->img2->GetBlue (q, b);
  912.                           char R = img.GetRed (p, d);
  913.                           char G = img.GetGreen (p, d);
  914.                           char B = img.GetBlue (p, d);
  915.                           // alpha 50% rect.
  916.                           r = wxColour::AlphaBlend (r, R, 0.5);
  917.                           g = wxColour::AlphaBlend (g, G, 0.5);
  918.                           b2 = wxColour::AlphaBlend (b2, B, 0.5);
  919.                           img.SetRGB (p, d, r, g, b2);
  920.                         }
  921.                       }
  922.                     }
  923.                   }      
  924.                 }
  925.               }
  926.               break;
  927.             case  tile_translat::CBG_FROM_ROOTTEXTURE:
  928.               {
  929.                 //   iterater.
  930.                 common :: limitBoard (pe);
  931.                 for  (int y = 0; y < m->mapRect.height; y+=8)  {
  932.                   for  (int x = 0; x < m->mapRect.width; x+=8)  {
  933.                     //   pick imgSlot .
  934.                     imgSlot *pq = m->slot_;
  935.  
  936.                     if (pq->enable == false)
  937.                       continue  ;
  938.                     int tx = x +  m->mapRect.x;
  939.                     int ty = y +  m->mapRect.y;
  940.                     int fx = x + pe.x;
  941.                     int fy = y + pe.y;
  942.  
  943.                     for (int y1 = 0; y1 != 8; y1++)  {
  944.                       for  (int x1 = 0; x1 != 8; x1++)  {
  945.                         // fetch source.
  946.                         int q = tx + x1;
  947.                         int b = ty + y1;
  948.                         int p = fx + x1;
  949.                         int d = fy + y1;
  950.                         if (p >= 0 && (p < e.x)
  951.                           && (d >= 0 && (d < e.y))
  952.                           && (q >= 0 && (q <= 127))
  953.                           && (b >= 0 && (b <= 127)) )
  954.                         {
  955.                           char r = pq->img2->GetRed (q, b);
  956.                           char g = pq->img2->GetGreen (q, b);
  957.                           char b2 = pq->img2->GetBlue (q, b);
  958.                           if ( (p -s2.x) < 0)
  959.                             continue  ;
  960.                           if ( (d - s2.y) < 0)
  961.                             continue  ;
  962.                           char R = img.GetRed (p, d);
  963.                           char G = img.GetGreen (p, d);
  964.                           char B = img.GetBlue (p, d);
  965.                           // alpha 50% rect.
  966.                           r = wxColour::AlphaBlend (r, R, 0.5);
  967.                           g = wxColour::AlphaBlend (g, G, 0.5);
  968.                           b2 = wxColour::AlphaBlend (b2, B, 0.5);
  969.                           img.SetRGB (p, d, r, g, b2);
  970.                         }
  971.                       }
  972.                     }
  973.                   }      
  974.                 }
  975.               }
  976.               break ;
  977.             }
  978.           }
  979.         }
  980.       }
  981.     }
  982.     // dummy dc.
  983.     wxBufferedPaintDC dc (this);
  984.     wxMemoryDC mdc;// (wxBitmap (img));
  985.     mdc.SelectObject (wxBitmap (img));
  986.     SetBackgroundStyle (wxBG_STYLE_CUSTOM);
  987.     dc.Clear ();
  988.     wxPoint pt (0, 0);
  989.     wxPoint pt2 (ptStart.x & 7, ptStart.y & 7);
  990.     wxSize ep;
  991.     GetClientSize2 (ep);
  992.     dc.Blit (pt, ep, & mdc, pt2);
  993.     // event.Skip ();
  994.   }
  995.  
  996.   bool GetClientSize2 (wxSize &se)  {
  997.     wxRect mvRect = this->GetClientRect();
  998.     se.x = mvRect.width -20;
  999.     se.y = mvRect.height-20;
  1000.  
  1001.     if (se.x <= 0 || (se.y <= 0))
  1002.       return false;
  1003.     else  
  1004.       return true;
  1005.   }
  1006.   void GetLogicSize2 (wxSize &se)  {
  1007.     se.x = chunkset.hnums * 256;
  1008.     se.y = chunkset.vnums * 256;
  1009.   }
  1010. public:
  1011.   class wxScrollBar *hScr;
  1012.   class wxScrollBar *vScr;
  1013.   class shared_cs & attach;
  1014.   struct tileChunkSet chunkset;
  1015.   struct tile_action_rt dgs;
  1016.   struct tile_translat tec_local;
  1017.   class wxPoint ptStart;
  1018.   class wxPoint ptPoll;
  1019. };
  1020.  
  1021. class cs_ViewRootTexture : public wxAuiNotebook {
  1022.  
  1023. public:
  1024.   cs_ViewRootTexture (class shared_cs & attach_, class wxWindow *parent)
  1025.     : wxAuiNotebook (parent), attach (attach_)
  1026.   { attach.cs_ViewRootTexture_ = this; }
  1027.  
  1028.   class shared_cs & attach;
  1029. };
  1030.  
  1031. // read. page.
  1032. class cs_NotePage : public wxNotebookPage {
  1033. public:
  1034.   cs_NotePage (class shared_cs & cs_, struct imgSlot *imgs, class wxWindow *parent, wxWindowID id = wxID_ANY)
  1035.     : attach (cs_), wxNotebookPage (parent, id)
  1036.   {
  1037.     pc_bank = imgs;
  1038.     art.init ();
  1039.  
  1040.     this->Connect (wxEVT_PAINT, wxPaintEventHandler (cs_NotePage::OnPaint_Event));
  1041.     this->Connect (wxEVT_MOTION, wxMouseEventHandler (cs_NotePage::OnMotion_Event));
  1042.     this->Connect (wxEVT_RIGHT_DOWN, wxMouseEventHandler (cs_NotePage::OnMouseRButtonDown_Event));
  1043.     this->Connect (wxEVT_RIGHT_UP, wxMouseEventHandler (cs_NotePage::OnMouseRButtonUp_Event));
  1044.   }
  1045.   void OnPaint_Event (wxPaintEvent& event) {
  1046.     class wxBufferedPaintDC dc (this);
  1047.     SetBackgroundStyle (wxBG_STYLE_CUSTOM);
  1048.  
  1049.     if  (art.canselectOrpt() != false)  {
  1050.        // alpha rect.
  1051.       class wxRect trs;
  1052.       class wxImage img = pc_bank->img->ConvertToImage();
  1053.       common :: getAbsRect2 (trs, ptStart, ptPoll);
  1054.       if (trs.x < 0 || trs.y < 0
  1055.         || trs.width < 0
  1056.         || trs.height < 0)
  1057.         return  ;
  1058.       // limit range.
  1059.       if ( (trs.x + trs.width) > imgSlot::image_size_w)
  1060.         trs.width = imgSlot::image_size_w - trs.x;
  1061.       if ( (trs.y + trs.height) > imgSlot::image_size_h)
  1062.         trs.height = imgSlot::image_size_h - trs.y;
  1063.       if (attach.cs_mainFrame_->tefcopy == & tec_local)
  1064.         tec_local.mapRect = trs;
  1065.       // alpha it.
  1066.       for  (int y = 0; y < trs.height; y++)  {
  1067.         for  (int x = 0; x < trs.width; x++)  {
  1068.           int u = x + trs.x;
  1069.           int v = y + trs.y;
  1070.           if (u >= 0 && u < imgSlot::image_size_w
  1071.             && v >= 0 && v < imgSlot::image_size_h)
  1072.           {
  1073.             char r = img.GetRed (u, v);
  1074.             char g = img.GetGreen (u, v);
  1075.             char b = img.GetBlue (u, v);
  1076.             r = wxColour::AlphaBlend (r, 0x6C, 0.25);
  1077.             g = wxColour::AlphaBlend (g, 0x00, 0.25);
  1078.             b = wxColour::AlphaBlend (b, 0xFF, 0.25);
  1079.             img.SetRGB (u, v, r, g, b);    
  1080.           }
  1081.         }      
  1082.       }
  1083.       class wxBitmap gbitmap (img);
  1084.       dc.Clear ();
  1085.       dc.DrawBitmap (gbitmap, 0, 0);
  1086.       return ;
  1087.     }
  1088.     dc.Clear ();
  1089.     dc.DrawBitmap (*pc_bank->img, 0, 0);
  1090.   }
  1091.   void OnMouseRButtonUp_Event (wxMouseEvent & event) {
  1092.     art.stop = true;
  1093.     art.collect = false;
  1094.   }
  1095.   void outputBaseInfos ()  {
  1096.  
  1097.     wxPoint s;
  1098.     wxString rc;
  1099.     common ::getMousePos (this, s);
  1100.     // GetClientSize2 (s2);
  1101.     int xi = -1;
  1102.     int yi = -1;
  1103.     int c = -1;
  1104.     if (s.x >= 0 && (s.x <= 127))
  1105.       xi = s.x >> 3;
  1106.     if (s.y >= 0 && (s.y <= 127))
  1107.       yi = s.y >> 3;
  1108.     if (xi != -1 && yi != -1)
  1109.       c = xi + yi * 16;
  1110.     rc.Printf (  
  1111.       wxT ("PAGE-%02X(%d) ID:-%02X(%d)"), pc_bank->id, pc_bank->id, c, c );
  1112.     attach.cs_mainFrame_->GetStatusBar ()->SetLabelText (rc);
  1113.   }
  1114.   void OnMotion_Event (wxMouseEvent & event){
  1115.     outputBaseInfos ();
  1116.     if (art.stop == false) {
  1117.       common :: getMousePos (this, ptPoll);
  1118.       this->Refresh ();
  1119.     }
  1120.   }
  1121.   bool inRange (wxPoint & pt)  {
  1122.     bool inRange_X =  (pt.x >= 0) && (pt.y < imgSlot::image_size_w);
  1123.     bool inRange_Y =  (pt.y >= 0) && (pt.y < imgSlot::image_size_h);
  1124.     return (inRange_Y && inRange_X);
  1125.   }
  1126.   void OnMouseRButtonDown_Event (wxMouseEvent & event) {
  1127.     art.stop = false;
  1128.     class wxPoint pe;
  1129.     common :: getMousePos (this, pe);
  1130.  
  1131.     // ctor tec_local.
  1132.     tec_local.type = tile_translat::CBG_FROM_ROOTTEXTURE;
  1133.     tec_local.slot_ = pc_bank;
  1134.  
  1135.     // check range.
  1136.     if (inRange (pe) == false) {
  1137.       if (attach.cs_mainFrame_->tefcopy == & tec_local) {
  1138.         attach.cs_mainFrame_->tefcopy = nullptr;
  1139.       }
  1140.     } else   {
  1141.       struct tile_action_rt *p = attach.cs_mainFrame_->umlink;
  1142.       attach.cs_mainFrame_->umlink = nullptr;
  1143.       if (p != nullptr)  p->set_discard ();
  1144.       attach.cs_mainFrame_->umlink = & art;
  1145.       attach.cs_mainFrame_->Refresh ();
  1146.       art.collect = true;
  1147.       pe.x += ! (pe.x % 8 );
  1148.       pe.y += ! (pe.y % 8 ); // round 8
  1149.       ptPoll = pe;
  1150.       ptStart = pe;
  1151.       attach.cs_mainFrame_->tefcopy = & tec_local;
  1152.     }
  1153.     this->Refresh ();
  1154.   }
  1155. public:
  1156.   struct imgSlot *pc_bank;
  1157.   class shared_cs &attach;
  1158.   struct tile_action_rt art;
  1159.   struct tile_translat tec_local;
  1160.   class wxPoint ptStart, ptPoll;
  1161. };
  1162.  
  1163. // read/wrire clay.
  1164. class cs_NotePage2 : public wxNotebookPage {
  1165. public:
  1166.   cs_NotePage2 (class shared_cs & cs_, struct tileChunkMap *cms, class wxWindow *parent, wxWindowID id_)
  1167.     : attach (cs_), wxNotebookPage (parent, id_)
  1168.   {
  1169.     map2 = cms;
  1170.     cls.init ();
  1171.  
  1172.     this->Connect (wxEVT_PAINT, wxPaintEventHandler (cs_NotePage2::OnPaint_Event));
  1173.     this->Connect (wxEVT_MOTION, wxMouseEventHandler (cs_NotePage2::OnMotion_Event));
  1174.     this->Connect (wxEVT_RIGHT_DOWN, wxMouseEventHandler (cs_NotePage2::OnMouseRButtonDown_Event));
  1175.     this->Connect (wxEVT_RIGHT_UP, wxMouseEventHandler (cs_NotePage2::OnMouseRButtonUp_Event));
  1176.     this->Connect (wxEVT_LEFT_DOWN, wxMouseEventHandler (cs_NotePage2::OnMouseLButtonDown_Event));
  1177.   }
  1178.   void OnPaint_PaintBase (class wxImage &src) {
  1179.     for (int y = 0; y != 256; y+= 8)  {
  1180.       for (int x = 0; x != 256; x+= 8)  {
  1181.         struct tileChunk *pck = & map2->map[x/8+y*4];
  1182.         struct imgSlot *s = pck->slot;
  1183.         if (s == nullptr)
  1184.           continue  ;
  1185.         if (pck->enable == false)
  1186.           continue  ;
  1187.         else if (s->enable == false)
  1188.           continue  ;
  1189.         else ;
  1190.         class wxPoint q;
  1191.         // pixel .
  1192.         q.x = pck->idInSlot & 15;
  1193.         q.y = pck->idInSlot >> 4;
  1194.         common :: setExpand (q);
  1195.  
  1196.         for (int u = 0; u != 8; u++)  {
  1197.           for  (int v = 0; v != 8; v++)  {
  1198.             int z = q.x + v;
  1199.             int m = q.y + u;
  1200.             char R = s->img2->GetRed (z, m);
  1201.             char G = s->img2->GetGreen (z, m);
  1202.             char B = s->img2->GetBlue (z, m);
  1203.             src.SetRGB (x+v, y+u, R, G, B );
  1204.           }
  1205.         }
  1206.       }
  1207.     }
  1208.   }
  1209.   bool inRange (wxPoint & pt)  {
  1210.     bool inRange_X =  (pt.x >= 0) && (pt.y <= 255);
  1211.     bool inRange_Y =  (pt.y >= 0) && (pt.y <= 255);
  1212.     return (inRange_Y && inRange_X);
  1213.   }
  1214.   void OnPaint_Event (wxPaintEvent& event)
  1215.   {
  1216.     // check/paint select alpha rect.
  1217.     class wxImage *ipr = nullptr;
  1218.     class wxBufferedPaintDC dc (this);
  1219.     SetBackgroundStyle (wxBG_STYLE_CUSTOM);
  1220.     dc.Clear ();
  1221.     class wxImage img (256, 256);
  1222.     img.Clear ();
  1223.    
  1224.     if (cls.canselectOrpt() != false)  {
  1225.       class wxRect trs;
  1226.       common :: getAbsRect2(trs, ptPoll, ptStart);
  1227.       if (trs.x < 0 || trs.y < 0
  1228.         || trs.width < 0
  1229.         || trs.height < 0)
  1230.         return  ;
  1231.       if ( (trs.x + trs.width) > 256)
  1232.         trs.width = 256 - trs.x;
  1233.       if ( (trs.y + trs.height) > 256)
  1234.         trs.height = 256 - trs.y;
  1235.       if (attach.cs_mainFrame_->tefcopy == & tec_local)
  1236.         tec_local.mapRect = trs;
  1237.       common :: limitBoard (trs);
  1238.       // draw base .
  1239.       OnPaint_PaintBase (img);
  1240.       ipr = & img;
  1241.       for  (int y = 0; y < trs.height; y+= 8)  {
  1242.         for  (int x = 0; x < trs.width; x+= 8)  {
  1243.           // get slot chunk.
  1244.           class wxPoint ac (trs.x + x, trs.y + y);
  1245.           common :: getRound (ac);
  1246.           struct tileChunk *u = & tec_local.map_->map[ac.x + ac.y*32];
  1247.           if (u->enable == false
  1248.             || u->slot->enable == false)
  1249.             continue  ;
  1250.           for  (int y1 = 0; y1 != 8; y1++) {
  1251.              for (int x1 = 0; x1 != 8; x1++)  {
  1252.                int u = x +x1+trs.x;
  1253.                int v = y +y1+trs.y;
  1254.                char r = img.GetRed (u, v);
  1255.                char g = img.GetGreen (u, v);
  1256.                char b = img.GetBlue (u, v);
  1257.                r = wxColour::AlphaBlend (r, 0x6C, 0.25);
  1258.                g = wxColour::AlphaBlend (g, 0x00, 0.25);
  1259.                b = wxColour::AlphaBlend (b, 0xFF, 0.25);
  1260.                img.SetRGB (u, v, r, g, b);
  1261.              }
  1262.           }
  1263.         }      
  1264.       }
  1265.     }
  1266.  
  1267.     if ( attach.cs_mainFrame_->tefcopy != nullptr)  {
  1268.       if (attach.cs_mainFrame_->umlink != nullptr) {
  1269.         if (attach.cs_mainFrame_->umlink->cando() != false)  {
  1270.           // check range.
  1271.           class wxPoint pe;
  1272.           common :: getMousePos (this, pe);
  1273.           if (inRange (pe) != false)  {
  1274.             // switch
  1275.             struct tile_translat *m = attach.cs_mainFrame_->tefcopy;
  1276.             // paint. base.
  1277.             if (ipr == nullptr)  {
  1278.               ipr = & img;
  1279.               OnPaint_PaintBase (*ipr);
  1280.             }
  1281.             //   alpha select rect/.
  1282.             common :: limitBoard (pe);
  1283.             switch (m->type)  {
  1284.             case  tile_translat::CBG_FROM_CLAY:
  1285.               {
  1286.                 class wxPoint ptg;
  1287.                 //   iterater.
  1288.                 for  (ptg.y = 0; ptg.y < m->mapRect.height; ptg.y+=8)  {
  1289.                   for  (ptg.x = 0; ptg.x < m->mapRect.width; ptg.x+=8)  {
  1290.                     //   pick imgSlot .
  1291.                     class wxPoint S ( m->mapRect.x, m->mapRect.y);
  1292.                     class wxPoint T;
  1293.                     common :: limitBoard (S);
  1294.                     S += ptg;
  1295.                     common :: getRound (S);
  1296.                     struct tileChunk *p = & attach.cs_mainFrame_->tps.map[S.x+S.y*32];
  1297.                     struct imgSlot *pq = p->slot;
  1298.                     if (pq == nullptr)
  1299.                       continue  ;
  1300.                     if (p->enable == false)
  1301.                       continue  ;
  1302.                     if (pq->enable == false)
  1303.                       continue  ;
  1304.                     S.x = pe.x;
  1305.                     S.y = pe.y;
  1306.                     S += ptg;
  1307.                     T.x = p->idInSlot & 0x0F;
  1308.                     T.y = p->idInSlot >> 4;
  1309.                     common :: setExpand (T);
  1310.                     class wxPoint K;
  1311.  
  1312.                     for (K.y = 0; K.y != 8; K.y++)  {
  1313.                       for  (K.x = 0; K.x != 8; K.x++)  {
  1314.                         // fetch source.
  1315.                         class wxPoint L (K);
  1316.                         class wxPoint R (K);
  1317.                         L += T;
  1318.                         R += S;
  1319.                         if (R.x >= 0 && (R.x <= 255)
  1320.                           && (R.y >= 0 && (R.y <= 255))
  1321.                           && (L.x >= 0 && (L.x <= 127))
  1322.                           && (L.y >= 0 && (L.y <= 127)) )
  1323.                         {
  1324.                           char r = pq->img2->GetRed (L.x, L.y);
  1325.                           char g = pq->img2->GetGreen (L.x, L.y);
  1326.                           char b2 = pq->img2->GetBlue (L.x, L.y);
  1327.                           char R2 = ipr->GetRed (R.x, R.y);
  1328.                           char G = ipr->GetGreen (R.x, R.y);
  1329.                           char B = ipr->GetBlue (R.x, R.y);
  1330.                           // alpha 50% rect.
  1331.                           r = wxColour::AlphaBlend (r, R2, 0.5);
  1332.                           g = wxColour::AlphaBlend (g, G, 0.5);
  1333.                           b2 = wxColour::AlphaBlend (b2, B, 0.5);
  1334.                           ipr->SetRGB (R.x, R.y, r, g, b2);
  1335.                         }
  1336.                       }
  1337.                     }
  1338.                   }      
  1339.                 }
  1340.               }
  1341.               break;
  1342.             case  tile_translat::CBG_FROM_ROOTTEXTURE:
  1343.               {
  1344.                 //   iterater.
  1345.                 for  (int y = 0; y < m->mapRect.height; y+=8)  {
  1346.                   for  (int x = 0; x < m->mapRect.width; x+=8)  {
  1347.                     //   pick imgSlot .
  1348.                     struct imgSlot *pq = m->slot_;
  1349.                     class wxPoint sPR (x +  m->mapRect.x, y +  m->mapRect.y);
  1350.                     class wxPoint dPR (x +  pe.x, y +  pe.y);
  1351.                     class wxPoint spS;
  1352.                     if (pq == nullptr)
  1353.                       continue  ;
  1354.                     if (pq->enable == false)
  1355.                       continue  ;
  1356.                     for (spS.y = 0; spS.y != 8; spS.y++)  {
  1357.                         for  (spS.x = 0; spS.x != 8; spS.x++)  {
  1358.                           // fetch source.
  1359.                           class wxPoint T (spS);
  1360.                           class wxPoint S (spS);
  1361.                           S += sPR;
  1362.                           T += dPR;
  1363.  
  1364.                           if ( (T.x >= 0 && (T.x <= 255))
  1365.                             && (T.y >= 0 && (T.y <= 255))
  1366.                             && (S.x >= 0 && (S.x <= 127))
  1367.                             && (S.y >= 0 && (S.y <= 127)) )
  1368.                           {
  1369.                             char r = pq->img2->GetRed (S.x, S.y);
  1370.                             char g = pq->img2->GetGreen (S.x, S.y);
  1371.                             char b2 = pq->img2->GetBlue (S.x, S.y);
  1372.                             char R = ipr->GetRed (T.x, T.y);
  1373.                             char G = ipr->GetGreen (T.x, T.y);
  1374.                             char B = ipr->GetBlue (T.x, T.y);
  1375.                             // alpha 50% rect.
  1376.                             r = wxColour::AlphaBlend (r, R, 0.5);
  1377.                             g = wxColour::AlphaBlend (g, G, 0.5);
  1378.                             b2 = wxColour::AlphaBlend (b2, B, 0.5);
  1379.                             ipr->SetRGB (T.x, T.y, r, g, b2);
  1380.                           }
  1381.                         }
  1382.                     }
  1383.                   }      
  1384.                 }
  1385.               }
  1386.               break ;
  1387.             }
  1388.           }
  1389.         }
  1390.       }
  1391.     }
  1392.     if (ipr != nullptr)  {
  1393.       class wxBitmap gbitmap (*ipr);
  1394.       dc.DrawBitmap (gbitmap, 0, 0);
  1395.     } else  {
  1396.       OnPaint_PaintBase (img);
  1397.       class wxBitmap gbitmap (img);
  1398.       dc.DrawBitmap (gbitmap, 0, 0);
  1399.     }
  1400.   }
  1401.   void OnMouseRButtonUp_Event (wxMouseEvent & event)
  1402.   {
  1403.     cls.stop = true;
  1404.     cls.collect = false;
  1405.   }
  1406.   void outputBaseInfos ()  {
  1407.  
  1408.     wxPoint s;
  1409.     wxString rc;
  1410.     common ::getMousePos (this, s);
  1411.     // GetClientSize2 (s2);
  1412.     int xi = -1;
  1413.     int yi = -1;
  1414.     int c = -1;
  1415.     int page = -1;
  1416.     int id = -1;
  1417.     bool inRange = false;
  1418.     if (s.x >= 0 && (s.x <= 255))
  1419.       xi = s.x >> 3;
  1420.     if (s.y >= 0 && (s.y <= 255))
  1421.       yi = s.y >> 3;
  1422.     if (xi != -1 && yi != -1)
  1423.       c = xi + yi * 32;
  1424.     if (c != -1){
  1425.         inRange = true;
  1426.         if (map2->map[c].enable != false)  {
  1427.           id = map2->map[c].idInSlot;
  1428.           if (map2->map[c].slot != nullptr)  {
  1429.             page = map2->map[c].slot->id ;
  1430.           }
  1431.         }
  1432.     }
  1433.     rc.Printf (  
  1434.       wxT ("INRANGE:%s BID-%02X(%d) PAGE-%02X(%d) ID:-%02X(%d)"), inRange ? wxT ("true") : wxT ("false"),
  1435.          c, c, page, page, id, id);
  1436.     attach.cs_mainFrame_->GetStatusBar ()->SetLabelText (rc);
  1437.   }
  1438.   void OnMotion_Event (wxMouseEvent & event)
  1439.   {
  1440.     // check drag done.
  1441.     outputBaseInfos ();
  1442.     if ( cls.stop == false && ( attach.cs_mainFrame_->tefcopy != nullptr))  {
  1443.       common :: getMousePos (this, ptPoll);
  1444.       this->Refresh ();
  1445.     } else  {
  1446.       this->Refresh ();
  1447.     }
  1448.   }
  1449.  
  1450.   void OnMouseRButtonDown_Event (wxMouseEvent & event)
  1451.   {
  1452.     cls.stop = false;
  1453.     wxPoint pe;
  1454.     common :: getMousePos (this, pe);
  1455.  
  1456.     tec_local.type = tile_translat::CBG_FROM_CLAY;
  1457.     tec_local.map_ = map2;
  1458.  
  1459.     if (pe.x > 255 || pe.y > 255
  1460.       || pe.x < 0 || pe.y < 0) {
  1461.       cls.collect = false;
  1462.       if (attach.cs_mainFrame_->tefcopy == & tec_local) {
  1463.         attach.cs_mainFrame_->tefcopy = nullptr;
  1464.       }
  1465.     } else  {
  1466.       struct tile_action_rt *p = attach.cs_mainFrame_->umlink;
  1467.       attach.cs_mainFrame_->umlink = nullptr;
  1468.       if (p != nullptr)  p->set_discard ();
  1469.       attach.cs_mainFrame_->umlink = & cls;
  1470.       attach.cs_mainFrame_->Refresh ();
  1471.       cls.collect = true;
  1472.       ptPoll = pe;
  1473.       ptStart = pe;
  1474.       attach.cs_mainFrame_->tefcopy = & tec_local;
  1475.       attach.cs_mainFrame_->tps.copy (*map2);
  1476.     }
  1477.     this->Refresh ();
  1478.   }
  1479.   void OnMouseLButtonDown_Event (wxMouseEvent & event)
  1480.   {
  1481.     wxPoint pe  = wxGetMousePosition ();
  1482.     common :: getMousePos (this, pe);
  1483.  
  1484.     if  (  pe.x >= 0
  1485.         && pe.x <= 255
  1486.        && pe.y >= 0
  1487.        && pe.y <= 255)
  1488.     {
  1489.        // fill rect.
  1490.       tile_translat *tf = attach.cs_mainFrame_->tefcopy;
  1491.       if (tf != nullptr && tf->type == tile_translat::CBG_FROM_CLAY)  {
  1492.         common :: limitBoard (pe);
  1493.         class wxPoint sp;
  1494.         class wxPoint ap;
  1495.         class wxPoint kpc;
  1496.         // limit range.
  1497.         if (pe.x + tf->mapRect.width > 256)
  1498.           sp.x = tf->mapRect.width - ( pe.x + tf->mapRect.width - 256);
  1499.         else
  1500.           sp.x = tf->mapRect.width;
  1501.         if (pe.y + tf->mapRect.height > 256)
  1502.           sp.y = tf->mapRect.height - ( pe.y + tf->mapRect.height - 256);
  1503.         else
  1504.           sp.y = tf->mapRect.height;
  1505.         common :: getRound (pe);
  1506.         ap.x = tf->mapRect.x;
  1507.         ap.y = tf->mapRect.y;
  1508.         struct tileChunkMap *mq = & attach.cs_mainFrame_->tps;
  1509.         struct tileChunkMap mt;
  1510.         if (map2 == tf->map_)  {
  1511.           memcpy (& mt, mq, sizeof (mt));
  1512.           mq = & mt;
  1513.         }
  1514.         for ( kpc.y = 0; kpc.y < sp.y; kpc.y+= 8)  {
  1515.           for (kpc.x = 0; kpc.x < sp.x; kpc.x+= 8)  {
  1516.             class wxPoint sgp (ap);
  1517.             sgp += kpc;
  1518.             common :: getRound (sgp);
  1519.             struct tileChunk *p = & mq->map[sgp.x+sgp.y*32];
  1520.             struct tileChunk *d = & map2->map[kpc.x/8+pe.x+(kpc.y/8+pe.y)*32];
  1521.             if (p->enable == false)
  1522.               continue  ;
  1523.             d->enable = true;
  1524.             d->idInSlot = p->idInSlot;
  1525.             d->slot = p->slot;
  1526.           }
  1527.         }
  1528.         this->Refresh ();
  1529.         return  ;
  1530.       }
  1531.  
  1532.        if (tf != nullptr && tf->type == tile_translat::CBG_FROM_ROOTTEXTURE)  {
  1533.          common :: limitBoard (pe);
  1534.          class wxPoint sp;
  1535.          class wxPoint ap;
  1536.          class wxPoint kpc;
  1537.          // limit range.
  1538.          if (pe.x + tf->mapRect.width > 256)
  1539.            sp.x = tf->mapRect.width - ( pe.x + tf->mapRect.width - 256);
  1540.          else
  1541.            sp.x = tf->mapRect.width;
  1542.          if (pe.y + tf->mapRect.height > 256)
  1543.            sp.y = tf->mapRect.height - ( pe.y + tf->mapRect.height - 256);
  1544.          else
  1545.            sp.y = tf->mapRect.height;
  1546.          common :: getRound (pe);
  1547.          ap.x = tf->mapRect.x;
  1548.          ap.y = tf->mapRect.y;
  1549.          common :: getRound (ap);
  1550.          for ( kpc.y = 0; kpc.y < sp.y; kpc.y+= 8)  {
  1551.              for (kpc.x = 0; kpc.x < sp.x; kpc.x+= 8)  {
  1552.                // to cachemap.
  1553.                class wxPoint ks (kpc);
  1554.                struct imgSlot *pq = tf->slot_;
  1555.                if (pq == nullptr)
  1556.                  continue  ;
  1557.                if (pq->enable == false)
  1558.                  continue  ;
  1559.                common :: getRound (ks);
  1560.                tileChunk *p = & map2->map[ks.x+pe.x+(ks.y+pe.y)*32];
  1561.                p->slot = pq;
  1562.                p->enable = true;
  1563.                p->idInSlot = ap.x + ks.x;
  1564.                p->idInSlot += ( ap.y + ks.y) * 16;
  1565.              }
  1566.          }
  1567.          this->Refresh ();
  1568.          return  ;
  1569.        }
  1570.     }
  1571.     this->Refresh ();
  1572.   }
  1573. public:
  1574.   // ptr to bank.
  1575.   class shared_cs &attach;
  1576.   struct tile_action_rt cls;
  1577.   struct tile_translat tec_local;
  1578.   class wxPoint ptStart;
  1579.   class wxPoint ptPoll;
  1580.   struct tileChunkMap  *map2;
  1581. };
  1582.  
  1583. void cs_mainFrame::OnView_BTexture  (class wxCommandEvent& event) {
  1584.  
  1585.   //  create notebook ctrl.
  1586.   wxUint16 id;
  1587.   fd_ViewRootTexture_ = new wxAuiNotebook (this);
  1588.  
  1589.   // serach rt.
  1590.   for (id = 0; id != sizeof (imgSlot_)/ sizeof (imgSlot_[0]); id++)  {
  1591.     if  (imgSlot_[id].enable == true)  {
  1592.       // append to pane.
  1593.       cs_NotePage *cn = new cs_NotePage (attach, & imgSlot_[id], fd_ViewRootTexture_);
  1594.       wxRect rt (0, 0, imgSlot::image_size_w, imgSlot::image_size_h);
  1595.       cn->SetSize(rt, 0);
  1596.       wxString wxStr;
  1597.       wxStr.Printf (wxT ("PAGE-%02X(%d)"), imgSlot_[id].id, imgSlot_[id].id);
  1598.       cn->SetBackgroundColour ( wxColour (0xd8b166));    // XXX:bgcolour.
  1599.       fd_ViewRootTexture_->AddPage ( cn, wxStr);
  1600.     }
  1601.   }
  1602.   aui_Manager.AddPane ( fd_ViewRootTexture_,
  1603.     wxAuiPaneInfo().Name (wxT ("VIEW-root texture")).Caption (wxT ("VIEW-root texture")).
  1604.     Right().Layer(0).Position(0).
  1605.     Icon (wxBitmap (g_xpmopgptex)));
  1606.   GetMenuBar()->Enable (wxID_BTEXTURE, false);
  1607.   aui_Manager.GetPane (fd_ViewRootTexture_).DestroyOnClose (true);
  1608.   // tell the manager to "commit" all the changes just made
  1609.   fd_ViewRootTexture_->Layout();
  1610.   aui_Manager.Update();
  1611. }
  1612.  
  1613. void cs_mainFrame::OnView_Clay  (class wxCommandEvent& event) {
  1614.  
  1615.   //  dummy notebook ctrl.
  1616.   fd_ViewClaySet_ = new wxAuiNotebook (this);
  1617.  
  1618.   std::list <tileChunkMap *>::iterator iter;
  1619.  
  1620.   for (iter = fmset.begin(); iter != fmset.end(); iter++)  
  1621.   {  
  1622.     cs_NotePage2 *cn = new cs_NotePage2 (attach, *iter, fd_ViewClaySet_, wxID_ANY );
  1623.     cn->SetSize(wxRect (0, 0, 256, 256), 0);
  1624.     cn->SetBackgroundColour ( wxColour (0xd8b166));
  1625.     fd_ViewClaySet_->AddPage ( cn, ( (*iter)->desc != nullptr ? *(*iter)->desc : wxT ("noname")));
  1626.   }  
  1627.   aui_Manager.AddPane ( fd_ViewClaySet_,
  1628.     wxAuiPaneInfo().Name (wxT ("VIEW-clay texture")).Caption (wxT ("VIEW-clay texture")).
  1629.     Right().Layer(0).Position(0).
  1630.     Icon (wxBitmap (g_xpmopgpclay)));
  1631.   GetMenuBar()->Enable (wxID_CLAY, false);
  1632.   aui_Manager.GetPane (fd_ViewClaySet_).DestroyOnClose (true);
  1633.   // tell the manager to "commit" all the changes just made
  1634.   fd_ViewClaySet_->Layout();
  1635.   aui_Manager.Update();
  1636. }
  1637.  
  1638. // load texture.
  1639.  
  1640. void cs_mainFrame::OnFile_LoadImage (class wxCommandEvent& event)  {
  1641.  
  1642.   wxString caption = wxString ("choose texture.");
  1643.   wxString wildcard = wxString ("BMP files(*.bmp)|*.bmp|JPG files(*.jpg)|*.jpg|JPEG files(*.jpeg)|*.jpeg|PNG files(*.png)|*.png");
  1644.   wxString defaultfn = wxEmptyString;
  1645.   wxFileDialog  dialog  (this, caption, wxEmptyString, wxEmptyString, wildcard, wxFD_OPEN);
  1646.   if ( dialog.ShowModal () == wxID_OK)  {
  1647.     wxString Path = dialog.GetPath ();
  1648.     int fid = dialog.GetFilterIndex ();
  1649.     // check image.
  1650.     wxBitmap img;
  1651.     if ( img.LoadFile (Path, wxBITMAP_TYPE_ANY) != false) {
  1652.       wxSize s = img.GetSize ();
  1653.       if ( ! ( s.x == imgSlot::image_size_w && (s.y == imgSlot::image_size_h))) {
  1654.         // size unmatch.
  1655.         wxString e;
  1656.         e.Printf (wxT ("errors:load texture failed"));
  1657.         StatusOutWrap (e);
  1658.         e.Printf (wxT ("reason:unmatch image size"));
  1659.         StatusOutWrap (e);
  1660.         e.Printf (wxT ("size-x:%d size-y:%d"), s.x, s.y);
  1661.         StatusOutWrap (e);
  1662.         e.Printf (wxT ("file:%s"), Path);
  1663.         StatusOutWrap (e);
  1664.         StatusShowText();
  1665.         return ;
  1666.       }
  1667.       // read it. size 128*128
  1668.       // set page and misc.
  1669.       wxNumberEntryDialog s2 ( this, wxT ("Please set current page"),
  1670.         wxT ("Enter a number:"), wxT ("Page Select"), 0, 0, 255);
  1671.       if (s2.ShowModal () == wxID_OK) {
  1672.         long nums = s2.GetValue ();
  1673.         // serach exist empty chunk..
  1674.         imgSlot *ptr = nullptr;
  1675.         bool s = false;
  1676.         for  (int id = 0; id != sizeof (imgSlot_)/ sizeof (imgSlot_[0]); id++)  {
  1677.           if (imgSlot_[id].enable != false)  {
  1678.             if  (imgSlot_[id].id == nums) {
  1679.               // find chunk.
  1680.               // do repleace.
  1681.               wxWindowID q = wxMessageBox ( wxT ("current page exist object, continue?"), wxT ("Page select"), wxOK | wxCENTER | wxCANCEL);
  1682.               if (q == wxCANCEL)
  1683.                 return  ;
  1684.               else  ;
  1685.               s = true;
  1686.               ptr = & imgSlot_[id];
  1687.               break;
  1688.             }
  1689.           } else  {
  1690.             if (ptr == nullptr)
  1691.               ptr = & imgSlot_[id];
  1692.             else ;
  1693.           }
  1694.         }
  1695.  
  1696.         assert (ptr != nullptr);
  1697.         ptr->uninit ();
  1698.         ptr->enable = true;
  1699.         ptr->id = nums;
  1700.         ptr->img = new wxBitmap (img);
  1701.         wxImage c = ptr->img->ConvertToImage();
  1702.         ptr->img2 = new wxImage (c);
  1703.         ptr->strPath = new wxString (Path);
  1704.        
  1705.         if (s != false && (fd_ViewRootTexture_ != nullptr))  {
  1706.           for  (int id = 0; id != fd_ViewRootTexture_->GetPageCount (); id++)  {
  1707.             cs_NotePage *cs = (cs_NotePage *) fd_ViewRootTexture_->GetPage (id);
  1708.             if (cs->pc_bank == ptr)  {
  1709.               fd_ViewRootTexture_->DeletePage (id);
  1710.               break  ;
  1711.             }
  1712.           }
  1713.         }
  1714.         if  (fd_ViewRootTexture_ != nullptr)  {
  1715.           // append item. to notebook.
  1716.           cs_NotePage *cn = new cs_NotePage (attach, ptr, fd_ViewRootTexture_, wxID_ANY);
  1717.           cn->SetBackgroundColour ( wxColour (0xd8b166));
  1718.           cn->SetSize (wxRect (0, 0, imgSlot::image_size_w, imgSlot::image_size_h), 0);
  1719.           wxString wxStr;
  1720.           wxStr.Printf (wxT ("PAGE-%02X(%d)"), ptr->id, ptr->id);
  1721.           fd_ViewRootTexture_->AddPage ( cn, wxStr);
  1722.         }
  1723.         return ;
  1724.       }
  1725.     }
  1726.     // file read fail.
  1727.     wxString e;
  1728.     e.Printf (wxT ("errors:load texture failed"));
  1729.     StatusOutWrap (e);
  1730.     e.Printf (wxT ("reason:load texture failed"));
  1731.     StatusOutWrap (e);
  1732.     e.Printf (wxT ("file:%s"), Path);
  1733.     StatusOutWrap (e);
  1734.     StatusShowText();
  1735.     return ;
  1736.   }
  1737. }
  1738.  
  1739. void cs_mainFrame::OnFile_ClayAdd (class wxCommandEvent& event) {
  1740.  
  1741.   wxDialog T (this, wxID_ANY, wxT ("Add Clay"), wxPoint (0, 0), wxSize (160, 80) );
  1742.   wxButton butOk (& T, wxID_OK, wxT ("OK"), wxPoint (4, 24), wxSize (60, 24));
  1743.   wxButton butCancel (& T, wxID_CANCEL, wxT ("CANCEL"), wxPoint (80, 24), wxSize (60, 24));
  1744.   wxTextCtrl textCtlPageDesc (& T, wxID_ANY, wxEmptyString, wxPoint (80, 4), wxSize (60, 19));
  1745.   wxStaticText textSetPageDesc (& T, wxID_ANY, wxT ("clay desc"), wxPoint (4, 4));
  1746.  
  1747.   // set range.
  1748.  
  1749.   T.SetIcon ( wxIcon ( g_xpmopgpclay));
  1750.   T.CenterOnParent ();
  1751.   int msgid = T.ShowModal();
  1752.   if (msgid == wxID_OK) {
  1753.     // append to list.
  1754.     tileChunkMap *cmap = new tileChunkMap;
  1755.     cmap->init();
  1756.     cmap->desc = nullptr;
  1757.     wxString s = textCtlPageDesc.GetValue ();
  1758.     if (s.size() > 0)
  1759.       cmap->desc = new wxString (s);
  1760.     else
  1761.       cmap->desc = new wxString ("noname");
  1762.     fmset.push_front (cmap);
  1763.     // cs_NotePage2 *cn = new cs_NotePage2 (attach, *iter, fd_ViewClaySet_, wxID_ANY );
  1764.     if  (fd_ViewClaySet_ != nullptr)  {
  1765.       // append item. to notebook.
  1766.       cs_NotePage2 *cn = new cs_NotePage2 (attach, cmap, fd_ViewClaySet_, wxID_ANY);
  1767.       cn->SetBackgroundColour ( wxColour (0xd8b166));
  1768.       cn->SetSize (wxRect (0, 0, 256, 256), 0);
  1769.       wxString wxStr;
  1770.       wxStr.Printf (wxT ("PAGE-%02s(%d)"));
  1771.       fd_ViewClaySet_->AddPage ( cn, *cmap->desc);
  1772.     }
  1773.     // new cs_PageTileTab (attach, note_tab2, wxID_PAGE_NEW, spinWidth.GetValue (), spinHeight.GetValue (),textCtlPageDesc.GetValue ()  );
  1774.   }
  1775. }
  1776.  
  1777. void  cs_mainFrame::OnView_Close  (wxAuiManagerEvent& event) {
  1778.  
  1779.   if (event.GetPane()->window == fd_ViewStatus_) {
  1780.     fd_ViewStatus_ = nullptr;
  1781.     attach.cs_ViewStatus_ = nullptr;
  1782.     GetMenuBar()->Enable (wxID_STATUS_OUTPUT, true);
  1783.   } else if ( event.GetPane()->window ==  fd_ViewRootTexture_) {
  1784.     fd_ViewRootTexture_ = nullptr;
  1785.     attach.cs_ViewRootTexture_ = nullptr;
  1786.     GetMenuBar()->Enable (wxID_BTEXTURE, true);
  1787.   } else if ( event.GetPane()->window ==  fd_ViewClaySet_) {
  1788.     fd_ViewClaySet_ = nullptr;
  1789.     attach.cs_ViewClaySet_ = nullptr;
  1790.     GetMenuBar()->Enable (wxID_CLAY, true);
  1791.   }
  1792. }
  1793.  
  1794. cs_mainFrame::cs_mainFrame (wxWindow* parent)
  1795.   : wxFrame (parent, wxID_ANY, wxT ("tilemap_editors")), attach (share_cs_)
  1796. {
  1797.   // clear attach .
  1798.   umlink = nullptr;
  1799.   tefcopy = nullptr;
  1800.  
  1801.   // init mgr solt.
  1802.   wxUint16 id;
  1803.   for  (id = 0; id != sizeof (imgSlot_)/ sizeof (imgSlot_[0]); id++) {
  1804.     imgSlot_[id].init ();
  1805.   }
  1806.  
  1807.   // init view assert .
  1808.   fd_mainFrame_ = nullptr;
  1809.   fd_ViewStatus_ = nullptr;
  1810.   fd_ViewGlobalZoom_ = nullptr;
  1811.   fd_ViewRootTexture_ = nullptr;
  1812.   fd_ViewClaySet_ = nullptr;
  1813.   fd_ViewPixel_ = nullptr;
  1814.  
  1815.   tps.init ();
  1816.   attach.cs_mainFrame_ = this;
  1817.   ctab = nullptr;
  1818.  
  1819.   // init menu.
  1820.   wxMenuBar *menubar = new wxMenuBar;
  1821.   wxMenu *submenu;
  1822.  
  1823.   submenu = new wxMenu;
  1824.   wxMenuItem *subitem = new wxMenuItem (submenu, wxID_LOAD_TEXTURE, wxT ("&load texture\tCtrl-Q"), wxT ("Read 128 square tile texture."));
  1825.   subitem->SetBitmap (wxBitmap (g_xpmoptex));
  1826.   submenu->Append (subitem);
  1827.   subitem = new wxMenuItem (submenu, wxID_LOAD_SETTINGS, wxT ("&load settings\tCtrl-T"), wxT ("Read environment configuration files."));
  1828.   subitem->SetBitmap (wxBitmap (g_xpmldset));
  1829.   submenu->Append (subitem);
  1830.   subitem = new wxMenuItem (submenu, wxID_SAVE_SETTINGS, wxT ("&save settings\tCtrl-C"), wxT ("Save environment configuration files."));
  1831.   subitem->SetBitmap (wxBitmap (g_xpmstset));
  1832.   submenu->Append (subitem);
  1833.   submenu->AppendSeparator ();
  1834.   subitem = new wxMenuItem (submenu, wxID_PAGE_SETTINGS, wxT ("&page settings\tCtrl-V"), wxT ("Current tile map edit"));
  1835.   subitem->SetBitmap (wxBitmap (g_xpmadjust_a));
  1836.   submenu->Append (subitem);
  1837.   subitem = new wxMenuItem (submenu, wxID_PAGE_NEW, wxT ("&page new\tCtrl-D"), wxT ("Alloc new tile-map page"));
  1838.   subitem->SetBitmap (wxBitmap (g_xpmpage_new));
  1839.   submenu->Append (subitem);
  1840.   subitem = new wxMenuItem (submenu, wxID_PAGE_CLOSE, wxT ("&page close\tCtrl-R"), wxT ("Close current tile-map page"));
  1841.   subitem->SetBitmap (wxBitmap (g_xpmpage_close));
  1842.   submenu->Append (subitem);
  1843.   subitem = new wxMenuItem (submenu, wxID_PAGE_SAVE, wxT ("&page save\tCtrl-E"), wxT ("Save tile-map files."));
  1844.   subitem->SetBitmap (wxBitmap (g_xpmstchr));
  1845.   submenu->Append (subitem);
  1846.   subitem = new wxMenuItem (submenu, wxID_CLAY_ADD, wxT ("&clay add\tCtrl-Z"), wxT ("Add clay files."));
  1847.   subitem->SetBitmap (wxBitmap (g_xpmopgpclay));
  1848.   submenu->Append (subitem);
  1849.   submenu->AppendSeparator ();
  1850.   subitem = new wxMenuItem (submenu, wxID_EXIT, wxT ("&exit\tCtrl-A"), wxT ("Exit ."));
  1851.   subitem->SetBitmap (wxBitmap (g_xpmopexit));
  1852.   submenu->Append (subitem);
  1853.   menubar->Append (submenu, wxT ("&File"));
  1854.  
  1855.   submenu = new wxMenu;
  1856.   subitem = new wxMenuItem (submenu, wxID_GVIEW, wxT ("&gview\tCtrl-S"), wxT ("Thumbnail previews"));
  1857.   subitem->SetBitmap (wxBitmap (g_xpmopgview));
  1858.   submenu->Append (subitem);
  1859.   submenu->AppendSeparator ();
  1860.   subitem = new wxMenuItem (submenu, wxID_BTEXTURE, wxT ("&basetexture\tCtrl-B"), wxT ("128 square tile texture."));
  1861.   subitem->SetBitmap (wxBitmap (g_xpmopgptex));
  1862.   submenu->Append (subitem);
  1863.   subitem = new wxMenuItem (submenu, wxID_CLAY, wxT ("&clay\tCtrl-L"), wxT ("Mixed tile set."));
  1864.   subitem->SetBitmap (wxBitmap (g_xpmopgpclay));
  1865.   submenu->Append (subitem);
  1866.   submenu->AppendSeparator ();
  1867.   subitem = new wxMenuItem (submenu, wxID_STATUS_OUTPUT, wxT ("&status output\tCtrl-O"), wxT ("Same as name."));
  1868.   subitem->SetBitmap (wxBitmap (g_xpmopgstatout));
  1869.   submenu->Append (subitem);
  1870.   submenu->AppendSeparator ();
  1871.   subitem = new wxMenuItem (submenu, wxID_PIXEL, wxT ("&pixel\tCtrl-M"), wxT ("Pixel status ."));
  1872.   subitem->SetBitmap (wxBitmap (g_xpmopgpixel));
  1873.   submenu->Append (subitem);
  1874.   menubar->Append (submenu, wxT ("&View"));
  1875.  
  1876.   submenu = new wxMenu;
  1877.   subitem = new wxMenuItem (submenu, wxID_ABOUT_WXWIDGETS, wxT ("&wxWidgets\tCtrl-U"), wxT ("About wxWidgets framework."));
  1878.   subitem->SetBitmap (wxBitmap (g_xpmop_wxwidgets));
  1879.   submenu->Append (subitem);
  1880.   subitem = new wxMenuItem (submenu, wxID_ABOUT_EDITORS, wxT ("&tilemap editors\tCtrl-G"), wxT ("About program."));
  1881.   subitem->SetBitmap (wxBitmap (g_xpmop_tilemap));
  1882.   submenu->Append (subitem);
  1883.   menubar->Append (submenu, wxT ("&About"));
  1884.  
  1885.   this->SetMenuBar (menubar);
  1886.   this->CreateStatusBar();
  1887.   this->Maximize ();
  1888.   this->note_tab2 = new cs_PageTile (attach, this);
  1889.   // this->note_tab2->SetArtProvider (new wxAuiSimpleTabArt ());
  1890.   this->note_tab2->Hide();
  1891.  
  1892.   aui_Manager.SetManagedWindow (this);
  1893.   aui_Manager.SetFlags ( wxAUI_MGR_ALLOW_FLOATING | wxAUI_MGR_VENETIAN_BLINDS_HINT | wxAUI_MGR_ALLOW_ACTIVE_PANE);
  1894.   aui_Manager.SetArtProvider (new wxAuiDefaultDockArt);
  1895.   aui_Manager.AddPane(this->note_tab2, wxCENTER);
  1896.   wxColour s;
  1897.   s.SetRGB (0x00ff13);
  1898.   aui_Manager.GetArtProvider()->SetColor (wxAUI_DOCKART_BORDER_COLOUR, s);
  1899.   s.SetRGB (0xff6600);
  1900.   aui_Manager.GetArtProvider()->SetColor (wxAUI_DOCKART_ACTIVE_CAPTION_COLOUR, s);
  1901.   s.SetRGB (0xdb844b);
  1902.   aui_Manager.GetArtProvider()->SetColor (wxAUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR, s);
  1903.  
  1904.   // tell the manager to "commit" all the changes just made
  1905.   aui_Manager.Update();
  1906.   StatusOutWrap (wxString ("init success..."));
  1907. }
  1908.  
  1909. void cs_mainFrame::OnView_StatusOutput  (class wxCommandEvent& event) {
  1910.  
  1911.   // init status out [only text ctrl]
  1912.   fd_ViewStatus_ = new cs_ViewStatus (share_cs_, this, wxID_ANY, wxT (""),
  1913.     wxDefaultPosition, wxSize (200,150),
  1914.     wxTE_MULTILINE);
  1915.   StatusShowText ();
  1916.   // disable it.
  1917.   // set panel .
  1918.   aui_Manager.AddPane ( fd_ViewStatus_,
  1919.     wxAuiPaneInfo().Name (wxT ("VIEW-status output")).Caption (wxT ("VIEW-status output")).
  1920.     Right().Layer(0).Position(0).
  1921.     Icon (wxBitmap (g_xpmopgstatout)));
  1922.   aui_Manager.GetPane (fd_ViewStatus_).DestroyOnClose (true);
  1923.   aui_Manager.Update ();
  1924.   GetMenuBar()->Enable (wxID_STATUS_OUTPUT, false);
  1925. }
  1926.  
  1927. // wxSmith.
  1928. class pageSettingsDialog: public wxDialog
  1929. {
  1930.     public:
  1931.         pageSettingsDialog (wxWindow* parent,wxWindowID id, tileChunkSet * cs, cs_mainFrame *ce);
  1932.     public:
  1933.         void CheckMtx (wxWindowID secid, wxCheckBox **ppBlock, int n) {
  1934.           for (int id =0 ; id != n; id++)  {
  1935.             if (ppBlock[id]->GetId () == secid)  {
  1936.               bool c = ppBlock[id]->IsChecked ();
  1937.               if (c == false)  {
  1938.                 // dis false.
  1939.                 ppBlock[id]->SetValue (true);
  1940.                 return  ;
  1941.               }
  1942.               // canel other.
  1943.               for (int id =0 ; id != n; id++)  {
  1944.                 if (ppBlock[id]->GetId () != secid)
  1945.                   ppBlock[id]->SetValue (false);
  1946.                 else  ;
  1947.               }
  1948.               return  ;
  1949.             }
  1950.           }
  1951.         }
  1952.         void On_CheckMtxOnCtl_Event (wxCommandEvent& event) {
  1953.  
  1954.           wxCheckBox *pg[3] = { checkBox_disall, checkBox_saveold, checkBox_fill };
  1955.           CheckMtx (event.GetId (), & pg[0], sizeof (pg)/ sizeof (pg[0]));
  1956.         }
  1957.         void On_CheckMtxOnH_Event (wxCommandEvent& event) {
  1958.  
  1959.           wxCheckBox *pg[2] = { checkBox_addh, checkBox_subh };
  1960.           CheckMtx (event.GetId (), & pg[0], sizeof (pg)/ sizeof (pg[0]));
  1961.         }
  1962.         void On_CheckMtxOnV_Event (wxCommandEvent& event) {
  1963.  
  1964.           wxCheckBox *pg[2] = { checkBox_addv, checkBox_subv };
  1965.           CheckMtx (event.GetId (), & pg[0], sizeof (pg)/ sizeof (pg[0]));
  1966.         }
  1967.  
  1968.         static const long wxID_DISALL;
  1969.         static const long wxID_SAVEOLD;
  1970.         static const long wxID_FILL;
  1971.         static const long wxID_SETPAGE;
  1972.         static const long wxID_SETLAND;
  1973.         static const long wxID_ADDH;
  1974.         static const long wxID_SUBH;
  1975.         static const long wxID_SETBPOSH;
  1976.         static const long wxID_SETBVOLH;
  1977.         static const long wxID_ADDV;
  1978.         static const long wxID_SUBV;
  1979.         static const long wxID_SETBPOSV;
  1980.         static const long wxID_SETBVOLV;
  1981.         //*)
  1982.  
  1983.         //(*Declarations(pageSettingsDialog)
  1984.         wxCheckBox *checkBox_disall;
  1985.         wxCheckBox *checkBox_saveold;
  1986.         wxCheckBox *checkBox_fill;
  1987.         wxCheckBox *checkBox_addh;
  1988.         wxCheckBox *checkBox_subh;
  1989.         wxCheckBox *checkBox_addv;
  1990.         wxCheckBox *checkBox_subv;
  1991.  
  1992.         DECLARE_EVENT_TABLE()
  1993. };
  1994.  
  1995. //(*IdInit(pageSettingsDialog)
  1996. const long pageSettingsDialog::wxID_DISALL = wxNewId();
  1997. const long pageSettingsDialog::wxID_SAVEOLD = wxNewId();
  1998. const long pageSettingsDialog::wxID_FILL = wxNewId();
  1999. const long pageSettingsDialog::wxID_SETPAGE = wxNewId();
  2000. const long pageSettingsDialog::wxID_SETLAND = wxNewId();
  2001. const long pageSettingsDialog::wxID_ADDH = wxNewId();
  2002. const long pageSettingsDialog::wxID_SUBH = wxNewId();
  2003. const long pageSettingsDialog::wxID_ADDV = wxNewId();
  2004. const long pageSettingsDialog::wxID_SUBV = wxNewId();
  2005. //*)
  2006.  
  2007. BEGIN_EVENT_TABLE(pageSettingsDialog,wxDialog)
  2008.   EVT_CHECKBOX (wxID_DISALL, On_CheckMtxOnCtl_Event)
  2009.   EVT_CHECKBOX (wxID_SAVEOLD, On_CheckMtxOnCtl_Event)
  2010.   EVT_CHECKBOX (wxID_FILL, On_CheckMtxOnCtl_Event)
  2011.   EVT_CHECKBOX (wxID_ADDH, On_CheckMtxOnH_Event)
  2012.   EVT_CHECKBOX (wxID_SUBH, On_CheckMtxOnH_Event)
  2013.   EVT_CHECKBOX (wxID_ADDV, On_CheckMtxOnV_Event)
  2014.   EVT_CHECKBOX (wxID_SUBV, On_CheckMtxOnV_Event)
  2015. END_EVENT_TABLE()
  2016.  
  2017. pageSettingsDialog::pageSettingsDialog (wxWindow* parent, wxWindowID id, tileChunkSet * cs, cs_mainFrame *ce)
  2018. {
  2019.   Create (parent, wxID_ANY, wxT("pagesettings"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, wxT("wxID_ANY"));
  2020.   SetClientSize (wxSize(402,285));
  2021.   wxString csHeight, csWidth ;
  2022.   csWidth.Printf (wxT ("%d"), cs->hnums);
  2023.   csHeight.Printf (wxT ("%d"), cs->vnums);
  2024.  
  2025.   new wxTextCtrl (this, wxID_ANY, csWidth, wxPoint(80,40), wxDefaultSize, wxTE_READONLY);
  2026.   new wxStaticText (this, wxID_ANY, wxT("width"), wxPoint(32,40), wxSize(40,14));
  2027.   new wxStaticText (this, wxID_ANY, wxT("height"), wxPoint(32,72));
  2028.   new wxTextCtrl (this, wxID_ANY, csHeight, wxPoint(80,72), wxDefaultSize, wxTE_READONLY);
  2029.   new wxStaticBox (this, wxID_ANY, wxT("H-VEC"), wxPoint(240,16), wxSize(128,96));
  2030.   new wxStaticBox (this, wxID_ANY, wxT("ctrl"), wxPoint(16,24), wxSize(192,136));
  2031.   new wxStaticBox (this, wxID_ANY, wxT("V-VEC"), wxPoint(248,120), wxSize(136,96));
  2032.   new wxStaticLine (this, wxID_ANY, wxPoint(16,232), wxSize(368,-1));
  2033.   new wxButton (this, wxID_OK, wxT("OK"), wxPoint(240,248), wxSize(64,24));
  2034.   new wxButton (this, wxID_CANCEL, wxT("CANCEL"), wxPoint(320,248), wxSize(67,24));
  2035.  
  2036.     // check box add.
  2037.   (checkBox_disall = new wxCheckBox (this, wxID_DISALL, wxT("disall"), wxPoint(32,104)))->SetValue (true);
  2038.   (checkBox_saveold = new wxCheckBox (this, wxID_SAVEOLD, wxT("old"), wxPoint(32,120)))->SetValue (false);
  2039.   (checkBox_fill = new wxCheckBox (this, wxID_FILL, wxT("fill"), wxPoint(32,136)))->SetValue (false);
  2040.   (checkBox_addv = new wxCheckBox (this, wxID_ADDV, wxT("+"), wxPoint(296,136)))->SetValue (true);
  2041.   (checkBox_subv = new wxCheckBox (this, wxID_SUBV, wxT("-"), wxPoint(336,136)))->SetValue (false);
  2042.   (checkBox_addh = new wxCheckBox (this, wxID_ADDH, wxT("+"), wxPoint(288,32)))->SetValue (true);
  2043.   (checkBox_subh = new wxCheckBox (this, wxID_SUBH, wxT("-"),  wxPoint(328,32)))->SetValue (false);
  2044.   // spin ctrl add.
  2045.   wxSpinCtrl *spc_SetPage = new wxSpinCtrl (this, wxID_ANY, wxT("0"), wxPoint(144,104), wxSize(56,22), 0, 0, 255, 0);
  2046.   wxSpinCtrl *spc_SetLand = new wxSpinCtrl (this, wxID_ANY, wxT("0"), wxPoint(144,128), wxSize(56,22), 0, 0, 255, 0);
  2047.   wxSpinCtrl *spc_SetBposH = new wxSpinCtrl (this, wxID_ANY, wxT("0"), wxPoint(296,56), wxSize(64,16), 0, 0, 65535, 0);
  2048.   wxSpinCtrl *spc_SetVolH = new wxSpinCtrl (this, wxID_ANY, wxT("0"), wxPoint(296,88), wxSize(64,16), 0, 0, 65535, 0);
  2049.   wxSpinCtrl *spc_SetBposV = new wxSpinCtrl (this, wxID_ANY, wxT("0"), wxPoint(300,156), wxSize(80,24), 0, 0, 65535, 0);
  2050.   wxSpinCtrl *spc_SetVolV = new wxSpinCtrl (this, wxID_ANY, wxT("0"), wxPoint(300,188), wxSize(80,22), 0, 0, 65535, 0);
  2051.   // some misctextg.
  2052.   new wxStaticText (this, wxID_ANY, wxT("page"), wxPoint(96,104), wxSize(40,14));
  2053.   new wxStaticText (this, wxID_ANY, wxT("land"), wxPoint(96,128), wxSize(30,14));
  2054.   new wxStaticText (this, wxID_ANY, wxT("phase"), wxPoint(248,32));
  2055.   new wxStaticText (this, wxID_ANY, wxT("bpos b"), wxPoint(248,56));
  2056.   new wxStaticText (this, wxID_ANY, wxT("volume"), wxPoint(248,88));
  2057.   new wxStaticText (this, wxID_ANY, wxT("phase"), wxPoint(256,136));
  2058.   new wxStaticText (this, wxID_ANY, wxT("bpos b"), wxPoint(256,152));
  2059.   new wxStaticText (this, wxID_ANY, wxT("volume"), wxPoint(256,184));
  2060.  
  2061.   SetIcon (wxIcon (g_xpmadjust_a));
  2062.   if ( ShowModal () == wxID_OK)  {
  2063.     // adjust page attr/size.
  2064.     bool bHAdd = checkBox_addh->GetValue ();
  2065.     bool bVAdd = checkBox_addv->GetValue ();
  2066.     bool bSaveOld  = checkBox_saveold->GetValue ();
  2067.     bool bDiscard = checkBox_disall->GetValue ();
  2068.     bool bSetPage = checkBox_fill->GetValue ();
  2069.     int nHPos = spc_SetBposH->GetValue ();
  2070.     int nHVolume = spc_SetVolH->GetValue ();
  2071.     int nVPos = spc_SetBposV->GetValue ();
  2072.     int nVVolume = spc_SetVolV->GetValue ();
  2073.     int nHNewVol = cs->hnums + (bHAdd ? nHVolume : -nHVolume);
  2074.     int nVNewVol = cs->vnums + (bVAdd ? nVVolume : -nVVolume);
  2075.     int clearRangeLeftH = nHPos;
  2076.     int clearRangeRightH = nHPos + nHVolume - 1;
  2077.     int clearRangeLeftV = nVPos;
  2078.     int clearRangeRightV = nVPos + nVVolume - 1;
  2079.     wxUint8 page = spc_SetPage->GetValue ();
  2080.     wxUint8 land = spc_SetLand->GetValue ();
  2081.     // TODO:check,
  2082.     tileChunkMap *ppBlock = new tileChunkMap [nHNewVol * nVNewVol];
  2083.     if (bDiscard != false)  goto LLCC;
  2084.     // copy. hori .
  2085.     for (int y = 0, ptY = 0; y != (bVAdd ? nVNewVol : cs->vnums); y ++)  {
  2086.       if (!  (y >= clearRangeLeftV && (y <= clearRangeRightV)))  {
  2087.         int ats = y;
  2088.         int atd = ptY;
  2089.         int mts = nHNewVol;
  2090.         int mtd = cs->hnums;
  2091.         if  (bVAdd != false)  {
  2092.             // small -> big
  2093.           ats = ptY;
  2094.           atd = y;
  2095.           mts = cs->hnums;
  2096.           mtd = nHNewVol;
  2097.         }  
  2098.         for (int x = 0, ptX = 0; x != (bHAdd ? nHNewVol : cs->hnums); x ++)  {
  2099.           // check range??
  2100.           if (!  (x >= clearRangeLeftH && (x <= clearRangeRightH)))  {
  2101.             int cts = x;
  2102.             int ctd = ptX;
  2103.  
  2104.             if  (bHAdd != false)  {
  2105.               // small -> big
  2106.               cts = ptX;
  2107.               ctd = x;            
  2108.             }  
  2109.  
  2110.             int s = cts + ats * mts;
  2111.             int d = ctd + atd * mtd;
  2112.             if (bSetPage == false)
  2113.               ppBlock [d].copy (cs->tcm[s]);
  2114.             else  
  2115.               ppBlock [d].copy (cs->tcm[s], ce->getSlotByID (page), land);
  2116.             ptX ++;
  2117.           }
  2118.         }
  2119.         ptY ++;
  2120.       }
  2121.     }
  2122. LLCC: delete [] cs->tcm;
  2123.     cs->hnums = nHNewVol;
  2124.     cs->vnums = nVNewVol;
  2125.     cs->tcm = ppBlock;
  2126.   }
  2127. }
  2128.  
  2129. void cs_mainFrame::OnFile_PageSettings  (class wxCommandEvent& event) {
  2130.  
  2131.   if (this->ctab == nullptr)  {
  2132.     wxMessageBox (wxT ("no attach page"), wxT ("tilemap editors"), wxICON_WARNING);
  2133.     return  ;
  2134.   }
  2135.   wxSizeEvent e;
  2136.   pageSettingsDialog p (this, wxID_ANY, & this->ctab->chunkset, this);
  2137.   this->ctab->OnSize_Event (e);
  2138.   this->ctab->XorBgColor ();
  2139.   return ;
  2140. }
  2141.  
  2142. void cs_mainFrame::OnFile_PageNew  (class wxCommandEvent& event) {
  2143.  
  2144.   wxDialog T (this, wxID_ANY, wxT ("Add Page"), wxPoint (0, 0), wxSize (160, 140) );
  2145.   wxButton butOk (& T, wxID_OK, wxT ("OK"), wxPoint (4, 80), wxSize (60, 24));
  2146.   wxButton butCancel (& T, wxID_CANCEL, wxT ("CANCEL"), wxPoint (80, 80), wxSize (60, 24));
  2147.   wxSpinCtrl spinWidth (& T, wxID_ANY, wxEmptyString, wxPoint (104, 6), wxSize (48, 19));
  2148.   wxSpinCtrl spinHeight (& T, wxID_ANY, wxEmptyString, wxPoint (104, 30), wxSize (48, 19));
  2149.   wxTextCtrl textCtlPageDesc (& T, wxID_ANY, wxEmptyString, wxPoint (76, 54), wxSize (60, 19));
  2150.   wxStaticText textSetWidth (& T, wxID_ANY, wxT ("set page width"), wxPoint (4, 6));
  2151.   wxStaticText textSetHeight (& T, wxID_ANY, wxT ("set page height"), wxPoint (4, 30));
  2152.   wxStaticText textSetPageDesc (& T, wxID_ANY, wxT ("page desc"), wxPoint (4, 54));
  2153.   wxStaticLine lineSper (& T, wxID_ANY, wxPoint (4, 75), wxSize (144,-1));
  2154.  
  2155.   // set range.
  2156.   spinWidth.SetRange (1, 0xFFFF);
  2157.   spinHeight.SetRange (1, 0xFFFF);
  2158.  
  2159.   T.SetIcon ( wxIcon ( g_xpmpage_new));
  2160.   T.CenterOnParent ();
  2161.   int msgid = T.ShowModal();
  2162.   if (msgid == wxID_OK) {
  2163.     // ctab =
  2164.     new cs_PageTileTab (attach, note_tab2, wxID_PAGE_NEW, spinWidth.GetValue (), spinHeight.GetValue (),textCtlPageDesc.GetValue ()  );
  2165.   }
  2166. }
  2167.  
  2168. void cs_mainFrame::OnAbout_wxWidgets (class wxCommandEvent& event) {
  2169.  
  2170.   wxDialog T (this, wxID_ANY, wxT ("About wxWidgets"));
  2171.  
  2172.   T.SetBackgroundColour ( wxSystemSettings::GetColour (wxSYS_COLOUR_WINDOW));
  2173.   T.SetSize (590, 500);
  2174.   T.SetIcon ( wxIcon ( g_xpmop_wxwidgets));
  2175.   T.CenterOnParent ();
  2176.  
  2177.   // set bitmap.
  2178.   wxBitmap q (g_xpmwxwidgets_page, wxBITMAP_TYPE_XPM);
  2179.   wxBitmap q2 (g_xpmwxWidgets, wxBITMAP_TYPE_XPM);
  2180.  
  2181.   wxStaticBitmap p (& T, wxID_ANY, q, wxPoint (0, 0) );
  2182.   wxStaticBitmap p2  (& T, wxID_ANY, q2, wxPoint (0, 430) );
  2183.  
  2184.   // set text .
  2185.   wxChar *e =  wxT ( "wxWidgets was started in 1992 by Julian Smart at the University of Edinburgh.\n")
  2186.                wxT ( "Initially started as a project for creating applications that were\n")
  2187.                wxT ( "portable across Unix and Windows, it has grown to support Mac OS u, GTK+,\n")
  2188.                wxT ( "and many other toolkits and platforms (see the history page for more details).\n")
  2189.                wxT ( "The number of developers contributing to the project is now in the hundreds\n")
  2190.                wxT ( "and the toolkit has a strong userbase that includes everyone from open\n")
  2191.                wxT ( "source developers to corporations. So what is special about wxWidgets compared with other cross-platform GUI toolkits?\n\n")
  2192.                wxT ( "wxWidgets gives you a single, easy-to-use API for writing GUI applications on\n")
  2193.                wxT ( "multiple platforms that still utilize the native platform’s controls and utilities.\n")
  2194.                wxT ( "Link with the appropriate library for your platform and compiler, and your application\n")
  2195.                wxT ( "will adopt the look and feel appropriate to that platform. On top of great GUI functionality,\n")
  2196.                wxT ( "wxWidgets gives you: online help, network programming, streams, clipboard and drag and drop, multithreading,\n")
  2197.                wxT ( "image loading and saving in a variety of popular formats, HTML viewing and printing, and much more.\n\n");
  2198.   wxChar *e2 = wxT (  "More about wxWidgets please read\n")
  2199.                wxT ( "and GitHub source code");
  2200.  
  2201.   wxStaticText s (& T, wxID_ANY, e, wxPoint (105,0), wxSize (466, 320));
  2202.   wxStaticText s2 (& T, wxID_ANY, e2, wxPoint (105, 350), wxSize (260, 40));
  2203.  
  2204.   // set hlink .
  2205.   wxHyperlinkCtrl c (& T, wxID_ANY, wxT ("https://www.wxwidgets.org"), wxT ("https://www.wxwidgets.org"), wxPoint (330, 350));
  2206.   wxHyperlinkCtrl c2 (& T, wxID_ANY, wxT ("https://github.com/wxWidgets/wxWidgets"), wxT ("https://github.com/wxWidgets/wxWidgets"), wxPoint (330, 368));
  2207.  
  2208.   // attach staticbiotmap .
  2209.   wxButton m (& p2, wxID_OK, wxT ("OK"), wxPoint (472, 6));
  2210.   T.ShowModal();
  2211. }
  2212.  
  2213. void cs_mainFrame::OnAbout_TileMap (class wxCommandEvent& event) {
  2214.   // wxCloseEvent ce;
  2215.   // this->Destroy ();
  2216.   wxMessageBox (wxT ("simple tile editors"), wxT ("tilemap_editors"), wxICON_NONE);
  2217. }
  2218.  
  2219. // our normal wxApp-derived class, as usual
  2220. class CApp : public wxApp {
  2221. public:
  2222.  
  2223.   bool OnInit()
  2224.   {
  2225.     wxInitAllImageHandlers();
  2226.     cs_mainFrame* frame = new cs_mainFrame(NULL);
  2227.     SetTopWindow(frame);
  2228.     frame->Show();
  2229.     return true;                    
  2230.   }
  2231. };
  2232.  
  2233. void cs_mainFrame:: StatusShowText () {  
  2234.   if (attach.cs_ViewStatus_ != nullptr)
  2235.     attach.cs_ViewStatus_->SetValue (statOut);
  2236. }
  2237. void cs_mainFrame:: StatusShowClearAppendBaseTextSetTemp (wxString &s) {  
  2238.   if (attach.cs_ViewStatus_ != nullptr) {
  2239.     // attach.cs_ViewStatus_->Clear();
  2240.     // GetVert.
  2241.     int n = attach.cs_ViewStatus_->GetScrollPos (wxSB_VERTICAL);
  2242.     wxString c (statOut);
  2243.     c.Append(s);
  2244.     attach.cs_ViewStatus_->SetValue (c);
  2245.   }
  2246. }
  2247. void cs_mainFrame::StatusOut (wxString & content) {
  2248.   statOut.Append (content);
  2249.   StatusShowText ();
  2250. }
  2251. void cs_mainFrame::StatusOutWrap (wxString & content) {
  2252.   statOut.Append (content);
  2253. #  if defined (_WIN32)
  2254.   statOut.Append (wxString ("\r\n"));
  2255. #  else
  2256.   statOut.Append (wxString ("\n"));
  2257. #  endif
  2258. }
  2259. void cs_mainFrame::StatusOutWrapShow (wxString & content) {
  2260.   statOut.Append (content);
  2261. #  if defined (_WIN32)
  2262.   statOut.Append (wxString ("\r\n"));
  2263. #  else
  2264.   statOut.Append (wxString ("\n"));
  2265. #  endif
  2266.   StatusShowText ();
  2267. }
  2268. void cs_mainFrame::OnFile_PageSave  (class wxCommandEvent& event) {
  2269.  
  2270.   if (this->ctab == nullptr)  {
  2271.     wxMessageBox (wxT ("no attach page"), wxT ("tilemap editors"), wxICON_WARNING);
  2272.     return  ;
  2273.   }
  2274.  
  2275.   wxDialog T (this, wxID_ANY, wxT ("Save Page"), wxPoint (0, 0), wxSize (160, 140) );
  2276.   wxButton butOk (& T, wxID_OK, wxT ("OK"), wxPoint (4, 80), wxSize (60, 24));
  2277.   wxButton butCancel (& T, wxID_CANCEL, wxT ("CANCEL"), wxPoint (80, 80), wxSize (60, 24));
  2278.   wxSpinCtrl spindispage (& T, wxID_ANY, wxEmptyString, wxPoint (104, 6), wxSize (48, 19));
  2279.   wxSpinCtrl spindisland (& T, wxID_ANY, wxEmptyString, wxPoint (104, 30), wxSize (48, 19));
  2280.   wxStaticText textSetWidth (& T, wxID_ANY, wxT ("dissetpage"), wxPoint (4, 6));
  2281.   wxStaticText textSetHeight (& T, wxID_ANY, wxT ("dissetland"), wxPoint (4, 30));
  2282.   wxStaticText textSetPageDesc (& T, wxID_ANY, wxT ("save type"), wxPoint (4, 54));
  2283.   wxRadioButton rbBut_CPP (& T, wxID_ANY, wxT ("CPP"), wxPoint (64, 54), wxSize(-1,-1), wxRB_GROUP);
  2284.   wxRadioButton rbBut_PNG (& T, wxID_ANY, wxT ("PNG"), wxPoint (111, 54), wxSize(-1,-1));
  2285.   wxStaticLine lineSper (& T, wxID_ANY, wxPoint (4, 75), wxSize (144,-1));
  2286.  
  2287.   // set range.
  2288.   spindispage.SetRange (0, 0xFF);
  2289.   spindisland.SetRange (0, 0xFF);
  2290.  
  2291.   T.SetIcon ( wxIcon ( g_xpmstchr));
  2292.   T.CenterOnParent ();
  2293.   int msgid = T.ShowModal();
  2294.   if (msgid == wxID_OK) {
  2295.     if (rbBut_PNG.GetValue () != false)  {
  2296.        // output png.
  2297.        
  2298.  
  2299.     } else {
  2300.        // c source.
  2301.      
  2302.       class wxString caption = wxString ("save c files.");
  2303.       class wxString wildcard = wxString ("c files(*.c)|*.c");
  2304.       class wxString defaultfn = wxEmptyString;
  2305.       class wxFileDialog  dialog  (this, caption, wxEmptyString, wxEmptyString, wildcard, wxFD_SAVE);
  2306.       if ( dialog.ShowModal () == wxID_OK)  {
  2307.         // create text files .
  2308.         wxString s1;
  2309.         wxTextFile t (dialog.GetPath ());
  2310.         wxUint8 dfp = spindispage.GetValue();
  2311.         wxUint8 dfl = spindisland.GetValue();
  2312.  
  2313.         t.Clear ();
  2314.         s1.Printf (wxT ("# define XXX_W %d"), ctab->chunkset.hnums);
  2315.         t.AddLine (s1);
  2316.         s1.Printf (wxT ("# define XXX_H %d"), ctab->chunkset.vnums);
  2317.         t.AddLine (s1);
  2318.         s1.Printf (wxT ("uint8_t ppta[] = { "));
  2319.         t.AddLine (s1);
  2320.  
  2321.         for (int y = 0; y != ctab->chunkset.vnums; y++)   {
  2322.             for (int x = 0; x != ctab->chunkset.hnums; x++)  {
  2323.                // 32 *  32 tile.
  2324.               bool final = (x == ctab->chunkset.hnums - 1) && (y == ctab->chunkset.vnums -1);
  2325.               s1.Printf (wxT ("// PAGE-H %d PAGE-V %d"), x, y);
  2326.               t.AddLine (s1);
  2327.               tileChunkMap &q = ctab->chunkset.tcm[x+y*ctab->chunkset.hnums];
  2328.               for (int z = 0; z != 32; z++)   {
  2329.                 wxString csp;
  2330.                 for (int p = 0; p != 32; p++)  {
  2331.                   bool final2 = (z == 31) && (p == 31);
  2332.                   tileChunk &cc = q.map[p+z*32];
  2333.                   if (cc.enable == false || (cc.slot == nullptr))  
  2334.                     s1.Printf (wxT (" 0x%02X,0x%02X"), dfp, dfl);
  2335.                   else
  2336.                     s1.Printf (wxT (" 0x%02X,0x%02X"), cc.slot->id, cc.idInSlot);
  2337.                   if (! (final2 && (final)))
  2338.                     s1.Append (wxT (","));
  2339.                   csp += s1;
  2340.                 }
  2341.                 t.AddLine (csp);
  2342.               }
  2343.             }
  2344.         }
  2345.         s1.Printf (wxT ("};"), ctab->chunkset.hnums);
  2346.         t.AddLine (s1);
  2347.         t.Write();
  2348.       }
  2349.     }
  2350.   }
  2351. }
  2352.  
  2353. void cs_mainFrame::OnFile_SaveSettings  (class wxCommandEvent& event) {
  2354.  
  2355.   // write into files.
  2356.  
  2357.   class wxString caption = wxString ("save epc files.");
  2358.   class wxString wildcard = wxString ("epc files(*.epc)|*.epc");
  2359.   class wxString defaultfn = wxEmptyString;
  2360.   class wxFileDialog  dialog  (this, caption, wxEmptyString, wxEmptyString, wildcard, wxFD_SAVE);
  2361.   if ( dialog.ShowModal () == wxID_OK)  {
  2362.     class wxString Path = dialog.GetPath ();
  2363.     class wxFile fd (Path, wxFile::write);
  2364.     fd.Seek (0);
  2365.     struct tile_file :: std_infos si;
  2366.     si.mg[0] = 0x8C;
  2367.     si.mg[1] = 0x9A;
  2368.     si.mg[2] = 0x68;
  2369.     si.mg[3] = 0x33;
  2370.     si.imgSlot_nums = 0;
  2371.     si.claySet_nums = 0;
  2372.     si.pageSet_nums = 0;
  2373.     si.claySetDesc_Offset = 0;
  2374.     si.claySetChunk_Offset = 0;
  2375.     si.pageSetChunk_Offset = 0;
  2376.     si.pageSetDesc_Offset = 0;
  2377.     //  dummy ac chunk.
  2378.     wxUint32 nc;
  2379.     wxUint16 id;
  2380.     wxUint8 *ac = nullptr;
  2381.     struct tile_file :: dummyroot *sc = nullptr;
  2382.     const wxUint16 _max = sizeof (imgSlot_)/ sizeof (imgSlot_[0]);
  2383.    
  2384.     for  (id =0; id != _max; id++)  {
  2385.       if (imgSlot_[id].enable != false)  {
  2386.         si.imgSlot_nums ++;
  2387.       }
  2388.     }
  2389.     if  (si.imgSlot_nums != 0)  {    
  2390.       sc = new  tile_file :: dummyroot [si.imgSlot_nums];
  2391.       ac = new  wxUint8 [si.imgSlot_nums];
  2392.       for  (id =0, nc = 0; id != _max; id++)  {
  2393.         if (imgSlot_[id].enable != false)  {  
  2394.           wxImage &p = *imgSlot_[id].img2;
  2395.           ac[nc] = imgSlot_[id].id;
  2396.           for  (int y = 0; y != imgSlot::image_size_h; y++)  {
  2397.             for  (int x = 0; x != imgSlot::image_size_w; x++)  {
  2398.               int k = y * imgSlot::image_size_w + x;
  2399.               sc[nc].rgroup[k] = p.GetRed (x, y);
  2400.               sc[nc].ggroup[k] = p.GetGreen (x, y);
  2401.               sc[nc].bgroup[k] = p.GetBlue (x, y);
  2402.             }
  2403.           }
  2404.           nc ++;
  2405.         }
  2406.       }
  2407.     }
  2408.  
  2409.     wxString uvdesc, npdesc;
  2410.     std::list <tileChunkMap *>::iterator iter;
  2411.     tile_file ::RVA_uv_chunk *uv =nullptr;
  2412.     tile_file ::RVA_as_chunk *as =nullptr;
  2413.     tile_file ::RVA_as_chunk *as_ppblock =nullptr;
  2414.     tile_file :: RVA_np_chunk *np = nullptr;
  2415.     si.claySet_nums = fmset.size ();
  2416.  
  2417.     if (si.claySet_nums != 0)  {
  2418.      
  2419.       uv = new tile_file ::RVA_uv_chunk [si.claySet_nums];
  2420.       as = new tile_file ::RVA_as_chunk [si.claySet_nums];
  2421.       si.claySetDesc_Offset = sizeof (struct tile_file :: std_infos)
  2422.                             +  (sizeof (wxUint8) + sizeof (tile_file :: dummyroot)) * si.imgSlot_nums
  2423.                             + sizeof (struct tile_file :: RVA_uv_chunk) * si.claySet_nums;
  2424.  
  2425.       for (id = 0, iter = fmset.begin(); iter != fmset.end(); id++, iter++)  
  2426.       {  
  2427.         uv[id].length = (*iter)->desc->size();
  2428.         uv[id].offset = si.claySetDesc_Offset + uvdesc.size () * 2;
  2429.         uvdesc.append ((*iter)->desc->wc_str(), (*iter)->desc->size());
  2430.       }
  2431.      
  2432.       si.claySetChunk_Offset = si.claySetDesc_Offset + uvdesc.size () * 2;
  2433.       for (id = 0, iter = fmset.begin(); iter != fmset.end(); id++, iter++)  
  2434.       {  
  2435.         tileChunkMap *p = *iter;
  2436.         tile_file :: maptoas (as[id], *p);
  2437.       }
  2438.     } else  {
  2439.        si.claySetDesc_Offset = sizeof (struct tile_file :: std_infos)
  2440.                             +  (sizeof (wxUint8) + sizeof (tile_file :: dummyroot)) * si.imgSlot_nums;
  2441.        si.claySetChunk_Offset = si.claySetDesc_Offset;                  
  2442.     }
  2443.    
  2444.     //  enum page pane.
  2445.     si.pageSet_nums = note_tab2->GetPageCount ();
  2446.     if  (si.pageSet_nums != 0)  {
  2447.       nc = 0;
  2448.       si.pageSetDesc_Offset = si.claySetChunk_Offset + sizeof (struct tile_file :: RVA_np_chunk) * si.pageSet_nums
  2449.                     +  si.claySet_nums * sizeof (struct tile_file :: RVA_as_chunk);
  2450.       np = new tile_file ::RVA_np_chunk [si.pageSet_nums];
  2451.       for (id = 0; id != si.pageSet_nums; id++)  {
  2452.         cs_PageTileTab *pt = (cs_PageTileTab *) note_tab2->GetPage (id);
  2453.         np[id].pg_Height = pt->chunkset.vnums;
  2454.         np[id].pg_Width = pt->chunkset.hnums;
  2455.         np[id].ch_length = pt->chunkset.desc.size ();
  2456.         np[id].ch_offset = si.pageSetDesc_Offset + npdesc.size () * 2;
  2457.         npdesc.append (pt->chunkset.desc.wc_str(), pt->chunkset.desc.size ());
  2458.         nc += (pt->chunkset.vnums  * pt->chunkset.hnums);
  2459.       }
  2460.       as_ppblock = new tile_file ::RVA_as_chunk [nc];
  2461.       tile_file ::RVA_as_chunk *ppc = as_ppblock;
  2462.       si.pageSetChunk_Offset = si.pageSetDesc_Offset + npdesc.size () *2;
  2463.       for (id = 0; id != si.pageSet_nums; id++)  {
  2464.         cs_PageTileTab *pt = (cs_PageTileTab *) note_tab2->GetPage (id);
  2465.  
  2466.         for  (int  y = 0; y != pt->chunkset.vnums; y++)  {
  2467.           for  (int  x = 0; x != pt->chunkset.hnums; x++)  {
  2468.             int a = y*pt->chunkset.hnums+x;
  2469.             tile_file :: maptoas (ppc[a], pt->chunkset.tcm[a]);
  2470.           }
  2471.         }
  2472.         ppc = & ppc[pt->chunkset.hnums*pt->chunkset.vnums];
  2473.       }
  2474.     } else {
  2475.       si.pageSetDesc_Offset = si.claySetChunk_Offset +  si.claySet_nums * sizeof (struct tile_file :: RVA_as_chunk);
  2476.       si.pageSetChunk_Offset = si.pageSetDesc_Offset;      
  2477.     }
  2478.     fd.Seek (0);
  2479.     fd.Write (& si, sizeof (si));
  2480.     if (si.imgSlot_nums != 0) fd.Write (ac, sizeof (wxUint8) * si.imgSlot_nums);
  2481.     if (si.imgSlot_nums != 0) fd.Write ( sc, sizeof (tile_file::dummyroot) * si.imgSlot_nums );
  2482.     if (si.claySet_nums != 0) fd.Write (uv, sizeof (tile_file::RVA_uv_chunk) * si.claySet_nums);
  2483.     if (si.claySet_nums != 0) fd.Write ( uvdesc.wc_str(), uvdesc.size () *2 );
  2484.     if (si.claySet_nums != 0) fd.Write ( as, sizeof (tile_file::RVA_as_chunk) * si.claySet_nums );
  2485.     if (si.pageSet_nums != 0) fd.Write ( np, sizeof (tile_file::RVA_np_chunk) * si.pageSet_nums );
  2486.     if (si.pageSet_nums != 0) fd.Write ( npdesc.wc_str(), npdesc.size () *2 );
  2487.     if (si.pageSet_nums != 0) fd.Write ( as_ppblock, sizeof (tile_file::RVA_as_chunk) *nc );
  2488.   }
  2489. }
  2490.  
  2491. void cs_mainFrame::OnFile_LoadSettings  (class wxCommandEvent& event) {
  2492.  
  2493.   wxString caption = wxString ("choose files.");
  2494.   wxString wildcard = wxString ("epc files(*.epc)|*.epc");
  2495.   wxString defaultfn = wxEmptyString;
  2496.   wxFileDialog  dialog  (this, caption, wxEmptyString, wxEmptyString, wildcard, wxFD_OPEN);
  2497.   if ( dialog.ShowModal () == wxID_OK)  {
  2498.     wxString Path = dialog.GetPath ();
  2499.     wxFile fd (Path, wxFile::read);
  2500.     fd.Seek (0);
  2501.     struct tile_file :: std_infos si;
  2502.     struct tile_file ::dummyroot *trs;
  2503.     fd.Read (& si, sizeof (si));
  2504.     wxUint8 idchunk[256];
  2505.     fd.Read (& idchunk[0], si.imgSlot_nums);
  2506.     trs = new tile_file ::dummyroot [si.imgSlot_nums];
  2507.     fd.Read (trs, sizeof (struct tile_file ::dummyroot) * si.imgSlot_nums);
  2508.     const wxUint16 _max = sizeof (imgSlot_)/ sizeof (imgSlot_[0]);
  2509.     int clayUv_Offset = sizeof (struct tile_file :: std_infos) + si.imgSlot_nums * (sizeof (wxUint8) + sizeof (tile_file :: dummyroot));
  2510.  
  2511.     //  clear slot.
  2512.     for  (int id =0; id != _max; id++)  {
  2513.       imgSlot_[id].uninit ();
  2514.     }
  2515.  
  2516.     //  fill slot.
  2517.     for  (int id =0; id != si.imgSlot_nums; id++)  {
  2518.       imgSlot_[id].enable = true;
  2519.       imgSlot_[id].id = idchunk[id];
  2520.       imgSlot_[id].strPath = nullptr;
  2521.       imgSlot_[id].img2 = new wxImage (imgSlot::image_size_w, imgSlot::image_size_h);
  2522.       // dummy image.
  2523.       for  (int y = 0; y != imgSlot::image_size_h; y++)  {
  2524.         for  (int x = 0; x != imgSlot::image_size_w; x++)  {
  2525.           int n = y * imgSlot::image_size_w + x;
  2526.           imgSlot_[id].img2->SetRGB (x, y, trs[id].rgroup[n], trs[id].ggroup[n], trs[id].bgroup[n]);
  2527.         }
  2528.       }
  2529.       imgSlot_[id].img = new wxBitmap (*imgSlot_[id].img2);
  2530.     }
  2531.     note_tab2->DeleteAllPages();
  2532.     std::list <tileChunkMap *>::iterator iter;
  2533.     for (iter = fmset.begin(); iter != fmset.end(); iter++)  
  2534.     {  
  2535.       delete *iter;
  2536.     }
  2537.     fmset.clear ();
  2538.     for (int id =0; id != si.claySet_nums; id++) {  
  2539.       tile_file::RVA_uv_chunk uc;
  2540.       tileChunkMap *ap = new  tileChunkMap;
  2541.       ap->init ();
  2542.       fd.Seek (clayUv_Offset + id* sizeof (tile_file::RVA_uv_chunk));
  2543.       fd.Read (& uc, sizeof (uc));
  2544.       fd.Seek (uc.offset);
  2545.       wchar_t *c = new wchar_t [uc.length];
  2546.       fd.Read (c, uc.length *2);
  2547.       ap ->desc = new wxString;
  2548.       ap ->desc->append (c, uc.length);
  2549.       tile_file::RVA_as_chunk dt;
  2550.       fd.Seek (si.claySetChunk_Offset + id* sizeof (tile_file::RVA_as_chunk));
  2551.       fd.Read (& dt, sizeof (tile_file::RVA_as_chunk));
  2552.       tile_file :: astomap (*ap, dt, *this);
  2553.       fmset.push_back (ap);
  2554.     }
  2555.     // add page.  
  2556.     for (int id =0, nc = 0; id != si.pageSet_nums; id++) {  
  2557.       // np chunk read.
  2558.       tileChunkSet tsc;
  2559.       tile_file ::RVA_np_chunk np;
  2560.       fd.Seek (si.claySetChunk_Offset + sizeof (tile_file :: RVA_as_chunk) *si.claySet_nums + id  *sizeof (np));
  2561.       fd.Read (& np, sizeof (np));
  2562.       fd.Seek (np.ch_offset);
  2563.       wchar_t *c= new wchar_t[np.ch_length];
  2564.       fd.Read (c, np.ch_length * 2);
  2565.       tsc.desc.append (c, np.ch_length);
  2566.       tsc.vnums = np.pg_Height;
  2567.       tsc.hnums = np.pg_Width;
  2568.       tsc.tcm = new tileChunkMap [tsc.hnums * tsc.vnums];
  2569.       struct tile_file ::RVA_as_chunk *pn = new tile_file ::RVA_as_chunk [tsc.hnums * tsc.vnums];
  2570.       fd.Seek (si.pageSetChunk_Offset + nc * sizeof (tile_file::RVA_as_chunk));
  2571.       fd.Read (pn, sizeof (tile_file ::RVA_as_chunk) * tsc.hnums * tsc.vnums);
  2572.       nc += (np.pg_Height * np.pg_Width);
  2573.       // as to map.
  2574.       for (int y = 0; y != tsc.vnums; y++)  {
  2575.         for (int x = 0; x != tsc.hnums; x++)  {
  2576.           int k = y * tsc.hnums + x;
  2577.           tile_file :: astomap (tsc.tcm[k], pn[k], *this);
  2578.         }    
  2579.       }
  2580.       new cs_PageTileTab (attach, note_tab2, wxID_PAGE_NEW, tsc.hnums, tsc.vnums, tsc.desc, & tsc  );
  2581.     }
  2582.     // close root window..
  2583.     if  (fd_ViewRootTexture_ != nullptr)  {
  2584.       fd_ViewRootTexture_->DeleteAllPages ();
  2585.       aui_Manager.ClosePane (aui_Manager.GetPane (fd_ViewRootTexture_));
  2586.       GetMenuBar()->Enable (wxID_BTEXTURE, true);
  2587.       fd_ViewRootTexture_ = nullptr;
  2588.       //  append. new.
  2589.       wxCommandEvent emt;
  2590.       OnView_BTexture  (emt);
  2591.     }
  2592.     // close clay window..
  2593.     if  (fd_ViewClaySet_ != nullptr)  {
  2594.       fd_ViewClaySet_->DeleteAllPages ();
  2595.       aui_Manager.ClosePane (aui_Manager.GetPane (fd_ViewClaySet_));
  2596.       GetMenuBar()->Enable (wxID_CLAY, true);
  2597.       fd_ViewClaySet_ = nullptr;
  2598.       // append. new.
  2599.       wxCommandEvent emt;
  2600.       OnView_Clay (emt);
  2601.     }
  2602.   }
  2603. }
  2604.  
  2605. DECLARE_APP(CApp);
  2606. IMPLEMENT_APP(CApp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement