fb:porticula NoPaste
Colorpicker Plugin wxFBE
Uploader: | MOD |
Datum/Zeit: | 10.12.2013 21:25:53 |
#Include Once "wx-c/wx.bi"
#Include Once "pluginsystem.bi"
'##########################################
'Menu IDs
Enum
pickColor = 0 'always start with 0!
menuCounter
End Enum
'Prepare API
Dim Shared As ProgramAPI Ptr programApi
'##########################################
'Implement must-have functions
Function getDyLibInfo Alias "getDyLibInfo" ( ) As DyLibInfo Ptr Export
Dim As DyLibInfo Ptr dyLibInfo = New DyLibInfo 'create new DyLibInfo object
dyLibInfo->libraryName = "colorpicker"
dyLibInfo->APIVersion = CURRENTAPIVERSION
dyLibInfo->libraryVersion = "1.0"
dyLibInfo->description = "This plugin provides a colorpicker"
dyLibInfo->author = "MOD"
dyLibInfo->authorEmail = ""
dyLibInfo->copyright = "MOD"
dyLibInfo->homepage = "http://www.freebasic-portal.de/"
dyLibInfo->flags = 0
Return dyLibInfo
End Function
'Tell the program, how many menus we provide
Function getMenuCount Alias "getMenuCount" ( ) As Integer Export
Return menuCounter
End Function
'##########################################
'Implement can-have functions
Function getProgramAPI Alias "getProgramAPI" ( ByRef api As ProgramAPI Ptr ) As Integer Export
programApi = api 'save API to be able to use it
Return 0
End Function
Function onLoad Alias "onLoad" ( ByRef dyLibID As Integer ) As Integer Export
'Use the onLoad function to install our menus
Dim As wxMenuBar Ptr menuBar = programApi->getEditorMenuBarPtr( ) 'get pointer to the menubar
Dim As wxMenu Ptr toolsMenu = wxMenuBar_GetMenu( menuBar, wxMenuBar_FindMenu( menuBar, wxString_ctorUTF8( programApi->getEditorTranslation( "menuTools" ) ) ) ) 'find the tools menu - we have to use the language key as the menu is called different in different languages
If toolsMenu <> WX_NULL Then
'append two menu items - as the menu ID use your menu ID + the provided dyLibID!!
wxMenuBase_Append( toolsMenu, dyLibID + pickColor, wxString_ctorUTF8( "Colorpicker" ), wxString_ctorUTF8( "Colorpicker" ), 0 )
EndIf
Return 0
End Function
'Function onUnload Alias "onUnload" ( ) As Integer Export
' Return 0
'End Function
'This will get called, when one of our menus is clicked
Function onDyLibMenu Alias "onDyLibMenu" ( ByRef menuID As Integer ) As Integer Export
Select Case menuID 'which menu was clicked
Case pickColor
Dim As wxStyledTextCtrl Ptr thisSTC = programApi->getSTCPtr( ) 'get pointer to the current styledtextctrl
If thisSTC <> WX_NULL Then
Dim As wxColourData Ptr colData = wxColourData_ctor( )
Dim As wxColourDialog Ptr colDialog = wxColourDialog_ctor( )
wxColourDialog_Create( colDialog, programApi->getEditorFramePtr( ), colData )
If wxColourDialog_ShowModal( colDialog ) = wxID_OK Then
Dim As wxColour Ptr col = wxColour_ctor( )
col = wxColourData_GetColour( wxColourDialog_GetColourData( colDialog ) )
wxStyledTextCtrl_AddText( thisSTC, wxString_ctorUTF8( "&H" & Hex( wxColour_Red( col ), 2 ) + Hex( wxColour_Green( col ), 2 ) + Hex( wxColour_Blue( col ), 2 ) ) )
EndIf
EndIf
Case Else
'This shouldn't happen ever
wxMsgBox( programApi->getEditorFramePtr( ), wxString_ctorUTF8( "Unknown menu event" ), wxString_ctorUTF8( "Error" ), wxOK, 150, 50 )
End Select
Return 0
End Function
'##########################################