Quartz text in qelems?


    Aug 02 2007 | 5:36 pm
    Hi all-
    I'm hacking away at the Kalim example in the SDK and have run across a situation where it seems I can draw Quartz text if I call the update function directly, but if I use a qelem, it doesn't display:
    (In this snippet, f_pad is a character string and f_pos is the position, or number of characters in the string)
    void kalim_update(t_kalim *x) { GrafPtr gp; // pointer to current GrafPort
    // set the GrafPort to kalim's wind and get and store a pointer to // the current GrafPort gp = wind_setport(x->k_wind); if (gp) { OSStatus quartz_status; CGContextRef myContext; quartz_status = QDBeginCGContext( gp, &myContext );
    // post( "quartz_status: %d", quartz_status ); if( quartz_status == noErr ){ CGContextSetShouldAntialias( myContext, false ); CGContextSelectFont( myContext, "Monaco", 10, kCGEncodingMacRoman); CGContextSetTextDrawingMode( myContext, kCGTextFill ); CGContextSetRGBFillColor( myContext, 0, 0, 0, 1); if( x->f_pos > 0 ) { post( "x->f_pos: %d x->f_pad %s", x->f_pos, x->f_pad ); CGContextShowTextAtPoint( myContext, 3, 12, x->f_pad, x->f_pos ); x->f_pos = 0; } CGContextShowTextAtPoint( myContext, 3, 24, "01234567891234567890", 20 );
    quartz_status = QDEndCGContext( gp, &myContext ); // Does // this dispose of gp so I don't need the below? } wind_restoreport(gp); // restore the saved GrafPort after drawing } }
    void kalim_key( t_kalim *x, short key, short modifiers, short keycode ) { if( key == 0x0d ){ x->f_pad[x->f_pos+1] = 0; kalim_update( x ); // qelem_set(x->k_qelem); } else{ x->f_pad[x->f_pos++] = key; post( "%c %d", key, x->f_pos ); if( x->f_pos > MAXLINE-1 ){ x->f_pos = MAXLINE-1; post("bing!"); } } }
    So if I use kalim_update(x) directly, everything's OK. qelem_set(x->k_qelem), however, fails to display text.
    Any thoughts?
    I could email or pastebin the entire file if anyone was interested.
    Thanks in advance!
    Charles Turner

    • Aug 03 2007 | 12:54 am
      Charles Turner wrote on 8/2/07 at 1:36 PM
      >I'm hacking away at the Kalim example in the SDK and have run across a >situation where it seems I can draw Quartz text if I call the update >function directly, but if I use a qelem, it doesn't display:
      I'm beyond this version right now, so I can't definitely confirm this, but it seems that my update function, if called via a qelem, is working with screen coordinates and not my window coordinates.
      In other words, it didn't seem to draw the text because it was drawing it in the lower left-hand corner of my display.
      I also omitted a call to either CGContextFlush() or CGContextSynchronize() just prior to QDEndCGContext().
      Best, Charles