Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 13 2016 03:24
    @PeterWAWood banned @Vexercizer
Oldes Huhuman
@Oldes
@rebred for png files you can use something like:
png-size: func[bin [binary! file! url!]][
    unless binary? bin [ bin: read/binary/part bin 1000 ]
    if bin: find/tail bin "IHDR" [
        as-pair
            to integer! copy/part bin 4
            to integer! copy/part skip bin 4 4
    ]
]
>> png-size %/r/icon4.png
== 16x16
It would be nice to have some systematic way... maybe using query on binary!?
Petr Krenzelok
@pekr
Amiga datatypes system? :-)
Oldes Huhuman
@Oldes
Hm.. now I see, that I should not use url! as a valid input above as read/part on url! is not yet supported in Red.
Still can be used as:
>> png-size read/binary https://avatars-04.gitter.im/gh/uv/4/rebred
== 420x420
Gregg Irwin
@greggirwin
I vote for a simple mezz that knows how to sniff the size from image data. Just add JPG and BMP to @Oldes' example.
Oldes Huhuman
@Oldes
I think it would be better to extend codecs with query function as there is more info in raw image data, not just size. The query function could than use it after file type identification.
Gregg Irwin
@greggirwin
How do you see it working @Oldes? If given a file, you get information about the file, not its contents, correct? Binary doesn't support query, and would have to either check all codecs or be told which one to use. Now, we can extend what query does, but then we need to think about all the file types out there and what it should return, whether they require a codec or not. If we do a mezz now, the logic in it can later be used in other places if desired, but at least we have it for now, without big design discussions.
Oldes Huhuman
@Oldes
query now only returns modification date of file, so I expect it must be extended.

I don't say it should not be a mezz function... the question is where it should live and if there is:

>> ? system/codecs/png
SYSTEM/CODECS/PNG is an object! with the following words and values:
     title      string!       ""
     name       word!         PNG
     mime-type  block!        length: 1  [image/png]
     suffixes   block!        length: 1  [%.png]
     encode     routine!      [img [image!] where [any-type!]]
     decode     routine!      [data [any-type!]]

I can imagine, there could be also query in such an object returning for example size.. or other info, if supported.

There could be also identify:
png-identify: func[data [binary!]][to logic! find/match data #{89504E47}]
>> png-identify read/binary http://avatars-04.gitter.im/gh/uv/4/oldes
== true
Gregg Irwin
@greggirwin
Ah, I see what you mean now, so not the query action for datatypes. Codec metadata/reflection info. Good for a general thought.
Oldes Huhuman
@Oldes
query on binary! could do all the things like a file type detection and so on, using the query workers in each possible codec.. but yes.. that is just me thinking aloud.
Gregg Irwin
@greggirwin
Trying to think of use cases where you have binary data but no idea what it is.
Oldes Huhuman
@Oldes
I don't know.. I just like to hack with file formats occasionally.
Boleslav Březovský
@rebolek
I like the idea.
Jose Luis
@planetsizecpu
+1 to extend query
Boleslav Březovský
@rebolek
first step is to make query do more than just return modification date :-)
Jose Luis
@planetsizecpu
I see it useful for game makers and CV stuff :^)
Jose Luis
@planetsizecpu
Think of a program for restaurants, where each menu option has a photo of the food, you want the photos to fit a certain size, and you will check the size before uploading the file. The same in a human resources program, the photos of the employees will want to have them in a specific size. And so on ...
Petr Krenzelok
@pekr
I don't remember how codecs and datatypes worked in Amiga days, but I imagine being it similar. You could have image.bmp in fact being a jpeg image. Each format has its decoder and it either loads the whole file, or has to find some header info in the beginning of file. The question is, if you can't make it part of Red system, somehow, e.g. via a query
GiuseppeChillemi
@GiuseppeChillemi
On Amiga we had "WhatIs" utility capable of giving you information about the file you provide or foreach file of a whole directory.
GiuseppeChillemi
@GiuseppeChillemi
@greggirwin Could I open a ticked on these "leaks"?
Gregg Irwin
@greggirwin
First we should make sure they are leaks.
nwtgthb
@nwtgthb
    main: layout [
        pict: image %image.jpg
        ship: image %iss.png
        do [      ;-- centre the button relative to the text face
            rnx: (pict/size/x / 2) - (ship/size/x / 2)
            rny: (pict/size/y / 2) - (ship/size/y / 2)
            irnx: to-integer rnx
            irny: to-integer rny
            ship/offset/x: pict/offset/x + irnx
            ship/offset/y: pict/offset/y + irny
            main/size:  pict/size
          ]
    ]

    view main
hi I am trying to resize the view after I have moved one of the images to the center of the other image. THe problem is that the view has allocated space for the second image. I keep getting an error main has no value. Thanks.
Brock Kalef
@bkalef88_gitlab
I haven't tested, but I believe your main/size: should be outside of the layout block.
nwtgthb
@nwtgthb
 view main [ main/size:  pict/size]
Commented line in layout and added it to the view still no success.
Toomas Vooglaid
@toomasv
@nwtgthb I also can't test now, but I think you can remove ship from layout flow by adding at 0x0 before ship: ... so that space will not be reserved for it. Then you don't need to resize the window.
nwtgthb
@nwtgthb
ship: image 0x0  %iss.png

this resulted in a non visible ship. in the do block I added

ship/size: 75x45

This seems to have dixed the problem. THanks.

nwtgthb
@nwtgthb

I am rewriting some of my ruby qml apps, Red is impressive. Qml has a window property

flags: Qt.SplashScreen

which removed the app from the application list. Is there anything like it in Red. I have tried the no-border option but it is not the same.

Petr Krenzelok
@pekr
I am not sure where to get the list of possible flags, but here is some example:
view/flags [
    text "Type something: " 
    f: field 100x22 
    button "print" [print f/text] 
    button "unview" [unview]
][no-title no-border]
Brock Kalef
@bkalef88_gitlab
window-flags: [
resize no-title no-border no-min no-max no-buttons modal popup
]
From Greg Irwinn back in July...
:point_up: July 10, 2020 5:44 PM
Toomas Vooglaid
@toomasv
@nwtgthb Here is what I meant:
im1: draw 200x200 [fill-pen red box 0x0 199x199]
im2: draw 100x100 [fill-pen blue box 0x0 99x99]
main: layout [
   pict: image im1 
   at 0x0 ship: image im2 
   do [
      rnx: (pict/size/x / 2) - (ship/size/x / 2) 
      rny: (pict/size/y / 2) - (ship/size/y / 2) 
      irnx: to-integer rnx 
      irny: to-integer rny 
      ship/offset/x: pict/offset/x + irnx 
      ship/offset/y: pict/offset/y + irny
   ]
] 
view main
image.png
Toomas Vooglaid
@toomasv
Does modal take it out of the application list?
nwtgthb
@nwtgthb
modal windows demand a response
Gregg Irwin
@greggirwin
@nwtgthb center-face may work for you. It's a func you call, not a window facet.
GiuseppeChillemi
@GiuseppeChillemi

About window flags see https://github.com/red/docs/blob/master/en/view.adoc#window

I can't find a flag to have a window "always on top"

Gregg Irwin
@greggirwin
You can open a request ticket for that. In the meantime, you need to use a routine to set that window flag.
GiuseppeChillemi
@GiuseppeChillemi
Other 2 questions:
Is there a way to set transparency?
Can we intercept hotkeys and combinations when window has not focus?
Ops, another two: is there a way to bring to front/back and show/minimize?
Gregg Irwin
@greggirwin
All have to be done with API calls currently. I believe someone has done transparency, maybe @rebolek or @hiiamboris. Global keyboard hooks...I don't recall seeing. Don't think I ever did them in R2. Z order and window state aren't hard, but you also need to be able to find the window you want in order to get its handle and send it messages. I have R2 code for all that, but not ported.
Finding windows is probably in my send-keys work. @toomasv may have posted his ported version somewhere.
Old stuff.
GiuseppeChillemi
@GiuseppeChillemi
Old but gold