MX Userlib 1.01 (OSX 10.5+)

Mac OSX specific forum
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

MX Userlib 1.01 (OSX 10.5+)

Post by wilbert »

Minimum requirements : OSX 10.5 (x86)
Download location : http://www.w73.nl/pb/libPBMX.zip
Last modified : Aug 20, 2011

The zip archive contains a x86 version of the library. Put the library file in
PureBasic/purelibraries/userlibraries/

I can't maintain a ppc version anymore since OSX 10.7 doesn't support ppc.
An older version with less commands that has ppc support can be downloaded at http://www.w73.nl/pb/oldLibPBMX.zip

Supported functions

Code: Select all


GLOBAL FUNCTIONS
----------------
MX_Release (object) - Release an object.
MX_ShowPoofEffect (cx.f, cy.f) - Show 'poof' effect at specified screen coordinates.


IMAGE FUNCTIONS AND FILTERS
---------------------------
Height = MXImage_Height (ImageID)
ImageID = MXImage_LoadFromURL (url.s)
Width = MXImage_Width (ImageID)

NewImageID = MXImageFilter_AffineTransform (imageID, m11.f, m12.f, m21.f, m22.f)
NewImageID = MXImageFilter_Crop (imageID, x.f, y.f, width.f, height.f)
NewImageID = MXImageFilter_ExposureAdjust (imageID, EV.f)
NewImageID = MXImageFilter_ComicEffect (imageID)
NewImageID = MXImageFilter_Grayscale (imageID)
NewImageID = MXImageFilter_NoiseReduction (imageID, noiseLevel.f, sharpness.f)
MXImageFilter_SetKeepExtent (keepExtent) - Force output rectangle to be the same as input rectangle.
NewImageID = MXImageFilter_SharpenLuminance (imageID, sharpness.f)
NewImageID = MXImageFilter_UnsharpMask (imageID, radius.f, intensity.f)


