⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iedraw.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    prevbr.x = MAKELOGPTX( prev_pt->x );
    prevbr.y = MAKELOGPTY( prev_pt->y );

    if (prevtl.x > prevbr.x) {
        temp = (int)prevbr.x;
        prevbr.x = prevtl.x + pointSize.x;
        prevtl.x = temp;
    } else {
        prevbr.x += pointSize.x;
    }

    if (prevtl.y > prevbr.y) {
        temp = (int)prevbr.y;
        prevbr.y = prevtl.y + pointSize.y;
        prevtl.y = temp;
    } else {
        prevbr.y += pointSize.y;
    }

    ++prevtl.x;
    ++prevtl.y;
    ++topleft.x;
    ++topleft.y;

    pres = _wpi_getpres( hwnd );
    _wpi_torgbmode( pres );
    prevROP2 = _wpi_setrop2( pres, R2_XORPEN );
    hbrush = _wpi_createsolidbrush( BLACK );
    hwhitepen = _wpi_createpen( PS_SOLID, 0, WHITE );

    holdbrush = _wpi_selectobject( pres, hbrush );
    holdpen = _wpi_selectobject( pres, hwhitepen );

    if (!firsttime) {
        if ((toolType == IMGED_CIRCLEO) || (toolType == IMGED_CIRCLEF)) {
            _wpi_ellipse( pres, prevtl.x, prevtl.y, prevbr.x, prevbr.y );
        } else {
            _wpi_rectangle( pres, prevtl.x, prevtl.y, prevbr.x, prevbr.y );
        }
    }

    if ((toolType == IMGED_CIRCLEO) || (toolType == IMGED_CIRCLEF)) {
        _wpi_ellipse( pres, topleft.x, topleft.y, bottomright.x, bottomright.y );
    } else {
        _wpi_rectangle( pres, topleft.x, topleft.y, bottomright.x, bottomright.y );
    }
    _wpi_selectobject( pres, holdpen );
    _wpi_selectobject( pres, holdbrush );

    _wpi_deleteobject( hwhitepen );
    _wpi_deleteobject( hbrush );
    _wpi_setrop2( pres, prevROP2 );
    _wpi_releasepres( hwnd, pres );
} /* OutlineRegion */

/*
 * FillArea - Fills the area.
 */
void FillArea( WPI_POINT *pt, int mousebutton )
{
    WPI_POINT   devicept;
    COLORREF    colour;
    wie_clrtype type;
    img_node    *node;

    devicept.x = pt->x / pointSize.x;
    devicept.y = pt->y / pointSize.y;
    colour = GetSelectedColour( mousebutton, NULL, &type );

    FillXorAnd(colour, &devicept, type);
    node = GetCurrentNode();
    InvalidateRect( node->viewhwnd, NULL, FALSE );
    BlowupImage( node->hwnd, NULL );
#ifdef __OS2_PM__
    currentMouseButton = currentMouseButton;    // just to suppres complaints
#endif
} /* FillArea */

/*
 * CreateNewDrawPad - creates a new draw pad which is a child of the client
 *                    window.  These are the mdi children.
 */
void CreateNewDrawPad( img_node *node )
{
#ifdef __OS2_PM__
    hDrawArea = PMNewDrawPad( node );
    WinSendMsg( hDrawArea, WM_ACTIVATE, MPFROMSHORT(TRUE), MPFROMHWND(hDrawArea) );
#else
    hDrawArea = WinNewDrawPad( node );
#endif
} /* CreateNewDrawPad */

/*
 * CreateDrawnImage - Creates the enlarged image in the drawing area.  (used
 *                    when activating a new image or selecting a new image).
 */
void CreateDrawnImage( img_node *node )
{
    WPI_RECT    rcclient;
    int         cx;
    int         cy;

    GetClientRect( node->hwnd, &rcclient );
    hDrawArea = node->hwnd;

    cx = _wpi_getwidthrect(rcclient);
    cy = _wpi_getheightrect(rcclient);

    cx = cx / node->width;
    cy = cy / node->height;

    pointSize.x = max (1, cx);
    pointSize.y = max (1, cy);

} /* CreateDrawnImage */

/*
 * CheckGridItem - Check the grid item and display the grid if necessary.
 *                 First we check if an item has been created or not, if not
 *                 we just check some flags so that when it is created, a
 *                 grid will (not) be displayed.
 */
