Re: wxEuphoria - get_facenames() issue

new topic     » goto parent     » topic index » view thread      » older message » newer message

Matt Lewis wrote:
> 
> Matt Lewis wrote:
> > 
> > Unfortunately, there is no way to get the available sizes through wxWidgets.
> > I did some research into doing this on GTK through pango (the GTK font lib 
> > or whatever), and didn't see any obvious way to do it, or if it were 
> > available at all.  I suspect that I may have to go down into X itself to 
> > get this information.
> 
> Heh, got a better look at the pango docs, and I saw this function:
> 
> void pango_font_face_list_sizes(PangoFontFace *face,
>                                 int **sizes,
>                                 int *n_sizes);
> 
> So I guess it's actually pretty simple to do...

OK, I've got it working on Windows and Linux now.  I also made a couple of
changes to your demo.  First, it wasn't documented in wxeu (but it was in
wxWidgets), using a wxStaticBox as a parent will cause crashes in GTK.  The
solution is to use the wxStaticBoxSizer, which somehow didn't make the 
transition when I overhauled the library.  It was in the docs, but not 
the code.  I put that back.

I also changed it a bit to display the 'correct' sizes for bitmapped fonts.
It all uses sizers, too.  Obviously, you'd need to rebuild the dll and get
the newest wxeud.e to use this.
-- wxFontDemo.exw

include wxeud.e
without warning

constant 
    frmMain     = create( wxFrame, {0, -1, "Font Demo", -1, -1, 640, 480} ),
    pnlMain     = create( wxPanel, {frmMain} ),
    lblFace     = create( wxStaticText, {pnlMain, -1, "&Face"}),
    lstFace     = create( wxListBox, pnlMain ),
    lblSize     = create( wxStaticText, {pnlMain, -1, "&Size"}),
    txtSize     = create( wxTextCtrl, {pnlMain, -1, "10"}),
    lstSize     = create( wxListBox, pnlMain ),
    grpExample  = create( wxStaticBox, {pnlMain, -1, "Box"}),
lblExample  = create( wxStaticText, {pnlMain, -1, "The quick brown fox jumps
    over the lazy dog."})

sequence faces, sizes
atom font


procedure init()
    sequence sizer
    sequence string_sizes
    -- first put everything into sizers:
    sizer = {create( wxBoxSizer, wxVERTICAL)}
    set_sizer( pnlMain, sizer[$] )
    
    -- Add a sizer for the lists up top
    sizer &= create( wxBoxSizer, wxHORIZONTAL )
    add_sizer_to_sizer( sizer[$-1], sizer[$], 1, wxGROW, 0 )
    
    -- Sizer for the faces
    sizer &= create( wxBoxSizer, wxVERTICAL )
    add_sizer_to_sizer( sizer[$-1], sizer[$], 1, wxGROW, 0 )
    add_window_to_sizer( sizer[$], lblFace, 0, 0, 0 )
    add_window_to_sizer( sizer[$], lstFace, 1, wxGROW, 0 )
    sizer = sizer[1..$-1]  -- pop the face sizer
    
    -- Sizer for the sizes
    sizer &= create( wxBoxSizer, wxVERTICAL )
    add_sizer_to_sizer( sizer[$-1], sizer[$], 0, wxGROW, 0 )
    add_window_to_sizer( sizer[$], lblSize, 0, wxGROW, 0 )
    add_window_to_sizer( sizer[$], txtSize, 0, wxGROW, 0 )
    add_window_to_sizer( sizer[$], lstSize, 1, wxGROW, 0 )
    sizer = sizer[1..$-1]  -- pop the sizes sizer
    sizer = sizer[1..$-1]  -- pop the top sizer
    
    sizer &= create( wxStaticBoxSizer, { grpExample, wxHORIZONTAL } )
    add_sizer_to_sizer( sizer[$-1], sizer[$], 1, wxGROW, 0 )
    add_window_to_sizer( sizer[$], lblExample, 1, wxGROW, 0 )
    
    -- should return fixed-width fonts *only*
    faces = get_facesizes( {wxFONTENCODING_SYSTEM, wxTrue} ) 
    faces = append( faces, repeat( 0, length(faces[1]) ) )
	
	sizes = {8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72}
	string_sizes = sizes
    for i = 1 to length( sizes ) do
    	string_sizes[i] = sprint( sizes[i] )
        
    end for
    for i = 1 to length( faces[1] ) do
        add_item( lstFace, faces[1][i] )
        if length( faces[2][i] ) then
        	faces[3][i] = repeat( 0, length(faces[2][i]) )
        	for j = 1 to length(faces[2][i]) do
        		faces[3][i][j] = sprint( faces[2][i][j] )
        	end for
        else
        	faces[2][i] = sizes
        	faces[3][i] = string_sizes
        end if
    end for
    
    
    
    set_selection( lstFace, 0 )
    add_item( lstSize, faces[3][1] )
    set_selection( lstSize, 2 )
	
    font = create( wxFont, {10, wxDEFAULT, wxDEFAULT, wxDEFAULT, 0, faces[1]} )
    set_default_font( lblExample, font )

end procedure

procedure lstFace_onSelect( atom this, atom event_type, atom id, atom event )

    sequence face
	integer fx
	
	fx = get_selection( this ) + 1
	if not fx then
		return
	end if
    face = faces[1][fx]
    set_font_face_name( font, face )
    
    clear_list( lstSize )
   	add_item( lstSize, faces[3][fx] )

    set_default_font( lblExample, font )
    
end procedure
set_event_handler( lstFace, get_id(lstFace), 
    wxEVT_COMMAND_LISTBOX_SELECTED, routine_id("lstFace_onSelect"))

procedure lstSize_onSelect( atom this, atom event_type, atom id, atom event )

    integer index, size, face
    
    face = get_selection( lstFace ) + 1
    if not face then
    	return
    end if
    index = get_selection( this )
    size = faces[2][face][index+1]
    set_label( txtSize, sprint(size) )
    set_point_size( font, size )
    set_default_font( lblExample, font )

end procedure
set_event_handler( lstSize, get_id(lstSize), 
    wxEVT_COMMAND_LISTBOX_SELECTED, routine_id("lstSize_onSelect"))

procedure txtSize_onUpdate( atom this, atom event_type, atom id, atom event )

    sequence text
    object val
    integer size, pos
    
    text = get_label( txtSize )
    val = value( text )
    if val[1] = GET_SUCCESS then
        size = val[2]
        set_point_size( font, size )
        set_default_font( lblExample, font )
        pos = find( size, sizes )
        set_selection( lstSize, pos - 1 )
    end if

end procedure
set_event_handler( txtSize, get_id(txtSize), wxEVT_COMMAND_TEXT_UPDATED, 
    routine_id("txtSize_onUpdate"))

init()
wxMain( frmMain )


new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu