4 #include <intuition/intuition.h>
5 #include <graphics/gfx.h>
6 #include <graphics/scale.h>
7 #include <utility/hooks.h>
8 #include <dos/rdargs.h>
10 #include <proto/exec.h>
11 #include <proto/intuition.h>
12 #include <proto/graphics.h>
13 #include <proto/layers.h>
14 #include <proto/dos.h>
16 #include <aros/asmcall.h>
17 #include <aros/libcall.h>
22 struct IntuitionBase
*IntuitionBase
;
23 struct GfxBase
*GfxBase
;
24 struct Library
*LayersBase
;
26 static struct Screen
*scr
;
27 static struct Window
*win
;
28 static struct DrawInfo
*dri
;
29 static struct BitMap
*scalebitmap
;
31 static BOOL follow
= FALSE
;
32 static BOOL do_lens
= FALSE
;
34 AROS_UFP3(void, LensCallback
,
35 AROS_UFPA(struct Hook
*, hook
, A0
),
36 AROS_UFPA(struct Layer
*, l
, A2
),
37 AROS_UFPA(struct CollectPixelsLayerMsg
*, cplm
, A1
));
46 static void Cleanup(char *msg
)
52 printf("lens: %s\n",msg
);
58 if (scalebitmap
) FreeBitMap(scalebitmap
);
60 if (win
) CloseWindow(win
);
62 if (dri
) FreeScreenDrawInfo(scr
,dri
);
63 UnlockPubScreen(0,scr
);
66 if (LayersBase
) CloseLibrary(LayersBase
);
67 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
68 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
73 static void OpenLibs(void)
75 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library",39)))
77 Cleanup("Can't open intuition.library V39!");
80 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library",39)))
82 Cleanup("Can't open graphics.library V39!");
85 if (!(LayersBase
= OpenLibrary("layers.library",39)))
87 Cleanup("Can't open layers.library V39!");
92 static void GetVisual(void)
94 if (!(scr
= LockPubScreen(0)))
96 Cleanup("Can't lock pub screen!");
99 if (!(dri
= GetScreenDrawInfo(scr
)))
101 Cleanup("Can't get drawinfo!");
106 * The ScaleLayer callback is doing the actul work of
109 AROS_UFH3(void, LensCallback
,
110 AROS_UFHA(struct Hook
*, hook
, A0
),
111 AROS_UFHA(struct Layer
*, l
, A2
),
112 AROS_UFHA(struct CollectPixelsLayerMsg
*, cplm
, A1
))
115 struct LensParam
* lp
= (struct LensParam
*)hook
->h_Data
;
116 if (NULL
!= cplm
->bm
) {
118 if (FALSE
== do_lens
) {
127 cplm
->xDest
- win
->LeftEdge
- lp
->dx
+ win
->Width
/2,
128 cplm
->yDest
- win
->TopEdge
- lp
->dy
+ win
->Height
/2,
134 * This is just a hack for now...
135 * Need to adjust the destination x/y coordinates
136 * in accordance to the source x/y coordinates taken
137 * from the absolute coordinates of the source.
139 struct BitScaleArgs bsa
;
140 bsa
.bsa_SrcX
= cplm
->xSrc
;
141 bsa
.bsa_SrcY
= cplm
->ySrc
;
142 bsa
.bsa_SrcWidth
= cplm
->width
;
143 bsa
.bsa_SrcHeight
= cplm
->height
;
146 bsa
.bsa_DestWidth
= cplm
->width
*2;
147 bsa
.bsa_DestHeight
= cplm
->height
*2;
148 bsa
.bsa_XSrcFactor
= cplm
->width
;
149 bsa
.bsa_XDestFactor
= cplm
->width
*2;
150 bsa
.bsa_YSrcFactor
= cplm
->height
;
151 bsa
.bsa_YDestFactor
= cplm
->height
*2;
152 bsa
.bsa_SrcBitMap
= cplm
->bm
;
153 bsa
.bsa_DestBitMap
= scalebitmap
;
157 * Display the scaled content.
166 cplm
->width
*2,//bsa.bsa_DestWidth,
167 cplm
->height
*2,//bsa.bsa_DestHeight,
175 static void DoLens(struct Window
* win
, LONG dx
, LONG dy
)
177 struct Region
* r
= NewRegion();
178 struct Rectangle rect
;
179 struct Layer
* l
= win
->RPort
->Layer
;
181 struct LensParam lp
= {win
,dx
,dy
};
182 ULONG QWidth
= win
->Width
/ 4;
183 ULONG QHeight
= win
->Height
/ 4;
184 ULONG HWidth
= win
->Width
/ 2;
185 ULONG HHeight
= win
->Height
/ 2;
186 h
.h_Entry
= (IPTR (*)())LensCallback
;
187 h
.h_Data
= (void *)&lp
;
189 rect
.MinX
= dx
+ win
->LeftEdge
+ QWidth
- HWidth
;
190 rect
.MinY
= dy
+ win
->TopEdge
+ QHeight
- HHeight
;
191 rect
.MaxX
= dx
+ win
->LeftEdge
+ win
->Width
- 1 - QWidth
- HWidth
;
192 rect
.MaxY
= dy
+ win
->TopEdge
+ win
->Height
- 1 - QHeight
- HHeight
;
200 OrRectRegion(r
, &rect
);
202 CollectPixelsLayer(l
->back
,
210 static void MakeWin(void)
212 if (!(win
= OpenWindowTags(0,WA_PubScreen
,(IPTR
)scr
,
218 WA_SmartRefresh
,TRUE
,
220 WA_DepthGadget
,FALSE
,
222 WA_IDCMP
,IDCMP_REFRESHWINDOW
| IDCMP_MOUSEMOVE
| IDCMP_DELTAMOVE
| IDCMP_CLOSEWINDOW
,
223 WA_ReportMouse
, TRUE
,
226 Cleanup("Can't open window!");
228 scalebitmap
= AllocBitMap(win
->Width
,
230 GetBitMapAttr(win
->RPort
->BitMap
, BMA_DEPTH
),
238 ScreenToFront(win
->WScreen
);
241 static void HandleAll(void)
243 struct IntuiMessage
*msg
;
249 WaitPort(win
->UserPort
);
251 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
255 case IDCMP_CLOSEWINDOW
:
259 case IDCMP_REFRESHWINDOW
:
261 EndRefresh(win
,TRUE
);
264 case IDCMP_MOUSEMOVE
:
265 if (win
== msg
->IDCMPWindow
) {
266 printf("mouse move %d/%d!\n",
269 if (TRUE
== follow
) {
271 win
->MouseX
, // - win->LeftEdge,
272 win
->MouseY
//- win->TopEdge
278 * this works, but center is a bit off.
280 DoLens(win
,win
->MouseX
,win
->MouseY
);
285 case IDCMP_DELTAMOVE
:
286 printf("delta move!");
290 ReplyMsg((struct Message
*)msg
);
297 STRPTR args
[2] = {(STRPTR
)FALSE
, (STRPTR
)FALSE
};
299 rda
= ReadArgs("FOLLOW/S,LENS/S",(IPTR
*)args
, NULL
);
300 if (TRUE
== (IPTR
)args
[0]) {
303 if (TRUE
== (IPTR
)args
[1]) {
313 int main(int argc
, char **argv
)