Changeset 12
- Timestamp:
- Nov 12, 2004, 9:40:10 PM (19 years ago)
- Location:
- trunk/MacFaceLibrary
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MacFaceLibrary/FaceDef.cs
r8 r12 74 74 } 75 75 } 76 77 78 /* 79 #import <Cocoa/Cocoa.h> 80 81 // 82 #define FACE_ROWMAX 3 83 #define FACE_COLMAX 11 84 #define FACE_PATMAX 8 85 #define FACE_IMGW 128 86 #define FACE_IMGH 128 87 #define FACE_IMGSIZE (NSMakeSize(128,128)) 88 89 // }[J[rbg}XN 90 #define FDMARKER_PAGEIN 0x0001 91 #define FDMARKER_PAGEOUT 0x0002 92 93 // 94 #define FACE_INFO_TITLE @"title" 95 #define FACE_INFO_AUTHOR @"author" 96 #define FACE_INFO_VERSION @"version" 97 #define FACE_INFO_SITE_URL @"web site" 98 99 #define FACE_INFO_PARTS @"parts" 100 #define FACE_INFO_PATTERN @"pattern" 101 #define FACE_INFO_MARKER @"markers" 102 #define FACE_INFO_TITLE_PATTERN @"title pattern" 103 #define FACE_INFO_MARK_PGOUT @"pagein pattern" 104 #define FACE_INFO_MARK_PGIN @"pageout pattern" 105 106 #define FACE_PART_IMAGE @"filename" 107 #define FACE_PART_POSX @"pos x" 108 #define FACE_PART_POSY @"pos y" 109 110 typedef struct { 111 NSString *filename; 112 NSImage *image; 113 NSPoint pos; 114 } PartDef; 115 116 typedef struct { 117 unsigned count; 118 int parts[FACE_PATMAX]; 119 } PatternDef; 120 121 122 @interface FaceDef : NSObject 123 { 124 NSString *packagePath; 125 NSDictionary *definition; 126 int partCount; 127 PartDef *parts; 128 PatternDef patterns[FACE_ROWMAX][FACE_COLMAX]; 129 int markers[8]; 130 PatternDef titlePattern; 131 } 132 133 + (NSDictionary*)infoAtPath:(NSString*)path; 134 135 + (id)faceDefWithContentOfFile:(NSString*)path; 136 137 - (id)initWithContentOfFile:(NSString*)path; 138 139 - (NSString*)path; 140 141 - (NSString*)title; 142 - (NSString*)author; 143 - (NSString*)version; 144 - (NSString*)siteURL; 145 146 - (NSImage*)titleImage; 147 148 - (int)partCount; 149 - (const PartDef*)partOfIndex:(int)index; 150 - (const PatternDef*)patternOfRow:(int)row col:(int)col; 151 - (int)patternCountOfRow:(int)row col:(int)col; 152 - (int)patternNoOfRow:(int)row col:(int)col index:(int)index; 153 154 - (NSImage*)imageOfRow:(int)row col:(int)col marker:(int)marker; 155 156 - (void)drawImageOfRow:(int)row col:(int)col marker:(int)marker atPoint:(NSPoint)pt; 157 - (void)drawPart:(PartDef*)part atPoint:(NSPoint)point; 158 159 - (void)dumpPattern:(NSString*)path; 160 161 @end 162 163 @implementation FaceDef 164 165 + (NSDictionary*)infoAtPath:(NSString*)path 166 { 167 NSDictionary *info; 168 169 info = [NSDictionary dictionaryWithContentsOfFile: 170 [path stringByAppendingPathComponent:@"faceDef.plist"]]; 171 172 return info; 173 } 174 175 + (id)faceDefWithContentOfFile:(NSString*)path 176 { 177 return [[[self alloc] initWithContentOfFile:path] autorelease]; 178 } 179 180 - (id)initWithContentOfFile:(NSString*)path 181 { 182 NSDictionary *partDefDict; 183 NSArray *partArray,*patternArray,*colArray,*elemArray; 184 NSEnumerator *enumerator; 185 NSString *imagePath; 186 NSNumber *value; 187 int i,count; 188 int row,col,no; 189 int maxPartNo; 190 191 [super init]; 192 193 NS_DURING 194 definition = [FaceDef infoAtPath:path]; 195 196 if (definition == nil) { 197 [NSException raise:@"FaceDefInfoLoadException" format:@"failuer loading faceDef.plist"]; 198 } 199 200 [definition retain]; 201 202 packagePath = [path retain]; 203 204 // p[cè`ÌÇÝÝ 205 partArray = [definition objectForKey:FACE_INFO_PARTS]; 206 207 if ([partArray isMemberOfClass:[NSArray class]]) { 208 [NSException raise:@"FaceDefPartListLoadException" format:@"failed in reading part list."]; 209 } 210 211 parts = calloc([partArray count],sizeof(PartDef)); 212 count = [partArray count]; 213 214 for (partCount = 0; partCount < count; partCount++){ 215 partDefDict = [partArray objectAtIndex:partCount]; 216 parts[partCount].filename = [[partDefDict objectForKey:FACE_PART_IMAGE] retain]; 217 parts[partCount].pos.x = [(NSNumber*)[partDefDict objectForKey:FACE_PART_POSX] floatValue]; 218 parts[partCount].pos.y = [(NSNumber*)[partDefDict objectForKey:FACE_PART_POSY] floatValue]; 219 imagePath = [path stringByAppendingPathComponent:parts[partCount].filename]; 220 parts[partCount].image = [[NSImage alloc]initWithContentsOfFile:imagePath]; 221 222 if (parts[partCount].image == nil){ // æªÇÝßÈ©Á½ 223 [NSException raise:@"FaceDefPartLoadException" 224 format:@"failed in loading of image '%@'",parts[partCount].filename]; 225 } 226 } 227 228 maxPartNo = count - 1; 229 230 // p^[è`ÌÇÝÝ 231 patternArray = [definition objectForKey:FACE_INFO_PATTERN]; 232 233 for (row = 0; row < FACE_ROWMAX; row++){ 234 colArray = [patternArray objectAtIndex:row]; 235 236 if ([colArray count] != FACE_COLMAX) { 237 [NSException raise:@"FaceDefPatternLoadException" 238 format:@"number of pattern columns is not 10 at row %d",row]; 239 } 240 241 for (col = 0; col < FACE_COLMAX; col++){ 242 elemArray = [colArray objectAtIndex:col]; 243 enumerator = [[colArray objectAtIndex:col] objectEnumerator]; 244 for (i = 0; i <= FACE_PATMAX && (value = [enumerator nextObject]) != nil; i++){ 245 no = [value intValue]; 246 patterns[row][col].parts[i] = no; 247 if (0 > no || no > maxPartNo) { // p[cÔ`FbN 248 [NSException raise:@"FaceDefPatternLoadException" 249 format:@"illigal part no %d in patterns[%d,%d,%d]",no,row,col,i]; 250 } 251 } 252 patterns[row][col].count = i; 253 } 254 } 255 256 // }[J[XgÌÇÝÝ 257 enumerator = [[definition objectForKey:FACE_INFO_MARKER] objectEnumerator]; 258 for (i = 0; i < 8 && (value = [enumerator nextObject]) != nil; i++){ 259 markers[i] = [value intValue]; 260 } 261 262 // ã\æp^[ÌÇÝÝ 263 enumerator = [[definition objectForKey:FACE_INFO_TITLE_PATTERN] objectEnumerator]; 264 for (i = 0; i <= FACE_PATMAX && (value = [enumerator nextObject]) != nil; i++){ 265 no = [value intValue]; 266 titlePattern.parts[i] = no; 267 if (0 > no || no > maxPartNo) { // p[cÔ`FbN 268 [NSException raise:@"FaceDefPatternLoadException" 269 format:@"illigal part no %d in title pattern",no]; 270 } 271 } 272 titlePattern.count = i; 273 NS_HANDLER 274 NSLog(@"FaceDef load error: %@",localException); 275 [self dealloc]; 276 self = nil; 277 NS_ENDHANDLER 278 279 return self; 280 } 281 282 - (void)dealloc 283 { 284 int i; 285 286 [packagePath release]; 287 [definition release]; 288 289 if (parts != nil) { 290 for (i = 0; i < partCount; i++){ 291 [parts[i].filename release]; 292 [parts[i].image release]; 293 } 294 free(parts); 295 } 296 } 297 298 -(NSString*)path 299 { 300 return packagePath; 301 } 302 303 -(NSString*)title 304 { 305 NSString *str; 306 str = [definition objectForKey:@"title"]; 307 return (str != nil) ? str : @""; 308 } 309 310 -(NSString*)author 311 { 312 NSString *str; 313 str = [definition objectForKey:@"author"]; 314 return (str != nil) ? str : @""; 315 } 316 317 -(NSString*)version 318 { 319 NSString *str; 320 str = [definition objectForKey:@"version"]; 321 return (str != nil) ? str : @""; 322 } 323 324 - (NSString*)siteURL 325 { 326 NSString *str; 327 str = [definition objectForKey:@"web site"]; 328 return (str != nil) ? str : @""; 329 } 330 331 - (NSImage*)titleImage 332 { 333 NSImage *image; 334 int i; 335 336 image = [[NSImage alloc] initWithSize:FACE_IMGSIZE]; 337 [image lockFocus]; 338 339 if (titlePattern.count > 0) { 340 for (i=0; i<titlePattern.count; i++) { 341 [self drawPart:&parts[titlePattern.parts[i]] atPoint:NSMakePoint(0,0)]; 342 } 343 } else { 344 [self drawImageOfRow:0 col:FACE_COLMAX marker:0 atPoint:NSMakePoint(0,0)]; 345 } 346 347 [image unlockFocus]; 348 return [image autorelease]; 349 } 350 351 - (int)partCount 352 { 353 return partCount; 354 } 355 356 - (const PartDef*)partOfIndex:(int)index 357 { 358 if (0 <= index && index < partCount) return &parts[index]; 359 else return nil; 360 } 361 362 - (const PatternDef*)patternOfRow:(int)row col:(int)col 363 { 364 if (0 <= row && row < FACE_ROWMAX 365 && 0 <= col && col < FACE_COLMAX) return &patterns[row][col]; 366 else return nil; 367 } 368 369 - (int)patternCountOfRow:(int)row col:(int)col 370 { 371 if (0 <= row && row < FACE_ROWMAX 372 && 0 <= col && col < FACE_COLMAX) return patterns[row][col].count; 373 else return -1; 374 } 375 376 - (int)patternNoOfRow:(int)row col:(int)col index:(int)index 377 { 378 if (0 <= row && row < FACE_ROWMAX 379 && 0 <= col && col < FACE_COLMAX 380 && 0 <= index && index < patterns[row][col].count) return patterns[row][col].parts[index]; 381 else return -1; 382 } 383 384 - (NSImage*)imageOfRow:(int)row col:(int)col marker:(int)marker 385 { 386 NSImage *image; 387 image = [[NSImage alloc] initWithSize:FACE_IMGSIZE]; 388 [image lockFocus]; 389 [self drawImageOfRow:row col:col marker:marker atPoint:NSMakePoint(0,0)]; 390 [image unlockFocus]; 391 return [image autorelease]; 392 } 393 394 - (void)drawImageOfRow:(int)row col:(int)col marker:(int)marker atPoint:(NSPoint)point 395 { 396 int count; 397 int i; 398 399 count = patterns[row][col].count; 400 for (i=0; i<count; i++){ 401 [self drawPart:&parts[patterns[row][col].parts[i]] atPoint:point]; 402 }; 403 404 if (marker != 0) { 405 for (i=0; i<8; i++) { 406 if (marker & (1<<i)) { 407 [self drawPart:&parts[markers[i]] atPoint:point]; 408 } 409 } 410 } 411 } 412 413 - (void)drawPart:(PartDef*)part atPoint:(NSPoint)point 414 { 415 point.x += part->pos.x; 416 point.y += part->pos.y; 417 [part->image compositeToPoint:point operation:NSCompositeSourceOver]; 418 } 419 420 -(void)dumpPattern:(NSString*)path; 421 { 422 NSImage *img; 423 NSSize imgSize; 424 NSPoint pos; 425 float offset; 426 int i,j,rows; 427 NSMutableDictionary *attr; 428 NSString *str; 429 430 rows = partCount / FACE_COLMAX + 1; 431 offset = rows * FACE_IMGW + 10; 432 imgSize.width = FACE_IMGW * FACE_COLMAX; 433 imgSize.height = FACE_IMGH * FACE_ROWMAX + offset + 14; 434 435 img = [[NSImage alloc] initWithSize:imgSize]; 436 if (img == nil) { 437 NSLog(@"failure dump pattern!"); 438 return; 439 } 440 441 [img lockFocus]; 442 [[NSColor whiteColor] set]; 443 NSRectFill(NSMakeRect(0,0,imgSize.width,imgSize.height)); 444 445 [[NSColor blackColor] set]; 446 NSRectFill(NSMakeRect(0,offset-6,imgSize.width,2)); 447 448 attr = [[NSMutableDictionary alloc] initWithObjectsAndKeys: 449 [NSFont systemFontOfSize:14.0], NSFontAttributeName, 450 [NSColor blackColor], NSForegroundColorAttributeName, 451 nil]; 452 453 for (i = 0; i <= partCount; i++) { 454 pos.x = (i % FACE_COLMAX) * FACE_IMGW; 455 pos.y = (rows-1 - i / FACE_COLMAX) * FACE_IMGH; 456 [self drawPart:&parts[i] atPoint:pos]; 457 458 str = [NSString stringWithFormat:@"%d",i]; 459 pos.x = (i % FACE_COLMAX) * FACE_IMGW; 460 pos.y = (rows-1 - i / FACE_COLMAX) * FACE_IMGH + FACE_IMGH - 12; 461 [str drawAtPoint:pos withAttributes:attr]; 462 } 463 464 for (i = 0; i < FACE_ROWMAX; i++) { 465 pos.y = (FACE_ROWMAX-1 - i) * FACE_IMGH + offset; 466 for (j=0; j<FACE_COLMAX; j++) { 467 pos.x = j * FACE_IMGW; 468 [self drawImageOfRow:i col:j marker:0 atPoint:pos]; 469 } 470 } 471 472 pos.y = imgSize.height - 14; 473 for (i = 0; i < FACE_COLMAX-1; i++) { 474 str = [NSString stringWithFormat:@"%d-%d%%",i*10,(i+1)*10-1]; 475 pos.x = i * FACE_IMGW; 476 [str drawAtPoint:pos withAttributes:attr]; 477 } 478 str = [NSString stringWithFormat:@"%d%%",100]; 479 pos.x = (FACE_COLMAX-1) * FACE_IMGW; 480 [str drawAtPoint:pos withAttributes:attr]; 481 482 [img unlockFocus]; 483 484 [[img TIFFRepresentation] writeToFile:path atomically:NO]; 485 [img release]; 486 } 487 488 @end 489 490 */ -
trunk/MacFaceLibrary/MacFaceLibrary.csproj
r8 r12 77 77 <Reference 78 78 Name = "System.XML" 79 AssemblyName = "System.X ML"79 AssemblyName = "System.Xml" 80 80 HintPath = "..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" 81 81 /> … … 95 95 /> 96 96 <File 97 RelPath = "Face.cs" 98 SubType = "Code" 99 BuildAction = "Compile" 100 /> 101 <File 97 102 RelPath = "FaceDef.cs" 103 SubType = "Code" 104 BuildAction = "Compile" 105 /> 106 <File 107 RelPath = "HostStatistics.cs" 98 108 SubType = "Code" 99 109 BuildAction = "Compile"
Note: See TracChangeset
for help on using the changeset viewer.