Changeset 53c4be3 in thomson for elec/CrO2/software/gui.cpp
- Timestamp:
- Feb 5, 2012, 3:25:32 PM (12 years ago)
- Branches:
- main
- Children:
- 1b74fa2
- Parents:
- c2a9854
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
elec/CrO2/software/gui.cpp
rc2a9854 r53c4be3 13 13 #include <string.h> 14 14 #include <sstream> 15 #include <ios tream>15 #include <ios> 16 16 17 17 #include <iupcontrols.h> … … 94 94 Callback<Gui, int, int, int>::create(blocklist, "SELECTION_CB", this, &Gui::selectBlock); 95 95 96 Ihandle*hexEd = IupMatrix(NULL);96 hexEd = IupMatrix(NULL); 97 97 98 98 // Setup title cells 99 IupSetAttribute(hexEd, "NUMLIN", "16"); 99 IupSetAttribute(hexEd, "FONT", "Courier, 10"); 100 IupSetAttribute(hexEd, "FONT*:17", "Courier, 10"); 100 101 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"); 102 IupSetAttribute(hexEd, "WIDTHDEF", "10"); 103 IupSetAttribute(hexEd, "WIDTH17", "105"); 104 IupSetAttribute(hexEd, "WIDTH0", "12"); 105 IupSetAttribute(hexEd, "HEIGHT0", "8"); 106 IupSetAttribute(hexEd, "SIZE", "400x230"); 105 107 IupSetAttribute(hexEd, "EXPAND", "YES"); 108 IupSetAttribute(hexEd, "ALIGNMENT", "ALEFT"); 106 109 Callback<Gui, const char*, int, int>::create(hexEd, "VALUE_CB", this, &Gui::matVal); 107 110 … … 173 176 { 174 177 // Load file 175 file = new K5(name); 178 try { 179 file = Tape::load(name); 180 } catch (const char* error) { 181 puts(error); 182 return IUP_DEFAULT; 183 } 176 184 177 185 // Fill in EXPLORE tab … … 179 187 int lastfile = -1; 180 188 189 IupSetAttribute(blocklist, "DELNODE", "ALL"); 190 181 191 for (int i = 0; i < count; ++i) 182 192 { 183 const K5::Block& blk = file->getBlock(i);184 switch(blk.type)193 const Tape::Block& blk = file->getBlock(i); 194 if (blk.isFile()) 185 195 { 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"); 196 IupSetAttributeId(blocklist, "INSERTBRANCH", lastfile, blk.getName().c_str()); 197 lastfile = i; 198 } else { 199 IupSetAttributeId(blocklist, "ADDLEAF", i-1, blk.getName().c_str()); 200 if (blk.isControl()) 198 201 IupSetAttributeId(blocklist, "IMAGE", i, "IMGLEAF"); 199 break;200 default:201 // regular block202 IupSetAttributeId(blocklist, "ADDLEAF", i-1, "DATA");203 break;204 202 } 205 203 } … … 217 215 if (what) 218 216 { 219 IupSetAttribute(hexEd, "REDRAW", "ALL"); 217 selblock = id; 218 std::ostringstream att; 219 att << (file->getBlock(id).length / 16); 220 IupSetAttribute(hexEd, "NUMLIN", att.str().c_str()); 221 222 IupSetAttribute(hexEd, IUP_REDRAW, "ALL"); 223 } else if (selblock == id) { 224 selblock = -1; 220 225 } 221 226 … … 223 228 } 224 229 225 const char* Gui::matVal(int x, int y)226 { 227 if ( x== 0)228 { 229 switch( y)230 const char* Gui::matVal(int y, int x) 231 { 232 if (y == 0) 233 { 234 switch(x) 230 235 { 231 236 case 0: … … 237 242 std::ostringstream name; 238 243 name << std::hex; 239 name << ( y-1);244 name << (x-1); 240 245 return name.str().c_str(); 241 246 } … … 243 248 } 244 249 245 if (y == 0) 246 { 247 return "C"; 248 } 249 250 return "V"; 250 if (x == 0) 251 { 252 std::ostringstream name; 253 name << std::hex; 254 name << (y-1)*16; 255 return name.str().c_str(); 256 } 257 258 if (file == NULL || selblock < 0 || selblock >= file->getBlockCount()) 259 return ""; 260 const Tape::Block& block = file->getBlock(selblock); 261 262 if (x == 17) 263 { 264 int off = (y-1)*16; 265 std::ostringstream txt; 266 for(int j = 0; j < 16; j++) 267 { 268 if (off + j >= block.length) 269 break; 270 char c = block.data[off+j]; 271 if (isprint(c)) 272 txt << c; 273 else 274 txt << '.'; 275 } 276 return txt.str().c_str(); 277 } else { 278 279 int pos = (y-1) * 16 + (x-1); 280 if (pos >= block.length) 281 return ""; 282 283 return toHex(block.data[pos]); 284 } 251 285 } 252 286 … … 263 297 return IUP_DEFAULT; 264 298 } 299 300 const char* Gui::toHex(int val) 301 { 302 std::ostringstream str; 303 str.flags(std::ios_base::hex | std::ios_base::uppercase); 304 str.width(2); 305 str.fill('0'); 306 str << val; 307 return str.str().c_str(); 308 }
Note:
See TracChangeset
for help on using the changeset viewer.