Linux fixes.

This commit is contained in:
leo 2012-06-21 22:03:30 +00:00
parent 8c04f52e14
commit 263753d726
7 changed files with 138 additions and 154 deletions

View file

@ -507,7 +507,7 @@ static const unsigned char sDefaultSettings[] =
static int lcGetMinifigSettings(lcMemFile& File)
{
#ifdef LC_HAVE_ZLIB
const int CHUNK = 16384;
const size_t CHUNK = 16384;
int ret;
unsigned have;
z_stream strm;

View file

@ -1792,7 +1792,7 @@ void Project::RenderScenePieces(View* view)
lcMesh* PreviousMesh = NULL;
bool PreviousSelected = false;
char* ElementsOffset;
char* ElementsOffset = NULL;
glEnableClientState(GL_VERTEX_ARRAY);
@ -2122,7 +2122,7 @@ void Project::RenderOverlays(View* view)
// Find the rotation from the focused piece if relative snap is enabled.
Object* Focus = NULL;
lcVector4 Rot;
lcVector4 Rot(0, 0, 1, 0);
if ((m_nSnap & LC_DRAW_GLOBAL_SNAP) == 0)
{
@ -2231,7 +2231,7 @@ void Project::RenderOverlays(View* view)
// Find the rotation from the focused piece if relative snap is enabled.
Object* Focus = NULL;
lcVector4 Rot;
lcVector4 Rot(0, 0, 1, 0);
if ((m_nSnap & LC_DRAW_GLOBAL_SNAP) == 0)
{
@ -2267,6 +2267,7 @@ void Project::RenderOverlays(View* view)
Rotation = lcVector4(90.0f, 0.0f, -1.0f, 0.0f);
break;
default:
Rotation = lcVector4(0.0f, 0.0f, 1.0f, 0.0f);
Angle = 0.0f;
break;
};
@ -2450,6 +2451,9 @@ void Project::RenderOverlays(View* view)
Angle = m_MouseTotalDelta[2];
Tangent = lcVector3(-Normal[1], Normal[0], 0.0f);
break;
default:
Angle = 0.0f;
break;
}
if (Angle < 0.0f)
@ -6551,7 +6555,7 @@ void Project::GetSnapIndex(int* SnapXY, int* SnapZ, int* SnapAngle) const
int Angles[] = { 0, 1, 5, 10, 15, 30, 45, 60, 90, 180 };
*SnapAngle = -1;
for (int i = 0; i < sizeof(Angles)/sizeof(Angles[0]); i++)
for (unsigned int i = 0; i < sizeof(Angles)/sizeof(Angles[0]); i++)
{
if (m_nAngleSnap == Angles[i])
{
@ -8187,6 +8191,9 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
Dir2 = lcVector3(0, 0, 1);
SingleDir = false;
break;
default:
Dir1 = lcVector3(1, 0, 0);
break;
}
// Find out what direction the mouse is going to move stuff.

View file

@ -2108,24 +2108,35 @@ int propertiesdlg_execute(void* param)
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(s.sum_comments));
gtk_text_buffer_set_text(buffer, opts->strComments, -1);
int i, j, col[LC_MAXCOLORS], totalcount[LC_MAXCOLORS];
memset(&totalcount, 0, sizeof(totalcount));
for (i = 0; i < opts->lines; i++)
for (j = 0; j < LC_MAXCOLORS; j++)
totalcount[j] += opts->count[i*LC_MAXCOLORS+j];
int ID = 2;
for (i = 0; i < LC_MAXCOLORS; i++)
if (totalcount[i])
ID++;
scroll_win = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_win),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_widget_show(scroll_win);
gtk_container_add(GTK_CONTAINER(notebook), scroll_win);
list = gtk_clist_new(ID);
int* ColorColumn = new int[gColorList.GetSize() + 1];
int NumColumns = 0;
const char** PieceNames = opts->PieceNames;
int NumPieces = opts->NumPieces;
int* PieceColorCount = opts->PieceColorCount;
int NumColors = opts->NumColors;
for (int ColorIdx = 0; ColorIdx < NumColors; ColorIdx++)
{
if (PieceColorCount[NumPieces * (NumColors + 1) + ColorIdx])
{
ColorColumn[ColorIdx] = NumColumns;
NumColumns++;
}
else
ColorColumn[ColorIdx] = -1;
}
ColorColumn[NumColors] = NumColumns;
NumColumns++;
list = gtk_clist_new(NumColumns);
gtk_widget_show(list);
gtk_container_add(GTK_CONTAINER(scroll_win), list);
gtk_container_border_width(GTK_CONTAINER(list), 5);
@ -2136,63 +2147,53 @@ int propertiesdlg_execute(void* param)
gtk_widget_show(label);
gtk_clist_set_column_widget(GTK_CLIST(list), 0, label);
for (ID = 0, i = 0; i < LC_MAXCOLORS; i++)
if (totalcount[i])
{
ID++;
col[i] = ID;
label = gtk_label_new(colornames[i]);
gtk_widget_show(label);
gtk_clist_set_column_widget(GTK_CLIST(list), ID, label);
}
ID++;
label = gtk_label_new("Total");
gtk_widget_show(label);
gtk_clist_set_column_widget(GTK_CLIST(list), ID, label);
char* row[LC_MAXCOLORS+2];
for (i = 0; i <= ID; i++)
row[i] = (char*)malloc(256);
for (i = 0; i < opts->lines; i++)
for (int ColorIdx = 0; ColorIdx < NumColors; ColorIdx++)
{
int total = 0;
for (j = 0; j < LC_MAXCOLORS; j++)
total += opts->count[i*LC_MAXCOLORS+j];
if (total == 0)
if (ColorColumn[ColorIdx] == -1)
continue;
strcpy(row[0], opts->names[i]);
for (j = 1; j < ID; j++)
row[j][0] = 0;
for (j = 0; j < LC_MAXCOLORS; j++)
if (opts->count[i*LC_MAXCOLORS+j])
sprintf(row[col[j]], "%d", opts->count[i*LC_MAXCOLORS+j]);
sprintf(row[ID], "%d", total);
gtk_clist_append(GTK_CLIST(list), row);
label = gtk_label_new(gColorList[ColorIdx].Name);
gtk_widget_show(label);
gtk_clist_set_column_widget(GTK_CLIST(list), ColorColumn[ColorIdx] + 1, label);
}
gtk_clist_sort(GTK_CLIST(list));
strcpy(row[0], "Total");
int total = 0;
label = gtk_label_new("Total");
gtk_widget_show(label);
gtk_clist_set_column_widget(GTK_CLIST(list), NumColumns, label);
for (i = 0; i < LC_MAXCOLORS; i++)
if (totalcount[i])
char** Row = new char*[NumColumns];
for (int ColumnIdx = 0; ColumnIdx < NumColumns; ColumnIdx++)
Row[ColumnIdx] = new char[256];
for (int PieceIdx = 0; PieceIdx < NumPieces + 1; PieceIdx++)
{
if (!PieceColorCount[PieceIdx * (NumColors + 1) + NumColors])
continue;
for (int ColumnIdx = 0; ColumnIdx < NumColumns; ColumnIdx++)
Row[ColumnIdx][0] = 0;
if (PieceIdx != NumPieces)
strcpy(Row[0], PieceNames[PieceIdx]);
else
strcpy(Row[0], "Total");
for (int ColorIdx = 0; ColorIdx < NumColors + 1; ColorIdx++)
{
sprintf(row[col[i]], "%d", totalcount[i]);
total += totalcount[i];
if (!PieceColorCount[PieceIdx * (NumColors + 1) + ColorIdx])
continue;
sprintf(Row[ColorColumn[ColorIdx] + 1], "%d", PieceColorCount[PieceIdx * (NumColors + 1) + ColorIdx]);
}
sprintf(row[ID], "%d", total);
gtk_clist_append(GTK_CLIST(list), row);
gtk_clist_append(GTK_CLIST(list), Row);
}
for (i = 0; i <= ID; i++)
free(row[i]);
for (int ColumnIdx = 0; ColumnIdx < NumColumns; ColumnIdx++)
delete Row[ColumnIdx];
delete[] Row;
label = gtk_label_new("General");
gtk_widget_show(label);
@ -2230,6 +2231,8 @@ int propertiesdlg_execute(void* param)
else
ret = LC_CANCEL;
delete[] ColorColumn;
gtk_widget_destroy(dlg);
return ret;

