Changeset c2a9854 in thomson


Ignore:
Timestamp:
Feb 4, 2012, 7:43:03 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
53c4be3
Parents:
192e299
Message:

WIP explorer

  • Fill in the block list
  • HexEditor in progress.

Commiting because I'm trying to improve iupplusplus and want to make sure I can revert it if I fail.

git-svn-id: svn://localhost/thomson@16 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

Location:
elec/CrO2/software
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • elec/CrO2/software/Makefile

    r192e299 rc2a9854  
    1414
    1515CC              = g++
    16 CPPFLAGS        = $(USBFLAGS) -O -Wall -I/usr/include/IUP/ -I/local/include -g -std=c++0x -mthreads
    17 LIBS    = $(USBLIBS) -L/usr/lib/ -mwindows -liup -lcomctl32 -lole32 -mthreads
     16CPPFLAGS = $(USBFLAGS) -Os -Wall -I/usr/include/IUP/ -I/local/include -std=c++0x -mthreads
     17LIBS = $(USBLIBS) -Os -L/usr/lib/ -mwindows -liup -liupcontrols -liupcd -lcd -lfreetype -lz -lcomctl32 -lole32 -mthreads
    1818
    1919PROJECT = CrO2
  • elec/CrO2/software/gui.cpp

    r192e299 rc2a9854  
    1111
    1212#include <stdint.h>
     13#include <string.h>
     14#include <sstream>
     15#include <iostream>
     16
    1317#include <iupcontrols.h>
    1418
     
    5054
    5155        IupOpen(argc, argv);
    52 //      IupControlsOpen();
     56        IupControlsOpen();
    5357
    5458        Ihandle* menu_open = IupItem("Open", NULL);
     
    7175        Ihandle* motoron = IupProgressBar();
    7276        IupSetAttribute(motoron, "RASTERSIZE", "16x16");
     77
     78        Ihandle* playToggle = IupToggle("play", NULL);
     79        Callback<Gui, int, int>::create(playToggle, "ACTION", this, &Gui::setPlaying);
    7380
    7481        // EXPLORE
     
    7986        IupSetAttribute(platformlist, "VALUE", "1");
    8087
    81         Ihandle* blocklist = IupTree();
     88        blocklist = IupTree();
    8289        IupSetAttribute(blocklist, "EXPAND", "VERTICAL");
    83 
    84         Ihandle* playToggle = IupToggle("play", NULL);
    85         Callback<Gui, int>::create(playToggle, "ACTION", this, &Gui::setPlaying);
    86 
     90        IupSetAttribute(blocklist, "ADDEXPANDED", "NO");
     91        IupSetAttribute(blocklist, "ADDROOT", "NO");
     92        IupSetAttribute(blocklist, "IMAGELEAF", "IMGBLANK");
     93        IupSetAttribute(blocklist, "RASTERSIZE", "140x200");
     94        Callback<Gui, int, int, int>::create(blocklist, "SELECTION_CB", this, &Gui::selectBlock);
     95
     96        Ihandle* hexEd = IupMatrix(NULL);
     97
     98        // Setup title cells
     99        IupSetAttribute(hexEd, "NUMLIN", "16");
     100        IupSetAttribute(hexEd, "NUMCOL", "17");
     101        IupSetAttribute(hexEd, "WIDTHDEF", "12");
     102        IupSetAttribute(hexEd, "WIDTH17", "48");
     103        IupSetAttribute(hexEd, "USETITLESIZE", "YES");
     104        IupSetAttribute(hexEd, "FONT", "Courier, Bold 12");
     105        IupSetAttribute(hexEd, "EXPAND", "YES");
     106        Callback<Gui, const char*, int, int>::create(hexEd, "VALUE_CB", this, &Gui::matVal);
     107       
     108        // WINDOW LAYOUT
    87109        Ihandle* tabs = IupTabs(
    88110                IupVbox(
     
    108130                                blocklist,
    109131                                IupVbox(
    110 //                                      IupMatrix(NULL),
     132                                        hexEd,
    111133                                        IupLabel("Checksum:"),
    112134                                        NULL
     
    129151        startPolling(motoron);
    130152
     153        // TODO the IUP main loop is blocking - it may be wise to move it out of
     154        // the constructor...
    131155        IupMainLoop();
    132 
     156}
     157
     158
     159Gui::~Gui()
     160{
     161        delete file;
     162
     163        IupControlsClose();
    133164        IupClose();
    134 }
    135 
    136 
    137 Gui::~Gui()
    138 {
    139         delete file;
    140165}
    141166
     
    149174                // Load file
    150175                file = new K5(name);
     176
     177                // Fill in EXPLORE tab
     178                int count = file->getBlockCount();
     179                int lastfile = -1;
     180
     181                for (int i = 0; i < count; ++i)
     182                {
     183                        const K5::Block& blk = file->getBlock(i);
     184                        switch(blk.type)
     185                        {
     186                                case 0:
     187                                        //start block
     188                                        char name[12];
     189                                        memcpy(name, blk.data, 11);
     190                                        name[11] = 0;
     191                                       
     192                                        IupSetAttributeId(blocklist, "INSERTBRANCH", lastfile, name);
     193                                        lastfile = i;
     194                                        break;
     195                                case 0xFF:
     196                                        // end block
     197                                        IupSetAttributeId(blocklist, "ADDLEAF", i-1, "EOF");
     198                                        IupSetAttributeId(blocklist, "IMAGE", i, "IMGLEAF");
     199                                        break;
     200                                default:
     201                                        // regular block
     202                                        IupSetAttributeId(blocklist, "ADDLEAF", i-1, "DATA");
     203                                        break;
     204                        }
     205                }
    151206        }
    152207        return IUP_DEFAULT;
     
    156211{
    157212        return IUP_CLOSE;
     213}
     214
     215int Gui::selectBlock(int id, int what)
     216{
     217        if (what)
     218        {
     219                IupSetAttribute(hexEd, "REDRAW", "ALL");
     220        }
     221
     222        return IUP_DEFAULT;
     223}
     224
     225const char* Gui::matVal(int x, int y)
     226{
     227        if (x == 0)
     228        {
     229                switch(y)
     230                {
     231                        case 0:
     232                                return "0x";
     233                        case 17:
     234                                return "ASCII";
     235                        default:
     236                        {
     237                                std::ostringstream name;
     238                                name << std::hex;
     239                                name << (y-1);
     240                                return name.str().c_str();
     241                        }
     242                }
     243        }
     244
     245        if (y == 0)
     246        {
     247                return "C";
     248        }
     249
     250        return "V";
    158251}
    159252
  • elec/CrO2/software/gui.h

    r192e299 rc2a9854  
    2020                int menu_exit();
    2121
     22                K5* file;
     23
     24                // Control
    2225                int setPlaying(int state);
    2326
    24                 K5* file;
     27                // Explore
     28                int selectBlock(int id, int what);
     29                const char* matVal(int x, int y);
     30                Ihandle* blocklist;
     31                Ihandle* hexEd;
    2532};
  • elec/CrO2/software/iupplusplus.h

    r192e299 rc2a9854  
    77#include <iup.h>
    88
    9 template<class Handler, typename... Args> class Callback
     9template<class Handler, typename ret = int, typename... Args> class Callback
    1010{
    11         typedef int(Handler::*T)(Args... args);
     11        typedef ret(Handler::*T)(Args... args);
    1212
    1313        public:
     
    2727                }
    2828
    29                 static int call(Ihandle* that, Args... args)
     29                static ret call(Ihandle* that, Args... args)
    3030                {
    3131                        Callback* call = (Callback*)IupGetAttribute(that, "LCALLBACK");
Note: See TracChangeset for help on using the changeset viewer.