Example #1
0
void WndPaintDirt( a_window *wnd )
{
    int                 i;
    wnd_line_piece      line;
    wnd_line_piece      next_piece_line;
    gui_rect            rect;
    wnd_dirt            *dirt;
    gui_coord           size;
    gui_coord           half_char;
    a_window            *next;
//    a_window            *last;

//    last = NULL;
    for( wnd = WndNext( NULL ); wnd != NULL; wnd = next ) {
        next = WndNext( wnd );
        if( wnd->vscroll_pending != 0 ) {
            if( wnd->hscroll_pending != -1 ) {
                _Set( wnd, WSW_REPAINT );
            }
            if( _Is( wnd, WSW_REPAINT ) ) {
                if( wnd->hscroll_pending != -1 ) {
                    GUIInitHScroll( wnd->gui, wnd->hscroll_pending );
                }
                WndRepaint( wnd );
                wnd->hscroll_pending = -1;
                wnd->vscroll_pending = 0;
            } else {
                for( i = 0; i < wnd->title_size; ++i ) {
                    GUIDrawTextExtent( wnd->gui, " ", 1, i, 0, GUI_BACKGROUND, GUI_NO_COLUMN );
                }
                GUIDoVScrollClip( wnd->gui, wnd->vscroll_pending,
                                  wnd->title_size, wnd->rows - 1 );
                wnd->vscroll_pending = 0;
            }
        }
        if( _Is( wnd, WSW_REPAINT ) ) {
            _Clr( wnd, WSW_REPAINT );
            WndKillCacheLines( wnd );
            WndCheckCurrentValid( wnd );
            GUIWndDirty( wnd->gui );
            if( wnd->max_indent != 0 && wnd->width >= wnd->max_indent ) {
                GUISetHScroll( wnd->gui, 0 );
                wnd->hscroll_pending = -1;
                GUISetHScrollRange( wnd->gui, wnd->max_indent );
            }
            next = wnd;
        } else {
            for( i = 0; i < wnd->dirtyrects; ++i ) {
                dirt = &wnd->dirty[i];
                if( dirt->row < 0 ) continue;
                if( dirt->row >= wnd->rows ) continue;
                if( dirt->piece == WND_NO_PIECE ) {
                    if( !WndGetLine( wnd, dirt->row, 0, &line ) ) continue;
                    GUIWndDirtyRow( wnd->gui, dirt->row );
                } else {
                    if( !WndGetLine( wnd, dirt->row, dirt->piece, &line ) ) continue;
                    if( line.bitmap ) {
                        GUIGetHotSpotSize( line.text[0], &size );
                        rect.x = line.indent;
                        rect.y = dirt->row * wnd->max_char.y;
                        rect.width = line.length;
                        rect.height = size.y;
                    } else if( dirt->col != WND_NO_COL ) {
                        if( line.length == 0 ) line.text = " ";
                        rect.x = line.indent;
                        rect.x += GUIGetExtentX(wnd->gui, line.text, dirt->col);
                        rect.y = dirt->row * wnd->max_char.y;
                        rect.width = GUIGetExtentX( wnd->gui, line.text+dirt->col, dirt->end_col-dirt->col+GUICharLen( line.text[dirt->col] ) );
                        rect.height = wnd->max_char.y;
                    } else if( line.extent == WND_MAX_EXTEND || line.master_tabstop ) {
                        rect.width = 0;
                        rect.height = 0;
                        GUIWndDirtyRow( wnd->gui, dirt->row );
                    } else {
                        rect.x = line.indent;
                        if( WndGetLine( wnd, dirt->row, dirt->piece+1, &next_piece_line ) ) {
                            if( next_piece_line.indent < line.indent ) {
                                rect.width = WND_APPROX_SIZE;
                            } else {
                                rect.width = next_piece_line.indent - line.indent;
                            }
                        } else {
                            rect.width = WND_APPROX_SIZE;
                        }
                        rect.y = dirt->row * wnd->max_char.y;
                        rect.height = wnd->max_char.y;
                    }
                    /* begin kludge for Kerning problem */
                    if( rect.width != 0 || rect.height != 0 ) {
                        half_char.x = WndAvgCharX( wnd ) / 2;
                        half_char.y = 0;
                        GUITruncToPixel( &half_char );
                        if( rect.x < half_char.x ) {
                            rect.width += half_char.x + rect.x;
                            rect.x = 0;
                        } else {
                            rect.x -= half_char.x;
                            rect.width += half_char.x + half_char.x;
                        }
                        GUIWndDirtyRect( wnd->gui, &rect );
                    }
                }
            }
        }
        if( wnd->hscroll_pending != -1 ) {
            GUISetHScroll( wnd->gui, wnd->hscroll_pending );
            wnd->hscroll_pending = -1;
        }
        wnd->dirtyrects = 0;
        WndSetThumb( wnd );
    }
}
Example #2
0
static void WndDrawTheLine( a_window *wnd, wnd_line_piece *line,
                            wnd_row row )
{
    gui_ord             extent;
    gui_point           start,end;
    gui_ord             max_y;
    gui_ord             max_x;
    wnd_bar_info        *bar_info;

    if( _Isnt( wnd, WSW_NOT_TO_SCREEN ) ) {
        if( line->underline ) {
            max_y = WndMaxCharY( wnd );
            start.x = line->indent;
            start.y = row * max_y + max_y / 2;
            end.x = line->indent + line->extent;
            end.y = start.y;
            GUIDrawLine( wnd->gui, &start, &end, GUI_PEN_SOLID, 0, line->attr );
            return;
        } else if( line->vertical_line ) {
            max_y = WndMaxCharY( wnd );
            max_x = WndAvgCharX( wnd );
            start.x = line->indent + max_x / 2;
            end.x = start.x;
            start.y = row * max_y;
            end.y = start.y + max_y;
            GUIDrawLine( wnd->gui, &start, &end, GUI_PEN_SOLID, 0, line->attr );
            return;
        } else if( line->draw_hook | line->draw_line_hook ) {
            if( GUIIsGUI() ) {
                max_y = WndMaxCharY( wnd );
                max_x = WndAvgCharX( wnd );
                start.x = line->indent + max_x / 2;
                end.x = start.x + max_x;
                start.y = row * max_y + max_y / 2;
                end.y = start.y;
                GUIDrawLine( wnd->gui, &start, &end, GUI_PEN_SOLID, 0, line->attr );
                start.x = line->indent + max_x / 2;
                end.x = start.x;
                start.y = row * max_y;
                end.y = start.y;
                if( line->draw_hook ) {
                    end.y += max_y / 2;
                } else {
                    end.y += max_y;
                }
                GUIDrawLine( wnd->gui, &start, &end, GUI_PEN_SOLID, 0, line->attr );
            } else {
                char    ch[3];
                if( line->draw_hook ) {
                    ch[0] = GUIGetCharacter( GUI_INACT_FRAME_LL_CORNER );
                } else {
                    ch[0] = GUIGetCharacter( GUI_INACT_RIGHT_TITLE_MARK );
                }
                ch[1] = GUIGetCharacter( GUI_INACT_FRAME_BOTTOM );
                ch[2] = '\0';
                GUIDrawText( wnd->gui, ch, 2, row, line->indent, line->attr );
            }
            return;
        } else if( line->draw_bar ) {
            bar_info = (wnd_bar_info *)line->text;
            if( bar_info->bar_group ) {
                GUIDrawBarGroup( wnd->gui, row, line->indent,
                            line->extent - bar_info->bar_size2,
                            bar_info->bar_size2, bar_info->bar_style,
                            bar_info->bar_colour, bar_info->bar_colour2,
                            bar_info->bar_selected );
            } else {
                GUIDrawBar( wnd->gui, row, line->indent, line->extent,
                            bar_info->bar_style, bar_info->bar_colour,
                            bar_info->bar_selected );
            }
            return;
        } else if( line->bitmap ) {
            GUIDrawHotSpot( wnd->gui, line->text[0],
                            row, line->indent, line->attr );
            return;
        } else if( line->extent == WND_NO_EXTEND ) {
            GUIDrawText( wnd->gui, line->text, line->length,
                         row, line->indent, line->attr );
        } else {
            GUIDrawTextExtent( wnd->gui, line->text, line->length,
                         row, line->indent, line->attr, line->extent );
        }
    }
    extent = GUIGetExtentX( wnd->gui, line->text, line->length );
    if( line->extent != WND_MAX_EXTEND ) {
        if( line->extent > extent ) {
            extent = line->extent;
        }
    }
    if( line->indent + extent > wnd->max_indent ) {
        wnd->max_indent = line->indent + extent;
    }
}
Example #3
0
static bool StatusEventProc( gui_window *gui, gui_event gui_ev, void *parm )
/**************************************************************************/
{
    static bool         button_pressed = false;
    gui_ctl_id          id;
    gui_key             key;
    gui_keystate        state;
    const char          *msg;

    parm = parm;
    if( gui == NULL )
        return( false );

    switch( gui_ev ) {

    case GUI_INIT_WINDOW:
        return( true );

    case GUI_PAINT:
        {
            if( StatusBarLen == 0 ) {
                break;
            }
            msg = GetVariableStrVal( Messages[MsgLine0] );
            GUIDrawTextExtent( gui, msg, strlen( msg ), LINE0_ROW,
                               LINE0_COL * CharSize.x, WND_STATUS_TEXT, GUI_NO_COLUMN );
            GUIDrawTextExtent( gui, StatusLine1, strlen( StatusLine1 ), LINE1_ROW,
                               LINE1_COL * CharSize.x, WND_STATUS_TEXT, GUI_NO_COLUMN );
#ifdef _UI
            {
                int         len1, len2;
                char        num[20];

                memset( StatusBarBuf, ' ', StatusBarLen );
                StatusBarBuf[StatusBarLen] = '\0';
                itoa( Percent, num, 10 );
                strcat( num, "%" );
                memcpy( StatusBarBuf + StatusBarLen / 2 - 1, num, strlen( num ) );
                // draw bar in two parts
                len1 = (StatusBarLen * (long)Percent) / 100;
                if( len1 < 0 ) {
                    len1 = 0;
                } else if( len1 > StatusBarLen ) {
                    len1 = StatusBarLen;
                }
                len2 = StatusBarLen - len1;
                if( len1 > 0 ) {
                    GUIDrawText( gui, StatusBarBuf, len1, STATUS_ROW,
                                 StatusBarRect.x, WND_STATUS_BAR );
                }
                if( len2 > 0 ) {
                    GUIDrawText( gui, StatusBarBuf + len1, len2, STATUS_ROW,
                                 StatusBarRect.x + len1 * CharSize.x, WND_STATUS_TEXT );
                }
                memset( StatusBarBuf, UiGChar[UI_SBOX_TOP_LINE], StatusBarLen );
                GUIDrawText( gui, StatusBarBuf, StatusBarLen, STATUS_ROW - 1,
                             StatusBarRect.x, WND_STATUS_TEXT );
                GUIDrawText( gui, StatusBarBuf, StatusBarLen, STATUS_ROW + 1,
                             StatusBarRect.x, WND_STATUS_TEXT );
            }
#else
            {
                gui_coord   coord;
                int         str_len, width, height;
                int         bar_width, len1, len2, divider;
                gui_point   start, end;
                gui_rect    rStatusBar;

//              sprintf( StatusBarBuf, "%d%%", Percent );
                // clear whole bar
                GUIFillRect( gui, &StatusBarRect, WND_STATUS_BAR );
                // calculate where divider splits rectangle
                bar_width = StatusBarRect.width;
                divider = (bar_width * (long)Percent) / 100;
                if( divider < 0 ) {
                    divider = 0;
                } else if( divider > bar_width ) {
                    divider = bar_width;
                }
                rStatusBar = StatusBarRect;
                rStatusBar.width = divider;
                // calculate position for text (centre it)
                str_len = strlen( StatusBarBuf );
                width = GUIGetExtentX( gui, StatusBarBuf, str_len );
                height = GUIGetExtentY( gui, StatusBarBuf );
                coord.y = StatusBarRect.y + (StatusBarRect.height - height) / 2;
                coord.x = StatusBarRect.x + (StatusBarRect.width - width) / 2;
                divider += StatusBarRect.x;
                if( coord.x > divider ) {
                    // text is completely to right of divider
                    GUIFillRect( gui, &rStatusBar, WND_STATUS_TEXT );
                    GUIDrawTextPos( gui, StatusBarBuf, str_len, &coord,
                                    WND_STATUS_TEXT );
                } else if( coord.x + width < divider ) {
                    // text is completely to left of divider
                    GUIFillRect( gui, &rStatusBar, WND_STATUS_TEXT );
                    GUIDrawTextPos( gui, StatusBarBuf, str_len, &coord,
                                    WND_STATUS_BAR );
                } else {
                    // need to split text
                    len1 = ((long)(divider - coord.x) * str_len) / width;
                    if( len1 < 0 ) {
                        len1 = 0;
                    } else if( len1 > str_len ) {
                        len1 = str_len;
                    }
                    len2 = str_len - len1;
                    // recalc divider, so it falls on a character boundary
                    divider = coord.x + GUIGetExtentX( gui, StatusBarBuf, len1 );
                    rStatusBar.width = divider - StatusBarRect.x;
                    GUIFillRect( gui, &rStatusBar, WND_STATUS_TEXT );
                    if( len1 > 0 ) {
                        GUIDrawTextPos( gui, StatusBarBuf, len1, &coord,
                                        WND_STATUS_BAR );
                    }
                    if( len2 > 0 ) {
                        coord.x = divider;
                        GUIDrawTextPos( gui, StatusBarBuf + len1, len2, &coord,
                                        WND_STATUS_TEXT );
                    }
                }
                // draw frame
                start.x = StatusBarRect.x;
                start.y = StatusBarRect.y;
                end.x = StatusBarRect.width + StatusBarRect.x;
                end.y = start.y;                                // top line
                GUIDrawLine( gui, &start, &end, GUI_PEN_SOLID, 1, WND_STATUS_FRAME );
                start.y = StatusBarRect.y + StatusBarRect.height; // bottom line
                end.y = start.y;
                GUIDrawLine( gui, &start, &end, GUI_PEN_SOLID, 1, WND_STATUS_FRAME );
                end.y = StatusBarRect.y;
                start.x = StatusBarRect.x;
                end.x = start.x;                            // left side
                GUIDrawLine( gui, &start, &end, GUI_PEN_SOLID, 1, WND_STATUS_FRAME );
                start.x = StatusBarRect.x + StatusBarRect.width;
                end.x = start.x;                           // right side
                GUIDrawLine( gui, &start, &end, GUI_PEN_SOLID, 1, WND_STATUS_FRAME );
            }
#endif
            return( false );
        }

    case GUI_DESTROY:
        StatusWnd = NULL;
        return( false );

    case GUI_CONTROL_CLICKED:
        GUIGetFocus( gui, &id );
        GUI_GETID( parm, id );
        switch( id ) {
        case CTL_CANCEL:
            if( !button_pressed ) {
                button_pressed = true;
                if( MsgBox( gui, "IDS_QUERYABORT", GUI_YES_NO ) == GUI_RET_YES ) {
                    CancelSetup = true;
                }
                button_pressed = false;
                break;
            }
        case CTL_DONE:
            if( !button_pressed ) {
                CancelSetup = true;
                break;
            }
        }
        return( true );
    case GUI_KEYDOWN:
        GUI_GET_KEY_STATE( parm, key, state );
        state = state;
        switch( key ) {
        case GUI_KEY_ESCAPE:
            if( !button_pressed ) {
                button_pressed = true;
                if( MsgBox( gui, "IDS_QUERYABORT", GUI_YES_NO ) == GUI_RET_YES ) {
                    CancelSetup = true;
                }
                button_pressed = false;
                break;
            }
        default:
            break;
        }
        return( true );
    default:
        break;
    }
    return( false );
}