mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-18 11:29:27 +02:00
openglcontrol: gtk2: send WMSize messages after every gtk resize. For some unknown reason the opengl context is resized in several steps
git-svn-id: trunk@13870 -
This commit is contained in:
parent
8bd4a8f969
commit
09528b2873
components/opengl
@ -25,7 +25,7 @@ uses
|
||||
Classes, SysUtils, LCLProc, LCLType, X, XUtil, XLib, gl, InterfaceBase,
|
||||
WSLCLClasses, GtkWSControls,
|
||||
{$IFDEF LCLGTK2}
|
||||
GtkDef, gdk2x, glib2, gdk2, gtk2, Gtk2Int,
|
||||
LMessages, GtkDef, gdk2x, glib2, gdk2, gtk2, Gtk2Int,
|
||||
{$ENDIF}
|
||||
{$IFDEF LCLGTK}
|
||||
glib, gdk, gtk, GtkInt,
|
||||
@ -715,6 +715,42 @@ begin
|
||||
Result:=gtk_gl_area_make_current(glarea);
|
||||
end;
|
||||
|
||||
{$IFDEF LCLGtk2}
|
||||
function gtkglarea_size_allocateCB(Widget: PGtkWidget; Size: pGtkAllocation;
|
||||
Data: gPointer): GBoolean; cdecl;
|
||||
const
|
||||
CallBackDefaultReturn = {$IFDEF GTK2}false{$ELSE}true{$ENDIF};
|
||||
var
|
||||
SizeMsg: TLMSize;
|
||||
GtkWidth, GtkHeight: integer;
|
||||
LCLControl: TWinControl;
|
||||
begin
|
||||
Result := CallBackDefaultReturn;
|
||||
if not GTK_WIDGET_REALIZED(Widget) then begin
|
||||
// the widget is not yet realized, so this GTK resize was not a user change.
|
||||
// => ignore
|
||||
exit;
|
||||
end;
|
||||
LCLControl:=TWinControl(Data);
|
||||
if LCLControl=nil then exit;
|
||||
//DebugLn(['gtkglarea_size_allocateCB ',DbgSName(LCLControl)]);
|
||||
|
||||
gtk_widget_get_size_request(Widget, @GtkWidth, @GtkHeight);
|
||||
|
||||
FillChar(SizeMsg,SizeOf(SizeMsg),0);
|
||||
with SizeMsg do
|
||||
begin
|
||||
Result := 0;
|
||||
Msg := LM_SIZE;
|
||||
SizeType := Size_SourceIsInterface;
|
||||
Width := SmallInt(GtkWidth);
|
||||
Height := SmallInt(GtkHeight);
|
||||
end;
|
||||
//DebugLn(['gtkglarea_size_allocateCB ',GtkWidth,',',GtkHeight]);
|
||||
LCLControl.WindowProc(TLMessage(SizeMsg));
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function LOpenGLCreateContext(AWinControl: TWinControl;
|
||||
WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
|
||||
DoubleBuffered, RGBA: boolean;
|
||||
@ -741,6 +777,8 @@ begin
|
||||
TGTKWidgetSet(WidgetSet).FinishCreateHandle(AWinControl,NewWidget,AParams);
|
||||
{$ELSE}
|
||||
TGTK2WidgetSet(WidgetSet).FinishCreateHandle(AWinControl,NewWidget,AParams);
|
||||
g_signal_connect_after(PGtkObject(NewWidget), 'size-allocate',
|
||||
TGTKSignalFunc(@gtkglarea_size_allocateCB), AWinControl);
|
||||
{$ENDIF}
|
||||
finally
|
||||
FreeMem(AttrList);
|
||||
|
@ -101,6 +101,7 @@ type
|
||||
procedure SetSharedControl(const AValue: TCustomOpenGLControl);
|
||||
protected
|
||||
procedure WMPaint(var Message: TLMPaint); message LM_PAINT;
|
||||
procedure WMSize(var Message: TLMSize); message LM_SIZE;
|
||||
procedure UpdateFrameTimeDiff;
|
||||
procedure OpenGLAttributesChanged;
|
||||
procedure EraseBackground(DC: HDC); override;
|
||||
@ -115,6 +116,7 @@ type
|
||||
function RestoreOldOpenGLControl: boolean;
|
||||
function SharingControlCount: integer;
|
||||
property SharingControls[Index: integer]: TCustomOpenGLControl read GetSharingControls;
|
||||
procedure Invalidate; override;
|
||||
public
|
||||
property FrameDiffTimeInMSecs: integer read FFrameDiffTime;
|
||||
property OnMakeCurrent: TOpenGlCtrlMakeCurrentEvent read FOnMakeCurrent
|
||||
@ -267,6 +269,12 @@ begin
|
||||
Exclude(FControlState, csCustomPaint);
|
||||
end;
|
||||
|
||||
procedure TCustomOpenGLControl.WMSize(var Message: TLMSize);
|
||||
begin
|
||||
if (Message.SizeType and Size_SourceIsInterface)>0 then
|
||||
DoOnResize;
|
||||
end;
|
||||
|
||||
procedure TCustomOpenGLControl.UpdateFrameTimeDiff;
|
||||
begin
|
||||
FCurrentFrameTime:=integer(GetTickCount);
|
||||
@ -409,6 +417,12 @@ begin
|
||||
Result:=FSharingOpenGlControls.Count;
|
||||
end;
|
||||
|
||||
procedure TCustomOpenGLControl.Invalidate;
|
||||
begin
|
||||
if csCustomPaint in FControlState then exit;
|
||||
inherited Invalidate;
|
||||
end;
|
||||
|
||||
{ TWSOpenGLControl }
|
||||
|
||||
class function TWSOpenGLControl.CreateHandle(const AWinControl: TWinControl;
|
||||
|
Loading…
Reference in New Issue
Block a user