Should I switch to PureBasic?

Just starting out? Need help? Post your questions and find answers here.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Should I switch to PureBasic?

Post by Trond »

drawing this image to the window or reassign it to the gadget - where is the difference?
It seems like the image gadget implementation has changed. Because before the image was copied, and you could free the original image. Now it seems to read directly from the original image, so it should be the same.

Edit: I tested with a 1024x768 image, and manually drawing to window output is slightly faster.
Last edited by Trond on Sat Jan 16, 2010 12:57 pm, edited 1 time in total.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Should I switch to PureBasic?

Post by Kaeru Gaman »

I think it's still kind of "copied", because the content of the ImageGadget only change when you reassign it, not to the time you draw on the image...
I never tried to free the source image, though....
oh... and have a nice day.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Should I switch to PureBasic?

Post by Trond »

Kaeru Gaman wrote:I think it's still kind of "copied", because the content of the ImageGadget only change when you reassign it, not to the time you draw on the image...
I never tried to free the source image, though....
Before it was like this, but try to draw on the image again, then move the window off the screen. The new image is drawn! So there is no copy any more.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Should I switch to PureBasic?

Post by Kaeru Gaman »

ah ok... so it's the "frontbuffer" of the OS that keeps showing the old state until a ReDraw (#WM_PAINT) happens...
oh... and have a nice day.
JustinJack
User
User
Posts: 89
Joined: Thu Feb 04, 2010 7:34 am
Location: Decatur, TX
Contact:

Re: Should I switch to PureBasic?

Post by JustinJack »

Code: Select all

;+-------------------------------------------+
;|                                                             |
;|  This example is just one way to set a         |
;|  custom background, it's probably the          |
;|  simplest here in PureBasic, to acheive         |
;|  the functionality you'd like without             |
;| the overhead of ImageGadgets and fighting  |
;| Z-Order, and putting Children windows         |
;| withing Children windows...                        |
;| Have fun with it...Justin Jack                     |
;|                                                             |
;+-------------------------------------------+


Enumeration
    #WM_SETBACKGROUNDIMAGE = #WM_APP + $01
EndEnumeration


Structure bkgrSTRUCT
    hOrigBkgrHandle.l
    hOldBkgrHandle.l
    hBkgr.l
EndStructure

Procedure WndProc( hWnd, uMsg, wParam, lParam )
    *myPtr = GetWindowLongPtr_(hWnd, #GWLP_USERDATA)
    If *myPtr > 0
        *imgInfo.bkgrSTRUCT = *myPtr
    EndIf
    Select uMsg
        Case #WM_CREATE
            *ptr = AllocateMemory(SizeOf(bkgrSTRUCT))
            SetWindowLongPtr_(hWnd, #GWLP_USERDATA, *ptr)
            *imgInfo.bkgrSTRUCT = *ptr
        Case #WM_SETBACKGROUNDIMAGE
            If lParam > 0
                hBkgr = GetClassLongPtr_(hWnd, #GCL_HBRBACKGROUND)
                *imgInfo\hBkgr = CreatePatternBrush_(ImageID(lParam))
                SetClassLongPtr_(hWnd, #GCL_HBRBACKGROUND, *imgInfo\hBkgr)
                InvalidateRect_(hWnd, 0, 1)
                If *imgInfo\hOrigBkgrHandle = 0
                    *imgInfo\hOrigBkgrHandle = hBkgr
                Else
                    DeleteObject_(hBkgr)
                EndIf
                ProcedureReturn *imgInfo\hBkgr
            Else
                ProcedureReturn 0
            EndIf
        Case #WM_DESTROY
            SetClassLongPtr_(hWnd, #GCL_HBRBACKGROUND, *imgInfo\hOrigBkgrHandle)
            DeleteObject_(*imgInfo\hBkgr)
    EndSelect
    ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure



Procedure Main()
    UseJPEGImageDecoder() ;Just to be safe...BitMaps will work too.
    imageFile.s = OpenFileRequester("Please Select an image to use as a background...", "*.BMP", "*.BMP", 1)

    If imageFile <> ""
        myImage = LoadImage(#PB_Any, imageFile, #PB_ImagePlugin_JPEG)
    EndIf
    

    SetWindowCallback(@WndProc())
    
    myWindow = OpenWindow(#PB_Any, 200, 200, 500, 500, "Test")
    hMainWindow = WindowID(myWindow)
    GetWindowRect_(hMainWindow, rc.RECT)
    
    ;- Resize our image to fit our window size
    If IsImage(myImage)
        ResizeImage(myImage, (rc\right-rc\left), (rc\bottom-rc\top))
    EndIf
    
    ;- Send our custom message to set the background as "myImage"
    If Not(SendMessage_(hMainWindow, #WM_SETBACKGROUNDIMAGE, 0, myImage))
        SetWindowTitle(myWindow, "Background Image Failed to Load.")
    Else
        SetWindowTitle(myWindow, "Background Image: " + imageFile)
    EndIf


    ; Regular PB Code...
    
    StringGadget(1,  10, 10, 150, 20, "")
    ButtonGadget(2, 180,  8,  75, 25, "Click Me!") 
    
    Repeat
        event = WaitWindowEvent()
        Select EventGadget()
            Case 2
                Select EventType()
                    Case #PB_EventType_LeftClick
                        myMsg.s = "You Typed: " + GetGadgetText(1) + #CRLF$
                        If IsImage(myImage)
                            myMsg.s + "Don't you like that background?"
                        EndIf
                        MessageBox_(hMainWindow, @myMsg.s, @"Please Note.", #MB_OK)
                EndSelect
        EndSelect
    Until event = #WM_CLOSE
    
    If IsImage(myImage)
        FreeImage(myImage)
    EndIf
    CloseWindow(myWindow)
EndProcedure

Main()
AndyMK
Enthusiast
Enthusiast
Posts: 582
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Re: Should I switch to PureBasic?

Post by AndyMK »

Pb's networking commands are just fine if you don't mind not being able to bind a socket to a specific interface. You can use the windows api for that stuff anyway. I just programmed an ICECAST style server. It handles 50 sources and 1000 listeners at very low cpu usage on a single core 2.6. The bottleneck was the 100meg connection :mrgreen: All done using Pb's own network commands and clever use of linkedlists ...
Post Reply