Changeset 11098


Ignore:
Timestamp:
03/13/10 05:54:59 (2 years ago)
Author:
adamk
Message:
  • New Padre::Wx::Display screen geometry library for handling multiple screens, weird geometry setups and other weird stuff that coders have on their development setups. Padre's main window uses this to calculate an elegant golden-ratio uniform-margin default position and size (ADAMK)
Location:
trunk/Padre
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/Changes

    r11081 r11098  
    1515    - Add language names/translated texts to select_language list (SEWI) 
    1616    - Fixed ticket #865 Wrong document type in View Document As (PLAVEN) 
     17    - New Padre::Wx::Display screen geometry library for handling multiple 
     18      screens, weird geometry setups and other weird stuff that coders 
     19      have on their development setups. Padre's main window uses this to 
     20      calculate an elegant golden-ratio uniform-margin default position 
     21      and size (ADAMK) 
    1722 
    18230.58 2010.03.08  **WARNING Still not stable** 
  • trunk/Padre/lib/Padre/Wx/Display.pm

    r11096 r11098  
    6767sub primary_default { 
    6868    my $primary = primary(); 
    69     return _rect_scale( 
    70         _rect_golden( 
    71             $primary->GetClientArea 
     69    return _rect_golden( 
     70        _rect_scale_margin( 
     71            $primary->GetClientArea, 
     72            0.9, 
    7273        ), 
    73         0.8, 
    7474    ); 
    7575} 
     
    104104    my $ratio  = shift; 
    105105    my $margin = (1 - $ratio) / 2; 
     106    $rect->width( int( $rect->width * $ratio ) ); 
     107    $rect->height( int( $rect->height * $ratio ) ); 
    106108    $rect->x( $rect->x + int($rect->width  * $margin) ); 
    107109    $rect->y( $rect->y + int($rect->height * $margin) ); 
    108     $rect->width( int( $rect->width * $ratio ) ); 
    109     $rect->height( int( $rect->height * $ratio ) ); 
     110    return $rect; 
     111} 
     112 
     113# Scale a rect by some ration at the centre, 
     114# while retaining a consistent margin. 
     115sub _rect_scale_margin { 
     116    my $rect    = shift; 
     117    my $ratio   = shift; 
     118    my $marginr = (1 - $ratio) / 2; 
     119    my $marginx = int($rect->width  * $marginr); 
     120    my $marginy = int($rect->height * $marginr); 
     121    my $margin  = ($marginx > $marginy) ? $marginy : $marginx; 
     122    $rect->width( $rect->width - $margin * 2 ); 
     123    $rect->height( $rect->height - $margin * 2 ); 
     124    $rect->x( $rect->x + $margin ); 
     125    $rect->y( $rect->y + $margin ); 
    110126    return $rect; 
    111127} 
     
    114130sub _rect_golden { 
    115131    my $rect = shift; 
    116     if ( $rect->width > $rect->height * GOLDEN ) { 
     132    if ( $rect->width > ($rect->height * GOLDEN) ) { 
    117133        # Shrink left from the right 
    118         $rect->width( int($rect->height * GOLDEN) ); 
     134        $rect->width( int($rect->height / GOLDEN) ); 
    119135    } else { 
    120136        # Shrink up from the bottom 
    121         $rect->height( int($rect->width * GOLDEN) ); 
     137        $rect->height( int($rect->width / GOLDEN) ); 
    122138    } 
    123139    return $rect; 
  • trunk/Padre/lib/Padre/Wx/Main.pm

    r11094 r11098  
    100100    Wx::InitAllImageHandlers(); 
    101101 
    102     # Determine the initial frame style 
    103     my $config = $ide->config; 
    104     my $style  = Wx::wxDEFAULT_FRAME_STYLE; 
     102    # Initialise the style and position 
     103    my $config   = $ide->config; 
     104    my $size     = [ $config->main_width, $config->main_height ]; 
     105    my $position = [ $config->main_left, $config->main_top ]; 
     106    my $style    = Wx::wxDEFAULT_FRAME_STYLE; 
     107 
     108    # If we closed while maximized on the previous run, 
     109    # the previous size is completely suspect. 
    105110    if ( $config->main_maximized ) { 
    106         $style |= Wx::wxMAXIMIZE; 
     111        $style   |= Wx::wxMAXIMIZE; 
     112        $size     = [ -1, -1 ]; 
     113        $position = [ -1, -1 ]; 
     114    } 
     115 
     116    # Generate a smarter default size than Wx does 
     117    if ( $size->[0] == -1 ) { 
     118        require Padre::Wx::Display; 
     119        my $rect  = Padre::Wx::Display::primary_default(); 
     120        $size     = $rect->GetSize; 
     121        $position = $rect->GetPosition; 
    107122    } 
    108123 
    109124    # Create the underlying Wx frame 
    110125    my $self = $class->SUPER::new( 
    111         undef, -1, 'Padre: New window', 
    112         [ $config->main_left, $config->main_top, ], 
    113         [ $config->main_width, $config->main_height, ], $style, 
     126        undef, -1, 
     127        'Padre', 
     128        $position, 
     129        $size, 
     130        $style, 
    114131    ); 
    115132 
Note: See TracChangeset for help on using the changeset viewer.