*/}}
Explorar o código

Colorful color picker

YimingWu hai 1 ano
pai
achega
a16cf813c3
Modificáronse 4 ficheiros con 26 adicións e 13 borrados
  1. 2 0
      la_interface.h
  2. 4 2
      resources/la_templates.c
  3. 1 1
      resources/la_tns_shaders.cpp
  4. 19 10
      resources/la_widgets.c

+ 2 - 0
la_interface.h

@@ -1086,6 +1086,8 @@ STRUCTURE(laWidget){
 #define LA_UI_FLAGS_PLAIN     (LA_UI_FLAGS_NO_DECAL|LA_UI_FLAGS_NO_EVENT)
 #define LA_TEXT_ALIGN (LA_TEXT_ALIGN_LEFT|LA_TEXT_ALIGN_CENTER|LA_TEXT_ALIGN_RIGHT|LA_TEXT_ALIGN_AUTO)
 
+#define LA_UI_FLAGS_COLORFUL LA_UI_FLAGS_ICON
+
 #define LA_UI_FLAGS_TERMINAL_INPUT LA_UI_FLAGS_COLOR_SPACE_CLAY
 
 #define LA_UI_SOCKET_LABEL_N LA_TEXT_ALIGN_LEFT

+ 4 - 2
resources/la_templates.c

@@ -1742,7 +1742,8 @@ void tnsui_Material(laUiList *uil, laPropPack *This, laPropPack *UNUSED_Extra, l
     if(!context){
         laShowLabel(uil,cl,"Name",0,0); laShowItem(uil,cr,This,"name");
     }
-    laShowLabel(uil,cl,"Color",0,0); laShowItemFull(uil,cr,This,"color",LA_WIDGET_FLOAT_COLOR,0,0,0);
+    laShowLabel(uil,cl,"Color",0,0);
+    laShowItemFull(uil,cr,This,"color",LA_WIDGET_FLOAT_COLOR,0,0,0)->Flags|=LA_UI_FLAGS_COLORFUL;
     laShowItemFull(uil,cr,This,"colorful",LA_WIDGET_ENUM_HIGHLIGHT,0,0,0);
 }
 void tnsui_MaterialListItem(laUiList *uil, laPropPack *This, laPropPack *UNUSED_Extra, laColumn *UNUSED_Colums, int context){
@@ -1756,7 +1757,8 @@ void tnsui_MaterialSlot(laUiList *uil, laPropPack *This, laPropPack *UNUSED_Extr
     laColumn* c=laFirstColumn(uil); laUiItem* b,*b1;
     b1=laOnConditionThat(uil,c,laPropExpression(This,"material"));{
         b=laBeginRow(uil,c,0,0);
-        laShowItemFull(uil,c,This,"material.color",LA_WIDGET_FLOAT_COLOR,0,0,0)->Flags|=LA_UI_FLAGS_NO_EVENT|LA_UI_FLAGS_ICON;
+        laShowItemFull(uil,c,This,"material.color",LA_WIDGET_FLOAT_COLOR,0,0,0)
+            ->Flags|=LA_UI_FLAGS_NO_EVENT|LA_UI_FLAGS_ICON|LA_UI_FLAGS_COLORFUL;
         laUiItem* ui=laShowItem(uil,c,This,"material.name"); ui->Flags|=LA_UI_FLAGS_PLAIN; ui->Expand=1;
         laEndRow(uil,b);
     }laElse(uil,b1);{

+ 1 - 1
resources/la_tns_shaders.cpp

@@ -703,7 +703,7 @@ vec4 halftone(vec4 color){
 }
 void main(){
     vec4 color=vec4(1,0,1,1);
-    if(TextureMode==0){ color = fColor;}
+    if(TextureMode==0){ color = fColor; if(UseHalftone>0) color.a=HalftoneSingle(color.a,htsize,rad(7),0); }
     else if(TextureMode==1){color = vec4(fColor.rgb,fColor.a*texture2D(TexColor,fUV.st).r);}
     else if(TextureMode==2){
         color=texture2D(TexColor,fUV.st);

+ 19 - 10
resources/la_widgets.c

@@ -718,6 +718,7 @@ void la_FloatArrayColorDraw(laUiItem *ui, int h){
     laBoxedTheme *bt = (*ui->Type->Theme);
     real Data[32];
     int Len, i, Y = ui->U;
+    int IsColorful=ui->Flags&LA_UI_FLAGS_COLORFUL;
 
     laGetFloatArray(&ui->PP, Data);
     Len = laGetArrayLength(&ui->PP);
@@ -725,18 +726,26 @@ void la_FloatArrayColorDraw(laUiItem *ui, int h){
     if(ui->PP.LastPs->p->Tag&LA_PROP_IS_LINEAR_SRGB){ tns2LogsRGB(Data); }
 
     tnsUseNoTexture();
-    tnsColor4d(Data[0], Data[1], Data[2], /*Len>3?Data[4]:*/ 1);
-    tnsVertex2d(ui->L, Y);
-    tnsVertex2d(ui->R, Y);
-    tnsVertex2d(ui->R, Y + h);
-    tnsVertex2d(ui->L, Y + h);
-    tnsPackAs(GL_TRIANGLE_FAN);
+    if(IsColorful){
+        int sw=(ui->R-ui->L)/2;
+        tnsColor4d(Data[0], Data[1], Data[2], 1);
+        tnsVertex2d(ui->L, Y); tnsVertex2d(ui->L+sw, Y);
+        tnsVertex2d(ui->L+sw, Y + h); tnsVertex2d(ui->L, Y + h);
+        tnsPackAs(GL_TRIANGLE_FAN);
+        tnsColor4d(Data[0], Data[1], Data[2], Len>3?Data[3]:1);
+        tnsVertex2d(ui->L+sw, Y); tnsVertex2d(ui->R, Y);
+        tnsVertex2d(ui->R, Y + h); tnsVertex2d(ui->L+sw, Y + h);
+        tnsUseHalftone(1.0); tnsPackAs(GL_TRIANGLE_FAN); tnsUseHalftone(0.0);
+    }else{
+        tnsColor4d(Data[0], Data[1], Data[2], 1);
+        tnsVertex2d(ui->L, Y); tnsVertex2d(ui->R, Y);
+        tnsVertex2d(ui->R, Y + h); tnsVertex2d(ui->L, Y + h);
+        tnsPackAs(GL_TRIANGLE_FAN);
+    }
 
     tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
-    tnsVertex2d(ui->L, Y);
-    tnsVertex2d(ui->R, Y);
-    tnsVertex2d(ui->R, Y + h);
-    tnsVertex2d(ui->L, Y + h);
+    tnsVertex2d(ui->L, Y); tnsVertex2d(ui->R, Y);
+    tnsVertex2d(ui->R, Y + h); tnsVertex2d(ui->L, Y + h);
     tnsPackAs(GL_LINE_LOOP);
 
     tnsFlush();