After a correction on my greyscale formula in my last post from Mark on facebook I reviewed the results of my code and decided the disabled look wasn’t quite right. What I wanted was a a washed out looking version. This code and plugin modifies the alphaData of the image to 33% of the original and greys the imageData 15% more. You can modify the constants in the button code if you want different ratios. Here’s the code:


constant kTranslucencyRatio = 0.33
constant kGreyRatio = 0.15

on fadeImage pImageID
   local tAlphaData,tOffset,tWidth,tHeight,tAlpha
   lock screen
   put the width of pImageID into tWidth
   put the height of pImageID onto tHeight
   put the alphaData of pImageID into tAlphaData
   repeat with tOffset = 0 to tWidth *tHeight
      put charToNum(char tOffset of tAlphaData) into tAlpha
      -- handle cases of very low alpha for edge smoothing
      if round(tAlpha*kTranslucencyRatio) > 0 then
         put NumToChar(round(tAlpha*kTranslucencyRatio)) into char tOffset of tAlphaData
      end if
   end repeat
   set the alphaData of pImageID to tAlphaData
end fadeImage

on greyImage pImageID
   local tImageData, tRed, tGreen, tBlue, tGrey, tOffset,tWidth,tHeight
   lock screen
   put the width of pImageID into tWidth
   put the height of pImageID onto tHeight
   put the imageData of pImageID into tImageData
   repeat with tOffset = 0 to tWidth *tHeight * 4 step 4
      put charToNum(char tOffset + 2 of tImageData) into tRed
      put charToNum(char tOffset + 3 of tImageData) into tGreen
      put charToNum(char tOffset + 4 of tImageData) into tBlue
      put (30*tRed+59*tGreen+11*tBlue)/100 into tGrey
      put round(tGrey*kGreyRatio+tRed*(1-kGreyRatio)) into tRed
      put round(tGrey*kGreyRatio+tGreen*(1-kGreyRatio)) into tGreen
      put round(tGrey*kGreyRatio+tBlue*(1-kGreyRatio)) into tBlue
      put NumToChar(tRed) into char tOffset + 2 of tImageData
      put NumToChar(tGreen) into char tOffset + 3 of tImageData
      put NumToChar(tBlue) into char tOffset + 4 of tImageData
   end repeat
   set the imageData of pImageID to tImageData
end greyImage

http://goulding.ws/wp-content/plugins/downloads-manager/img/icons/download.png download: disableImage (1.38KB) added: 04/09/2010
description: This little plugin creates a disabled version of any selected images. Default settings are changing the translucency of the image to 33% of the original and greying it out 15% of the original.
 

Greyscale an image

On September 4, 2010, in Code, handy scripts, LiveCode, LiveCode Desktop, Plugins, by Monte Goulding

Now that I’ve got all my icons into the image library (see my recursive image library creation post) I wanted to limit the number of times I need to go back to an image editor to mess with the original files to create variations. One of the most common variations for button icons is the greyed out disabled icon so I wrote a little rev plugin to greyscale the selected images.

The plugin uses the following command:


on greyscale pImageID
   local tImageData, tRed, tGreen, tBlue, tGrey, tOffset,tWidth,tHeight
   lock screen
   put the width of pImageID into tWidth
   put the height of pImageID onto tHeight
   put the imageData of pImageID into tImageData
   repeat with tOffset = 0 to tWidth *tHeight * 4 step 4
      put charToNum(char tOffset + 2 of tImageData) into tRed
      put charToNum(char tOffset + 3 of tImageData) into tGreen
      put charToNum(char tOffset + 4 of tImageData) into tBlue
      --correction for better greyscale from Mark
      --put (tRed+tGreen+tBlue) div 3 into tGrey
      put (tRed*30+tGreen*59+tBlue*11) / 100 into tGrey
      put NumToChar(tGrey) into char tOffset + 2 of tImageData
      put NumToChar(tGrey) into char tOffset + 3 of tImageData
      put NumToChar(tGrey) into char tOffset + 4 of tImageData
   end repeat
   set the imageData of pImageID to tImageData
end greyscale

http://goulding.ws/wp-content/plugins/downloads-manager/img/icons/download.png download: greyscaleIt (1.19KB) added: 04/09/2010
description: This is a quick little plugin I wrote for converting selected images to greyscale. Handy for creating disabled icons from active ones.
 

After having a play with the Image Library in Revolution I remembered seeing a cool concept in a screencast from Shao Sean where a button was added in a handy empty spot on the tools palette to pull up a menu for inserting custom objects into stacks. Here I have applied the idea to the Object Library in Revolution.

Shao Sean’s original concept is seen here

The object library menu button in action

http://goulding.ws/wp-content/plugins/downloads-manager/img/icons/download.png download: revTools with Object Library Button (50.69KB) added: 31/08/2010
description: A mod to the revTools stack for copying custom objects into new stacks inspired by Shao Sean.
 

I use an icon collection that is a whole pile (around 2000) of png images stored in a hierarchy of folders (eg Objects and People/48×48/plain/). It has become annoying finding and importing these images one by one into my applications as needed so I wrote a little drag and drop plugin to import images into a stack whenever they are dropped. It works until you have an app your working on that uses drag and drop and then it fails so I thought I’d give the rev image library setup a go. Rather than import images into libraries by hand I decided to slap together a little recursive image library from folder script. Copy the code to a button then click it. The library name is built out of the names of the folders starting with the one you selected.


on mouseUp
   local tLibraryFileA
   answer folder "Choose a folder:"
   if the result is "cancel" then exit mouseUp
   recursiveImageLibrary it,"",tLibraryFileA
   repeat for each line tLine in the keys of tLibraryFileA
      createImageLibrary tLine,tLibraryFileA[tLine]
   end repeat
end mouseUp

on recursiveImageLibrary pFolder,pLibraryName,@pLibraryFileA
   local tOldFolder
   put the defaultFolder into tOldFolder
   set the defaultFolder to pFolder
   set the itemDel to "/"
   if pLibraryName <> "" then put " " after pLibraryName
   put item -1 of pFolder after pLibraryName
   set the itemDel to "."
   repeat for each line tFile in the files
      if item -1 of tFile is among the items of "jpg.png.gif" then
         put pFolder&"/"&tFile&cr after pLibraryFileA[pLibraryName]
      end if
   end repeat
   repeat for each line tFolder in line 2 to -1 of the folders
      recursiveImageLibrary pFolder&"/"&tFolder,pLibraryName,pLibraryFileA
   end repeat
end recursiveImageLibrary

on createImageLibrary pLibraryName,pLibraryFiles
   local tHighID,tList
   -- create the stack
   put 230000 into tHighID
   if char 1 to 6 of pLibraryName is not "revLib" then put "revLib" before pLibraryName
   if there is a stack pLibraryName then
      answer error "A library with the same name ("&pLibraryName&") as this library already exists." with "Cancel"
      exit createImageLibrary
   end if
   put revAbsoluteFolderListing(revEnvironmentUserResourcesPath("Icon Libraries",true)) into tList
   put cr & "revGeneralIcons" & cr & "revCompatibilityIcons1" after tList
   repeat for each line l in tList
      if l is empty or there is not a stack l then next repeat
      if the name of stack l is pLibraryName then
         answer error "That library already exists." with "Cancel"
         exit createImageLibrary
      end if
      put the ID of stack l into item (the number of items in tHighID+1) of tHighID
   end repeat
   if there is a file (pLibraryName & ".rev") then
      answer error "A library with the name" && pLibraryName & ".rev" && "already exists." with "Cancel"
      exit createImageLibrary
   end if
   set the name of the templateStack to pLibraryName
   set the destroyStack of the templateStack to false
   lock messages
   set the style of the templateStack to "modeless"
   create invisible stack
   reset the templateStack
   set the mainStack of stack pLibraryName to pLibraryName
   set the ID of stack pLibraryName to (max(tHighID)+1)
   set the fileName of stack pLibraryName to revEnvironmentUserResourcesPath("Icon Libraries") & "/" & pLibraryName & ".rev"
   set the defaultStack to pLibraryName -- just to make sure
   -- now import all the images
   repeat for each line tImage in pLibraryFiles
      if there is a file tImage then
         if tImage is not empty then
            import paint from file tImage
         end if
      end if
   end repeat
   compact stack pLibraryName
   save stack pLibraryName
   close stack pLibraryName
   unlock messages
