BBC BASIC for Windows
Programming >> Graphics and Games >> Custom color control (background & foreground )
http://bb4w.conforums.com/index.cgi?board=graphics&action=display&num=1458438004

Custom color control (background & foreground )
Post by michael on Mar 20th, 2016, 01:40am

I hope this is helpful

Finally I figured it out. I made a custom control for foreground and background control

It isn't really saving you a huge amount of coding, but it is one command

This is if you are making intensive custom color modifications and really want to make your project pretty

For Beginners:
R would be a color Range of (0-255) which is a scale of RED
G would be a color Range of (0-255) which is a scale of GREEN
B would be a color Range of (0-255) which is a scale of BLUE

I am working on translating RGB color mixer program so its easy for you to select your color.

PROC_color("f",R,G,B) for foreground color (draw and floodfill)
or
PROC_color("b",R,G,B) for background color (text background and CLG-

*** with a transparent text background, the background setting would be irrelevant, except for CLG, but oh well... its figured out.
Code:
      REM custom R G B foreground and background control (total control)

      MODE 8
      VDU 5 : REM Treat text as graphics (transparent background)
      REM set background color to white
      PROC_color("b",255,255,255)
      REM clear the screen with background color
      CLG
      REM set foreground color to blue
      PROC_color("f",0,0,255)
      MOVE 0,800
      PRINT "text is a custom blue and background is custom white"
      PROC_color("f",50,150,255)
      PRINT "text is now a custom color"
      WAIT 0
      END

      DEF PROC_color(fb$,r,g,b)
      IF fb$="f" OR fb$="F" THEN COLOUR 0,r,g,b : GCOL 0
      IF fb$="b" OR fb$="B" THEN COLOUR 1,r,g,b : GCOL 128+1
      ENDPROC
 



Re: Custom color control (background & foreground
Post by michael on Mar 20th, 2016, 11:07pm

And here is a sample text box program
Code:
  
    MODE 8
      COLOUR 1,255,255,255 REM Set palette color 1 to RGB triplet (my custom text background color)
      GCOL 0 : REM Set graphics foreground to palette color 0  (BLACK)
      GCOL 128+1 : REM Set graphics background to palette color 1
      VDU 5 : REM Treat text as graphics (transparent background)
      OFF
      CLG
      initialx%=0
      PROC_pr(100,500,9,15,"COLORED TEXT BOX WITH ANY FILL COLOR AND BORDER COLOR",150,20,100)
      PROC_pr(10,300,2,5,"But I am having issues centering my text",150,155,255)
      PROC_pr(200,200,4,4,"Maybe someone could help me do the math?",250,150,200)
      PROC_color("f",0,0,0) REM set draw color to black
      MOVE 0,800
      PRINT "I printed this black text using a custom color with PROC_color"
      PROC_pr(10,900,4,4,"TINY BOX?",250,190,100)
      MOVE 0,0 REM move the > out of view
      WAIT 0
      END
      REM X,Y,text color,boarder color,message,r,g,b
      DEF PROC_pr(X,Y,C,CT,msg$,r,g,b)
      initialx%=LEN(msg$)
      COLOUR 0,r,g,b
      GCOL 0
      LET tx= X+initialx%+25
      LET ty= Y
      initialx%=initialx%*22
      FOR fill=1 TO 58
        LINE X+3,Y+20-fill,X+initialx%,Y+20-fill
      NEXT fill
      GCOL CT
      MOVE tx,ty
      PRINT msg$
      GCOL C
      LINE X,Y+20,X+initialx%,Y+20
      LINE X,Y+20,X,Y-40
      LINE X,Y-40,X+initialx%,Y-40
      LINE X+initialx%,Y-40,X+initialx%,Y+20
      LINE X-5,Y+25,X+initialx%+5,Y+25
      LINE X-5,Y+25, X-5,Y-45
      LINE X+initialx%+5,Y+25,X+initialx%+5,Y-45
      LINE X-5,Y-45,X+initialx%+5,Y-45
      MOVE 0,0 REM hide that thing

      ENDPROC

      DEF PROC_color(fb$,r,g,b)
      IF fb$="f" OR fb$="F" THEN COLOUR 0,r,g,b : GCOL 0
      IF fb$="b" OR fb$="B" THEN COLOUR 1,r,g,b : GCOL 128+1
      ENDPROC