English Amiga Board


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

 
 
Thread Tools
Old 07 March 2015, 00:37   #21
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by AlfaRomeo View Post
How I could concatenate a string with a qualifier key result so it could be used with the Text() function?
Another option is exec.library RawDoFmt(). It might be a little faster and probably would give a smaller program depending on compiler options. For portable code, sprintf() would be preferable but for Amiga code, RawDoFmt() may be preferable.
matthey is offline  
Old 22 February 2017, 17:00   #22
AlfaRomeo
A1200 040 SAM440EP 667
 
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
I´m trying to figuring out how to modify the next example code to obtain a transparent and semi-transparent window background so could see the WB screen trought the background of the window but I have no idea on how to do it, can someone help, please?

Code:
#include <exec/types.h>
#include <exec/exec.h>
#include <intuition/intuition.h>
#include <graphics/gfx.h>
#include <dos/dos.h>

#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/dos.h>
#include <proto/exec.h>

#define WIDTH  300
#define HEIGHT 200

struct Window *Win;
struct IntuitionBase *intuiBase;
struct GfxBase *graphBase;
struct RastPort *rp;

long red_pen,green_pen,blue_pen,white_pen,yellow_pen,magenta_pen,cyan_pen;

int main(void){
    intuiBase=(struct IntuitionBase *)OpenLibrary("intuition.library",36L);

    if(intuiBase != NULL){
        graphBase=(struct GfxBase *)OpenLibrary("graphics.library",39L);

        Win=OpenWindowTags(NULL, WA_Left,100, WA_Top,100, WA_Width,WIDTH,
                           WA_Height,HEIGHT, WA_Title,"RGB Demo",
                           WA_ScreenTitle,"RGB Demo", WA_CloseGadget,TRUE,
                           WA_DragBar,TRUE, WA_DepthGadget,TRUE,
                           WA_GimmeZeroZero,TRUE, WA_IDCMP,IDCMP_CLOSEWINDOW,
                           WA_Activate,TRUE, TAG_DONE);
        if(Win != NULL){
            rp=Win->RPort;
   	    red_pen=ObtainBestPen(Win->WScreen->ViewPort.ColorMap,
                                  0xFFFFFFFF,0x00000000,0x00000000,
                                  OBP_Precision,PRECISION_EXACT,TAG_DONE);

            green_pen=ObtainBestPen(Win->WScreen->ViewPort.ColorMap,
                                  0x00000000,0xFFFFFFFF,0x00000000,
                                  OBP_Precision,PRECISION_EXACT,TAG_DONE);

            blue_pen=ObtainBestPen(Win->WScreen->ViewPort.ColorMap,
                                  0x00000000,0x00000000,0xFFFFFFFF,
                                  OBP_Precision,PRECISION_EXACT,TAG_DONE);


            white_pen=ObtainBestPen(Win->WScreen->ViewPort.ColorMap,
                                  0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
                                  OBP_Precision,PRECISION_EXACT,TAG_DONE);


            yellow_pen=ObtainBestPen(Win->WScreen->ViewPort.ColorMap,
                                  0xFFFFFFFF,0xFFFFFFFF,0x00000000,
                                  OBP_Precision,PRECISION_EXACT,TAG_DONE);


            magenta_pen=ObtainBestPen(Win->WScreen->ViewPort.ColorMap,
                                  0xFFFFFFFF,0x00000000,0xFFFFFFFF,
                                  OBP_Precision,PRECISION_EXACT,TAG_DONE);


            cyan_pen=ObtainBestPen(Win->WScreen->ViewPort.ColorMap,
                                  0x00000000,0xFFFFFFFF,0xFFFFFFFF,
                                  OBP_Precision,PRECISION_EXACT,TAG_DONE);

            SetRast(rp,1L);

            SetAPen(rp,red_pen);
            RectFill(rp,10,10,WIDTH-20,20);

            SetAPen(rp,green_pen);
            RectFill(rp,10,30,WIDTH-20,40);

            SetAPen(rp,blue_pen);
            RectFill(rp,10,50,WIDTH-20,60);

            SetAPen(rp,white_pen);
            RectFill(rp,10,70,WIDTH-20,80);

            SetAPen(rp,yellow_pen);
            RectFill(rp,10,90,WIDTH-20,100);

            SetAPen(rp,magenta_pen);
            RectFill(rp,10,110,WIDTH-20,120);

            SetAPen(rp,cyan_pen);
            RectFill(rp,10,130,WIDTH-20,140);

            // Wait for click in the CloseWindow Gadget, in that case a flag bit
            // will be sent and then the LongWord (1L) will be shifted to left
            // so many times as mp_SigBit so the BitFlag can be verified,
            // case it is the CloseWindow flag the window will be closed
            Wait(1L<<Win->UserPort->mp_SigBit);

            // Release the pen again
            ReleasePen(Win->WScreen->ViewPort.ColorMap,red_pen);
            ReleasePen(Win->WScreen->ViewPort.ColorMap,green_pen);
            ReleasePen(Win->WScreen->ViewPort.ColorMap,blue_pen);
            ReleasePen(Win->WScreen->ViewPort.ColorMap,white_pen);
            ReleasePen(Win->WScreen->ViewPort.ColorMap,yellow_pen);
            ReleasePen(Win->WScreen->ViewPort.ColorMap,magenta_pen);
            ReleasePen(Win->WScreen->ViewPort.ColorMap,cyan_pen);

            CloseWindow(Win);   //Close window
            }  //End if
        }      //End if
    //Close libraries
    if(graphBase != NULL) CloseLibrary((struct Library *)GfxBase);
    if(intuiBase != NULL) CloseLibrary((struct Library *)IntuitionBase);

    return 0;
    }
AlfaRomeo is offline  
Old 22 February 2017, 18:05   #23
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,187
There are 2 ways to do it. If you are on a pallette display, compute the average of the foreground color and the background color of each palette entry such that you can use dual playfield mode on the blitter window and single playfield mode for the display. If you want to support a graphics card, on the other hand, you'll need to use alpha blending to accomplish transparency.

Also, if you are using an extended colormap structure, each entry is 96 bits per pen color. That's 32 bits per component.
Samurai_Crow is offline  
Old 22 February 2017, 18:27   #24
AlfaRomeo
A1200 040 SAM440EP 667
 
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
Thanks for the hint Samurai_Crow.
I want to execute the code in graphics card and the examples of amiga code are mostly for palette displays, but even for that, I didn´t find any Amiga example of the transparent windows.
I will try to figure out how alpha blending and 32 bits per component works to accomplish transparency.
AlfaRomeo is offline  
Old 22 February 2017, 20:48   #25
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,002
Mixing pixels and alpha blending are quite difficult and very very slow.

But keeping the background and drawing only the parts which should be visible is rather easy.

Example:
Code:
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>


int main (void)

{
struct Screen *scr;

if ((scr = LockPubScreen (NULL)))
	{
	struct Window *win;

	if ((win = OpenWindowTags (NULL,
			WA_Left, scr->Width / 4,
			WA_Top, scr->Height / 4,
			WA_Width, scr->Width / 2,
			WA_Height, scr->Height / 2,
			WA_Flags, WFLG_BORDERLESS | WFLG_ACTIVATE | WFLG_NOCAREREFRESH,
			WA_IDCMP, IDCMP_VANILLAKEY | IDCMP_MOUSEBUTTONS | IDCMP_INACTIVEWINDOW,
			WA_BackFill, LAYERS_NOBACKFILL,
			TAG_END)))
		{
		BOOL cont = TRUE;

		#define N 11

		int i;
		int w = win->Width * (2*N-1) / (2*N);
		int h = win->Height * (2*N-1) / (2*N);
		struct RastPort *rp = win->RPort;

		for (i = 0; i < N; i++)
			{
			SetAPen (rp,i);
			RectFill (rp,
				i * w / N,
				i * h / N,
				(i * 2 + 3) * w / (2*N) - 1,
				(i * 2 + 3) * h / (2*N) - 1);

			RectFill (rp,
				(N-1 - i) * w / N,
				i * h / N,
				((N-1 - i) * 2 + 3) * w / (2*N) - 1,
				(i * 2 + 3) * h / (2*N) - 1);
			}


		do	{
			struct IntuiMessage *imsg;

			if (Wait ((1L << win->UserPort->mp_SigBit) | SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
				cont = FALSE;

			while ((imsg = (struct IntuiMessage *) GetMsg (win->UserPort)))
				{
				switch (imsg->Class)
					{
				case IDCMP_MOUSEBUTTONS:
					if (imsg->Code == IECODE_LBUTTON)
						cont = FALSE;
					break;
				case IDCMP_VANILLAKEY:
					if (imsg->Code == 0x1b)
						cont = FALSE;
					break;
				case IDCMP_INACTIVEWINDOW:
					cont = FALSE;
					break;
					}
				
				ReplyMsg ((struct Message *) imsg);
				}
			}
		while (cont);

		CloseWindow (win);
		}

	UnlockPubScreen (NULL,scr);
	}

return (RETURN_OK);
}
thomas is online now  
Old 23 February 2017, 01:07   #26
AlfaRomeo
A1200 040 SAM440EP 667
 
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
Many thanks for your example code thomas
Will try to understand it better tomorrow
AlfaRomeo is offline  
 


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

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 08:31.

Top

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