end createImageLibrary

OK, once you are done there are two IDE mods that you should make.

If you had a big hierarchy of folders like me you will probably want to sort the image library list so choose View > Revolution UI Elements In Lists from the menu then open up the application browser and find the images card of the revImageLibrary stack and edit the script. Just after “delete last char of tStacksList” add “sort tStacksList”

Next for some reason way back in the depths of time the good people at RunRev forgot to upgrade the icon chooser to support image libraries. “What’s the point of image libraries without them being in the icon chooser?” I hear you ask. Very good question.

Replace the preOpenStack handler in revIconChooser card 1 with:


on preOpenStack
   put revAbsoluteFolderListing(revEnvironmentResourcesPath("Icon Libraries")) into tEnvironmentIcons
   put revAbsoluteFolderListing(revEnvironmentUserResourcesPath("Icon Libraries")) into tUserIcons
   put revCombineFilePaths(tUserIcons,tEnvironmentIcons) into tList
   repeat for each line l in tList
      if there is not a stack l then next repeat -- windows placeholder
      if char 1 to 6 of the short name of stack l is "revLib" then put char 7 to -1 of the short name of stack l & cr after tStacksList
      else if char 1 to 3 of the short name of stack l is "rev" then put char 4 to -1 of the short name of stack l & cr after tStacksList
      else put the short name of stack l & cr after tStacksList
   end repeat
   delete last char of tStacksList
   sort tStacksList
    put the text of btn "library chooser" into tText
  if the platform is "MacOS"
   then put "-" into tDivider
   else put empty into tDivider
   if tStacksList is not empty
   then put line 1 to 5 tText & cr & tDivider & cr & tStacksList into btn "library chooser"
   else put line 1 to 5 of tText into btn "library chooser"
   send "menuPick" && the label of btn "library chooser" to btn "library chooser"
   set the thumbPosition of scrollbar "iconchooserscrollbar" to 0
   put the cCurrentIcon of this stack into fld "ID"

   # TH-2008-03-06 : Fix for bug 5987
   set the pageIncrement of scrollbar "iconchooserscrollbar" to 20
   set the lineIncrement of scrollbar "iconchooserscrollbar" to 10
end preOpenStack

Then edit the script of the “library chooser” button on that card. Where it says:


 else  put "rev" & pWhich into tStackName

Change to

else
      put "rev" & pWhich into tStackName
      if there is not a stack tStackName then
         put "revLib"&pWhich into tStackName
      end if
   end if
 

Database functions and commands

On August 27, 2010, in Code, handy scripts, LiveCode, LiveCode Desktop, by Monte Goulding

Some handy little general database functions and commands I wrote for an app I’m working on. They need some extra error handling but they are good for getting up and running quickly.


function getTable pTable
   local tReturn,tSQL
   put "SELECT * FROM "&pTable into tSQL
   put revDataFromQuery(tab ,cr ,sDB ,tSQL) into tReturn
   if tReturn contains "revdberr" then return ""
   set the itemDel to tab
   return tReturn
end getTable

