Author |
Topic: Custom 3D borders.. The begining of new windows (Read 286 times) |
|
michael
Senior Member
member is offline


Posts: 335
|
 |
Custom 3D borders.. The begining of new windows
« Thread started on: Mar 14th, 2016, 05:57am » |
|
As I am told on other forums that I should use just normal text boxes and windows, my thoughts are: I defy the normal and go against the grain... I just slapped this completely custom border together syntax:(or what ever) border(H ,V ,BEGIN ,SIZE ,R ,G ,B ,DIMMER )
H,V - the horizontal and vertical location BEGIN : the starting center size SIZE: the largest point of your border R,G,B : Your R (0-255) G (0-255) B (0-255) color range DIMMER: controls the depth levels or color reduction rate
Keep in mind the above description variables are not the same as in the DEF PROCedure layout
Its just a explaination of how the command works Code: REM SET MODE TO 8 USING VDU
VDU 22,8
REM SET LINE THICKNESS TO 3
VDU 23,23,3|
OFF
GCOL 1
PROC_border(500,500,320,350,170,200,170,5)
END
DEF PROC_border(H,V,BEGIN,SIZE,X,C,A,DI)
R=X
G=C
B=A
P=SIZE-BEGIN
P=P/2
P=BEGIN+P
FOR Y=P TO SIZE
COLOUR 1,X,C,A
LINE H-Y,V-Y,H+Y,V-Y
LINE H+Y,V-Y,H+Y,V+Y
LINE H+Y,V+Y,H-Y,V+Y
LINE H-Y,V+Y,H-Y,V-Y
X=X-DI
C=C-DI
A=A-DI
IF X<2 THEN X=2
IF C<2 THEN C=2
IF A<2 THEN A=2
NEXT Y
P=SIZE-BEGIN
P=P/2
P=BEGIN+P
FOR Y=BEGIN TO P
COLOUR 1,X,C,A
LINE H-Y,V-Y,H+Y,V-Y
LINE H+Y,V-Y,H+Y,V+Y
LINE H+Y,V+Y,H-Y,V+Y
LINE H-Y,V+Y,H-Y,V-Y
X=X+DI
C=C+DI
A=A+DI
NEXT Y
ENDPROC
|
|
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
Zaphod
Guest
|
 |
Re: Custom 3D borders.. The begining of new window
« Reply #1 on: Mar 14th, 2016, 4:15pm » |
|
Well Mike you can do this quite a bit simpler in BB4W by using the built in graphics commands like RECTANGLE.
I know you are just beginning to get to grips with BB4W and there are, if you like, good style guidelines that are really incorporated into the Cross Reference Utility that I mentioned before. If you run that and get warnings it means that your program is not quite the idealized BB4W style. Certainly it is a matter of personal choice how you program if it is within the allowable syntax of BB4W, but if you want a broader audience then conforming to a common style will be helpful to others. It will look more familiar and easier to read.
I really don't want to go on and on but the idea of Local and Global variables having something that distinguishes them is very useful indeed. Globals start with an Upper case letter and locals are all lower case. All formal parameters are local by definition. I personally also like the suffix to show that something is an integer so again we don't make silly assumptions thinking the result might be a floating point number.
So I would like to offer a BB4W styled version of your program, with the additional versatility that the box can be rectangular. Code:
REM SET MODE TO 8 USING VDU
VDU 22,8
OFF
GCOL 1
PROCborder(500,500,320,200,21,200,170,170,10)
END
DEF PROCborder(x%, y%, dx%, dy%, wide%, r%, g%, b%, grade%)
LOCAL midx%, midy%, I%
midx%=x%+wide%/2
midy%=y%+wide%/2
FOR I% =1 TO wide%/2
COLOUR 1,r%,g%,b%
RECTANGLE midx%-I%,midy%-I%, dx%+2*I%, dy%+2*I%
RECTANGLE midx%+I%,midy%+I%, dx%-2*I%, dy%-2*I%
r%-=grade%
g%-=grade%
b%-=grade%
IF r%<2 THEN r%=2
IF g%<2 THEN g%=2
IF b%<2 THEN b%=2
NEXT
ENDPROC
The x, y, dx and dy are using the usual Windows and BB4W graphics conventions, 0,0 being the top left hand corner.
I did not use dimmer% as it clashes with the lower case keyword dim, but I could have used di%, of course.
Does this help anyone or should I just shut up? (Seriously)
|
|
Logged
|
|
|
|
michael
Senior Member
member is offline


Posts: 335
|
 |
Re: Custom 3D borders.. The begining of new window
« Reply #2 on: Mar 14th, 2016, 10:30pm » |
|
Your helping me see the way it should be done. It also is helping me see the way the variables are used..
I see the global I% being used in a FOR/NEXT loop
I also see the other lower case variables and how they are used in the PROC. Much of the programming I am doing is not different than the previous language mainly because I am using CAPS to essentially convert my program.. But its not a perfect conversion. SUBs are replaced with DEF PROC_ and CALLs are replaced with PROC_. Also the screen command and VDU command was initially for me really confusing.. but, I think I have enough know how to customize the VDU easily and also I will make sure that it has REM statements for other novices so they know what I was doing. Otherwise they may not think its easy.. which it is.. once you learn it.
|
|
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
Zaphod
Guest
|
 |
Re: Custom 3D borders.. The begining of new window
« Reply #3 on: Mar 14th, 2016, 11:30pm » |
|
Quote:I see the global I% being used in a FOR/NEXT loop |
|
No it is declared as LOCAL! You can have a LOCAL version of the Static variables in Procedures or Functions. Any existing value in the Static variable that is declared as LOCAL is put on the stack and restored when you exit the Procedure or Function. It is just a habit of mine to use Static variables as loop counters. But something that is only used inside the Procedure really should be declared as LOCAL. The advantage over using the Global I% is that you don't leave old values in I% and the "New" Local one is always set to zero upon being declared.
As an aside perhaps but talking of stacks, one of the problems in mixing old style and structured programming, as you are, is that you can get into big trouble if you goto lines that would jump into or out of a Procedure or Function. I have seen learners getting to the end of a Procedure and wanting to get to another and using goto to get there. That leaves return addresses on the stack. Eventually that program will fail if it runs long enough. The stack grows and you run out of space. Conversely jumping into a Procedure will pull off a value from the stack when it gets to ENDPROC that it thinks is a return address but will be an indeterminate location and may well crash the whole program if it points outside of the program space allocated for BB4W. Worse still it might actually go somewhere in the program and work, but you would have no idea how it got there. Goto does not mix well with Procedures and Functions. Sorry about the lecture but it is best if you know and so avoid the problem.
|
|
Logged
|
|
|
|
|