Commit c4d0ea8c authored by Gargaj's avatar Gargaj
Browse files

add mouse down/move/up for click-drag text selection

parent 8c65bdeb
......@@ -82,6 +82,12 @@ namespace Renderer
extern KeyEvent keyEventBuffer[512];
extern int keyEventBufferCount;
enum MOUSEEVENTTYPE
{
MOUSEEVENTTYPE_DOWN = 0,
MOUSEEVENTTYPE_MOVE,
MOUSEEVENTTYPE_UP,
};
enum MOUSEBUTTON
{
MOUSEBUTTON_LEFT = 0,
......@@ -90,6 +96,7 @@ namespace Renderer
};
struct MouseEvent
{
MOUSEEVENTTYPE eventType;
int x;
int y;
MOUSEBUTTON button;
......
......@@ -10,6 +10,7 @@ ShaderEditor::ShaderEditor( Scintilla::Surface *s )
surfaceWindow = s;
sFontFile = "";
nFontSize = 16;
bHasMouseCapture = false;
}
void ShaderEditor::SetAStyle(int style, Scintilla::ColourDesired fore, Scintilla::ColourDesired back, int size, const char *face)
......@@ -197,12 +198,12 @@ void ShaderEditor::CopyToClipboard( const Scintilla::SelectionText &selectedText
void ShaderEditor::SetMouseCapture( bool on )
{
bHasMouseCapture = on;
}
bool ShaderEditor::HaveMouseCapture()
{
return false;
return bHasMouseCapture;
}
sptr_t ShaderEditor::DefWndProc( unsigned int iMessage, uptr_t wParam, sptr_t lParam )
......@@ -306,3 +307,19 @@ void ShaderEditor::ButtonDown( Scintilla::Point pt, unsigned int curTime, bool s
pt.y -= rect.top;
Scintilla::Editor::ButtonDown( pt, curTime, shift, ctrl, alt );
}
void ShaderEditor::ButtonMovePublic( Scintilla::Point pt )
{
Scintilla::PRectangle rect = wMain.GetPosition();
pt.x -= rect.left;
pt.y -= rect.top;
ButtonMove(pt);
}
void ShaderEditor::ButtonUp( Scintilla::Point pt, unsigned int curTime, bool ctrl )
{
Scintilla::PRectangle rect = wMain.GetPosition();
pt.x -= rect.left;
pt.y -= rect.top;
Scintilla::Editor::ButtonUp( pt, curTime, ctrl );
}
......@@ -61,6 +61,7 @@ class ShaderEditor : public Scintilla::Editor
bool bReadOnly;
std::string sFontFile;
int nFontSize;
bool bHasMouseCapture;
public:
ShaderEditor(Scintilla::Surface *surfaceWindow);
......@@ -88,6 +89,8 @@ public:
void Tick();
int KeyDown(int key, bool shift, bool ctrl, bool alt, bool *consumed);
void ButtonDown( Scintilla::Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt );
void ButtonMovePublic( Scintilla::Point pt );
void ButtonUp( Scintilla::Point pt, unsigned int curTime, bool ctrl );
void AddCharUTF( const char *s, unsigned int len, bool treatAsDBCS=false );
void NotifyStyleToNeeded(int endStyleNeeded);
......
......@@ -138,7 +138,20 @@ int main()
for(int i=0; i<Renderer::mouseEventBufferCount; i++)
{
if (bShowGui)
mShaderEditor.ButtonDown( Scintilla::Point( Renderer::mouseEventBuffer[i].x, Renderer::mouseEventBuffer[i].y ), time * 1000, false, false, false );
{
switch (Renderer::mouseEventBuffer[i].eventType)
{
case Renderer::MOUSEEVENTTYPE_MOVE:
mShaderEditor.ButtonMovePublic( Scintilla::Point( Renderer::mouseEventBuffer[i].x, Renderer::mouseEventBuffer[i].y ) );
break;
case Renderer::MOUSEEVENTTYPE_DOWN:
mShaderEditor.ButtonDown( Scintilla::Point( Renderer::mouseEventBuffer[i].x, Renderer::mouseEventBuffer[i].y ), time * 1000, false, false, false );
break;
case Renderer::MOUSEEVENTTYPE_UP:
mShaderEditor.ButtonUp( Scintilla::Point( Renderer::mouseEventBuffer[i].x, Renderer::mouseEventBuffer[i].y ), time * 1000, false );
break;
}
}
}
Renderer::mouseEventBufferCount = 0;
......
......@@ -267,16 +267,39 @@ namespace Renderer
}
}
else if (E.type == SDL_MOUSEMOTION)
{
mouseEventBuffer[mouseEventBufferCount].eventType = MOUSEEVENTTYPE_MOVE;
mouseEventBuffer[mouseEventBufferCount].x = E.motion.x;
mouseEventBuffer[mouseEventBufferCount].y = E.motion.y;
if (E.motion.state & SDL_BUTTON(1)) mouseEventBuffer[mouseEventBufferCount].button = MOUSEBUTTON_LEFT;
mouseEventBufferCount++;
}
else if (E.type == SDL_MOUSEBUTTONDOWN)
{
mouseEventBuffer[mouseEventBufferCount].eventType = MOUSEEVENTTYPE_DOWN;
mouseEventBuffer[mouseEventBufferCount].x = E.button.x;
mouseEventBuffer[mouseEventBufferCount].y = E.button.y;
switch(E.button.button)
{
case SDL_BUTTON_MIDDLE: mouseEventBuffer[mouseEventBufferCount].button = MOUSEBUTTON_MIDDLE; break;
case SDL_BUTTON_RIGHT: mouseEventBuffer[mouseEventBufferCount].button = MOUSEBUTTON_RIGHT; break;
case SDL_BUTTON_LEFT:
default: mouseEventBuffer[mouseEventBufferCount].button = MOUSEBUTTON_LEFT; break;
}
mouseEventBufferCount++;
}
else if (E.type == SDL_MOUSEBUTTONUP)
{
mouseEventBuffer[mouseEventBufferCount].eventType = MOUSEEVENTTYPE_UP;
mouseEventBuffer[mouseEventBufferCount].x = E.button.x;
mouseEventBuffer[mouseEventBufferCount].y = E.button.y;
switch(E.button.button)
{
case SDL_BUTTON_MIDDLE: mouseEventBuffer[mouseEventBufferCount].button = MOUSEBUTTON_MIDDLE; break;
case SDL_BUTTON_RIGHT: mouseEventBuffer[mouseEventBufferCount].button = MOUSEBUTTON_RIGHT; break;
case SDL_BUTTON_LEFT:
default: mouseEventBuffer[mouseEventBufferCount].button = MOUSEBUTTON_LEFT; break;
case SDL_BUTTON_MIDDLE: mouseEventBuffer[mouseEventBufferCount].button = MOUSEBUTTON_MIDDLE; break;
case SDL_BUTTON_RIGHT: mouseEventBuffer[mouseEventBufferCount].button = MOUSEBUTTON_RIGHT; break;
case SDL_BUTTON_LEFT:
default: mouseEventBuffer[mouseEventBufferCount].button = MOUSEBUTTON_LEFT; break;
}
mouseEventBufferCount++;
}
......
......@@ -198,15 +198,28 @@ namespace Renderer
case WM_LBUTTONDOWN:
{
mouseEventBuffer[mouseEventBufferCount].eventType = MOUSEEVENTTYPE_DOWN;
mouseEventBuffer[mouseEventBufferCount].button = MOUSEBUTTON_LEFT;
mouseEventBuffer[mouseEventBufferCount].x = GET_X_LPARAM(lParam);
mouseEventBuffer[mouseEventBufferCount].y = GET_Y_LPARAM(lParam);
mouseEventBufferCount++;
} break;
case WM_MOUSEMOVE:
{
mouseEventBuffer[mouseEventBufferCount].eventType = MOUSEEVENTTYPE_MOVE;
mouseEventBuffer[mouseEventBufferCount].x = GET_X_LPARAM(lParam);
mouseEventBuffer[mouseEventBufferCount].y = GET_Y_LPARAM(lParam);
mouseEventBufferCount++;
} break;
case WM_LBUTTONUP:
{
//nLeftMouse = 0;
mouseEventBuffer[mouseEventBufferCount].eventType = MOUSEEVENTTYPE_UP;
mouseEventBuffer[mouseEventBufferCount].button = MOUSEBUTTON_LEFT;
mouseEventBuffer[mouseEventBufferCount].x = GET_X_LPARAM(lParam);
mouseEventBuffer[mouseEventBufferCount].y = GET_Y_LPARAM(lParam);
mouseEventBufferCount++;
} break;
case WM_ACTIVATE:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment