User Tag List

Results 1 to 9 of 9

Thread: Rendering a custom owner-drawn button in Runtime

  1. #1
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5+ DLC (Steam)

    Join Date
    Jan 2021
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rendering a custom owner-drawn button in Runtime

    Hey there,

    So I am working on a custom owner-drawn button in the Win32 runtime. I have a RenderTo() function that I created which renders the button the way I want it to appear.

    The RenderTo function has this signature:

    Code:
    void RenderTo(LPSURFACE ps, mv _far* mV, RECT FAR* rc, HFONT hFont, COLORREF dwBackColor, 
    COLORREF dwTextColor, TCHAR *sFilename, DWORD dwAlignFlags, TCHAR* wText);
    It works correctly in the Edittime.cpp when called like so:

    Code:
    void WINAPI DLLExport EditorDisplay(mv _far *mV, fpObjInfo oiPtr, fpLevObj loPtr, LPEDATA edPtr, RECT FAR *rc)
    {
    #ifndef RUN_ONLY
    	LPSURFACE ps = WinGetSurface((int)mV->mvIdEditWin);
    	HFONT hFnt = CreateFontIndirect(&edPtr->textFont);
    	COLORREF dwBackColor = edPtr->backColor;
    	COLORREF dwTextColor = edPtr->textColor;
    	TCHAR* sFilename = edPtr->sFilename;
    	RenderTo(ps, mV, rc, hFnt, dwBackColor, dwTextColor, sFilename, edPtr->dwAlignFlags, edPtr->sText);
    	// Delete font
    	if (hFnt != NULL)
    		DeleteObject(hFnt);
    	
    #endif // !defined(RUN_ONLY)
    }
    So I am trying to call the same drawing function from the Runtime.cpp file but can't figure out why it isn't working correctly and can't really find much in the way of documentation for this.

    Here's one attempt, using the owner drawn Win32 message (in WindowProc):

    Code:
    	case WM_DRAWITEM:
    	{
    		LPDRAWITEMSTRUCT pDIS = (LPDRAWITEMSTRUCT)lParam;
    		if (NULL != pDIS) {
    			// Get a pointer to the RUNDATA structure (see GetRdptr function above for more info)
    			rdPtr = GetRdPtr(pDIS->hwndItem, rhPtr);
    
    			LPRH rhPtr = rdPtr->rHo.hoAdRunHeader;
    			LPSURFACE ps = WinGetSurface((int)rhPtr->rhIdEditWin);
    			TCHAR* sFilename = rdPtr->sFilename;
    			WCHAR wText[99];
    			int len = SendMessage(rdPtr->hWnd, WM_GETTEXT, ARRAYSIZE(wText), (LPARAM)wText);
    			rdPtr->rHo.hoRect.left = 0;
    			RECT rc;
    			rc.left = rdPtr->rHo.hoX;
    			rc.top = rdPtr->rHo.hoY;
    			rc.right = rc.left + rdPtr->rHo.hoImgWidth;
    			rc.bottom = rc.top + rdPtr->rHo.hoImgHeight;
    
    			RenderTo(ps, rhPtr->rh4.rh4Mv, &rc, rdPtr->hFont, rdPtr->backColor, rdPtr->textColor, rdPtr->sFilename, rdPtr->dwAlignFlags, wText);
    
    			WinAddZone(rhPtr->rhIdEditWin, &rc);
    			
    		}
        }
    The code is being called but all I get is a blank white rectangle where the control should be (but this does not seem to come from any of my drawing code).

    I also tried to call RenderTo() from DisplayRunObject:

    Code:
    short WINAPI DLLExport DisplayRunObject(LPRDATA rdPtr)
    {
    	// Begin render process...
    	LPRH rhPtr = rdPtr->rHo.hoAdRunHeader;
    	LPSURFACE ps = WinGetSurface((int)rhPtr->rhIdEditWin);
    	TCHAR* sFilename = rdPtr->sFilename;
    	WCHAR wText[99];
    	int len = SendMessage(rdPtr->hWnd, WM_GETTEXT, ARRAYSIZE(wText), (LPARAM)wText);
    	rdPtr->rHo.hoRect.left = 0;
    	RECT rc;
    	rc.left = rdPtr->rHo.hoX;
    	rc.top = rdPtr->rHo.hoY;
    	rc.right = rc.left + rdPtr->rHo.hoImgWidth;
    	rc.bottom = rc.top + rdPtr->rHo.hoImgHeight;
    
    	RenderTo(ps, rhPtr->rh4.rh4Mv, &rc, rdPtr->hFont, rdPtr->backColor, rdPtr->textColor, rdPtr->sFilename, rdPtr->dwAlignFlags, wText);
    
    	WinAddZone(rhPtr->rhIdEditWin, &rc);
    
    	return 0;
    }
    (I return REFLAG_DISPLAY from HandleRunObject() so this is getting called). But again, nothing actually shows up.

    Any ideas how I can get this to work?

  2. #2
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5+ DLC (Steam)

    Join Date
    Jan 2021
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The white rectangle seems to come from the child window I created in CreateRunObject(), so I guess the real question is -- how can I get a valid Surface for this child window so I can render to it using the same code I use when rendering in the editor?

  3. #3
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5+ DLC (Steam)

    Join Date
    Jan 2021
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Replacing my draw code in Runtime with the example from the help file doesn't even seem to work (I moved the child window so it wouldn't cover anything up):

    Code:
    // Runtime
    short WINAPI DLLExport DisplayRunObject(LPRDATA rdPtr)
    {
        LPRH    rhPtr = rdPtr->rHo.hoAdRunHeader;
    
        LPSURFACE ps = WinGetSurface((int)rhPtr->rhIdEditWin);
        if ( ps != NULL )
        {
            RECT    rc;
    
            int x = rc.left = rdPtr->rHo.hoX - rhPtr->rhWindowX;
            int y = rc.top = rdPtr->rHo.hoY - rhPtr->rhWindowY;
            int w = rdPtr->rHo.hoImgWidth;
            int h = rdPtr->rHo.hoImgHeight;
            rc.right = x + w;
            rc.bottom = y + h;
    
            COLORREF color = RGB(255,0,0);
            ps->Fill(x, y, w, h, color);
    
            WinAddZone(rhPtr->rhIdEditWin, &rc);
        }
    
        // OK
        return 0;
    }
    Just a blank window with the background color of the Frame:

    Click image for larger version. 