PRINT FUNCTIONS
---------------
MXPrint_AppendText (text.s, [underline])
MXPrint_AppendUniChar (uniChar.l, [underline])
Context = MXPrint_BeginDocument [String], ([fileName.s]) - Begin a document (no fileName = printer output, filename = pdf output).
MXPrint_DrawLine (x1.f, y1.f, x2.f, y2.f)
MXPrint_DrawRect (x.f, y.f, width.f, height.f)
MXPrint_EndDocument ()
MXPrint_FillRect (x.f, y.f, width.f, height.f)
Height.f = MXPrint_GetPageHeight ()
Width.f = MXPrint_GetPageWidth ()
Length = MXPrint_GetTextLength ()
Context = MXPrint_NextPage ()
MXPrint_SetContext (context, contextWidth, contextHeight) - Override the MXPrint context.
MXPrint_SetFillColor ((a)rgbColor)
MXPrint_SetFont (font.s, size.f, (a)rgbColor)
MXPrint_SetFontWithFamily (fontFamily.s, style, size.f, (a)rgbColor) - Style 0 = normal, 1 = italic, 2 = bold, 3 = bold italic
MXPrint_SetLineStyle (width.f, (a)rgbColor, style) - Set the line style (style 0 = normal, 1 = dotted, 2 = dashed).
MXPrint_SetOrientation (orientation) - Set the page orientation (0 = portait, 1 = landscape).
MXPrint_SetPaperSize (width.f, height.f) - Set the paper size in points.
MXPrint_SetParagraphStyle (alignment, lineSpacing.f) - Set the paragraph style (alignment 0 = left, 1 = right, 2 = center, 3 = justify, 4 = natural).
MXPrint_SetShowDialog (show) - Show print dialog (#True or #False). 
MXPrint_SetText (text.s, [underline])
MXPrint_ShowImageInRect (imageID, x.f, y.f, width.f, height.f)
NextPos = MXPrint_ShowTextInRect (x.f, y.f, width.f, height.f [, pos.l])


SCRIPT FUNCTIONS
----------------
Result.s = MXScript_AppleScript (script.s) - Execute AppleScript code.


SNAPSHOT FUNCTIONS
------------------
ImageID = MXSnapshot_TakeSnapshot([width])
MXSnapshot_StopSession()


SPEECH FUNCTIONS
----------------
MXSpeech_BlocksOtherRecognizers (blockOther)
MXSpeech_ListenInForegroundOnly (foregroundOnly)
MXSpeech_Recognize (commands.s [, title.s]) - Set a comma separated list of commands.
Command.s = MXSpeech_RecognizedCommand ()
MXSpeech_RecognizedCallback (@RecognizedCallback())
MXSpeech_Say (text.s [, voice.s])
MXSpeech_StartListening ()
MXSpeech_StopListening ()


WEBGADGET FUNCTIONS
-------------------
MXWebGadget_LoadSWFData (WebGadgetID, memoryAddress, size)
Result.s = MXWebGadget_JavaScript (WebGadgetID, script.s)
Last edited by wilbert on Wed May 31, 2017 3:13 pm, edited 4 times in total.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: MX Userlib 1.0 (OSX 10.5+)

Post by wilbert »

MXImage example

Code: Select all

If OpenWindow(0, 0, 0, 245, 105, "MXImage Demo", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  img = MXImage_LoadFromURL("http://www.purebasic.com/images/box.png")
  If img
    img_t1 = MXImageFilter_Grayscale(img)
    img_t2 = MXImageFilter_AffineTransform (img_t1, -1.5, 0, 0, 0.5)
    ImageGadget(0,  10, 10, 100, 83, img)
    ImageGadget(1, 130, 10, 100, 83, img_t2)
    MX_Release(img_t2)
    MX_Release(img_t1)
    MX_Release(img)
  EndIf
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  
EndIf
Last edited by wilbert on Mon Jul 18, 2011 5:38 pm, edited 1 time in total.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: MX Userlib 1.0 (OSX 10.5+)

Post by wilbert »

MXSpeech example

Press [esc] while saying one of the commands in the example ('pure basic' , 'print' , 'talk' , 'you') into the mic and see if it gets recognized.
Some commands seem to be recognized easier compared to others.

Code: Select all

Procedure Callback()
  MXSpeech_Say("Recognized " + MXSpeech_RecognizedCommand(), "com.apple.speech.synthesis.voice.Agnes")
EndProcedure

MXSpeech_RecognizedCallback(@Callback())
MXSpeech_ListenInForegroundOnly(#False)
MXSpeech_BlocksOtherRecognizers(#False)
MXSpeech_Recognize("pure basic,print,talk,you", "Purebasic Speech Test")
MXSpeech_StartListening()

If OpenWindow(0, 0, 0, 300, 200, "MXSpeech Demo", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

MXSpeech_StopListening()
Last edited by wilbert on Wed Jul 20, 2011 6:08 am, edited 2 times in total.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: MX Userlib 1.0 (OSX 10.5+)

Post by wilbert »

MXScript demo

Code: Select all

MXScript_AppleScript("beep 3")
Debug MXScript_AppleScript("tell application " + Chr(34) + "Finder" + Chr(34) + " to get the name of every item in the desktop")
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: MX Userlib 1.0 (OSX 10.5+)

Post by wilbert »

MXPrint demo

Code: Select all

ImportC ""
  CGContextSaveGState(context)
  CGContextRestoreGState(context)
  CGContextConcatCTM(context, a.f, b.f, c.f, d.f, tx.f, ty.f)
  CGContextBeginPath(context)
  CGContextMoveToPoint(context, x.f, y.f)
  CGContextAddQuadCurveToPoint(context, cpx.f, cpy.f, x.f, y.f)  
  CGContextStrokePath(context)      
  CGContextFillEllipseInRect(context, x.f, y.f, w.f, h.f)
  CGContextStrokeEllipseInRect(context, x.f, y.f, w.f, h.f)
EndImport

EnableExplicit

Define.l context, img, img_t1, img_t2, size, len, pos
Define.f w, h 

MXPrint_SetPaperSize(420, 595); A5 paper
MXPrint_SetOrientation(0); portrait mode
MXPrint_SetShowDialog(#True); show printer dialog

context = MXPrint_BeginDocument()
If context
  
  w = MXPrint_GetPageWidth()
  h = MXPrint_GetPageHeight()
  
  MXPrint_SetFillColor($fff8f0)
  MXPrint_SetLineStyle(0.5, 0, 1)
  
  MXPrint_FillRect(20, 20, w - 40, 40)
  MXPrint_DrawRect(20, 20, w - 40, 40)
  
  MXPrint_SetParagraphStyle(2, 0); center text, no extra space between lines
  MXPrint_SetFont("Times", 32, $402000)
  MXPrint_SetText("The Purebasic Times ")
  MXPrint_AppendUniChar($f8ff)
  MXPrint_ShowTextInRect(20, 20, w - 40, 50)
  
  img = MXImage_LoadFromURL("http://www.purebasic.com/images/box.png")
  MXPrint_ShowImageInRect(img, w - 79, 80, 59, 91)
  MX_Release(img)
  
  MXPrint_SetParagraphStyle(4, 0); natural text, no extra space between lines
  
  MXPrint_SetFont("Helvetica-Oblique", 12, $800000); set font
  MXPrint_SetText("Helvetica text in different sizes"+Chr(10), #True); set text buffer
  
  For size = 8 To 36 Step 2
    MXPrint_SetFont("Helvetica", size, $000000)
    MXPrint_AppendText("Helvetica text size " + Str(size) +Chr(10)); append text to text buffer
  Next
  
  MXPrint_FillRect(20, 80, w - 109, 90)
  MXPrint_FillRect(20, 190, w - 40, h - 210)
  
  len = MXPrint_GetTextLength(); get length of buffered text
  pos = MXPrint_ShowTextInRect(20, 80, w - 109, 90); show buffered text in frame and return the position after the last visible character
  If pos < len; check if there is need to continue in another frame
    MXPrint_ShowTextInRect(20, 190, w - 40, h - 210, pos); continue at the last visible position in a new frame
  EndIf
  
  MXPrint_SetOrientation(1); landscape mode for next page
  context = MXPrint_NextPage(); next page
  
  w = MXPrint_GetPageWidth()
  h = MXPrint_GetPageHeight()
  
  MXPrint_SetLineStyle(2, $000080, 0)
  MXPrint_DrawLine(140, 140, 260, 180)
  
  ; adding some html text
  
  MXPrint_SetParagraphStyle(1, 0); align right, no extra space between lines
  MXPrint_SetFontWithFamily("Palatino", 1, 18, $800000); set font with family name
  MXPrint_SetText("Font setting using family name")
  MXPrint_ShowTextInRect(20, 20, w - 40, 650)
  
  MXPrint_SetFillColor($ffff80)
  MXPrint_SetLineStyle(4, $008000, 2)
  
  ; using standard functions
  ; cgcontext has flipped y coordinates : (0,0) is bottom left.
  ; the MXPrint functions compensate for that to mimic the normal PureBasic coordinate system
  ; but now we have to do that manually
  
  CGContextFillEllipseInRect(context, 20, h - 20 - 100, 100, 100)
  CGContextStrokeEllipseInRect(context, 20, h - 20 - 100, 100, 100)
  
  ; another way to work with the flipped coordinates is to use a transform matrix
  
  CGContextSaveGState(context); save current state
  CGContextConcatCTM(context, 1, 0, 0, -1, 0, h); transform the coordinate system
  CGContextBeginPath(context)
  CGContextMoveToPoint(context, 200, 100)
  CGContextAddQuadCurveToPoint(context, 400, 150, 300, 200)  
  CGContextStrokePath(context)
  CGContextRestoreGState(context); restore previous state
  
  MXPrint_EndDocument()
  
EndIf
While intended for printing, you could also output to other devices if you have a CGContextRef

Code: Select all

ImportC ""
  GetWindowPort(*WindowRef)
  QDBeginCGContext(*WindowPtr, *CGContextRef)
  QDEndCGContext(*WindowPtr, *CGContextRef)  
EndImport

OpenWindow(0, 0, 0, 400, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

*wPort = GetWindowPort(WindowID(0))
QDBeginCGContext(*wPort, @cg)

w = 400
h = 300

; set context to screen and inform the MXPrint functions about the size of the context
MXPrint_SetContext(cg, w, h)

MXPrint_SetFillColor($fff8f0)
MXPrint_SetLineStyle(0.5, 0, 1)
  
MXPrint_FillRect(20, 20, w - 40, 40)
MXPrint_DrawRect(20, 20, w - 40, 40)
  
MXPrint_SetParagraphStyle(2, 0); center text, no extra space between lines
MXPrint_SetFont("Times", 32, $402000)
MXPrint_SetText("The Purebasic Times ")
MXPrint_AppendUniChar($f8ff)
MXPrint_ShowTextInRect(20, 20, w - 40, 50)

QDEndCGContext(*wPort, @cg)
  
Repeat
  Event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow

End
Last edited by wilbert on Wed Jul 20, 2011 7:05 am, edited 1 time in total.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: MX Userlib 1.01 (OSX 10.5+)

Post by wilbert »

MXWebGadget demo

Example of calling javascript inside a WebGadget from PureBasic.

Code: Select all

If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  
  ButtonGadget(0, 10, 10, 200, 20, "Add 3 + 4")
  WebGadget(1, 10, 40, 580, 250, "") 
  WebGadgetID = GadgetID(1)
  
  HTML.s = "<html><head><script type='text/javascript'>" + Chr(10)
  HTML+ "function add(a, b) { return a + b  }" + Chr(10)
  HTML+ "</script></head><body>JavaScript add</body></html>"
  
  SetGadgetItemText(1, #PB_Web_HtmlCode, HTML)
 
  Repeat
    Event = WaitWindowEvent()
    
    Select Event
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0 : Debug MXWebGadget_JavaScript(WebGadgetID, "add(3, 4)")
        EndSelect
    EndSelect
    
  Until Event = #PB_Event_CloseWindow 
  
EndIf
WilliamL
Addict
Addict
Posts: 1214
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: MX Userlib 1.01 (OSX 10.5+)

Post by WilliamL »

This is great wilbert! :D

For all of us that wanted clear text all you have to do is run the Print demo with the MX userlib and see how good it can be!

On top of printing clear text you can also use image filters, AppleScript, and javascript.

This is my idea of a library!
MacBook Pro-M1 (2021), Sonoma 14.3.1 (CLT 15.3), PB 6.10b7 M1
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: MX Userlib 1.01 (OSX 10.5+)

Post by jesperbrannmark »

In PB 4.7 beta 1 64bit i get this:

ld: warning: ignoring file libPBMX_x86.a, file was built for archive which is not the architecture being linked (x86_64): libPBMX_x86.a
ld: warning: ignoring file libPBCocoa_x86.a, file was built for archive which is not the architecture being linked (x86_64): libPBCocoa_x86.a
ld: warning: ignoring file libPBWebPrint_x86.a, file was built for archive which is not the architecture being linked (x86_64): libPBWebPrint_x86.a
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: MX Userlib 1.01 (OSX 10.5+)

Post by J. Baker »

This looks great Wilbert! I'll have to try it out later. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: MX Userlib 1.01 (OSX 10.5+)

Post by wilbert »

I'm working on a new library for the Cocoa version of PB.
http://www.purebasic.fr/english/viewtop ... 19&t=50688

If there are any commands from this MX library you often use, let me know.
Maybe I can add them to the new library.
Post Reply