Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ctrl+MiddleMouse to set Camera position and enable Z window scaling #685

Open
wants to merge 3 commits into
base: 1.6-release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 40 additions & 37 deletions radiant/z.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,22 @@ void Z_MouseMoved( int x, int y, int buttons ){
if ( buttons == MK_RBUTTON ) {
Sys_GetCursorPos( &x, &y );
if ( y != cursory ) {
z.origin[2] += y - cursory;
//Sys_Printf("Z_MouseMoved buttons==MK_RBUTTON x=%d y=%d z.height=%d delta_y=%d z.scale=%f\n", x, y, z.height, y - cursory, z.scale);
float delta_y = y - cursory;
z.origin[2] += delta_y / z.scale;
Sys_SetCursorPos( cursorx, cursory );
Sys_UpdateWindows( W_Z );
}
return;
}
// control mbutton = move camera
int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
float mouse_pos_in_3d = z.origin[2] + ( y - ( z.height / 2 ) ) / z.scale;
//Sys_Printf("Z_MouseMoved x=%d y=%d mouse_pos_in_3d=%f (z.origin[2]=%f + ( y=%d - ( z.height=%d / 2 ) / z.scale=%f)\n", x, y, mouse_pos_in_3d, z.origin[2], y, z.height, z.scale);
if ( ( buttons == ( MK_CONTROL | nMouseButton ) ) || ( buttons == ( MK_CONTROL | MK_LBUTTON ) ) ) {
g_pParentWnd->GetCamWnd()->Camera()->origin[2] = ( y - ( z.height / 2 ) ) / z.scale;
g_pParentWnd->GetCamWnd()->Camera()->origin[2] = mouse_pos_in_3d;
Sys_UpdateWindows( W_CAMERA | W_XY_OVERLAY | W_Z );
}

}


Expand Down Expand Up @@ -182,55 +185,50 @@ void Z_DrawGrid( void ){
ze = 64 * ceil( ze / 64 );

// draw major blocks

int mayor_step_size;
qglColor3fv( g_qeglobals.d_savedinfo.colors[COLOR_GRIDMAJOR] );

if ( g_qeglobals.d_showgrid ) {
if ( g_qeglobals.d_gridsize < 128 ) {
qglBegin( GL_LINES );
qglBegin( GL_LINES );

qglVertex2f( 0, zb );
qglVertex2f( 0, ze );
qglVertex2f( 0, zb );
qglVertex2f( 0, ze );

for ( zz = zb ; zz < ze ; zz += 64 )
{
qglVertex2f( -w, zz );
qglVertex2f( w, zz );
}
float step = 64;
step /= z.scale;
if (step < 8.0)
step = 8.0;
mayor_step_size = (int)step;

qglEnd();
zb = z.origin[2] - h;
if ( zb < region_mins[2] ) {
zb = region_mins[2];
}
else
{
qglBegin( GL_LINES );

qglVertex2f( 0, zb );
qglVertex2f( 0, ze );

for ( zz = zb ; zz < ze ; zz += 64 )
{
// d_gridsize >= 128 .. it's an int for sure
if ( ( (int)zz & ( (int)g_qeglobals.d_gridsize - 1 ) ) != 0 ) {
continue;
}

qglVertex2f( -w, zz );
qglVertex2f( w, zz );
}
zb = step * floor( zb / step );

qglEnd();
for ( zz = zb ; zz < ze ; zz += step )
{
qglVertex2f( -w, zz );
qglVertex2f( w, zz );
}

qglEnd();
}

// draw minor blocks
if ( g_qeglobals.d_showgrid && g_qeglobals.d_gridsize * z.scale >= 4 &&
if ( g_qeglobals.d_showgrid && g_qeglobals.d_gridsize &&
g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR] != g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK] ) {
qglColor3fv( g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR] );

qglBegin( GL_LINES );
for ( zz = zb ; zz < ze ; zz += g_qeglobals.d_gridsize )
float step = mayor_step_size / 8;
if (step < 1.0)
step = 1.0;

for ( zz = zb ; zz < ze ; zz += step )
//for ( zz = zb ; zz < ze ; zz += g_qeglobals.d_gridsize )
{
if ( !( (int)zz & 63 ) ) {
if ( !( (int)zz & (mayor_step_size-1) ) ) {
continue;
}
qglVertex2f( -w, zz );
Expand All @@ -244,13 +242,17 @@ void Z_DrawGrid( void ){
if ( g_qeglobals.d_savedinfo.show_coordinates ) {
qglColor3fv( g_qeglobals.d_savedinfo.colors[COLOR_GRIDTEXT] );

int step = (int)( g_qeglobals.d_gridsize > 64 ? g_qeglobals.d_gridsize : 64 );
float step = 64;
step /= z.scale;
if (step < 1.0)
step = 1.0;
zb = z.origin[2] - h;
if ( zb < region_mins[2] ) {
zb = region_mins[2];
}
zb = step * floor( zb / step );

//Sys_Printf("Z_DrawGrid: zb=%f ze=%f step=%f g_qeglobals.d_gridsize=%f\n", zb, ze, step, g_qeglobals.d_gridsize);
for ( zz = zb ; zz < ze ; zz += step )
{
qglRasterPos2f( -w + ( 1 / z.scale ), zz );
Expand Down Expand Up @@ -299,7 +301,8 @@ void Z_Draw( void ){
qtexture_t *q;
float top, bottom;
vec3_t org_top, org_bottom, dir_up, dir_down;
int xCam = z.width / 3;
float xCam = z.width / 3;
xCam /= z.scale; // x-value scales down so horizontally everything fits in z-window

if ( !active_brushes.next ) {
return; // not valid yet
Expand Down
38 changes: 29 additions & 9 deletions radiant/zwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,46 @@ void ZWnd::OnRButtonUp( guint32 nFlags, int pointx, int pointy ){
}

void ZWnd::OnMouseMove( guint32 nFlags, int pointx, int pointy ){
float fz = z.origin[2] + ( ( m_pWidget->allocation.height - 1 - pointy ) - ( z.height / 2 ) ) / z.scale;
pointy = m_pWidget->allocation.height - 1 - pointy;
float fz = z.origin[2] + ( pointy - ( z.height / 2 ) ) / z.scale;
fz = floor( fz / g_qeglobals.d_gridsize + 0.5 ) * g_qeglobals.d_gridsize;
CString strStatus;
strStatus.Format( "Z:: %.1f", fz );
g_pParentWnd->SetStatusText( 1, strStatus );
Z_MouseMoved( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags );
Z_MouseMoved( pointx, pointy, nFlags );
// very handy for understanding
//float mouse_pos_in_3d = z.origin[2] + ( pointy - ( z.height / 2 ) ) / z.scale;
//Sys_Printf("Z_MouseMoved x=%d y=%d mouse_pos_in_3d=%f (z.origin[2]=%f + ( y=%d - ( z.height=%d / 2 ) / z.scale=%f)\n", pointx, pointy, mouse_pos_in_3d, z.origin[2], pointy, z.height, z.scale);
}

void ZWnd::OnMouseWheel(bool bUp, int pointx, int pointy) {
float old_z = z.origin[2] + ( pointy - ( z.height / 2 ) ) / z.scale;
if (bUp) {
z.scale *= 2;
z.scale = fmin(z.scale, 128); // 2 ** 7 which is seven "zoom-ins"
} else {
z.scale /= 2;
z.scale = fmax(z.scale, 0.0078125); // 0.5 ** 7 which is seven "zoom-outs"
}
float new_z = z.origin[2] + ( pointy - ( z.height / 2 ) ) / z.scale;
float delta = new_z - old_z;
// Sys_Printf("Delta: %f\n", delta);
// Zoom into the mouse position
z.origin[2] += delta;
// Sys_Printf("ZWnd::OnMouseWheel> bUp=%d pointx=%d pointy=%d z.scale=%f\n", bUp, pointx, pointy, z.scale);
Sys_UpdateWindows(W_Z);
}

void ZWnd::OnExpose(){
if ( !MakeCurrent() ) {
Sys_FPrintf( SYS_ERR, "ERROR: wglMakeCurrent failed..\n " );
Sys_Printf( "Please restart Radiant if the Z view is not working\n" );
return;
}
else
{
QE_CheckOpenGLForErrors();
Z_Draw();
QE_CheckOpenGLForErrors();
SwapBuffers();
}
QE_CheckOpenGLForErrors();
Z_Draw();
QE_CheckOpenGLForErrors();
SwapBuffers();
}

void ZWnd::OnSize( int cx, int cy ){
Expand Down
1 change: 1 addition & 0 deletions radiant/zwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void OnLButtonUp( guint32 flags, int pointx, int pointy );
void OnRButtonUp( guint32 flags, int pointx, int pointy );
void OnMButtonUp( guint32 flags, int pointx, int pointy );
void OnMouseMove( guint32 flags, int pointx, int pointy );
void OnMouseWheel(bool bUp, int pointx, int pointy);
void OnSize( int cx, int cy );
};

Expand Down