Name:	blank.jpg 
Views:	6 
Size:	37.4 KB 
ID:	29937

  4. #4
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleSWF Export ModuleUnicode Add-on
    Looki's Avatar
    Join Date
    Aug 2006
    Location
    Karlsruhe, Germany
    Posts
    3,741
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)
    The default runtime of Fusion these days is Direct3D (9 or 11) which does not implement the majority of cSurface drawing routines for hardware-accelerated surfaces. If not even the simple SDK example works, I assume that you are using the hardware-accelerated runtime, in which case I suggest setting the display mode to "Standard" in the application settings and see if that works. To render onto the screen in Direct3D, you can call Blit() onto it from a texture Surface, see https://github.com/clickteam-plugin/...Main.cpp#L4356 for how to create a texture from a bitmap Surface.

  5. #5
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5+ DLC (Steam)

    Join Date
    Jan 2021
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, yes of course, that was the problem with the basic SDK example. I got something appearing on the screen finally.

    So the next issue is if it's possible to do something like WinGetSurface with a child window? I want the control to be able to have keyboard focus, etc. so it makes the most sense to make it an owner drawn object and let Windows continue to do all that stuff. I wasn't able to find anything that would obviously take a HWND and return a cSurface however. Is there a way to do this or do I need to rewrite my drawing code to use plain Win32 at runtime in this case?

    Or maybe a way to blit from a cSurface directly to a HWND's drawing context? WM_DRAWITEM sets up a dc for you, so if there's a way to get a DIB from the cSurface I can just blit that to the child form I think.

    Again thanks for the help!

  6. #6
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5+ DLC (Steam)

    Join Date
    Jan 2021
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah and I just found some code in the help file that does actually do something like what I want, so I have something showing up in the child window now.

    Now just to figure out why it can't load the image at runtime...

  7. #7
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)Firefly 3D Module (Steam)
    Phi's Avatar
    Join Date
    Jan 2010
    Location
    England
    Posts
    1,952
    Mentioned
    25 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by airways View Post
    Ah and I just found some code in the help file that does actually do something like what I want, so I have something showing up in the child window now.

    Now just to figure out why it can't load the image at runtime...
    Make sure you request the image filters, maybe look into EnumElts in help file too.
    Be aware any text-drawing extensions in Unicode mode will need their Unicode text passed as unsigned short *, not wchar_t *, due to an old compatibility issue.

  8. #8
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5+ DLC (Steam)

    Join Date
    Jan 2021
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah storing the images in the image bank and using EnumElts ended up being better way to go since the images are stored in the produced app. I'm still a little puzzled why the external PNG load didn't work even though it works in the editor.

  9. #9
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)Firefly 3D Module (Steam)
    Phi's Avatar
    Join Date
    Jan 2010
    Location
    England
    Posts
    1,952
    Mentioned
    25 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by airways View Post
    Yeah storing the images in the image bank and using EnumElts ended up being better way to go since the images are stored in the produced app. I'm still a little puzzled why the external PNG load didn't work even though it works in the editor.
    You could refer to Surface object source code to see how it does it

Similar Threads

  1. How to make custom button
    By UnicornMan in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 25th February 2017, 11:40 PM
  2. Player Drawn Sprites at Runtime
    By Soilydude in forum Fusion 2.5
    Replies: 2
    Last Post: 18th January 2017, 03:47 PM
  3. EDIF - Object not rendering at runtime when Y<= 0 ou X<= 0
    By iOSC in forum Extension Development
    Replies: 6
    Last Post: 28th January 2015, 11:11 AM
  4. Can i refine this custom button?
    By sheppard1 in forum Fusion 2.5
    Replies: 4
    Last Post: 21st May 2014, 11:26 PM
  5. Custom Button?
    By Shizzle in forum The Games Factory 2 - Technical Support
    Replies: 2
    Last Post: 5th September 2010, 01:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •