Annotation of Examples/AppKit/Draw/Inspector.m, revision 1.1.1.1

1.1       root        1: #import "draw.h"
                      2: 
                      3: @interface Inspector(PrivateMethods)
                      4: 
                      5: - reloadGraphic:(Graphic *)graphic;
                      6: - loadOrReloadGraphic:(Graphic *)graphic;
                      7: 
                      8: @end
                      9: 
                     10: @implementation Inspector
                     11: 
                     12: static void setTitle(Button *button, int row)
                     13: {
                     14:     [button setTitle:[[[[button target] itemList] cellAt:row :0] title]];
                     15:     [[[button target] itemList] selectCellAt:row :0];
                     16: }
                     17: 
                     18: - reloadGraphic:(Graphic *)graphic
                     19: /*
                     20:  * Loads up the size fields if they have changed since last time
                     21:  * we loaded up the panel with this graphic.  This is used since we
                     22:  * know that none of the things controlled by the InspectorPanel
                     23:  * except the size or the fill color can change from event to event
                     24:  * (we should probably not make that assumption, but it makes the
                     25:  * updating of this panel go much faster and since it has to happen
                     26:  * on every event, it seems a worthwhile optimization).
                     27:  */
                     28: {
                     29:     NXRect bounds;
                     30: 
                     31:     if (!graphic) return self;
                     32:     [graphic getBounds:&bounds];
                     33:     if (lastSize.width != bounds.size.width) {
                     34:        [width setFloatValue:bounds.size.width];
                     35:        lastSize.width = bounds.size.width;
                     36:     }
                     37:     if (lastSize.height != bounds.size.height) {
                     38:        [height setFloatValue:bounds.size.height];
                     39:        lastSize.height = bounds.size.height;
                     40:     }
                     41:     if ([graphic fill] != [[[filled target] itemList] selectedRow]) setTitle(filled, [graphic fill]);
                     42:     if (graphic && !NXEqualColor([fillColor color], [graphic fillColor])) [fillColor setColor:[graphic fillColor]];
                     43: 
                     44:     return self;
                     45: }
                     46: 
                     47: - loadOrReloadGraphic:(Graphic *)graphic
                     48: {
                     49:     if (selectedGraphic == graphic) 
                     50:         return [self reloadGraphic:graphic];
                     51:     else
                     52:         return [self loadGraphic:graphic];
                     53: }
                     54: 
                     55: - loadGraphic:(Graphic *)graphic
                     56: /*
                     57:  * Loads up the InspectorPanel with a new graphic's attributes.
                     58:  */
                     59: {
                     60:     NXRect bounds;
                     61: 
                     62:     selectedGraphic = graphic;
                     63:     if (!selectedGraphic) return self;
                     64: 
                     65:     [lineWidthField setFloatValue:[graphic lineWidth]];
                     66:     [lineWidthSlider setFloatValue:[graphic lineWidth]];
                     67:     [lineColor setColor:[graphic lineColor]];
                     68:     [fillColor setColor:[graphic fillColor]];
                     69:     [graphic getBounds:&bounds];
                     70:     [width setFloatValue:bounds.size.width];
                     71:     [height setFloatValue:bounds.size.height];
                     72:     lastSize = bounds.size;
                     73:     setTitle(filled, [graphic fill]);
                     74:     setTitle(lineCap, [graphic lineCap]);
                     75:     setTitle(arrows, [graphic lineArrow]);
                     76:     setTitle(lineJoin, [graphic lineJoin]);
                     77:     [formEntry setIntValue:[graphic isFormEntry]];
                     78: 
                     79:     return self;
                     80: }
                     81: 
                     82: - load:(GraphicView *)view
                     83: /*
                     84:  * If the view has only one selected graphic, then the panel is loaded with it.
                     85:  */
                     86: {
                     87:     graphicView = view;
                     88:     [self loadOrReloadGraphic:[view selectedGraphic]];
                     89:     return self;
                     90: }
                     91: 
                     92: - initializeGraphic:(Graphic *)graphic
                     93: /*
                     94:  * Goes the opposite way of loadGraphic.  Gives the Graphic the attributes
                     95:  * which are in the InspectorPanel.
                     96:  */
                     97: {
                     98:     float value;
                     99:     const char *s;
                    100:     NXColor color;
                    101: 
                    102:     s = [lineWidthField stringValue];
                    103:     if (s && s[0] && (value = atof(s))) [graphic setLineWidth:&value];
                    104:     color = [lineColor color];
                    105:     [graphic setLineColor:&color];
                    106:     color = [fillColor color];
                    107:     [graphic setFillColor:&color];
                    108:     [graphic setFill:[[[filled target] itemList] selectedRow]];
                    109:     [graphic setLineCap:[[[lineCap target] itemList] selectedRow]];
                    110:     [graphic setLineArrow:[[[arrows target] itemList] selectedRow]];
                    111:     [graphic setLineJoin:[[[lineJoin target] itemList] selectedRow]];
                    112: 
                    113:     return self;
                    114: }
                    115: 
                    116: - preset
                    117: {
                    118:     [fillColor setColor:NX_COLORWHITE];
                    119:     [lineColor setColor:NX_COLORBLACK];
                    120:     return self;
                    121: }
                    122: 
                    123: /* Overridden from superclass */
                    124: 
                    125: - windowDidUpdate:(Window *)sender
                    126: /*
                    127:  * Called each time an event occurs.  Loads up the panel.
                    128:  */
                    129: {
                    130:     [self load:[[NXApp currentDocument] view]];
                    131:     return self;
                    132: }
                    133: 
                    134: - changeContinuous:sender
                    135: {
                    136:     [[NXColorPanel sharedInstance:NO] setContinuous:([sender intValue] ? YES : NO)];
                    137:     return self;
                    138: }
                    139: 
                    140: /* Target/Action methods */
                    141: 
                    142: - changeFormEntry:sender
                    143: {
                    144:     [graphicView takeFormEntryStatusFrom:formEntry];
                    145:     return self;
                    146: }
                    147: 
                    148: - changeFilled:sender
                    149: {
                    150:     [graphicView takeFillValueFrom:[[filled target] itemList]];
                    151:     return self;
                    152: }
                    153: 
                    154: - changeLineCap:sender
                    155: {
                    156:     [graphicView takeLineCapFrom:[[lineCap target] itemList]];
                    157:     return self;
                    158: }
                    159: 
                    160: - changeArrows:sender
                    161: {
                    162:     [graphicView takeLineArrowFrom:[[arrows target] itemList]];
                    163:     return self;
                    164: }
                    165: 
                    166: - changeLineJoin:sender
                    167: {
                    168:     [graphicView takeLineJoinFrom:[[lineJoin target] itemList]];
                    169:     [[graphicView window] makeKeyWindow];
                    170:     return self;
                    171: }
                    172: 
                    173: - changeLineWidth:sender
                    174: {
                    175:     float linewidth;
                    176: 
                    177:     linewidth = [sender floatValue];
                    178:     if (sender == lineWidthSlider) {
                    179:        if ([NXApp currentEvent]->type == NX_MOUSEDRAGGED) {
                    180:            [[graphicView selectedGraphics] makeObjectsPerform:@selector(deselect)];
                    181:        } else {
                    182:            [[graphicView selectedGraphics] makeObjectsPerform:@selector(select)];
                    183:        }
                    184:        [lineWidthField setFloatValue:linewidth];
                    185:     } else {
                    186:        if ([lineWidthSlider maxValue] < linewidth) {
                    187:            [lineWidthSlider setMaxValue:linewidth];
                    188:        }
                    189:        [lineWidthSlider setFloatValue:linewidth];
                    190:        [[graphicView window] makeKeyWindow];
                    191:     }
                    192:     [graphicView takeLineWidthFrom:lineWidthField];
                    193:     return self;
                    194: }
                    195: 
                    196: - changeLineColor:sender
                    197: {
                    198:     [graphicView takeLineColorFrom:sender];
                    199:     return self;
                    200: }
                    201: 
                    202: - changeFillColor:sender
                    203: {
                    204:     [graphicView takeFillColorFrom:sender];
                    205:     if ([[[filled target] itemList] selectedRow] == 0)
                    206:         setTitle(filled, 2);
                    207:     return self;
                    208: }
                    209: 
                    210: - changeDimensions:sender
                    211: {
                    212:     NXSize size;
                    213:     id change;
                    214: 
                    215:     size.width = [width floatValue];
                    216:     size.height = [height floatValue];
                    217:     change = [[DimensionsGraphicsChange alloc] initGraphicView:graphicView];
                    218:     [change startChange];
                    219:        [graphicView graphicsPerform:@selector(sizeTo:) with:&size];
                    220:        [[[graphicView window] flushWindow] makeKeyWindow];
                    221:     [change endChange];
                    222: 
                    223:     return self;
                    224: }
                    225: 
                    226: - setFilled:anObject
                    227: {
                    228:     Matrix *matrix = [[anObject target] itemList];
                    229:     [matrix setTarget:self];
                    230:     [matrix setAction:@selector(changeFilled:)];
                    231:     [matrix selectCellAt:0 :0];
                    232:     filled = anObject;
                    233:     return self;
                    234: }
                    235: 
                    236: - setLineJoin:anObject
                    237: {
                    238:     Matrix *matrix = [[anObject target] itemList];
                    239:     [matrix setTarget:self];
                    240:     [matrix setAction:@selector(changeLineJoin:)];
                    241:     [matrix selectCellAt:0 :0];
                    242:     lineJoin = anObject;
                    243:     return self;
                    244: }
                    245: 
                    246: - setLineCap:anObject
                    247: {
                    248:     Matrix *matrix = [[anObject target] itemList];
                    249:     [matrix setTarget:self];
                    250:     [matrix setAction:@selector(changeLineCap:)];
                    251:     [matrix selectCellAt:0 :0];
                    252:     lineCap = anObject;
                    253:     return self;
                    254: }
                    255: 
                    256: - setArrows:anObject
                    257: {
                    258:     Matrix *matrix = [[anObject target] itemList];
                    259:     [matrix setTarget:self];
                    260:     [matrix setAction:@selector(changeArrows:)];
                    261:     [matrix selectCellAt:0 :0];
                    262:     arrows = anObject;
                    263:     return self;
                    264: }
                    265: 
                    266: @end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.