void CheckGridItem( HMENU hmenu )
{
    WPI_ENUMPROC        fp_enum;
    HCURSOR             prevcursor;

    prevcursor = _wpi_setcursor( _wpi_getsyscursor(IDC_WAIT) );
    if ( _wpi_isitemchecked(hmenu, IMGED_GRID) ) {
        _wpi_checkmenuitem( hmenu, IMGED_GRID, MF_UNCHECKED, FALSE );
        ImgedConfigInfo.grid_on = FALSE;
        BlowupImage( NULL, NULL );
        PrintHintTextByID( WIE_GRIDTURNEDOFF, NULL );
    } else {
        _wpi_checkmenuitem( hmenu, IMGED_GRID, MF_CHECKED, FALSE );
        ImgedConfigInfo.grid_on = TRUE;
        BlowupImage( NULL, NULL );
        PrintHintTextByID( WIE_GRIDTURNEDON, NULL );
    }
    PressGridButton();

    if( DoImagesExist() ) {
        fp_enum = _wpi_makeenumprocinstance( GridEnumProc, Instance );
        _wpi_enumchildwindows( ClientWindow, fp_enum, 0L );
        _wpi_freeprocinstance( fp_enum );
    }
    _wpi_setcursor( prevcursor );
} /* CheckGridItem */

/*
 * ResetDrawArea - Resets the drawing area when a new image is selected from
 *                 the select icon menu option. (only for icon files).
 */
void ResetDrawArea( img_node *node )
{
    WPI_RECT    rcclient;
    WPI_RECT    rc;
    WPI_PARAM2  lparam;
    short       new_width;
    short       new_height;

    GetClientRect( node->hwnd, &rcclient );

    pointSize.x = max (1, _wpi_getwidthrect(rcclient) / node->width);
    pointSize.y = max (1, _wpi_getheightrect(rcclient) / node->height);

    if (ImgedConfigInfo.square_grid) {
        GetClientRect( ClientWindow, &rc );
        if (pointSize.y * node->height > _wpi_getheightrect(rc) ) {
            pointSize.y = pointSize.x;
        } else {
            pointSize.x = pointSize.y;
        }
        /*
         * I add 1 to cause ResizeChild to resize the window.
         */
        new_width = (short)(pointSize.x*node->width+1);
        new_height = (short)(pointSize.y*node->height+1);
        lparam = WPI_MAKEP2(new_width, new_height);
        ResizeChild(lparam, node->hwnd, TRUE );
    }
    BlowupImage( node->hwnd, NULL );
} /* ResetDrawArea */

/*
 * SetDrawTool - Sets the appropriate tool type.
 */
void SetDrawTool( int tool_type )
{
    toolType = tool_type;
} /* SetDrawTool */

/*
 * SetBrushSize - sets the size of the brush for the brush tool option.
 */
void SetBrushSize( short new_size )
{
    ImgedConfigInfo.brush_size = new_size;
    WriteSetSizeText( WIE_NEWBRUSHSIZE, new_size, new_size );
} /* SetBrushSize */

static void SetGridSize( int x, int y )
{
    WriteSetSizeText( WIE_NEWGRIDSIZE, x, y );
} /* SetGridSize */

/*
 * RepaintDrawArea - handles the WM_PAINT message.
 */
void RepaintDrawArea( HWND hwnd )
{
    WPI_PRES            pres;
    PAINTSTRUCT         ps;

    if (hwnd) {
        pres = _wpi_beginpaint( hwnd, NULL, &ps );
        BlowupImage( hwnd, pres );
        _wpi_endpaint( hwnd, pres, &ps );
    }
} /* RepaintDrawArea */

/*
 * GetPointSize - returns the point size.
 */
WPI_POINT GetPointSize( HWND hwnd )
{
    WPI_POINT   pt = {0, 0};
    img_node    *node;
    WPI_RECT    rc;
    int         width;
    int         height;

    node = SelectImage( hwnd );
    if (!node) return( pt );

    GetClientRect( hwnd, &rc );
    width = _wpi_getwidthrect(rc);
    height = _wpi_getheightrect(rc);
    pt.x = width / node->width;
    pt.y = height / node->height;

    if( pt.x == 0 ) {
        pt.x = 1;
    }
    if( pt.y == 0 ) {
        pt.y = 1;
    }
    return( pt );
} /* GetPointSize */

/*
 * ResizeChild - resizes the draw area of the child window.
 */
