X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=tools%2Fquake2%2Fextra%2Ftexpaint%2Fwin_pal.c;fp=tools%2Fquake2%2Fextra%2Ftexpaint%2Fwin_pal.c;h=09ebe51f7604320b0031905ae8560054105f075e;hp=0000000000000000000000000000000000000000;hb=62d99f889c0e98be65f779d3983109c84ce58cec;hpb=54a001001813df3c27c2b2369ce2ce23d2d39d6a diff --git a/tools/quake2/extra/texpaint/win_pal.c b/tools/quake2/extra/texpaint/win_pal.c new file mode 100644 index 00000000..09ebe51f --- /dev/null +++ b/tools/quake2/extra/texpaint/win_pal.c @@ -0,0 +1,257 @@ +/* +=========================================================================== +Copyright (C) 1997-2006 Id Software, Inc. + +This file is part of Quake 2 Tools source code. + +Quake 2 Tools source code is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the License, +or (at your option) any later version. + +Quake 2 Tools source code is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Quake 2 Tools source code; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +=========================================================================== +*/ + +#include "texpaint.h" + +#define PALETTE_WINDOW_CLASS "TPPalette" + +HDC paldc; +int pal_width, pal_height; +int blocks_x, blocks_y; + +int selected_index; +unsigned selected_rgb; + +byte palette[768]; + +float SnapAspect (float aspect) +{ + if (aspect > 128) + return 256; + if (aspect > 32) + return 128; + if (aspect > 8) + return 64; + if (aspect > 2) + return 32; + return 16; +} + +void Pal_SetIndex (int index) +{ + selected_index = index; + selected_rgb = palette[index*3] + (palette[index*3+1]<<8) + (palette[index*3+2]<<16); + InvalidateRect (palettewindow, NULL, false); +} + +void Pal_Draw (void) +{ + int x, y; + float aspect; + float xs, ys; + int c; + + if (pal_width < 1 || pal_height < 1) + return; + + // + // determine the block arrangement + // + if (pal_width > pal_height) + { + aspect = SnapAspect (pal_width / pal_height); + blocks_x = aspect; + blocks_y = 256/blocks_x; + } + else + { + aspect = SnapAspect (pal_height / pal_width); + blocks_y = aspect; + blocks_x = 256/blocks_y; + } + + // + // draw it + // + glViewport (0,0,pal_width, pal_height); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + glOrtho (0,1,0,1,-100,100); + glMatrixMode (GL_MODELVIEW); + glLoadIdentity (); + + glClear (GL_COLOR_BUFFER_BIT); + glDisable (GL_DEPTH_TEST); + glDisable (GL_CULL_FACE); + glDisable (GL_TEXTURE_2D); + + xs = 1.0/blocks_x; + ys = 1.0/blocks_y; + + for (x=0 ; x