function getTableRecord pTable,pKey,pID
   local tReturn,tSQL,tQuery
   put "SELECT * FROM "&pTable&" WHERE "&pKey&" = "&pID into tSQL
   put revQueryDatabase(sDB,tSQL) into tQuery
   if not revdb_iseof(tQuery) then
      revMoveToFirstRecord tQuery
      repeat for each item tColumn in revDatabaseColumnNames(tQuery)
         put unSQLString(revDatabaseColumnNamed(tQuery,tColumn)) into tReturn[tColumn]
      end repeat
   end if
   revCloseCursor tQuery
   return tReturn
end getTableRecord

command deleteTableRecord pTable,pKey,pID
   local tReturn,tSQL,tQuery
   put "DELETE FROM "&pTable&" WHERE "&pKey&" = "&pID into tSQL
    revExecuteSQL sDB,tSQL
end deleteTableRecord

on updateTableRecord pTable,pKey,pID,pRecordA
   local tSQL,tField
   put "UPDATE "&pTable&" SET" into tSQL
   repeat for each line tField in keys(pRecordA)
      if pRecordA[tField] is a number then
          put " "&tField&"="&pRecordA[tField]&"," after tSQL
      else
         put " "&tField&"="&sqlString(pRecordA[tField])&"," after tSQL
      end if
   end repeat
   delete char -1 of tSQL
   put " WHERE "&pKey&"="&pID into tSQL
   revExecuteSQL sDB,tSQL
end updateTableRecord
 

Finding out the LAN IP

On August 27, 2010, in Code, handy scripts, LiveCode, LiveCode Desktop, by Monte Goulding

I had to work out the LAN IP for the machine my app is running on because the IP is needed to enter into an iPhone app so it can sync to the desktop. This is just an temporary measure while we implement zeroconf. Here’s a little modification of Ken Ray’s great GetMACAddress function to return the LAN IP.

function getLANIP
   -- value to return
   local retVal,tCard,ifConfigs,winExists,sys32Exists,temp
   set the itemDel to "."
   switch (the platform)
      case "MacOS"
         if item 1 of the systemVersion <10 then
            return ""
         else
            -- OS X
            repeat with X=1 to 10
               put "en"&X into tCard
               put shell("ifconfig "&tCard) into ifConfigs
               if char 1 to 9 of ifConfigs = "ifconfigs:" then
                  exit repeat
               else if char 1 to 4 of ifConfigs = "zsh:" then
                  return ""
               else
                  get matchText(ifconfigs,"(?s)inet (.*?) ",retVal) -- These are spaces on either side of (.*?)
                  if it is false then
                     return ""
                  else
                     exit repeat
                  end if
               end if
            end repeat
         end if
         break
      case "Win32"
         -- All Windows
         put (there is a file (specialFolderPath("system") & "/IPCONFIG.EXE")) into winExists
         put (there is a file (specialFolderPath("system") & "/SYSTEM32/IPCONFIG.EXE")) into sys32Exists
         if winExists or sys32Exists then
            set the hideConsoleWindows to true
            put shell("ipconfig /all") into temp
            if word 2 of systemVersion() < 6 then
               get matchText(temp,"IP Address[\. ]*: ([A-Z0-9-.]*)",retVal)
            else
               get matchText(temp,"IPv4 Address[\. ]*: ([A-Z0-9-.]*)",retVal)
            end if
         else
            return ""
         end if
         break
   end switch
   return retVal
end getLANIP
 

revWeb Widget for WordPress

On August 21, 2010, in LiveCode, LiveCode Web Plugin, WordPress Plugins, by Monte Goulding

Adding a revlet to a wordpress sidebar just got a whole lot easier with this plugin. Just unzip and copy the files to your wordpress plugins folder and it will appear in your plugins list for you to activate. Once activated you will have a widget to add to your sidebar where you can enter the revlet url, CSLID, stack name, stack width and stack height.

You won’t find this plugin in the add new plugin search in wordpress admin because I haven’t uploaded it yet.

http://goulding.ws/wp-content/plugins/downloads-manager/img/icons/download.png download: revWeb Widget (4.08KB) added: 21/08/2010
description: revWeb Widget for WordPress