// DrawStatusLine(): // Called to draw the Status Line. void DrawStatusLine(LWControl *ctl, FreeKeyInterface *ui, DrMode mode) { CDrawFuncs *df = fk_int->panel_funcs->DrawFuncs; int cx = CON_HOTX( ctl ); int cy = CON_HOTY( ctl ); int cw = CON_HOTW( ctl ); int ch = CON_HOTH( ctl ); if( fk_int->processing ) { // Progress Bar Drawing // Draw the bar df->DrawRGBBox( fk_int->main_panel, 0, 60, 150, cx+1, cy+1, (int)( (cw-2) * ((double)fk_int->progress_cur / (double)fk_int->progress_total) ), ch-2 ); // Clear the area outside the bar df->DrawRGBBox( fk_int->main_panel, 132, 130, 132, cx + (cw-2) * ((double)fk_int->progress_cur / (double)fk_int->progress_total) + 1, cy+1, cw - (int)( ((double)(cw-2) * ((double)fk_int->progress_cur / (double)fk_int->progress_total)) - 2), ch-2 ); // Write the name of the current object on the bar df->WriteText( fk_int->main_panel, fk_int->status_text, COLOR_WHITE, cx+4, cy ); } else { // Standard Message Drawing if( fk_int->status_mode == STATUSMODE_ERROR ) { df->DrawRGBBox( fk_int->main_panel, 175, 0, 0, cx+1, cy+1, cw-2, ch-2 ); df->WriteText( fk_int->main_panel, fk_int->status_text, COLOR_LT_YELLOW, cx+4, cy ); } else if( fk_int->status_mode == STATUSMODE_NOTICE ) { df->DrawRGBBox( fk_int->main_panel, 200, 185, 0, cx+1, cy+1, cw-2, ch-2 ); df->WriteText( fk_int->main_panel, fk_int->status_text, COLOR_BLACK, cx+4, cy ); } else { // Default to Info mode df->DrawRGBBox( fk_int->main_panel, 132, 130, 132, cx+1, cy+1, cw-2, ch-2 ); df->WriteText( fk_int->main_panel, fk_int->status_text, COLOR_BLACK, cx+4, cy ); } } }
// MakeKeySelectionControls(): bool FreeKeyInterface::MakeKeySelectionControls() { try { int x = CON_HOTW( select_info_area ); int y = CON_HOTH( select_info_area ); // Keyframe Selection Info if( !( key_select_info_area = AREA_CTL( panel_funcs->orig_struct, main_panel, "", x, y ) ) ) throw false; x = CON_X( select_info_area ); y = CON_Y( select_info_area ); MOVE_CON( key_select_info_area, x, y ); // Set the Draw Functions ival.intv.value = (int)&DrawKeySelectInfo; (*key_select_info_area->set)( key_select_info_area, CTL_USERDRAW, &ival ); return true; } catch( bool ) { return false; } return true; }
static void sevent( LWControl *ctl, void *data ) { LWPanelFuncs *panf; const LWDisplayMetrics *dmet; LWPanelID panel; LWValue ival = { LWT_INTEGER }, ivecval = { LWT_VINT }; int x, y, w, h, m; char a[ 32 ]; /* panel, panf, dmet */ panel = ( LWPanelID ) CON_PAN( ctl ); panf = ( LWPanelFuncs * ) CON_PANFUN( ctl ); dmet = panf->drawFuncs->dispMetrics(); /* control dimensions */ x = CON_HOTX( ctl ); y = CON_HOTY( ctl ); w = CON_HOTW( ctl ); h = CON_HOTH( ctl ); x += w; y += ( h - dmet->textHeight ) / 2; /* mouse drag coordinates */ GET_INT( ctl, m ); sprintf( a, "%d", m ); panf->drawFuncs->drawBox( panel, COLOR_LT_YELLOW, x + 10, y, 40, dmet->textHeight ); panf->drawFuncs->drawText( panel, a, COLOR_BLACK, x + 12, y ); }
static void create_controls( ConvolveInst *inst ) { const LWDisplayMetrics *dm; int x, y, dx, dy, w, i, pw, ph; /* create a control */ ctl[ 0 ] = FLOAT_CTL( panf, panel, "" ); /* find out how much vertical space the panel wants for drawing its own decorations */ ph = PAN_GETH( panf, panel ); ph -= CON_H( ctl[ 0 ] ); /* create the rest of the controls */ for ( i = 1; i < 9; i++ ) ctl[ i ] = FLOAT_CTL( panf, panel, "" ); ctl[ 9 ] = WPOPUP_CTL( panf, panel, "Presets", preset, 150 ); /* position all of the controls */ x = CON_X( ctl[ 0 ] ); y = CON_Y( ctl[ 0 ] ); dx = CON_HOTW( ctl[ 0 ] ) + 8; dy = CON_HOTH( ctl[ 0 ] ) + 4; for ( i = 1; i < 9; i++ ) MOVE_CON( ctl[ i ], x + dx * ( i % 3 ), y + dy * ( i / 3 )); w = CON_W( ctl[ 9 ] ); MOVE_CON( ctl[ 9 ], x + 3 * dx - w, y + 10 * dy / 3 ); /* now that we know how much room the controls will take up, set the height of the panel and center it */ ph += CON_Y( ctl[ 9 ] ); ph += CON_HOTH( ctl[ 9 ] ); PAN_SETH( panf, panel, ph - 6 ); pw = PAN_GETW( panf, panel ); dm = panf->drawFuncs->dispMetrics(); MOVE_PAN( panf, panel, ( dm->width - pw ) / 2, ( dm->height - ph ) / 2 ); /* initialize the controls */ set_kernctl( inst ); SET_INT( ctl[ 9 ], pindex ); /* set the control event callbacks */ CON_SETEVENT( ctl[ 9 ], handle_preset, inst ); }
// DrawLWListerHSlider(): void DrawLWListerHSlider( LWControl *ctl, LWLister *lister, DrMode mode ) { CDrawFuncs df( lister->GetPanelFuncs()->drawFuncs ); LWRasterFuncs *rf = lister->GetRasterFuncs(); // Get some sizes int cx = CON_HOTX( lister->GetHSlider() ); int cy = CON_HOTY( lister->GetHSlider() ); int cw = CON_HOTW( lister->GetHSlider() ); int ch = CON_HOTH( lister->GetHSlider() ); // Figure out where the slider should be drawn double slider_start = 0.0; double slider_end = 1.0; lister->GetHSliderKnobExtents( slider_start, slider_end ); double slider_center = slider_start + (slider_end - slider_start)/2; // Draw the trough and knob double here; for( int i=0; i < cw; i++ ) { here = ((double)i/(double)cw); if( (here < slider_start) || (here > slider_end) ) rf->blitPanel( lister->GetHSliderRasterTrough(), 0, 0, lister->GetPanel(), cx+i, cy, 1, 15 ); else rf->blitPanel( lister->GetHSliderRasterKnob(), 0, 0, lister->GetPanel(), cx+i, cy, 1, 15 ); } // Draw ticks on the knob int tick_start = (int)(slider_center * (double)cw) - 8; for( i=0; i < 4; i++ ) { df.DrawLine( lister->GetPanel(), RGB_(108, 120, 108), cx + tick_start, cy+3, cx+tick_start, cy+12 ); df.DrawLine( lister->GetPanel(), RGB_(204, 216, 204), cx + tick_start+1, cy+3, cx+tick_start+1, cy+12 ); tick_start += 5; } // Draw the border PanelDraw::EmptyBox( lister->GetPanel(), &df, cx-1, cy-1, cw+2, ch+2, 1, 1, 80, 80, 80, 80, 80, 80 ); }
// GetHSliderExtents(): bool LWLister::GetHSliderKnobExtents( double &slider_start, double &slider_end ) { CDrawFuncs df( panel_funcs->drawFuncs ); slider_start = 0.0; slider_end = 1.0; int cw = CON_HOTW( hslider ); if( max_hscroll > cw ) { double slider_size = (double)cw / (double)max_hscroll; if( slider_size < 1.0 ) { slider_start = (double)leftmost_visible_pixel / (double)max_hscroll; slider_end = slider_start + slider_size; } else { leftmost_visible_pixel = 0; } } // See if the knob is too small double slider_center = slider_start + (slider_end - slider_start)/2; if( ((slider_end - slider_start) * (double)cw) < 30 ) { double shift = (15.0/(double)cw); slider_start = slider_center - shift; slider_end = slider_center + shift; } // Make sure the knob exists entirely in the trough if( slider_start < 0.0 ) { slider_end += 0.0 - slider_start; slider_start = 0.0; } if( slider_end > 1.0 ) { slider_start -= slider_end - 1.0; slider_end = 1.0; } return true; }
// WPopdown_ControlDraw(): void WPopdown_ControlDraw( LWControl *con, void *data, DrMode mode ) { PanelControls_WPopdown *popdown = (PanelControls_WPopdown *)data; int x = CON_HOTX( popdown->control ) - 1; int y = CON_HOTY( popdown->control ) - 1; int w = CON_HOTW( popdown->control ) + 2; int h = CON_HOTH( popdown->control ) + 2; LWRasterID raster = popdown->raster_funcs->create( w, h, 0 ); popdown->control->get( popdown->control, CTL_FLAGS, &ival ); const char *title = (popdown->title == NULL) ? "(unknown)" : popdown->title; if( mode == DR_ERASE ) { if( ival.intv.value != CTLF_INVISIBLE ) popdown->raster_funcs->drawBox( raster, LWP_BG, 0, 0, w, h ); } else { RasterDraw::Button( raster, popdown->raster_funcs, 0, 0, w, h, 184, 196, 184, 0 ); if( ival.intv.value == CTLF_DISABLE ) { // Ghosted RasterDraw::DrawArrow( raster, popdown->raster_funcs, w - 9, h/2, RasterDraw::arrow_popup, RasterDraw::arrow_solid, RGB_( 204, 216, 204 ) ); popdown->raster_funcs->drawText( raster, (char *)title, RGB_( 204, 216, 204 ), 6, 4 ); RasterDraw::DrawArrow( raster, popdown->raster_funcs, w - 12, h/2 - 1, RasterDraw::arrow_popup, RasterDraw::arrow_solid, RGB_( 108, 120, 108 ) ); popdown->raster_funcs->drawText( raster, (char *)title, RGB_( 108, 120, 108 ), 5, 3 ); } else { // Normal RasterDraw::DrawArrow( raster, popdown->raster_funcs, w - 12, h/2 - 1, RasterDraw::arrow_popup, RasterDraw::arrow_solid, RGB_( 0, 0, 0 ) ); popdown->raster_funcs->drawText( raster, (char *)title, RGB_( 0, 0, 0 ), 5, 3 ); } } popdown->raster_funcs->blitPanel( raster, 0, 0, popdown->panel, x, y, w, h ); popdown->raster_funcs->destroy( raster ); }
static void ctl_draw( LWControl *ectl, void *edata, DrMode mode ) { int x, y, w, h, dx, dy, npts, npols; char buf[ 24 ]; elcount( &npts, &npols ); x = CON_HOTX( ectl ); y = CON_HOTY( ectl ); w = CON_HOTW( ectl ); h = CON_HOTH( ectl ); panf->drawFuncs->drawBox( panel, LWP_INFO_BG, x, y, w, h ); dy = ( h - 2 * dmet->textHeight ) / 3; dx = w / 2 - panf->drawFuncs->textWidth( panel, "Points:" ); sprintf( buf, "Points: %d", npts ); panf->drawFuncs->drawText( panel, buf, LWP_INFO_IMG, x + dx, y + dy ); dy += dy + dmet->textHeight; dx = w / 2 - panf->drawFuncs->textWidth( panel, "Polygons:" ); sprintf( buf, "Polygons: %d", npols ); panf->drawFuncs->drawText( panel, buf, LWP_INFO_IMG, x + dx, y + dy ); }
// Handle(): bool LWLister::Handle( int flags, int x, int y ) { static bool was_down = false; static int down_x, down_y; static int active_control = -1; static bool do_more; static bool was_dragging; static int item_count; static int previous_first_visible_item; static int most_recent_first_visible_item; static int previous_leftmost_visible_pixel; static int most_recent_leftmost_visible_pixel; #ifdef _DEBUG static bool clear_log = true; ofstream out( "i:\\mousetest.txt", (clear_log ? 0 : ios::app) ); clear_log = false; out << "X/Y: " << x << "/" << y << " " << ((flags & MOUSE_DOWN) ? "Mouse Down" : "Mouse Up" ) << endl; #endif // See if the mouse has just been clicked and find out which control we're in if( flags & MOUSE_DOWN ) { if( was_down == false ) { down_x = x; down_y = y; was_down = true; do_more = true; was_dragging = false; item_count = count( user_data ); previous_first_visible_item = first_visible_item; most_recent_first_visible_item = previous_first_visible_item; previous_leftmost_visible_pixel = leftmost_visible_pixel; most_recent_leftmost_visible_pixel = previous_leftmost_visible_pixel; // Test the Lister int cx = CON_HOTX( lister ); int cy = CON_HOTY( lister ); int cw = CON_HOTW( lister ); int ch = CON_HOTH( lister ); if( (x >= cx) && (y >=cy) && (x <= cx+cw) && (y <= cy+ch) ) { active_control = 0; #ifdef _DEBUG out << "- Mouse Down: Lister" << endl; #endif } else { // Test the Vertical Scrollbar cx = CON_HOTX( vslider ); cy = CON_HOTY( vslider ); cw = CON_HOTW( vslider ); ch = CON_HOTH( vslider ); #ifdef _DEBUG out << "- Mouse Down: Vertical Scrollbar" << endl; #endif if( (x >= cx) && (y >=cy) && (x <= cx+cw) && (y <= cy+ch) ) { active_control = 1; } else { // Test the Horizontal Scrollbar cx = CON_HOTX( hslider ); cy = CON_HOTY( hslider ); cw = CON_HOTW( hslider ); ch = CON_HOTH( hslider ); #ifdef _DEBUG out << "- Mouse Down: Horizontal Scrollbar" << endl; #endif if( (x >= cx) && (y >=cy) && (x <= cx+cw) && (y <= cy+ch) ) { active_control = 2; } else { active_control = -1; return false; } } } } } else { #ifdef _DEBUG out << "- Mouse Up" << endl; #endif was_down = false; } // Mouse was clicked; decide how to handle it if( was_down && do_more ) { if( active_control == 0 ) { // Lister #ifdef _DEBUG out << "- Handle Lister" << endl; #endif return true; } else if( active_control == 1 ) { // Vertical Scrollbar double slider_start, slider_end; GetVSliderKnobExtents( slider_start, slider_end ); // See if the slider fills the trough if( (slider_start <= 0.0) && (slider_end >= 1.0) ) { do_more = false; #ifdef _DEBUG out << "- Handle Vertical Scrollbar: Slider Fills Trough" << endl; #endif return true; } // See if the user clicked in an empty part of the trough int ch = CON_HOTH( vslider ); int cy = CON_HOTY( vslider ); double click = (double)(y-cy)/(double)ch; int slider_size = (int)((slider_end - slider_start) * item_count); if( !was_dragging ) { int jump = 0; if( click < slider_start ) jump = -1; else if( click > slider_end ) jump = 1; if( jump != 0 ) { #ifdef _DEBUG out << "- Handle Vertical Scrollbar: Jump " << jump << endl; #endif slider_size *= jump; first_visible_item += slider_size; if( first_visible_item < 0 ) first_visible_item = 0; if( first_visible_item > (item_count - slider_size) ) first_visible_item = item_count - slider_size; do_more = false; Redraw(); return true; } } // Handle the user dragging the scrollbar was_dragging = true; double delta = (double)(y - down_y) / (double)ch; #ifdef _DEBUG out << "- Handle Vertical Scrollbar: Drag -- Delta " << (y - down_y) << endl; #endif first_visible_item = previous_first_visible_item + (int)(delta * (double)item_count); if( first_visible_item < 0 ) first_visible_item = 0; if( first_visible_item > (item_count - slider_size) ) first_visible_item = item_count - slider_size; if( most_recent_first_visible_item != first_visible_item ) // This just keeps the UI from flickering when nothing has changed Redraw(); most_recent_first_visible_item = first_visible_item; return true; } else if( active_control == 2 ) { // Horizontal Scrollbar double slider_start, slider_end; GetHSliderKnobExtents( slider_start, slider_end ); // See if the slider fills the trough if( (slider_start <= 0.0) && (slider_end >= 1.0) ) { do_more = false; #ifdef _DEBUG out << "- Handle Horizontal Scrollbar: Slider Fills Trough" << endl; #endif return true; } // See if the user clicked in an empty part of the trough int cw = CON_HOTW( hslider ); int cx = CON_HOTX( hslider ); double click = (double)(x-cx)/(double)cw; int slider_size = (int)((slider_end - slider_start) * max_hscroll); if( !was_dragging ) { int jump = 0; if( click < slider_start ) jump = -1; else if( click > slider_end ) jump = 1; if( jump != 0 ) { #ifdef _DEBUG out << "- Handle Horizontal Scrollbar: Jump " << jump << endl; #endif slider_size *= jump; leftmost_visible_pixel += slider_size; if( leftmost_visible_pixel < 0 ) leftmost_visible_pixel = 0; if( leftmost_visible_pixel > (max_hscroll - slider_size) ) leftmost_visible_pixel = max_hscroll - slider_size; do_more = false; Redraw(); return true; } } // Handle the user dragging the scrollbar was_dragging = true; double delta = (double)(x - down_x) / (double)cw; leftmost_visible_pixel = previous_leftmost_visible_pixel + (int)(delta * (double)max_hscroll); #ifdef _DEBUG out << "- Handle Horizontal Scrollbar: Drag -- Delta " << (x - down_x) << "; new LVP: " << leftmost_visible_pixel << endl; #endif if( leftmost_visible_pixel < 0 ) leftmost_visible_pixel = 0; if( leftmost_visible_pixel > (max_hscroll - slider_size) ) leftmost_visible_pixel = max_hscroll - slider_size; if( most_recent_leftmost_visible_pixel != leftmost_visible_pixel ) // This just keeps the UI from flickering when nothing has changed Redraw(); most_recent_leftmost_visible_pixel = leftmost_visible_pixel; return true; } } return false; }
// DrawLWLister(): void DrawLWLister( LWControl *ctl, LWLister *lister, DrMode mode ) { CDrawFuncs df( lister->GetPanelFuncs()->drawFuncs ); LWRasterFuncs *rf = lister->GetRasterFuncs(); // Get some sizes int cx = CON_HOTX( lister->GetLister() ); int cy = CON_HOTY( lister->GetLister() ); int cw = CON_HOTW( lister->GetLister() ); int ch = CON_HOTH( lister->GetLister() ); int line_height = df.DispMetrics()->textHeight + 2; int line, col; int col_x = 0; int count = (*lister->count)( lister->GetUserData() ); int text_pad; for( line=0; ((line+1) * line_height) < ch; line++ ) { if( (lister->GetFirstVisibleItem() + (line - 1)) >= count ) break; col_x = 0; for( col = 0; col < (int)lister->GetColumnWidths().NumElements(); col++ ) { text_pad = (col == 0) ? 5 : 2; // Compute the raster size and possible negative X offset int raster_col_x = col_x - lister->GetLeftmostVisiblePixel(); int raster_col_w = lister->GetColumnWidths()[ col ]; if( (raster_col_x + raster_col_w) < 0 ) { // Ends before left edge // Set the next column's X position col_x += lister->GetColumnWidths()[ col ]; continue; } if( raster_col_x > (lister->GetLeftmostVisiblePixel() + cw) ) // Starts after right edge break; if( raster_col_x < 0 ) raster_col_w += raster_col_x; else raster_col_x = 0; // Compute the drawing position int draw_x = 0; if( col_x > lister->GetLeftmostVisiblePixel() ) draw_x = col_x - lister->GetLeftmostVisiblePixel(); // Adjust the raster width for the drawing position if( raster_col_w > (cw - draw_x) ) raster_col_w = (cw - draw_x); // Create a raster area for this column of this line LWRasterID raster = rf->create( raster_col_w, line_height, 0 ); if( line == 0 ) { // Header Line rf->drawRGBBox( raster, 112, 112, 112, 0, 0, raster_col_w, line_height ); // Clear background const char * text = (*lister->name)( lister->GetUserData(), -1, col ); if( text != NULL ) rf->drawText( raster, (char *)text, COLOR_BLACK, raster_col_x + text_pad, 1 ); // Text rf->drawLine( raster, COLOR_BLACK, 0, line_height-1, raster_col_w-1, line_height -1 ); // Draw row seperator line if( (col_x - lister->GetLeftmostVisiblePixel() + lister->GetColumnWidths()[ col ]) < cw ) rf->drawLine( raster, COLOR_BLACK, raster_col_w-1, 0, raster_col_w-1, line_height - 1 ); // Draw column seperator Line } else { // Item Line rf->drawRGBBox( raster, 128, 128, 128, 0, 0, raster_col_w, line_height ); // Clear background const char * text = (*lister->name)( lister->GetUserData(), lister->GetFirstVisibleItem() + (line - 1), col ); if( text != NULL ) rf->drawText( raster, (char *)text, COLOR_BLACK, raster_col_x + text_pad, 1 ); // Text rf->drawLine( raster, RGB_(112, 112, 112), 0, line_height-1, raster_col_w-1, line_height -1 ); // Draw row seperator line } rf->blitPanel( raster, 0, 0, lister->GetPanel(), cx + draw_x, cy + (line * line_height), raster_col_w, line_height ); rf->destroy( raster ); // Set the next column's X position col_x += lister->GetColumnWidths()[ col ]; // Exit the column loop if no more columns can fit if( col_x >= cw ) break; } // Handle running out of columns int right_edge = col_x - lister->GetLeftmostVisiblePixel(); if( right_edge < 0 ) right_edge = 0; if( right_edge < cw ) { // Create a raster area for this column of this line LWRasterID raster = rf->create( cw - right_edge, line_height, 0 ); if( line == 0 ) { // Header Line rf->drawRGBBox( raster, 112, 112, 112, 0, 0, cw - right_edge, line_height ); // Clear background rf->drawLine( raster, COLOR_BLACK, 0, line_height-1, cw - right_edge -1, line_height -1 ); // Draw row seperator line } else { // Item Line rf->drawRGBBox( raster, 128, 128, 128, 0, 0, cw - right_edge, line_height ); // Clear background rf->drawLine( raster, RGB_(112, 112, 112), 0, line_height-1, cw - right_edge -1, line_height -1 ); // Draw row seperator line } rf->blitPanel( raster, 0, 0, lister->GetPanel(), cx + right_edge, cy + (line * line_height), cw-right_edge, line_height ); rf->destroy( raster ); } } // Fill in the empty part of the list int remaining = (line * line_height); df.DrawRGBBox( lister->GetPanel(), 128, 128, 128, cx, cy+remaining, cw, ch-remaining ); }
sprintf( buffer, "Zin: Factor: %g", fk_int->ms_zoom ); REDRAW_CON( ctl ); REDRAW_CON( fk_int->item_list ); // Test Zoom Out } else if( ( mx > (cx+fk_int->ms_divider - 125) ) && ( mx < (cx+fk_int->ms_divider - 105) ) ) { last_clicked = CLICKED_ZOOM_OUT; fk_int->ms_zoom *= 2.0; if( fk_int->ms_zoom > 1.0 ) fk_int->ms_zoom = 1.0; sprintf( buffer, "Zout: Factor: %g", fk_int->ms_zoom ); REDRAW_CON( ctl ); REDRAW_CON( fk_int->item_list ); // No Item Clicked */ // Originally from OnMouse(): int cx = CON_HOTX( fk_int->item_multiscroll ); int cy = CON_HOTY( fk_int->item_multiscroll ); int cw = CON_HOTW( fk_int->item_multiscroll ); int ch = CON_HOTH( fk_int->item_multiscroll ); // Test for Item MutliScroll if( (mx > cx) && (mx < (cx+cw)) && (my > cy) && (my < (cy+ch) ) ) OnItemMultiScroll( fk_int->item_multiscroll, mx, state );