Element Image BaseElements include 'Win.inc' EndBase GlobalProc proc Image.Draw hdc locals r RECT bm BITMAP bmhdc dd ? p.x dd ? p.y dd ? endl lea eax,[r] invoke GetClientRect,[pImage.hwnd],eax mov eax,[pImage.hBitmap] or eax,eax je .drawrest lea ecx,[bm] invoke GetObject,eax,sizeof.BITMAP,ecx invoke CreateCompatibleDC,[hdc] mov [bmhdc],eax invoke SelectObject,[bmhdc],[pImage.hBitmap] mov eax,[pImage.ViewStyle] ; Center,Stretch,Scale,Mosaic,None or eax,eax jne .noCenter mov eax,[r.right] sub eax,[bm.bmWidth] sar eax,1 mov [p.x],eax mov eax,[r.bottom] sub eax,[bm.bmHeight] sar eax,1 mov [p.y],eax invoke BitBlt,[hdc],[p.x],[p.y],[bm.bmWidth],[bm.bmHeight],[bmhdc],0,0,SRCCOPY mov eax,[bm.bmWidth] add eax,[p.x] mov edx,[bm.bmHeight] add edx,[p.y] invoke ExcludeClipRect,[hdc],[p.x],[p.y],eax,edx jmp .cleanup .noCenter: cmp eax,1 jne .noStretch mov eax,[r.right] cmp eax,[bm.bmWidth] jb .halftone mov eax,[r.bottom] cmp eax,[bm.bmHeight] jae .nohalftone .halftone: invoke SetStretchBltMode,[hdc],HALFTONE ;invoke SetBrushOrgEx,0,0,0 .nohalftone: invoke StretchBlt,[hdc],0,0,[r.right],[r.bottom],[bmhdc],0,0,[bm.bmWidth],[bm.bmHeight],SRCCOPY invoke DeleteDC,[bmhdc] jmp .exit .noStretch: cmp eax,2 jne .noScale mov ecx,[bm.bmWidth] or ecx,ecx je .cleanup mov eax,[r.right] imul [bm.bmHeight] idiv ecx cmp eax,[r.bottom] jb .scale1 mov ecx,[bm.bmHeight] or ecx,ecx je .cleanup mov eax,[r.bottom] imul [bm.bmWidth] idiv ecx mov [p.x],eax mov eax,[r.bottom] mov [p.y],eax jmp .scale2 .scale1: mov [p.y],eax mov eax,[r.right] mov [p.x],eax .scale2: mov eax,[p.x] cmp eax,[bm.bmWidth] jb .halftone2 mov eax,[p.y] cmp eax,[bm.bmHeight] jae .nohalftone2 .halftone2: invoke SetStretchBltMode,[hdc],HALFTONE ;invoke SetBrushOrgEx,0,0,0 .nohalftone2: invoke StretchBlt,[hdc],0,0,[p.x],[p.y],[bmhdc],0,0,[bm.bmWidth],[bm.bmHeight],SRCCOPY invoke ExcludeClipRect,[hdc],0,0,[p.x],[p.y] jmp .cleanup .noScale: cmp eax,3 jne .noMosaic push esi xor esi,esi .mosloop1: xor edi,edi .mosloop2: invoke BitBlt,[hdc],edi,esi,[bm.bmWidth],[bm.bmHeight],[bmhdc],0,0,SRCCOPY add edi,[bm.bmWidth] cmp edi,[r.right] jb .mosloop2 add esi,[bm.bmHeight] cmp esi,[r.bottom] jb .mosloop1 pop esi invoke DeleteDC,[bmhdc] jmp .exit .noMosaic: invoke BitBlt,[hdc],0,0,[bm.bmWidth],[bm.bmHeight],[bmhdc],0,0,SRCCOPY invoke ExcludeClipRect,[hdc],0,0,[bm.bmWidth],[bm.bmHeight] .cleanup: invoke DeleteDC,[bmhdc] .drawrest: lea eax,[r] invoke FillRect,[hdc],eax,[pImage.hbrush] .exit: ret endp proc Image.AutoSize self locals bm BITMAP endl push esi mov esi,[self] mov eax,[pImage.hBitmap] or eax,eax je .exit lea ecx,[bm] invoke GetObject,eax,sizeof.BITMAP,ecx invoke SetWindowPos,[pImage.hwnd],0,0,0,[bm.bmWidth],[bm.bmHeight],SWP_NOMOVE+SWP_NOZORDER .exit: pop esi ret endp proc Image.Fill self,oldBitmap locals hdc dd ? hdc2 dd ? bm BITMAP bm2 BITMAP endl push esi mov esi,[self] mov eax,[pImage.hBitmap] or eax,eax je .exit lea ecx,[bm] invoke GetObject,eax,sizeof.BITMAP,ecx invoke CreateCompatibleDC,0 mov [hdc],eax invoke SelectObject,eax,[pImage.hBitmap] push [bm.bmHeight] push [bm.bmWidth] push 0 push 0 mov eax,esp invoke FillRect,[hdc],eax,[pImage.hbrush] add esp,16 mov eax,[oldBitmap] or eax,eax je .nooldbmp lea ecx,[bm2] invoke GetObject,eax,sizeof.BITMAP,ecx invoke CreateCompatibleDC,0 mov [hdc2],eax invoke SelectObject,[hdc2],[oldBitmap] mov eax,[bm.bmWidth] cmp eax,[bm2.bmWidth] jb @f mov eax,[bm2.bmWidth] @@:mov edx,[bm.bmHeight] cmp edx,[bm2.bmHeight] jb @f mov edx,[bm2.bmHeight] @@:invoke BitBlt,[hdc],0,0,eax,edx,[hdc2],0,0,SRCCOPY invoke DeleteDC,[hdc2] .nooldbmp: invoke DeleteDC,[hdc] .exit: pop esi ret endp proc Image.Resize x,y locals hdc dd ? endl mov eax,[pImage.hBitmap] or eax,eax je .exit push eax invoke GetDC,0 mov [hdc],eax invoke CreateCompatibleBitmap,eax,[x],[y] mov [pImage.hBitmap],eax invoke ReleaseDC,0,[hdc] stdcall Image.Fill,esi,[esp] invoke DeleteObject .exit: ret endp proc Image.Load self,hbmp locals bm BITMAP endl push esi mov esi,[self] mov eax,[pImage.hBitmap] or eax,eax je @f invoke DeleteObject,eax xor eax,eax mov [pImage.hBitmap],eax @@:mov eax,[hbmp] or eax,eax je .exit lea ecx,[bm] invoke GetObject,eax,sizeof.BITMAP,ecx invoke CopyImage,[hbmp],IMAGE_BITMAP,[bm.bmWidth],[bm.bmHeight],0 mov [pImage.hBitmap],eax .exit: pop esi ret endp Vars Self#.hBitmap dd ? Self#.ViewStyle dd ? Create if Self#.prop.Picture eq 0 xor eax,eax else invoke LoadImage,[hinstance],Self#.prop.Picture,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE end if mov [Self#.hBitmap],eax mov [Self#.ViewStyle],Self#.prop.ViewStyle NewControl Self,Parent,window_class,0 if Self#.prop.AutoSize eq 0 lea eax,[Self] stdcall Image.AutoSize,eax end if Destroy mov eax,[Self#.hBitmap] or eax,eax je @f invoke DeleteObject,eax @@: MessageMap cmp [wmsg],WM_ERASEBKGND jne .nopaint stdcall Image.Draw,[wparam] jmp Self#.finish .nopaint: if Self#.prop.Draw eq 1 cmp [wmsg],WM_SIZE jne .nosize mov eax,[lparam] shr eax,16 push eax mov eax,[lparam] and eax,0FFFFh push eax stdcall Image.Resize jmp Self#.exit .nosize: end if PointWork doClear if Self#.prop.Draw eq 1 lea eax,[Self] stdcall Image.Fill,eax,0 else mov eax,[Self#.hBitmap] or eax,eax je @f invoke DeleteObject,eax xor eax,eax mov [Self#.hBitmap],eax @@: end if invoke InvalidateRect,[Self#.hwnd],0,1 EndPoint PointWork doLoad \local res ReadBitmap res,data,data.type,Self#.Bitmap,0 lea ecx,[Self] stdcall Image.Load,ecx,res if Self#.prop.AutoSize eq 0 lea eax,[Self] stdcall Image.AutoSize,eax end if invoke InvalidateRect,[Self#.hwnd],0,1 EndPoint PointWork doRefresh invoke InvalidateRect,[Self#.hwnd],0,1 EndPoint PointWork doViewStyle \local res ToInteger res,data,data.type mov_ex eax,res mov [Self#.ViewStyle],eax invoke InvalidateRect,[Self#.hwnd],0,1 EndPoint PointVar ImageBitmap,data_bitmap result equ [Self#.hBitmap] EndPoint EndElement