It is currently Sun Jan 17, 2021 8:00 am

All times are UTC + 1 hour

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Timesaver: Auto-convert hardcoded numbers to scalable values
PostPosted: Wed Apr 22, 2020 9:39 pm 
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8149
Location: Fort Nelson, BC, Canada
In creating vector drawings, I find it's easiest to design images to hardcoded sizes. This way you can make small (or large) adjustments to the size and location of components efficiently. It's really a lot of trial and error. Once you've created your masterpiece at the base size and you're happy with it, next job is to make it scalable. So if your image is 600x600 you'll want to change all your hardcoded numbers to percentages of 600. So 150 needs changed to 0.2500*size for example. This is beyond tedious working with a calculator and changing the numbers individually. That's where this tool comes in. Select a group of numbers, hit your keyboard shortcut and it all transforms instantly. All you have to do is put the following comment on the very first line of your code: ; 600,size where 600 represents your base size and 'size' is the name of the var you have set to it. Once you've done the conversion your image is now scalable to any size. Anyway the code is simple, here it is for Windows:
; 640,sz
; Size converter IDE external tool
; Usage: Compile this code and install as an IDE
;        external tool with keyboard shortcut
;        activation. (I used CTRL-P)
;        Place a commented line at the top of your
;        source in this format: ; size,var
;        Example top line: ; 640,sz
;        select numbers or groups of numbers from
;        your code and hit your shortcut
;        320,55,19,420 gets instantly changed to:
;        0.5000*sz,0.0859*sz,0.0297*sz,0.6563*sz
;        I actually used the tool for this demo,
;        note the comment in the first line
;        Spaces will get trimmed out, so just modify
;        this code if you don't want that.

*size = AllocateMemory(34)

HandleIDESci = Val(GetEnvironmentVariable("PB_TOOL_Scintilla"))

SendMessage_(HandleIDESci, #WM_GETTEXT, 32, *size)
a$ = PeekS(*size)
a$ = Left(a$, FindString(a$, #CR$)-1)
a$ = RemoveString(a$, ";")
a$ = RemoveString(a$," ")
size$ = StringField(a$, 1, ",")
var$ = StringField(a$, 2, ",")
a.d = ValD(size$)

SendMessage_(HandleIDESci, #WM_COPY,0,0)   
b$ = GetClipboardText()
For i = 1 To j+1
  num.d = ValD(Trim(StringField(b$,i,",")))
  num$+StrD(num/a,4)+"*"+var$ :If i<j+1:num$+",":EndIf

SendMessage_(HandleIDESci, #WM_PASTE,0,0)     


Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour

Who is online

Users browsing this forum: No registered users and 21 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye