User talk:Demivec: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
<lang PureBasic> |
|||
<pre> |
|||
Demivec |
|||
thank you. |
|||
; i hope there are no hard feeling... here's some code for you... |
|||
you did not offend me. |
|||
please note i have not finalized my solutions. |
|||
declare.i MakeDesktopScreenshot(ImageNr,x,y,Width,Height) |
|||
i will be going over each one continuously looking to make improvements. |
|||
Enumeration |
|||
i do not wish to shotgun this site with half-baked code. |
|||
#ButtonMakeScreenShot |
|||
#ButtonMakeNewScreenShot |
|||
#ImageFullScreenShot |
|||
#ImageHalfScreenShot |
|||
#ImageTempScreenShot |
|||
#ImageSelectedArea |
|||
EndEnumeration |
|||
StopSelecting=#TRUE |
|||
for instance: i realized this morning that i may have cheated on the color quantization task. |
|||
style=#PB_Window_SystemMenu |
|||
style|#PB_Window_MinimizeGadget |
|||
style|#PB_Window_Screencentered |
|||
LoadFont(0,"tahoma",9,#PB_Font_HighQuality|#PB_Font_Bold) |
|||
and that one is FAR from finished. |
|||
SetGadgetFont(#PB_Default, FontID(0)) |
|||
ExamineDesktops():dtw=DesktopWidth(0):dth=DesktopHeight(0) |
|||
i personally have to work on multiple problems at the same time or i usually will get stuck on one. |
|||
w=dtw/2:h=dth/2 |
|||
MakeDesktopScreenshot(#ImageFullScreenShot,0,0,dtw,dth) |
|||
i also can not personally read nested code very well since my first esposure to computers was with spreadsheets. |
|||
CopyImage(#ImageFullScreenShot,#ImageHalfScreenShot) |
|||
ResizeImage(#ImageHalfScreenShot,w,h) |
|||
OpenWindow(0,0,0,w,h+20,"",style):StickyWindow(0,1) |
|||
regarding the tools i use an example might make the connect with spreadsheets clearer. |
|||
ButtonGadget(#ButtonMakeNewScreenShot,w-200,h,100,20,"New",#PB_Button_Toggle) ;:PureCOLOR_SetButtonColor(#ButtonMakeNewScreenShot,$ffffff,$000000) |
|||
ButtonGadget(#ButtonMakeScreenShot,w-100,h,100,20,"SnipIt",#PB_Button_Toggle) ;:PureCOLOR_SetButtonColor(#ButtonMakeScreenShot,$ffffff,$000000) |
|||
ImageGadget(#ImageHalfScreenShot,0,0,w,h,ImageID(#ImageHalfScreenShot)) |
|||
Repeat |
|||
say i wanted to build an array from: [without typos] |
|||
msg= WaitWindowEvent () ;WindowEvent (): Sleep_ (1) |
|||
wid= EventWindow () |
|||
mid= EventMenu () |
|||
gid= EventGadget () |
|||
etp= EventType () |
|||
ewp= EventwParam () |
|||
elp= EventlParam () : If msg=16 or GetAsyncKeyState_(#VK_ESCAPE) : End : EndIf |
|||
if msg=#WM_LBUTTONUP |
|||
int U[][9] = {{ 1, -2, 2, 2, -1, 2, 2, -2, 3}, |
|||
if gid=#ImageHalfScreenShot |
|||
{ 1, 2, 2, 2, 1, 2, 2, 2, 3}, |
|||
StopSelecting=#TRUE |
|||
{-1, 2, 2, -2, 1, 2, -2, 2, 3}}; |
|||
endif |
|||
steps: |
|||
endif |
|||
if gid=#ImageHalfScreenShot |
|||
1] a little cleaning |
|||
if etp=#PB_EventType_LeftClick |
|||
x1 =WindowMouseX(0) |
|||
y1 =WindowMouseY(0) |
|||
t1.s="" |
|||
t1.s+str(x1*2 )+"|" |
|||
t1.s+str(y1*2 )+"|" |
|||
SetWindowTitle(0,t1.s) |
|||
StopSelecting=#FALSE |
|||
endif |
|||
endif |
|||
if gid=#ImageHalfScreenShot |
|||
here i could use a datasection but not for multi-dim arrays [i think] |
|||
if msg=#WM_MOUSEMOVE and not StopSelecting=#TRUE |
|||
x2 =WindowMouseX(0) |
|||
y2 =WindowMouseY(0) |
|||
sw =abs(x2-x1) |
|||
sh =abs(y2-y1) |
|||
t1.s="" |
|||
1, -2, 2, 2, -1, 2, 2, -2, 3} |
|||
t1.s+str(x1*2)+"|" |
|||
1, 2, 2, 2, 1, 2, 2, 2, 3} |
|||
t1.s+str(y1*2)+"|" |
|||
-1, 2, 2, -2, 1, 2, -2, 2, 3} |
|||
t2.s="" |
|||
t2.s+str(sw*2)+"|" |
|||
t2.s+str(sh*2)+"|" |
|||
SetWindowTitle(0,t1.s+t2.s) |
|||
SetGadgetState(#ImageHalfScreenShot,ImageID(#ImageHalfScreenShot)) |
|||
2] build my mask |
|||
GrabImage(#ImageHalfScreenShot,#ImageTempScreenShot,0,0,w,h) |
|||
StartDrawing(ImageOutput(#ImageTempScreenShot)) |
|||
DrawImage(ImageID(#ImageTempScreenShot), 0, 0) |
|||
DrawingMode(#PB_2DDrawing_XOr | #PB_2DDrawing_Outlined) |
|||
Box(x1,y1,sw,sh, $FFFFFF) |
|||
StopDrawing() |
|||
SetGadgetState(#ImageHalfScreenShot,ImageID(#ImageTempScreenShot)) |
|||
endif |
|||
endif |
|||
Select msg |
|||
U(1,~1)=~2:U(2,~1)=~3:U(3,~1)=~4 |
|||
case #PB_Event_Gadget |
|||
9 <--- hightlight 9 and hit f12 |
|||
Select gid |
|||
case #ButtonMakeNewScreenShot |
|||
hidewindow(0,1) |
|||
sleep_(1000) |
|||
MakeDesktopScreenshot(#ImageFullScreenShot,0,0,dtw,dth) |
|||
CopyImage(#ImageFullScreenShot,#ImageHalfScreenShot) |
|||
ResizeImage(#ImageHalfScreenShot,w,h) |
|||
SetGadgetState(#ImageHalfScreenShot,ImageID(#ImageHalfScreenShot)) |
|||
hidewindow(0,0) |
|||
case #ButtonMakeScreenShot : |
|||
3] generate indices to clipboard and output pane |
|||
Select GetGadgetState(#ButtonMakeScreenShot) |
|||
case 0 |
|||
SetGadgetState(#ImageHalfScreenShot,ImageID(#ImageHalfScreenShot)) |
|||
case 1 |
|||
t.s=GetWindowTitle(0) |
|||
t3.s=" - " |
|||
t3.s+str(x1*2)+"|" |
|||
t3.s+str(y1*2)+"|" |
|||
t3.s+str(sw*2)+"|" |
|||
t3.s+str(sh*2)+"|" |
|||
SetWindowTitle(0,t1.s+t2.s+t3.s) |
|||
GrabImage(#ImageFullScreenShot, #ImageSelectedArea, x1*2-2,y1*2-2,sw*2,sh*2) |
|||
SetClipboardImage(#ImageSelectedArea) |
|||
SetGadgetState(#ImageHalfScreenShot,ImageID(#ImageSelectedArea)) |
|||
EndSelect |
|||
EndSelect |
|||
U(1,~1)=~2:U(2,~1)=~3:U(3,~1)=~4 |
|||
EndSelect |
|||
1 |
|||
ForEver |
|||
2 |
|||
End |
|||
3 |
|||
4 |
|||
5 |
|||
6 |
|||
7 |
|||
8 |
|||
9 |
|||
Procedure.i MakeDesktopScreenshot(ImageNr,x,y,Width,Height) |
|||
4] break data into columns |
|||
hImage = CreateImage(ImageNr,Width,Height) |
|||
hDC = StartDrawing(ImageOutput(ImageNr)) |
|||
DeskDC = GetDC_(GetDesktopWindow_()) |
|||
BitBlt_(hDC,0,0,Width,Height,DeskDC,x,y,#SRCCOPY) |
|||
StopDrawing() |
|||
ReleaseDC_(GetDesktopWindow_(),DeskDC) |
|||
ProcedureReturn hImage |
|||
EndProcedure |
|||
</lang> |
|||
1, -2, 2, 2, -1, 2, 2, -2, 3} |
|||
1, 2, 2, 2, 1, 2, 2, 2, 3} |
|||
-1, 2, 2, -2, 1, 2, -2, 2, 3} |
|||
a] highlight commas |
|||
b] hit find/replace toolbar icon |
|||
c] select tool "chr(10)" from tools menu |
|||
d] hit enter |
|||
e] reselect result and replace } with chr(10)+"^" [note the chr(10) is still in the replace with field] |
|||
5] build it [the tool is called BuildExtractMake.exe] |
|||
a] ~1,~2,... the columns to fill |
|||
b] ^ the number of rows delimiter |
|||
U(1,~1)=~2:U(2,~1)=~3:U(3,~1)=~4 |
|||
1 |
|||
2 |
|||
3 |
|||
4 |
|||
5 |
|||
6 |
|||
7 |
|||
8 |
|||
9 |
|||
^ |
|||
1 |
|||
-2 |
|||
2 |
|||
2 |
|||
-1 |
|||
2 |
|||
2 |
|||
-2 |
|||
3 |
|||
^ |
|||
1 |
|||
2 |
|||
2 |
|||
2 |
|||
1 |
|||
2 |
|||
2 |
|||
2 |
|||
3 |
|||
^ |
|||
-1 |
|||
2 |
|||
2 |
|||
-2 |
|||
1 |
|||
2 |
|||
-2 |
|||
2 |
|||
3 |
|||
6] clean up |
|||
now the connection to spreadsheets becomes clear. |
|||
dim U(3,9) |
|||
U(1,1)= 1:U(2,1)=1:U(3,1)=-1 |
|||
U(1,2)=-2:U(2,2)=2:U(3,2)= 2 |
|||
U(1,3)= 2:U(2,3)=2:U(3,3)= 2 |
|||
U(1,4)= 2:U(2,4)=2:U(3,4)=-2 |
|||
U(1,5)=-1:U(2,5)=1:U(3,5)= 1 |
|||
U(1,6)= 2:U(2,6)=2:U(3,6)= 2 |
|||
U(1,7)= 2:U(2,7)=2:U(3,7)=-2 |
|||
U(1,8)=-2:U(2,8)=2:U(3,8)= 2 |
|||
U(1,9)= 3:U(2,9)=3:U(3,9)= 3 |
|||
since the entire purpose of a computer program is to take input and provide output... |
|||
how any programmer lives without BOTH input AND and output panes is hard for me to understand. |
|||
that's where all the experimentation takes place and that is the joy of programming. |
|||
the final results of that experimentation belong within an IDE to be organized and shared. |
|||
every IDE i have including VS2010 ultimate seems designed to take the joy OUT of programming. |
|||
so until the tasks are finalized... it is much easier for me to leave them with |
|||
ConsoleWrite[Type](Type) < cw[Type](Type) ~ "Debug" |
|||
StdOut[Type](Type) < so[Type](Type) ~ "Debug" commented. |
|||
but when they are "IDE ready" i will "clean'em up" |
|||
take care... brianO |
|||
</pre> |
Revision as of 22:15, 26 August 2012
<lang PureBasic>
- i hope there are no hard feeling... here's some code for you...
declare.i MakeDesktopScreenshot(ImageNr,x,y,Width,Height)
Enumeration
- ButtonMakeScreenShot
- ButtonMakeNewScreenShot
- ImageFullScreenShot
- ImageHalfScreenShot
- ImageTempScreenShot
- ImageSelectedArea
EndEnumeration
StopSelecting=#TRUE style=#PB_Window_SystemMenu style|#PB_Window_MinimizeGadget style|#PB_Window_Screencentered
LoadFont(0,"tahoma",9,#PB_Font_HighQuality|#PB_Font_Bold) SetGadgetFont(#PB_Default, FontID(0))
ExamineDesktops():dtw=DesktopWidth(0):dth=DesktopHeight(0) w=dtw/2:h=dth/2
MakeDesktopScreenshot(#ImageFullScreenShot,0,0,dtw,dth) CopyImage(#ImageFullScreenShot,#ImageHalfScreenShot) ResizeImage(#ImageHalfScreenShot,w,h)
OpenWindow(0,0,0,w,h+20,"",style):StickyWindow(0,1) ButtonGadget(#ButtonMakeNewScreenShot,w-200,h,100,20,"New",#PB_Button_Toggle) ;:PureCOLOR_SetButtonColor(#ButtonMakeNewScreenShot,$ffffff,$000000) ButtonGadget(#ButtonMakeScreenShot,w-100,h,100,20,"SnipIt",#PB_Button_Toggle) ;:PureCOLOR_SetButtonColor(#ButtonMakeScreenShot,$ffffff,$000000) ImageGadget(#ImageHalfScreenShot,0,0,w,h,ImageID(#ImageHalfScreenShot))
Repeat msg= WaitWindowEvent () ;WindowEvent (): Sleep_ (1) wid= EventWindow () mid= EventMenu () gid= EventGadget () etp= EventType () ewp= EventwParam () elp= EventlParam () : If msg=16 or GetAsyncKeyState_(#VK_ESCAPE) : End : EndIf
if msg=#WM_LBUTTONUP if gid=#ImageHalfScreenShot StopSelecting=#TRUE endif endif
if gid=#ImageHalfScreenShot if etp=#PB_EventType_LeftClick x1 =WindowMouseX(0) y1 =WindowMouseY(0) t1.s="" t1.s+str(x1*2 )+"|" t1.s+str(y1*2 )+"|" SetWindowTitle(0,t1.s) StopSelecting=#FALSE endif endif
if gid=#ImageHalfScreenShot if msg=#WM_MOUSEMOVE and not StopSelecting=#TRUE x2 =WindowMouseX(0) y2 =WindowMouseY(0) sw =abs(x2-x1) sh =abs(y2-y1)
t1.s="" t1.s+str(x1*2)+"|" t1.s+str(y1*2)+"|" t2.s="" t2.s+str(sw*2)+"|" t2.s+str(sh*2)+"|" SetWindowTitle(0,t1.s+t2.s)
SetGadgetState(#ImageHalfScreenShot,ImageID(#ImageHalfScreenShot)) GrabImage(#ImageHalfScreenShot,#ImageTempScreenShot,0,0,w,h) StartDrawing(ImageOutput(#ImageTempScreenShot)) DrawImage(ImageID(#ImageTempScreenShot), 0, 0) DrawingMode(#PB_2DDrawing_XOr | #PB_2DDrawing_Outlined) Box(x1,y1,sw,sh, $FFFFFF) StopDrawing() SetGadgetState(#ImageHalfScreenShot,ImageID(#ImageTempScreenShot)) endif endif
Select msg case #PB_Event_Gadget Select gid case #ButtonMakeNewScreenShot hidewindow(0,1) sleep_(1000) MakeDesktopScreenshot(#ImageFullScreenShot,0,0,dtw,dth) CopyImage(#ImageFullScreenShot,#ImageHalfScreenShot) ResizeImage(#ImageHalfScreenShot,w,h) SetGadgetState(#ImageHalfScreenShot,ImageID(#ImageHalfScreenShot)) hidewindow(0,0)
case #ButtonMakeScreenShot : Select GetGadgetState(#ButtonMakeScreenShot) case 0 SetGadgetState(#ImageHalfScreenShot,ImageID(#ImageHalfScreenShot)) case 1 t.s=GetWindowTitle(0) t3.s=" - " t3.s+str(x1*2)+"|" t3.s+str(y1*2)+"|" t3.s+str(sw*2)+"|" t3.s+str(sh*2)+"|" SetWindowTitle(0,t1.s+t2.s+t3.s) GrabImage(#ImageFullScreenShot, #ImageSelectedArea, x1*2-2,y1*2-2,sw*2,sh*2) SetClipboardImage(#ImageSelectedArea) SetGadgetState(#ImageHalfScreenShot,ImageID(#ImageSelectedArea)) EndSelect
EndSelect EndSelect ForEver End
Procedure.i MakeDesktopScreenshot(ImageNr,x,y,Width,Height) hImage = CreateImage(ImageNr,Width,Height) hDC = StartDrawing(ImageOutput(ImageNr)) DeskDC = GetDC_(GetDesktopWindow_()) BitBlt_(hDC,0,0,Width,Height,DeskDC,x,y,#SRCCOPY) StopDrawing() ReleaseDC_(GetDesktopWindow_(),DeskDC) ProcedureReturn hImage EndProcedure
</lang>