View file

@ -8,6 +8,7 @@
//
#include "lc_global.h"
#include "lc_colors.h"
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <stdio.h>
@ -27,7 +28,7 @@
// =========================================================
// Minifig Wizard
typedef struct
struct LC_MINIFIGDLG_STRUCT
{
MinifigWizard* wizard;
GtkWidget *pieces[LC_MFW_NUMITEMS];
@ -35,7 +36,7 @@ typedef struct
GtkWidget *angles[LC_MFW_NUMITEMS];
GtkWidget *preview;
GtkWidget *combo;
} LC_MINIFIGDLG_STRUCT;
};
// User wants to add the minifig to the project
static void minifigdlg_ok(GtkWidget *widget, gpointer data)
@ -65,7 +66,7 @@ static void minifigdlg_color_response (GtkWidget *widget, gpointer data)
info->wizard->SetColor (i, GPOINTER_TO_INT (data));
info->wizard->Redraw ();
set_button_pixmap2 (button, FlatColorArray[GPOINTER_TO_INT(data)]);
set_button_pixmap2(button, gColorList[GPOINTER_TO_INT(data)].Value);
}
// A color button was clicked
@ -76,18 +77,17 @@ static void minifigdlg_color_clicked (GtkWidget *widget, gpointer data)
menu = gtk_menu_new ();
for (i = 0; i < LC_MAXCOLORS; i++)
for (i = 0; i < gNumUserColors; i++)
{
menuitem = gtk_menu_item_new_with_label (colornames[i]);
gtk_widget_show (menuitem);
gtk_menu_append (GTK_MENU (menu), menuitem);
menuitem = gtk_menu_item_new_with_label(gColorList[i].Name);
gtk_widget_show(menuitem);
gtk_menu_append(GTK_MENU(menu), menuitem);
gtk_object_set_data (GTK_OBJECT (menuitem), "button", widget);
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (minifigdlg_color_response), (void*)i);
gtk_object_set_data(GTK_OBJECT(menuitem), "button", widget);
gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(minifigdlg_color_response), (void*)i);
}
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 0, 0);
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, 0);
}
// New piece was selected
@ -167,7 +167,7 @@ static void minifigdlg_load (GtkWidget *widget, gpointer data)
for (int i = 0; i < LC_MFW_NUMITEMS; i++)
{
set_button_pixmap2 (s->colors[i], FlatColorArray[s->wizard->m_Colors[i]]);
set_button_pixmap2(s->colors[i], gColorList[s->wizard->m_Colors[i]].Value);
if (s->angles[i] != NULL)
gtk_spin_button_set_value (GTK_SPIN_BUTTON (s->angles[i]), s->wizard->m_Angles[i]);
}
@ -402,7 +402,7 @@ int minifigdlg_execute (void* param)
for (i = 0; i < LC_MFW_NUMITEMS; i++)
{
set_button_pixmap2(s.colors[i], FlatColorArray[s.wizard->m_Colors[i]]);
set_button_pixmap2(s.colors[i], gColorList[s.wizard->m_Colors[i]].Value);
}
return dlg_domodal(dlg, LC_CANCEL);

View file

@ -79,7 +79,7 @@ void set_button_pixmap (GtkWidget* widget, float* color)
gdk_gc_destroy(gc);
}
void set_button_pixmap2 (GtkWidget* widget, unsigned char* color)
void set_button_pixmap2(GtkWidget* widget, float* color)
{
GdkColor c;
GdkGC* gc;
@ -95,9 +95,9 @@ void set_button_pixmap2 (GtkWidget* widget, unsigned char* color)
pixmap = gdk_pixmap_new (widget->window, widget->allocation.width - 10,
widget->allocation.height - 10, -1);
c.red = color[0]*256;
c.green = color[1]*256;
c.blue = color[2]*256;
c.red = (gushort)(color[0]*0xFFFF);
c.green = (gushort)(color[1]*0xFFFF);
c.blue = (gushort)(color[2]*0xFFFF);
gdk_color_alloc (gtk_widget_get_colormap(widget), &c);
gdk_gc_set_foreground(gc, &c);

View file

@ -4,9 +4,9 @@
GtkWidget* new_pixmap(GtkWidget* widget, const char** data);
GtkWidget* clist_title_with_arrow(GtkWidget* clist, char col, const char* label_text);
void set_notebook_tab (GtkWidget *notebook, gint page_num, GtkWidget *widget);
void set_button_pixmap (GtkWidget* widget, float* color);
void set_button_pixmap2 (GtkWidget* widget, unsigned char* color);
void set_notebook_tab(GtkWidget *notebook, gint page_num, GtkWidget *widget);
void set_button_pixmap(GtkWidget* widget, float* color);
void set_button_pixmap2(GtkWidget* widget, float* color);
#endif // _GTKTOOLS_H_

View file

@ -2,6 +2,8 @@
//
#include "lc_global.h"
#include "lc_colors.h"
#include "lc_math.h"
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include <stdio.h>
@ -570,88 +572,60 @@ static void piececombo_changed (GtkWidget *widget, gpointer data)
// Draw a pixmap for the colorlist control
static void colorlist_draw_pixmap(GtkWidget *widget)
{
GdkGC* gc = gdk_gc_new(widget->window);
int i;
GdkRectangle rect;
GdkColor c;
GdkGC* gc = gdk_gc_new(widget->window);
GdkRectangle rect;
GdkColor c;
gdk_gc_set_fill(gc, GDK_SOLID);
rect.y = 0;
rect.width = widget->allocation.width/14+1;
rect.height = widget->allocation.height/2;
gdk_gc_set_fill(gc, GDK_SOLID);
for (i = 0; i < 28; i++)
{
if (i == 14)
rect.y = rect.height;
int NumColumns = 14;
int NumRows = gNumUserColors / NumColumns;
if (i < 14)
rect.x = widget->allocation.width * i / 14;
else
rect.x = widget->allocation.width * (i-14) / 14;
for (int ColorIdx = 0; ColorIdx < gNumUserColors; ColorIdx++)
{
rect.x = (float)widget->allocation.width / NumColumns * (ColorIdx % NumColumns);
rect.y = (float)widget->allocation.height / NumRows * (ColorIdx / NumColumns);
rect.width = (float)widget->allocation.width / NumColumns * (ColorIdx % NumColumns + 1) - rect.x;
rect.height = (float)widget->allocation.height / NumRows * (ColorIdx / NumColumns + 1) - rect.y;
c.red = (gushort)(FlatColorArray[i][0]*0xFF);
c.green = (gushort)(FlatColorArray[i][1]*0xFF);
c.blue = (gushort)(FlatColorArray[i][2]*0xFF);
gdk_color_alloc(gtk_widget_get_colormap(widget), &c);
gdk_gc_set_foreground(gc, &c);
c.red = (gushort)(gColorList[ColorIdx].Value[0] * 0xFFFF);
c.green = (gushort)(gColorList[ColorIdx].Value[1] * 0xFFFF);
c.blue = (gushort)(gColorList[ColorIdx].Value[2] * 0xFFFF);
gdk_draw_rectangle (colorlist_pixmap, gc, TRUE,
rect.x, rect.y,
rect.width, rect.height);
gdk_color_alloc(gtk_widget_get_colormap(widget), &c);
gdk_gc_set_foreground(gc, &c);
if (i > 13 && i < 21)
{
int x, y;
gdk_color_white(gtk_widget_get_colormap(widget), &c);
gdk_gc_set_foreground(gc, &c);
for (x = rect.x; x < rect.x + rect.width; x++)
{
for (y = rect.y + x%4; y < rect.y + rect.height; y += 4)
gdk_draw_point(colorlist_pixmap, gc, x, y);
gdk_draw_rectangle(colorlist_pixmap, gc, TRUE, rect.x, rect.y, rect.width, rect.height);
}
for (y = rect.y + rect.height - x%4; y > rect.y; y -= 4)
gdk_draw_point(colorlist_pixmap, gc, x, y);
}
}
}
gdk_color_black(gtk_widget_get_colormap(widget), &c);
gdk_gc_set_foreground(gc, &c);
gdk_gc_set_line_attributes(gc, 1, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);
gdk_color_black(gtk_widget_get_colormap(widget), &c);
gdk_gc_set_foreground(gc, &c);
gdk_gc_set_line_attributes(gc, 1,
GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);
for (i = 0; i < 14; i++)
gdk_draw_line (colorlist_pixmap, gc,
widget->allocation.width * i / 14, 0,
widget->allocation.width * i / 14, widget->allocation.height);
for (int ColumnIdx = 0; ColumnIdx < NumColumns; ColumnIdx++)
gdk_draw_line(colorlist_pixmap, gc, widget->allocation.width * ColumnIdx / NumColumns, 0,
widget->allocation.width * ColumnIdx / NumColumns, widget->allocation.height);
gdk_draw_line (colorlist_pixmap, gc, 0, widget->allocation.height-1,
widget->allocation.width, widget->allocation.height-1);
gdk_draw_line (colorlist_pixmap, gc, 0, widget->allocation.height/2,
widget->allocation.width, widget->allocation.height/2);
gdk_draw_line (colorlist_pixmap, gc, widget->allocation.width-1, 0,
widget->allocation.width-1, widget->allocation.height);
gdk_draw_line (colorlist_pixmap, gc, 0, 0, widget->allocation.width, 0);
for (int RowIdx = 0; RowIdx < NumRows; RowIdx++)
gdk_draw_line(colorlist_pixmap, gc, 0, (float)widget->allocation.height / NumRows * RowIdx,
widget->allocation.width, (float)widget->allocation.height / NumRows * RowIdx);
c.red = (gushort)(0.4f*0xFFFF);
c.green = (gushort)(0.8f*0xFFFF);
c.blue = (gushort)(0.4f*0xFFFF);
gdk_color_alloc(gtk_widget_get_colormap(widget), &c);
gdk_gc_set_foreground(gc, &c);
c.red = (gushort)(0.4f*0xFFFF);
c.green = (gushort)(0.8f*0xFFFF);
c.blue = (gushort)(0.4f*0xFFFF);
gdk_color_alloc(gtk_widget_get_colormap(widget), &c);
gdk_gc_set_foreground(gc, &c);
int l, r, t, b;
i = cur_color;
if (i > 13) i -= 14;
l = widget->allocation.width * i / 14;
r = widget->allocation.width * (i+1) / 14;
t = (cur_color < 14) ? 0 : widget->allocation.height/2;
b = (cur_color < 14) ? widget->allocation.height/2 : widget->allocation.height-1;
int l, r, t, b;
gdk_draw_rectangle (colorlist_pixmap, gc, FALSE, l, t, r-l, b-t);
l = widget->allocation.width / NumColumns * cur_color;
r = widget->allocation.width / NumColumns * (cur_color + 1);
t = widget->allocation.height / NumRows * (cur_color / NumColumns);
b = widget->allocation.height / NumRows * (cur_color / NumColumns + 1);
gdk_gc_destroy(gc);
gdk_draw_rectangle (colorlist_pixmap, gc, FALSE, l, t, r-l, b-t);
gdk_gc_destroy(gc);
}
static gint colorlist_configure(GtkWidget *widget, GdkEventConfigure *event)
@ -849,7 +823,7 @@ static void statusbar_listener (int message, void *data, void *user)
if (message == LC_MSG_FOCUS_CHANGED)
{
char text[32];
Vector3 pos;
lcVector3 pos;
lcGetActiveProject()->GetFocusPosition(pos);
lcGetActiveProject()->ConvertToUserUnits(pos);