void ResizeChild( WPI_PARAM2 lparam, HWND hwnd, BOOL firsttime )
{
    short       min_width;
    short       width;
    short       height;
    img_node    *node;
    short       x_adjustment;
    short       y_adjustment;
    short       new_width;
    short       new_height;
    WPI_POINT   point_size;
    WPI_POINT   max;
    HWND        frame;
    HMENU       hmenu;
    WPI_RECT    rc;
    WPI_RECT    rect;

    frame = _wpi_getframe( hwnd );
    width = LOWORD( lparam );
#ifdef __OS2_PM__
    height = SHORT2FROMMP( lparam );
#else
    height = HIWORD( lparam );
#endif

    GetClientRect( hwnd, &rc );
    GetWindowRect( hwnd, &rect );
    if( frame ) {
        GetClientRect( frame, &rc );
        GetWindowRect( frame, &rect );
    }

    max.x = _wpi_getsystemmetrics( SM_CXSCREEN );
    max.y = _wpi_getsystemmetrics( SM_CYSCREEN );

    x_adjustment = _wpi_getwidthrect( rect ) - _wpi_getwidthrect( rc );
    y_adjustment = _wpi_getheightrect( rect ) - _wpi_getheightrect( rc );

    #if 1
        min_width = MIN_DRAW_WIN_WIDTH;
    #else
        min_width = (short)(2*_wpi_getsystemmetrics(SM_CXSIZE)) +
                    x_adjustment +
                    8; // fudge factor to allow some of title bar to show
    #endif

#ifdef __OS2_PM__
    ++y_adjustment;
#endif

    node = SelectImage( hwnd );
    if (!node) return;

    // the following assumes that max.x >> min_width
    point_size.x = min( max.x / node->width, width / node->width );
    point_size.x = max( min_width / node->width + 1, point_size.x );

    point_size.y = min( max.y / node->height, height / node->height );
    point_size.y = max( 1, point_size.y );

    if( ImgedConfigInfo.square_grid ) {
        point_size.x = min( point_size.x, point_size.y );
        if( point_size.x < ( min_width / node->width + 1 ) ) {
            point_size.x = min_width / node->width + 1;
        }
        if( point_size.x > ( max.y / node->height ) ) {
            hmenu = GetMenu( _wpi_getframe(HMainWindow) );
            CheckSquareGrid( hmenu );
        } else {
            point_size.y = point_size.x;
        }
    }

    new_width = (short)(point_size.x * node->width + x_adjustment);
    new_height = (short)(point_size.y * node->height + y_adjustment);

    pointSize = point_size;

    if( (pointSize.x*node->width != width) ||
        (pointSize.y*node->height != height) ) {
        SetWindowPos( frame, HWND_TOP, 0, 0, new_width, new_height,
                        SWP_SIZE | SWP_ZORDER | SWP_NOMOVE | SWP_SHOWWINDOW);
        SetGridSize( pointSize.x, pointSize.y );
    }
    if( !firsttime ) {
        BlowupImage( node->hwnd, NULL );
    }
} /* ResizeChild */

/*
 * CheckSquareGrid - checks the square grid item
 */
void CheckSquareGrid( HMENU hmenu )
{
    if ( _wpi_isitemchecked(hmenu, IMGED_SQUARE) ) {
        _wpi_checkmenuitem(hmenu, IMGED_SQUARE, MF_UNCHECKED, FALSE);
        ImgedConfigInfo.square_grid = FALSE;
        PrintHintTextByID( WIE_SQUAREGRIDOFF, NULL );
    } else {
        _wpi_checkmenuitem( hmenu, IMGED_SQUARE, MF_CHECKED, FALSE );
        ImgedConfigInfo.square_grid = TRUE;
        PrintHintTextByID( WIE_SQUAREGRIDON, NULL );
    }
} /* CheckSquareGrid */

/*
 * MaximizeCurrentChild - makes the current edit window as large as it can
 *                        possibly be.
 */
void MaximizeCurrentChild( void )
{
    short       max_width;
    short       max_height;
    WPI_POINT   max_pt_size;
    WPI_RECT    client;
    WPI_RECT    rect;
    WPI_RECT    rc;
    img_node    *node;
    short       x_adjustment;
    short       y_adjustment;

    node = GetCurrentNode();
    if (!node) return;

    GetClientRect( node->hwnd, &rc );
    GetWindowRect( node->hwnd, &rect );

    x_adjustment = _wpi_getwidthrect( rect ) - _wpi_getwidthrect( rc );
    y_adjustment = _wpi_getheightrect( rect ) - _wpi_getheightrect( rc );

    GetClientRect( ClientWindow, &client );
    max_width = (short)( _wpi_getwidthrect(client) );
    max_height = (short)( _wpi_getheightrect(client) );

    max_pt_size.x = max_width / node->width;
    max_pt_size.y = max_height / node->height;

    if( ImgedConfigInfo.square_grid ) {
        max_pt_size.x = min( max_pt_size.x, max_pt_size.y );
        max_pt_size.y = max_pt_size.x;
    }

    if( max_pt_size.x <= pointSize.x && max_pt_size.y <= pointSize.y ) {
        return;
    }

    max_width = max_pt_size.x * node->width + x_adjustment;
    max_height = max_pt_size.y * node->height + y_adjustment;

    SetWindowPos( node->hwnd, HWND_TOP, 0, 0, max_width, max_height,
                        SWP_SIZE | SWP_MOVE | SWP_ZORDER | SWP_SHOWWINDOW );
} /* MaximizeCurrentChild */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -