Buttons and Images

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Buttons and Images

Post by Traxgeek » Tue Jan 15, 2013 3:07 pm

Hi,

I'm trying to display an image on a card programatically/at run-time... (say, the picture of a particular person from a list of people) . Sounds simple enough... and, to be fair, I have sorted out how to do this if I use an Image control (imgImage).

Code: Select all

local N, sFile
put [1 | 2 | 3 | 4] into N ##simply makes this demo code easier. There are various images in the Images folder all referenced as 'Image-1.jpg', 'Image-2.jpg', 'Image-3.jpg'  etc...)
put specialfolderpath("Documents") & "/Images/image-" & N & ".jpg" into sFile
if there is a file sFile then
    set the filename of image "imgImage" to sFile
else
    //do something else / warn of missing file...
end if
This seems to work fine BUT... (isn't there just always a 'BUT' ? !!) the image on the card resizes itself to the size of each image I load and I'm not always in control of these source images - so don't know their size !

Ideally, I'd like to 'fix' the image 'holder' / LC control size so that ANY image I select is ALWAYS displayed the same size. ie. the 'Image' control should NOT resize to the size of the loaded image - the source image should expand / contract to fit the container / Image control. Naturally, I'd still like to be able to resize my card at which point the image in it should re-size itself proportionally and accordingly...

Have I missed some properties here ? If so, where, which ones please ?

Additionally and because I've been struggling (again), I've been 'playing' with Button controls. I'd also like to be able to set the icon / image ofa Button control (btnImage). Again, programatically / at run-time - much the same as per the Image Control. To do this I think the code should go a little like :

Code: Select all

set the filename of button "btnImage" to sFile
But it doesn't work for me - no errors - just no image in my button... BUT, my button doesn't seem to resize... good or bad ? :?

Ideas on one or both counts please ?

Many thanks
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Buttons and Images

Post by Klaus » Tue Jan 15, 2013 3:54 pm

Hi Traxgeek,

1. did you solve your datagrid problem?

2. "the filename" is a property of an IMAGE, so setting this for a BUTTON will do nothing.
You need to modify the IMAGE itself that you use as an ICON in the button!

3. If you do not set the "locLock" for your image(s) to TRUE (check "Lock size and position" in the inspector -> Size and Position),
the images will always resize to their original dimensions (width and height) after you
a. go to another card and come back to the card with the image(s)
b. when you set their filename(s) (again)

4, To get the original dimension of an (unknown) image you can check its "formattedwidth" and "formattedheight"
...
lock screen
set the filenmae of img "whatever" to "any/valid/path_to/image.jpg"
put the formattedwidth of img "whatever" into tOriginalWidth
put the formattedheight of img "whatever" into tOriginalHeight
## Now you can do something with this info...
...

Best

Klaus

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: Buttons and Images

Post by Traxgeek » Tue Jan 15, 2013 4:56 pm

Hi Klaus,

Thanks for that.

No, I haven't yet figurred out my DataGrid issue. Very strange. In the end, in the interests of my not going totally insane (some would say a pointless task, it happened a long, long time ago), I decided to 'shelve' the idea for a few days and continue with my project. I have a need of DataGrids on three cards... I just thought that I'd try and not lose all interest... to be fair I'm finding the documentation (although there is LOTS of it) rather confusing / difficult to follow.

The Image / button icon being two points in question. Another, for example, being how to SET a particular radio button in a group of three (programatically). Plenty of stuff on Radio buttons and groups but I can't seem to findan example / instructions on how to set / read the state of a group of buttons...

I seem to spend an age wading through the manual, the dictionary and web examples but not finding the item I'm looking for... which in most cases would be completely satisfied by a document listing the available controls and the properties associated with each - then an example of how to set the particular property and how to read the particular property.

This doesn't seem to me to be too onerous - but I can't find something like it which (1) adds incredibly to my frustration, 'wastes' an inordinate amount of time and generally detracts from the 'fun' of programming (for me anyway!). Please excuse me, this in NOT a rant ! I'm just extremely frustrated at having so much data available to read through / watch and yet not find simple / concise instructions grouped in some sort of (what I would consider to be) an orderly fashion...

In all honesty if it weren't for you and this forum... well...

Maybe I'm just too old (47) to be switching to a new language (C / C++ / Java for 20 years, Ruby for 5years, PCSoft for 5years, Corona and Rhodes last year and now LC...) And LC is sooooo alien to all of those.

Anway, I'll get there with continued support I'm sure... I'm making detailed notes on my progress (or lack of it !) with a view of posting a finished 'diary' of 'How to's' (Controls, properties and methods) once I've finished 'porting' my existing app and releasing it, cross-platform, in wonderful LC (at the moment it's Windows desktop and Mobile via PCSoft)... Just can't help thinking I can't be the only person struggling with the simple things that I am struggling with - being a newcommer and all to LC...

Anyway, as always, thanks a million...

I'll get back to the DatGrid issue probably next week and will update the post I started as I go...

Regards.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Buttons and Images

Post by Klaus » Tue Jan 15, 2013 5:27 pm

Hi Traxgeek,

you should take a look at the stack "Controls", and the others, too, here:
http://www.runrev.com/developers/lesson ... nferences/
Will give you more info about buttons (and other controls) than you ever wanted to know :D

Regarding your datagrid, please read my last posting in that thread!


Best

Klaus

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: Buttons and Images

Post by Traxgeek » Tue Jan 15, 2013 6:19 pm

Hi Klaus,

Th
Thanks Klaus.

I'm (normally) a sad, determined little thing - I like to run somehting down til I totally understand it. I will get back to the DataGrid issue some time later this / early next week - maybe then I can take you up on your offer ? I'd like to give it one last go before I bother you with code - that's all... either way I will revert to DataGrids and how I get on etc.

Thanks a mil - I appreciate you are not solely here for my benefit but at the moment I'm really needing the help :oops: . I'll get better I promise ! :evil:

Regards.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Buttons and Images

Post by Klaus » Tue Jan 15, 2013 7:01 pm

Hi Traxgeek,
Traxgeek wrote:... I will get back to the DataGrid issue some time later this / early next week - maybe then I can take you up on your offer ?...
Sure!


Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Buttons and Images

Post by jacque » Wed Jan 16, 2013 6:39 pm

Traxgeek wrote: The Image / button icon being two points in question. Another, for example, being how to SET a particular radio button in a group of three (programatically). Plenty of stuff on Radio buttons and groups but I can't seem to findan example / instructions on how to set / read the state of a group of buttons...
See the hilitedButton or the hilitedButtonName.

Don't despair. People coming from other languages have a harder time than those who have never programmed before. There's some "unlearning" to do. But once the paradigm kicks in you'll be glad you took the time.

I think you already know about the list of objects at the left side of the dictionary. That can be very helpful for isolating properties of particular objects. And we're here when you need us.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: Buttons and Images

Post by Traxgeek » Thu Jan 17, 2013 6:37 pm

Thanks Jacque.

The responses I've received - both by way of helpfulness and speedieness have been fantastic. Bravo RunRev, LiveCode and the forum members !

I think you're right - coming from years and years of C/VB/Java script -style programming to LiveCode is proving... hmm... 'challenging'...

To date this is undoubtedly the hardest learning curve of all for me. There's always getting used to a new IDE (it was the same for Eclipse and xCode not to mention Rhodes-Ruby and then Corona-Lua) but LiveCode is soooooo very different in both its approach and its 'englishness' that I am struggling.

Having said that, I am deffinitely making progress and finding that as I learn I am enjoying it more and more... and I pretty much always enjoy my job so I'm really looking forward to getting my feet under the table and the basics (at least) learnt so that my programming becomes fun again !

Well, as always, a thousand thanks.

Regards.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Buttons and Images

Post by jacque » Thu Jan 17, 2013 7:26 pm

Read lots and lots of other people's code. There are hundreds of examples in the User Samples on RevOnline -- just click the icon in the toolbar and you'll have free access to any stack that looks interesting. You will find a wide variety of samples there (some are more professionally written than others so don't consider any of them definitive,) and many were uploaded to show sample code for lots of common behaviors.

It will probably take 6-8 weeks before you obtain critical mass and all the pieces fall into place. Once that happens the rest is easy. Before that happens, you lose hair and sleep. :)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply