Forum Replies Created
-
AuthorPosts
-
> I’m not sure, but I think Red and Blue’s been switched.
Haha!
It’s actually doing the same thing here, only my desktop is so psychedelic I didn’t notice!
Fixed code:
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119#Import "<std>"Using std..#Import "<windows.h>"#Import "<libuser32.a>"ExternAlias DWORD:UIntAlias HGDIOBJ:Void PtrStruct HDC__EndAlias HDC:HDC__ PtrStruct HWND__EndAlias HWND:HWND__ PtrStruct HBITMAP__EndAlias HBITMAP:HBITMAP__ PtrStruct BITMAPINFOHEADERField biSize:DWORDField biWidth:IntField biHeight:IntField biPlanes:ShortField biBitCount:ShortField biCompression:DWORDEndStruct BITMAPINFOField bmiHeader:BITMAPINFOHEADEREndConst SM_CYVIRTUALSCREEN:IntConst SM_CXVIRTUALSCREEN:IntConst SRCCOPY:DWORDConst NOTSRCCOPY:DWORDConst CAPTUREBLT:DWORDConst DIB_PAL_COLORS:UIntConst DIB_RGB_COLORS:UIntConst BI_RGB:DWORDFunction GetDesktopWindow:HWND()Function GetDC:HDC(hwnd:HWND)Function CreateCompatibleDC:HDC(hdc:HDC)Function GetSystemMetrics:int(index:Int)Function CreateCompatibleBitmap:HBITMAP(hdc:HDC,width:Int,height:Int)Function SelectObject:HGDIOBJ(hdc:HDC,hgdiobj:HGDIOBJ)Function DeleteObject:Int( hgdiobj:HGDIOBJ )Function BitBlt:Int(hdcDest:HDC,nXDest:Int,nYDest:Int,nWidth:Int,nHeight:Int,hdcSrc:HDC,nXSrc:Int,nYSrc:Int,dwRop:DWORD)Function ReleaseDC:Int(hwnd:HWND,hdc:HDC)Function DeleteDC:Int(hdc:HDC)Function GetDIBits:Int( hdc:HDC,hbmp:HBITMAP,firstLine:UInt,numlines:UInt,bitmapData:Void Ptr,bitmapInfo:BITMAPINFO Ptr,usage:UInt )PublicFunction CaptureWindow:Pixmap()Local hwnd:=GetDesktopWindow()Local w:=GetSystemMetrics( SM_CXVIRTUALSCREEN )Local h:=GetSystemMetrics( SM_CYVIRTUALSCREEN )Local hwnddc:=GetDC( hwnd )Local hcapturedc:=CreateCompatibleDC( hwnddc )Local hcapturebmp:=CreateCompatibleBitmap( hwnddc,w,h )SelectObject( hcapturedc,hcapturebmp )BitBlt( hcapturedc,0,0,w,h,hwnddc,0,0,SRCCOPY|CAPTUREBLT )Local bmpInfo:BITMAPINFOlibc.memset( Varptr bmpInfo,0,libc.sizeof( bmpInfo ) )bmpInfo.bmiHeader.biSize = libc.sizeof( bmpInfo.bmiHeader )bmpInfo.bmiHeader.biWidth = wbmpInfo.bmiHeader.biHeight = -hbmpInfo.bmiHeader.biPlanes = 1bmpInfo.bmiHeader.biBitCount = 24bmpInfo.bmiHeader.biCompression = BI_RGBLocal pixmap:=New Pixmap( w,h,PixelFormat.RGB8 )GetDIBits( hcapturedc,hcapturebmp,0,h,pixmap.Data,Varptr bmpInfo,DIB_RGB_COLORS )For Local y:=0 Until hLocal p:=pixmap.PixelPtr( 0,y )For Local x:=0 Until wLocal t:=p[0]p[0]=p[2]p[2]=tp+=3NextNextDeleteDC( hcapturedc )DeleteObject( hcapturebmp )Return pixmapEndFunction Main()Local pm:=CaptureWindow()Print "Captured! w="+pm.Width+", h="+pm.Heightpm.Save( DesktopDir()+"test.png" )EndActually, PixelFormat.RGB8 is just an alias I added for RGB24 – should probably have used RGB24 in the above code to prevent confusion. I recently added a number of GL depth/float pixel formats recently (which aren’t well supported in the Pixmap class yet) and decided I quite like the GL ‘notation’ (which is very similar to mx2 anyway) so have been playing around with switching to it (but leaving the old ones in there). Haven’t decided what to do here in general though.
But I’m surprised the code doesn’t work for you. What OS are you using? What desktop mode? Can you post a pic?
There’s this, but it appears to be c++14 only. I have asked the author if he can backport it to c++11 for us (I’m not moving to c++14 just yet…) but I don’t like our chances.
In the meantime, here’s some Windows only source…
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110#Import "<std>"Using std..#Import "<windows.h>"#Import "<libuser32.a>"ExternAlias DWORD:UIntAlias HGDIOBJ:Void PtrStruct HDC__EndAlias HDC:HDC__ PtrStruct HWND__EndAlias HWND:HWND__ PtrStruct HBITMAP__EndAlias HBITMAP:HBITMAP__ PtrStruct BITMAPINFOHEADERField biSize:DWORDField biWidth:IntField biHeight:IntField biPlanes:ShortField biBitCount:ShortField biCompression:DWORDEndStruct BITMAPINFOField bmiHeader:BITMAPINFOHEADEREndConst SM_CYVIRTUALSCREEN:IntConst SM_CXVIRTUALSCREEN:IntConst SRCCOPY:DWORDConst NOTSRCCOPY:DWORDConst CAPTUREBLT:DWORDConst DIB_PAL_COLORS:UIntConst DIB_RGB_COLORS:UIntConst BI_RGB:DWORDFunction GetDesktopWindow:HWND()Function GetDC:HDC(hwnd:HWND)Function CreateCompatibleDC:HDC(hdc:HDC)Function GetSystemMetrics:int(index:Int)Function CreateCompatibleBitmap:HBITMAP(hdc:HDC,width:Int,height:Int)Function SelectObject:HGDIOBJ(hdc:HDC,hgdiobj:HGDIOBJ)Function DeleteObject:Int( hgdiobj:HGDIOBJ )Function BitBlt:Int(hdcDest:HDC,nXDest:Int,nYDest:Int,nWidth:Int,nHeight:Int,hdcSrc:HDC,nXSrc:Int,nYSrc:Int,dwRop:DWORD)Function ReleaseDC:Int(hwnd:HWND,hdc:HDC)Function DeleteDC:Int(hdc:HDC)Function GetDIBits:Int( hdc:HDC,hbmp:HBITMAP,firstLine:UInt,numlines:UInt,bitmapData:Void Ptr,bitmapInfo:BITMAPINFO Ptr,usage:UInt )PublicFunction CaptureWindow:Pixmap()Local hwnd:=GetDesktopWindow()Local w:=GetSystemMetrics( SM_CXVIRTUALSCREEN )Local h:=GetSystemMetrics( SM_CYVIRTUALSCREEN )Local hwnddc:=GetDC( hwnd )Local hcapturedc:=CreateCompatibleDC( hwnddc )Local hcapturebmp:=CreateCompatibleBitmap( hwnddc,w,h )SelectObject( hcapturedc,hcapturebmp )BitBlt( hcapturedc,0,0,w,h,hwnddc,0,0,SRCCOPY|CAPTUREBLT )Local bmpInfo:BITMAPINFOlibc.memset( Varptr bmpInfo,0,libc.sizeof( bmpInfo ) )bmpInfo.bmiHeader.biSize = libc.sizeof( bmpInfo.bmiHeader )bmpInfo.bmiHeader.biWidth = wbmpInfo.bmiHeader.biHeight = -hbmpInfo.bmiHeader.biPlanes = 1bmpInfo.bmiHeader.biBitCount = 24bmpInfo.bmiHeader.biCompression = BI_RGBLocal pixmap:=New Pixmap( w,h,PixelFormat.RGB8 )pixmap.Clear( Color.Red )GetDIBits( hcapturedc,hcapturebmp,0,h,pixmap.Data,Varptr bmpInfo,DIB_RGB_COLORS )DeleteDC( hcapturedc )DeleteObject( hcapturebmp )Return pixmapEndFunction Main()Local pm:=CaptureWindow()Print "Captured! w="+pm.Width+", h="+pm.Heightpm.Save( DesktopDir()+"test.png" )EndWindows only…
Want to use GridView but got memory access violation – “style is null”.
Try the latest at develop.
GridView uses Style=GetStyle( “GridView” ) in its ctor, but ted2go’s default theme doesn’t have a ‘GridView’ style. Still, it shouldn’t crash if GetStyle can’t find a style so GetStyle should now return a simple ’empty’ Style if all else fails, never Null.
Some more on this: I’d recommend removing ted2go’s ‘default.json’ theme, and moving any customizations you may have made there to ted2-default.json. This should still work, and should cause ted2go to use mojox’s default.json instead, which *does* have a GridView style, and will also include any future default styles I may add.
By providing a default.json theme file with ted2go, the mojox one is actually being overwritten. This behaviour is by design – assets are imported in ‘module dependancy order’, allowing you to ‘overwrite’ (or ‘override’) any assets imported by any imported modules. Hope that makes sense…!
Was there a reason structs are by-value and classes are by-reference as opposed to allowing the user to specify?
‘Coz it’s WAY simpler and the alternative opens a pandora’s box of complexity. For starters, people would have to starting tagging many of their variables, parameters, return types etc with ‘ByRef’ or something. I would personally hate this as a user.
There’d be confusion over when to use ByRef, a bunch of technical issues like dereferencing, in place construction, probably GC issues, slicing issues (not currently an issue as structs can’t extend) – all that really *fun* stuff from C++ that makes me want to write new languages!
GetFileTime should return the time the file was last modified – if you don’t modify the file, it wont change!
Seems to work OK as mx2cc uses it often and if it didn’t nothing would build properly!
Working OK here, well compiling anayway. Fails when it needs to load something.
I’ve just made more changes and pushed again – perhaps I forgot to push last time, anyway try again.
You will need to be using the ‘develop’ branch and you’ll have to do an updatemx2cc.
Sorry, probably should’ve explained a bit better.
Your code has the same problem as my ‘Struct S’ example above, ie: it delcares a type that contains an instance of itself (which therefore contains an instance of itself etc etc). In your case the type is Bob<N> but the idea’s the same. It works when you use a class because a type can of course contain a reference to itself, and classes are ‘reference types’.
The compiler should of course not hang – you should get a ‘recursive type definition’ error or something, be cool if you could add this to github so I remember! – but ultimately your code can’t work as is and will need to change.
There’s a potential fix up on the develop branch now, although you’ll need to updatemx2cc to use it.
You may also be able to fix the problem by assigning the ‘media’ global var to itself somewhere in the problem file.
This fix is actually pretty cool, and has given me some (more) ideas for fixing this forward reference stuff for good! I wont be attempting this just as though it’ll be a reasonably major job.
Are you still having a problem t_mojo_graphics_Image under 1.1.04?
Here, I’m having a problem with t_default_Media instead.
Can you try a normal/windows mouse on the mac?
Also, hard to see how much scrolling is going on. Can you just show the screen while you try to scroll ‘click by click’?
Great stuff!
For example, in the Ted2 IDE, if I just scroll the wheel a tiny bit, I’ve jumped about 30 lines.
I am not getting this effect on macos here. One ‘wheel click’=about 2 lines of code scrolling in ted2, on both macos/windows.
I am however getting wheel.y values oustide the range [-1,1] only on macos. On windows, wheel.y is always -1, 0 or 1.
What values are you getting from this code? For me, one ‘click’ of the wheel is -1 or 1. On macos, spinning wheel faster gives greater values:
Monkey123456789101112131415161718192021222324252627282930313233343536373839Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowMethod New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()canvas.DrawText( "Hello World!",Width/2,Height/2,.5,.5 )EndMethod OnMouseEvent( event:MouseEvent ) OverrideIf event.Type=EventType.MouseWheel Print event.Wheel.yEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndAwesome stuff Adam!
-
AuthorPosts