1. IDE release 0.10.5

Announcing a new release of IDE at 
http://www2.txcyber.com/~camping/judith.html with many new features and 
fixes of bugs from prior releases. Please see IDE.html for a list of new 
items.

Thanks to the people who tested this version and offered suggestions and 
improvements.

Judith

new topic     » topic index » view message » categorize

2. Re: IDE release 0.10.5

Hi Judith,
here is a reworking of your code. Hope it helps.

-------------------------
--demo of reading xpm_icon.e and trapping the sequence of the xpm and
--then adding to window at x,y

include win32lib.ew
without warning
constant win=create(Window,"test xpm",0,0,0,300,320,0)

sequence XPM  XPM = {}
sequence XPMNames XPMNames = {}

integer ok

function trims(sequence text)
    integer start, finish

    start = 1
    finish = length(text)
    --now trim text at right
    for i=length(text) to 1 by -1 do
        if text[i]!=' ' then
            finish = i
            exit
        end if
    end for

    --now trim text from left
    for i=1 to finish do
        if text[i]!=' ' then
            start = i
            exit
        end if
    end for

    return text[start .. finish]
end function

atom hdib
procedure onOpen_win()
    integer handle, ignore, at
    object text
    sequence fName, text2
    integer eof, XPMI


    fName="XPM_Icon.e"
    XPM={}
    XPMNames = {}

    eof = False

    handle=open( fName, "r" )
    if handle = -1 then
        -- give message and exit
        ignore = message_box(   "Open File Error",
                                "Unable to read the file " & fName,
                                MB_ICONHAND+MB_TASKMODAL )
        return
    end if

    -- parse the file
    while not eof do

        -- get a line of text
        text = gets( handle )
        if atom( text ) then
            exit   --EOF
        end if

        -- remove line feed
        if text[length(text)] = '\n' then
            text= text[1 .. length(text) - 1]
        end if
        text=trims(text)

        if length(text) >= 4 and equal(text[1 .. 4], "XPM_") then
           XPMNames = append(XPMNames, text)
           XPM  = append(XPM, {})
           XPMI = length(XPM)
           -- If ONLY we had a "continue" statement, this would look a lot
cleaner.
        elsif length(XPM) != 0 then
            --see dummy test below to see what data looks like
            at=find( '{', text )
            if at then
                text=text[at+1..length(text)]
            else
                at=find( '}', text )
                if at then
                    text=text[1..at-1]
                end if
            end if
            text = trims(text)
            if length(text) > 0 then
                if text[1] = '"' then
                   text = text[2 .. length(text)-2]
                end if
                if length(text) > 0 then
                 XPM[XPMI] = append(XPM[XPMI], text)
                end if
            end if
        end if
    end while

    repaintWindow( win )

--if I need the {} then do
--XPM="{" & XPM & "}"


--at=message_box(XPM,"",0)

--dummy test which works
--XPM = {
--"24 24 3 1",
--"          c None",
--".        c #FFFFFF",
--"+        c #808080",
--"                        ",
--"                        ",
--"                        ",
--"                        ",
--"                        ",
--"                        ",
--"                        ",
--"........................",
--"                       +",
--"+++++++++++++++++      +",
--"                .    . +",
--"                .   .+ +",
--"                .  .+. +",
--"                . .+.+ +",
--"..................+.+  +",
--"                       +",
--"++++++++++++++++++++++++",
--"                        ",
--"                        ",
--"                        ",
--"                        ",
--"                        ",
--"                        ",
--"                        "}


end procedure

procedure paint_win(integer x1, integer y1, integer x2, integer y2)
    integer x, y

    -- These values are hard coded but
    -- you should really get the Rect size of each bitmap
    -- and window to adjust for full viewing.
    x = 10
    y = 10
    for i = 1 to length( XPM ) do
        hdib=xpmToPixmap(XPM[i])
        transBlt(win,x,y,hdib)
        x += 40
        if x > 260 then
           y += 40
           x = 10
        end if
    end for
end procedure
onPaint[win]=routine_id("paint_win")


onOpen[win]=routine_id("onOpen_win")

WinMain( win, Normal )
------------------------------------

The main problem that I saw was that you were not constructing the correct
sequence format for the XPM to Pixmap conversion routine. That requires a
sequence of sequences. You were building up a sequence of atoms.  Using '&'
instead of append().

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu