English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 03 April 2014, 05:12   #1
mritter0
Registered User
 
Join Date: Sep 2013
Location: Bettendorf, IA, USA
Age: 52
Posts: 204
Set pen color

I am looking for a way to draw a box with no frame at position 20x20 and width/height 150x50, RectFill() to color #F0F0F0, and be in the background so whatever is placed on top is not affected.

It looks very straight forward in OS4, but I am using OS3.9 and below.

Code:
rastPort=MainWindow->RPort;
SetDrMd(rastPort,JAM2);  // in background
SetBPen(rastPort,5);   // color #F0F0F0
RectFill(rastPort,20,20,150,50);
This draws the box but is in front of everything and can't get the color I want.
mritter0 is offline  
Old 03 April 2014, 07:34   #2
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,030
RectFill always draws with pen A, so SetBPen has no effect for it. Similarly it does not matter if you use JAM1 or JAM2.

I didn't understand the part with "in the background". RectFill always draws into the RastPort. Everything which was in that RastPort before is overwritten. If your window is in the background, only non-hidden parts will be drawn. For SMART_REFRESH windows the hidden parts are stored and shown when the window comes to front. This includes the parts affected by RectFill.

Code:
/* in the beginning of your program */

scr = LockPubScreen (pubscreennname);
red_pen = ObtainBestPen (scr->ViewPort.ColorMap,
           0xffffffff, 0x00000000, 0x00000000,
           OBP_FailIfBad, FALSE,
           OBP_Precision, PRECISION_GUI,
           TAG_END);





/* the part you want to know */

rastPort=MainWindow->RPort;
SetAPen (rastPort,red_pen);
RectFill (rastPort,20,20,150,50);





/* in the end of your program */

ReleasePen (scr->ViewPort.ColorMap, red_pen);
UnlockPubScreen (NULL,scr);
thomas is online now  
Old 04 April 2014, 03:23   #3
mritter0
Registered User
 
Join Date: Sep 2013
Location: Bettendorf, IA, USA
Age: 52
Posts: 204
Thanks again.

I figured it out a while after I posted it. Then I found another reply of yours about ObtainPen(). One last thing to figure out........
mritter0 is offline  
Old 11 April 2014, 02:15   #4
mritter0
Registered User
 
Join Date: Sep 2013
Location: Bettendorf, IA, USA
Age: 52
Posts: 204
I have it almost working the way I want. A new issue has come up:

Open window. ObtainPen. SetRGB32. SetAPen. RectFill. Place PNG image (loaded with datatypes) with transparent background over RectFill region.

The transparency shows the window background color, not the color of the RectFill.

Am I setting the right pen using SetAPen?
mritter0 is offline  
Old 11 April 2014, 07:45   #5
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,030
Quote:
ObtainPen. SetRGB32
This only works if there is a free pen left on the screen. In a multitasking environment you should really use ObtainBestPen.


Quote:
Place PNG image (loaded with datatypes) with transparent background
Please describe this more detailed.


Quote:
The transparency shows the window background color, not the color of the RectFill.
Probably you don't handle transparency. The system does not do this for you, at least not before OS 4.0.
thomas is online now  
Old 11 April 2014, 10:13   #6
Zetr0
Ya' like it Retr0?
 
Zetr0's Avatar
 
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
Its been a while but unless you want to write your own routine you will need to store your PNG in PLANAR with a Transparency Plane.

For that you can use BlitBitMask, sadly its been a while and I cannot remember the control syntax.
Zetr0 is offline  
Old 12 April 2014, 18:40   #7
mritter0
Registered User
 
Join Date: Sep 2013
Location: Bettendorf, IA, USA
Age: 52
Posts: 204
Loading image:
Code:
	if (!(New_dto=NewDTObject("PROGDIR:imgs/PNGImage.png",
			DTA_GroupID,	GID_PICTURE,
			PDTA_Remap,		TRUE,
			PDTA_Screen,	DefaultPubScreen,
			PDTA_DestMode,	PMODE_V43,
		TAG_END)))
	{
		return FALSE;
	}
	DoDTMethod(New_dto,NULL,NULL,DTM_PROCLAYOUT,NULL,TRUE);
	GetDTAttrs(New_dto,
		PDTA_BitMapHeader,	&New_bmhd,
		PDTA_BitMap,		&New_bm,
	TAG_END);
Draw my rectangle:
Code:
	if (V39)
	{
		if (GetBitMapAttr(handle->Screen->RastPort.BitMap,BMA_DEPTH)<=8)
		{
			handle->BgPen=ObtainBestPen(handle->Screen->ViewPort.ColorMap,
//				0xf0f0f0f0, 0xf0f0f0f0, 0xf0f0f0f0,	// light grey
				0xe3e3e3e3, 0xe3e3e3e3, 0xe3e3e3e3,	// light grey
//				0xfcfcfcfc, 0xfcfcfcfc, 0xfcfcfcfc,	// light grey
				OBP_FailIfBad,		FALSE,
			    OBP_Precision,		PRECISION_GUI,
		    TAG_END);

			handle->LinePen=ObtainBestPen(handle->Screen->ViewPort.ColorMap,
				0x49494949, 0x49494949, 0x49494949,	// dark grey
				OBP_FailIfBad,		FALSE,
				OBP_Precision,		PRECISION_GUI,
		    TAG_END);
		}
		else
		{
			handle->BgPen=ObtainBestPen(handle->Screen->ViewPort.ColorMap,-1,0xf0f0f0f0,0xf0f0f0f0,0xf0f0f0f0,PENF_EXCLUSIVE);
			if (handle->BgPen != -1)
				SetRGB32(&handle->Screen->ViewPort,handle->BgPen,0xf0f0f0f0,0xf0f0f0f0,0xf0f0f0f0);

			handle->LinePen=ObtainBestPen(handle->Screen->ViewPort.ColorMap,-1,0xa0a0a0a0,0xa0a0a0a0,0xa0a0a0a0,PENF_EXCLUSIVE);
			if (handle->LinePen != -1)
				SetRGB32(&handle->Screen->ViewPort,handle->LinePen,0xa0a0a0a0,0xa0a0a0a0,0xa0a0a0a0);
		}
	}
	if (handle->BgPen==-1)
		handle->BgPen=0;
	SetAPen(&handle->RPort,handle->BgPen);
	RectFill(&handle->RPort,0,0,handle->Window->Width,24+14);
	if (handle->LinePen==-1)
		handle->LinePen=1;
	SetAPen(&handle->RPort,handle->LinePen);
	RectFill(&handle->RPort,0,24+14+1,handle->Window->Width,24+14+1);
Using gtlayout.library:
Code:
                LT_New(MainHandle,
                    LA_Type,                IMAGE_KIND,
                    LA_ID,                  IMAGE_NEW,
					LAIM_BitMap,			New_bm,
					LAIM_BitMapLeft,		0,
					LAIM_BitMapTop,			0,
					LAIM_BitMapWidth,		New_bmhd->bmh_Width,
					LAIM_BitMapHeight,		New_bmhd->bmh_Height,
				TAG_DONE);
to layout gadgets, boxes, etc.

It looks like the attachment. It is a little small, zoom in. The dark grey is the window background color. It should all be the lighter grey color around the dark grey. It's like the transparency color is already set to the window background color, not taking into account the RectFill() that it is really on top of.
Attached Images
 
mritter0 is offline  
Old 14 April 2014, 11:58   #8
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,030
Like I said above you did not do anything to preserve transparency. You only pass a bitmap pointer. The bitmap does not contain any transparency information.

The least you have to do is to ask datatypes for a mask bitplane (PDTA_MaskPlane) and supply this mask to the function which does the drawing. Hopefully it supports masking.

In the worst case you have to read the alpha channel from the PNG file using pngalpha.library and write your own drawing routine with alpha blending.


BTW, your handling of pens in the code excerpt above is ugly at best. If the bitmap's depth is bigger than 8, you call ObtainBestPen with the syntax of ObtainPen. A wonder that it compiles without a warning. Anyway it will most likely crash at this point.

Further down you change the stored pen numbers to 0 resp. 1 if you didn't get any pen. In the end of your program you have to release the obtained pen. How do you distinguish between "got no pen" or "got pen 0 resp 1"? You will always release pen 0 resp 1 even if you didn't obtain them.

Finally if you call ObtainPen without PENF_NO_SETCOLOR the pen will already be set to the supplied color. You don't need to call SetRGB32 for it.

Obtaining two pens in a truecolor environment is a waste. If you want different pens for different colors, you can use the same ObtainBestPen calls as in a CLUT environment.

The advantage of truecolor is that if you change a pen's color, the areas which were already drawn with this pen don't change. So you can obtain one pen and do all drawing with this one pen. Just call SetRGB32 each time before your draw. You don't need a second pen.
thomas is online now  
Old 16 April 2014, 04:53   #9
mritter0
Registered User
 
Join Date: Sep 2013
Location: Bettendorf, IA, USA
Age: 52
Posts: 204
I know it is ugly. Still a work in progress. Little project to get me back into programming. The background color with RectFill() is not needed, but would be nice. Not going to pull my hair out for V39 and down to work when I really want to get one of the new X5000 when they come out to use OS4.

Back to the grind stone.....
mritter0 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Color Saturation and Color Tint/Hue Retro-Nerd support.WinUAE 22 02 August 2018 10:38
Printing in color with WinUAE on color laser source support.Apps 7 14 April 2013 00:32
Vectrex collection with 3D Imager, light-pen and complete set of games Tolls Retrogaming General Discussion 5 24 April 2011 13:45
ISO true color to 256 color algorithm Lord Riton Coders. General 19 15 April 2011 17:49
Pen-Pen Xmas Olympics released tomcat666 Nostalgia & memories 0 24 December 2007 00:15

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 15:01.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07835 seconds with 14 queries