BlitzMax NG - MaxGUI - SetGadgetPixmap

Started by degac, March 24, 2018, 09:43:21

Previous topic - Next topic

degac

Hi
just 'testing' BlitzMax NG+MaxGUI. I found this 'bug' (meaning that no pixmap is shown)

Import MaxGui.Drivers
SuperStrict
Global window:TGadget = CreateWindow("Buttons",40,40,400,330,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
Global icon:Ticonstrip=LoadIconStrip(CurrentDir()+"/_risorse/icone.png")
If icon=Null Print "Icon: NULL" Else Print "Icon: OK!"
Global pix:TPixmap=PixmapFromIconStrip(icon,2)
Global btn_1:Tgadget= CreateButton("Hallo",10,10,100,30,window)
SetGadgetPixmap btn_1,pix,GADGETPIXMAP_ICON|GADGETPIXMAP_NOTEXT

Repeat
Select WaitEvent()
Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
End
EndSelect
Forever


Tested with NG and Vanilla: in NG no icon is shown, while in Vanilla everything is ok

If there's a problem, there's at least one solution.
www.blitzmax.org

Henri

Hi,

your example doesn't work 'as is' either in regular nor NG for me (Win 7).

If I remember correctly, images in buttons need certain (ole?) library version to work (Vista upwards, in essence the 'Vista look').
For this, application needs manifest file included.

For regular:
Code (blitzmax) Select
Import maxgui.xpmanifest

For NG (and also for regular):
Code (blitzmax) Select
?Win32 'If 64bit then change to Win64. Also the object file need to be compiled with 64bit Windres
Import "my_manifest_file.o"
?


-Henri

- Got 01100011 problems, but the bit ain't 00000001

degac

I'm using Window10 x64 and BlitzMax vanilla app runs without problems.
If there's a problem, there's at least one solution.
www.blitzmax.org

Henri

I don't have 10 so can't test out yet. Does it work if you import the manifest ?

-Henri

- Got 01100011 problems, but the bit ain't 00000001

degac

Hi
no luck

With a x86 manifest file - I got an error

F:/BlitzMaxNG/MinGW32x64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible F:/_BlitzMax/manifest_test_2.o when searching for F:/_BlitzMax/manifest_test_2.o
F:/BlitzMaxNG/MinGW32x64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible F:/_BlitzMax/manifest_test_2.o when searching for F:/_BlitzMax/manifest_test_2.o
F:/BlitzMaxNG/MinGW32x64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find F:/_BlitzMax/manifest_test_2.o
collect2.exe: error: ld returned 1 exit status
Build Error: Failed to link F:/_BlitzMax/ng-test.createbutton.debug.exe


And trying to build a x64 manifest file using WindRes (under MinGW32x86) got other errors

F:\BlitzMaxNG\MinGW32x64\bin>windres -i F:/_BlitzMax/_AutomatorManifest/output/AutomatorManifest.icon.rc -o F:/_BlitzMax/_AutomatorManifest/output/AutomatorManifest.icon.o -J rc -O coff -v
Using `gcc -E -xc -DRC_INVOKED  F:/_BlitzMax/_AutomatorManifest/output/AutomatorManifest.icon.rc'
Using popen to read preprocessor output
gcc: error: CreateProcess: No such file or directory
windres: preprocessing failed.


So it's quite 'obscure' what kind of error I'm making!

If there's a problem, there's at least one solution.
www.blitzmax.org

col

#5
Maybe you could look at the maxide source code in the bmxng repo?
https://github.com/bmx-ng/maxide

That does something similar to what you're looking to achieve - creates a button with an image except for a toolbar strip.
It builds and works as expected for x86 and x64. It may help shed some light on any differences from what you're doing?

I remember a long time ago when I did this I had some glitches with images on buttons and my brain seem to remember that I had to scale the pixmap image to the correct size that is expected for the button - maybe even a pixel or two smaller. May be worth a short too.

Your windres error may be caused by the toolchain expecting '\' instead of '/' in the file path?
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

degac

Hi

thanks, good advice.
I will look at the source code to understand the 'right' way!

Thanks
If there's a problem, there's at least one solution.
www.blitzmax.org

Henri

Just for reference, here is my process to create .o file.

For 32 bit set arc-variable in *.bat to 32 (+ 3 filenames/locations)
For 64 bit set arc-variable in *.bat to 64 (+ 3 filenames/locations)

Also, it's important that in manifest file, both processorArchitecture atributes (usually in 2 places) are set for "x86" for 32 bit, and "amd64" for 64 bit.


test_build.bat
@echo off

rem *** 64bit or 32bit? ***
set arc=32

rem *** Set locations without quotes ***
set blitzmax_folder=D:\BlitzMax
set resource_file=test_resource.rc
set output=test_object

set output=%output%_%arc%.o
if %arc%==32 set arc=86

set windres_dir=%blitzmax_folder%\MinGW32x%arc%\bin
set command=%windres_dir%\windres -I %windres_dir% -i %resource_file% -o %output%

SET PATH=%PATH%;%windres_dir%

rem *** Execute ***
echo on
%command%
@echo off
pause



test_resource.rc      ' I have excluded icon part. For icon,add 101 ICON "myicon.ico"

1 24 "Test.manifest"

1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEOS 0x40004
FILETYPE 0x1
{
BLOCK "StringFileInfo"
{
BLOCK "040904b0"
{
  VALUE "Comments", "Testing manifest"
  VALUE "CompanyName", "My company"
  VALUE "FileVersion", "1.0.0.0"
  VALUE "FileDescription", "Main executable."
  VALUE "InternalName", "Test"
  VALUE "LegalCopyright", "My copyright"
  VALUE "LegalTrademarks", "All rights reserved"
  VALUE "OriginalFilename", "Test.exe"
  VALUE "ProductName", "Testing program"
  VALUE "ProductVersion", "1.0.0.0"
}
}
BLOCK "VarFileInfo"
{
  VALUE "Translation", 0x0409, 0
}
}



test.manifest    'This is for 64 bit

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
    <asmv3:windowsSettings
         xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
      <dpiAware>true</dpiAware>
    </asmv3:windowsSettings>
  </asmv3:application>
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="amd64"
name="Application"
type="win32"
/>
<description>Test program</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="amd64"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>



test_program.bmx
Code (blitzmax) Select

SuperStrict

?Win32x86
Import "test_object_32.o"
?

?Win32x64
Import "test_object_64.o"
?

Import MaxGui.Drivers

Global window:TGadget = CreateWindow("Buttons",40,40,400,330,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
Global icon:Ticonstrip = LoadIconStrip(CurrentDir()+"/icone.png")
If icon = Null Print "Icon: NULL" Else Print "Icon: OK!"

Global pix:TPixmap = PixmapFromIconStrip(icon,2)
If Not pix Then Notify "Error!"; End
Global btn_1:Tgadget = CreateButton("Hallo",10,10,100,30,window)
SetGadgetPixmap btn_1, pix, GADGETPIXMAP_ICON|GADGETPIXMAP_NOTEXT

Repeat
Select WaitEvent()
Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
End
EndSelect
Forever



-Henri
- Got 01100011 problems, but the bit ain't 00000001

Brucey

Okay. I'm going to build in manifest/resource functionality into bmk for win32 gui builds.
There's really no need to have to faff around with all this stuff in this day and age. I'm getting older and even more lazy ;-)

I'm thinking along the lines of auto-generating the files just before the final link stage.
It could also look for an icon file (say, "app name.ico") and possible another file with the app details in (say, "app name.fileinfo.txt") which could be in the format of an init/properties file - key=value

That would get you automatic resources included for all your win32 apps.

And an extra bmk flag to disable all of that if you'd rather do something yourself...

Derron

Keep somewhere in your mind, that additional information might be needed for "android" too - so maybe make it compatible to that.

While an ".txt" file is surely even less complicated it might be a better choice to have it in a .bmk file (so a LUA script) as this might allow for even more dynamic things (cannot come up with, but eg. the file information could become dynamic - time stamps and the likes).

These .bmk files should not become too complicated (there is a blabla.bmk in the bmxng\bin folder for defaults, and any override has to be in appname.bmk). As a coder we should be able to "decipher" where to change the icon name or the application name.


bye
Ron

Scaremonger

Quote from: Brucey on March 29, 2018, 17:34:34
Okay. I'm going to build in manifest/resource functionality into bmk for win32 gui builds.

Hi Brucey.

Perfect!

If there is any way you could increment a build number every time you compile and use this directly in the resource file as part of the version number, that would make identifying different builds much easier.

Si...



Derron

I've done it that way:
- created a file "source/version.txt" (empty as it gets overwritten)
- created a file "pre.bmk" (executed before compilation of your main file)

https://github.com/TVTower/TVTower/blob/master/pre.bmk:
Code (Lua) Select


@define CreateVersionFile
bmk.Sys("echo \"\" > ".. %BUILDPATH% .."/source/version.txt")
@end

@define doVersion
version = os.date('%d.%m.%y %H:%M')

bmk.Sys("echo \"" .. version .. "\" > " .. %BUILDPATH% .. "/source/version.txt")
# file = io.open(arg1,"w")
# file:write(version)
# file:close()
@end

# run the pre compile step install
#CreateVersionFile
doVersion


I create that file as "non-NG-BMK" does not execute pre.bmk and so the file might be missing if people compile it with vanilla. Next step is:

Code (Blitzmax) Select

'projectfile.bmx
Incbin "source/version.txt"

'main.bmx
VersionDate = LoadText("incbin::source/version.txt").Trim()
VersionString = "vx.y.z Build ~q" + VersionDate+"~q"



It only refreshes if a "new linking" is needed. So everytime you hit "compile" on a "quick build" without changing anything the build date will stay the same.


bye
Ron

Scaremonger


degac

Wow, full of answers and ideas!

Thanks everyone!
If there's a problem, there's at least one solution.
www.blitzmax.org

Steve Elliott

Quote
Wow, full of answers and ideas!

Thanks everyone!

Of course, this is SyntaxBomb  ;)
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb