//------------------------------------------------------------------------------ // gso_Frame class -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "gso_Frame.cpp" // [Author] "Piero Giubilato" // [Version] "1.2" // [Modified by] "Piero Giubilato" // [Last revision] "23 Apr 2009" // [Language] "C++" // [Compiler] "Visual C++ 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Source for the gso_Frame class" // [Key documentation] // "Visual C++ Reference Help" // "Root reference guide" // {Trace} //______________________________________________________________________________ // Standard component // Application component #include "global.h" #include "gso_Shaper.h" #include "gso_Frame.h" // CINT Preprocessor class import definition ClassImp(gso_Frame) //______________________________________________________________________________ gso_Frame::gso_Frame(const TGWindow* window, UInt_t width, UInt_t height, UInt_t bvl_Size, Float_t bvl_Thick, UInt_t bvl_Style, UInt_t bvl_Color, UInt_t back_Color, bool fill): TGCompositeFrame(window, (width + bvl_Size * 2), (height + bvl_Size * 2)) { // Default constructor. gso_Frame provides display functionalities for // gso_Objects, including a 3D shaded grame border. // Debug dbg_Print("gso_Frame::gso_Frame:(default)", DBG_LVL_ZERO); // The hosting window window_Hnd = window; // Bevel brd_Size = bvl_Size; brd_Thick = bvl_Thick; brd_Style = bvl_Style; brd_Color = bvl_Color; // Computes the shaded back color bck_Color = back_Color; //gso_Shaper::map_Pixel(&dsk_Color, bck_Color); // Sets the shaded inner color frm_Fill = fill; //(fill) ? gso_Shaper::map_Pixel(&inn_Color, brd_Color): inn_Color = dsk_Color; //ChangeBackground(inn_Color); // Set no layout manager SetLayoutBroken(kTRUE); // Clears the bevel pxMaps for (int i = 0; i < 8; i++) bvl_PxMap[i] = 0; // Sets up the graphic context frame_gc_Set = new GCValues_t(); frame_gc_Set->fMask = kGCClipMask | kGCClipXOrigin | kGCClipYOrigin; frame_gc_Set->fClipMask = kNone; frame_gc_Set->fClipXOrigin = 0; frame_gc_Set->fClipYOrigin = 0; frame_gc_Hnd = gVirtualX->CreateGC(GetId(), frame_gc_Set); // Generate appearance graphics Draw(); } //______________________________________________________________________________ gso_Frame::~gso_Frame() { // Default destructor dbg_Print("gso_Frame::~gso_Frame:()", DBG_LVL_ZERO); // Removes the border if any for (int i = 0; i < 8; i++) if (bvl_PxMap[i]) gVirtualX->DeletePixmap(bvl_PxMap[i]); // Removes the frame from the container delete frame_gc_Set; } //______________________________________________________________________________ void gso_Frame::Draw() { // Draws a 3D bevel dbg_Print("gso_Frame::Draw:()", DBG_LVL_MAKE); // Gets the shadedd desk color gso_Shaper::map_Pixel(&dsk_Color, bck_Color); // Sets the inner back color if (frm_Fill) { gso_Shaper::map_Pixel(&inn_Color, brd_Color); } else { inn_Color = dsk_Color; } ChangeBackground(inn_Color); // Creates the border pxMaps if (brd_Size) { draw_Corners(); draw_Sides(); } // Update fClient->NeedRedraw(this); } //______________________________________________________________________________ void gso_Frame::draw_Corners() { // Draws a 3D bevel dbg_Print("gso_Frame::draw_Corners:()", DBG_LVL_MAKE); // Pivot vars UInt_t width = GetWidth(); UInt_t height = GetHeight(); UInt_t size = brd_Size; // Pivot maps Float_t* cS_Map = new Float_t[(2 * size + 1) * (2 * size + 1)]; // The surface map UChar_t* cS_Msk = new UChar_t[(2 * size) * (2 * size)]; // The surface mask UChar_t* cC_Map = new UChar_t[4 * size * size * 4]; // The surface color map UChar_t* cP_Map = new UChar_t[size * size * 4]; // The final color map //UChar_t* cB_Map = new UChar_t[4 * size * size * 4]; // The background color map //UChar_t* cB_Msk = new UChar_t[4 * size * size * 4]; // The background color mask // Set the border material and color gso_Material mat_Brd(gso_Renderer::k_Material); mat_Brd.k_Color = brd_Color; gso_Renderer::l_Strenght(gso_Renderer::kl_Default); // Generates and places the four corner maps switch (brd_Style) { case ks_Bevel: gso_Shaper::shape_Funnel(cS_Map, cS_Msk, size * 2, size * 2, (float)size, brd_Thick); break; case ks_Notch: gso_Shaper::shape_Ring(cS_Map, cS_Msk, size * 2, size * 2, (Float_t)size / 4, (Float_t)size / 4 * 3, brd_Thick, frm_Fill); } gso_Shaper::shape_Render(cC_Map, cS_Map, cS_Msk, 2 * size, 2 * size, &mat_Brd, dsk_Color); // In case the notch style is selected, generates a flat map with the // inner color of the frame, and a mask that is the opposite of the // surface one, then stitches this coloured flat with the color map // derived from the surface map. if (brd_Style == ks_Notch) { //gso_Shaper::map_Flat(cB_Map, 2 * size, 2 * size, desk_Color); //gso_Shaper::mask_Invert(cB_Msk, cS_Msk, 2 * size, 2 * size); //gso_Shaper::map_Sum(cC_Map, cS_Msk, cB_Map, cB_Msk, 2 * size, 2 * size, 1); } // Put the four corners into the different final map for (int dir = 0; dir < 8; dir += 2) { switch (dir) { case 0: gso_Shaper::map_From(cP_Map, size, size, cC_Map, 2 * size, 2* size, 0 ,0); break; case 2: gso_Shaper::map_From(cP_Map, size, size, cC_Map, 2 * size, 2* size, 0 ,size); break; case 4: gso_Shaper::map_From(cP_Map, size, size, cC_Map, 2 * size, 2* size, size ,size); break; case 6: gso_Shaper::map_From(cP_Map, size, size, cC_Map, 2 * size, 2* size, size, 0); break; } // Registers the pxMap if (bvl_PxMap[dir]) gVirtualX->DeletePixmap(bvl_PxMap[dir]); bvl_PxMap[dir] = gVirtualX->CreatePixmapFromData(cP_Map, size, size); } // Remove the pivot maps //delete []cB_Msk; //delete []cB_Map; delete []cC_Map; delete []cP_Map; delete []cS_Msk; delete []cS_Map; } //______________________________________________________________________________ void gso_Frame::draw_Sides() { // Draws a 3D bevel dbg_Print("gso_Frame::draw_Sides:()", DBG_LVL_MAKE); // Pivot vars UInt_t width = GetWidth(); UInt_t height = GetHeight(); UInt_t size = brd_Size; // Pivot maps Float_t* bS_Map = new Float_t[(size + 1) * (size + 1)]; UChar_t* bS_Msk = new UChar_t[size * size]; UChar_t* bC_Map = new UChar_t[size * size * 4]; // Set the border material and color gso_Material mat_Brd(gso_Renderer::k_Material); mat_Brd.k_Color = brd_Color; gso_Renderer::l_Strenght(gso_Renderer::kl_Default); // Generates and renders the bevel tiles for (int dir = 1; dir < 8; dir += 2) { // Renders the basic tile switch (brd_Style) { case ks_Bevel: gso_Shaper::shape_Exp(bS_Map, bS_Msk, size, size, (dir - 1) / 2, brd_Thick); break; case ks_Notch: gso_Shaper::shape_Notch(bS_Map, bS_Msk, size, size, (dir - 1) / 2, (Float_t)size / 4, (Float_t)size / 4 * 3, brd_Thick, frm_Fill); } gso_Shaper::shape_Render(bC_Map, bS_Map, bS_Msk, size, size, &mat_Brd, dsk_Color); // Creates the pixmap used by the graphic server if (bvl_PxMap[dir]) gVirtualX->DeletePixmap(bvl_PxMap[dir]); bvl_PxMap[dir] = gVirtualX->CreatePixmapFromData(bC_Map, size, size); } // Remove the pivot maps delete []bS_Msk; delete []bS_Map; delete []bC_Map; } //______________________________________________________________________________ void gso_Frame::SetColor(Pixel_t fore, Pixel_t back) { // This function overloads the TGFrame original one. dbg_Print("gso_Frame::SetColor:(UInt, UInt)", DBG_LVL_STEP); // Stores the pure colors brd_Color = fore; bck_Color = back; // Redraw the frame Draw(); } //______________________________________________________________________________ void gso_Frame::SetForegroundColor(Pixel_t color) { // This function overloads the TGFrame original one. dbg_Print("gso_Frame::SetForegroundColor:(UInt)", DBG_LVL_STEP); // Stores the color and apply brd_Color = color; SetColor(brd_Color, bck_Color); } //______________________________________________________________________________ void gso_Frame::SetBackgroundColor(Pixel_t color) { // This function overloads the TGFrame original one. dbg_Print("gso_Frame::SetBackgroundColor:(UInt)", DBG_LVL_STEP); // Stores the color and apply bck_Color = color; SetColor(brd_Color, bck_Color); } //______________________________________________________________________________ UInt_t gso_Frame::GetShadedColor() const { // This function returns the shaded tint of the background color dbg_Print("gso_Frame::GetBackgroundColor:()", DBG_LVL_STEP); // Returns the shaded color! if (frm_Fill) return inn_Color; else return dsk_Color; } //______________________________________________________________________________ void gso_Frame::Refresh() { // Nothing to do here dbg_Print("gso_Frame::Refresh:()", DBG_LVL_FLOW); // Nothing to do here? Hmmmmm..... } //______________________________________________________________________________ void gso_Frame::MoveResize(Int_t left, Int_t top, UInt_t width, UInt_t height) { // Overloaded TGFrame move and resize function. dbg_Print("gso_Frame::MoveResize:(Int, Int, UInt, UInt)", DBG_LVL_FLOW); // Moves and resizes the frame. TGFrame::MoveResize(left - brd_Size, top - brd_Size, width + brd_Size * 2, height + brd_Size * 2); } //______________________________________________________________________________ void gso_Frame::Move(Int_t left, Int_t top) { // Overloaded TGFrame move and resize function. dbg_Print("gso_Frame::Move:(Int, Int)", DBG_LVL_FLOW); // Moves and resizes the map frame. Tthis will call a DoRedraw in case of need. TGFrame::Move(left - brd_Size, top - brd_Size); } //______________________________________________________________________________ void gso_Frame::Resize(TGDimension size) { // Overloaded TGFrame resize function. Resize(size.fWidth, size.fHeight); } //______________________________________________________________________________ void gso_Frame::Resize(UInt_t width, UInt_t height) { // Overloaded TGFrame resize function. dbg_Print("gso_Frame::Resize:(UInt, UInt)", DBG_LVL_FLOW); // Moves and resizes the frame. TGFrame::Resize(width + brd_Size * 2, height + brd_Size * 2); } //______________________________________________________________________________ void gso_Frame::DoRedraw() { // Actually, nothing to do here! dbg_Print("gso_Frame::DoRedraw:()", DBG_LVL_FLOW); // Put the border in case if (brd_Size) { // Pivot UInt_t ref_Right = GetWidth() - brd_Size; UInt_t ref_Bottom = GetHeight() - brd_Size; // Vertical sides for (UInt_t p = brd_Size; p < ref_Bottom; p += brd_Size) { gVirtualX->CopyArea(bvl_PxMap[1], GetId(), frame_gc_Hnd, 0, 0, brd_Size, brd_Size, 0, p); gVirtualX->CopyArea(bvl_PxMap[5], GetId(), frame_gc_Hnd, 0, 0, brd_Size, brd_Size, ref_Right, p); } // Horizontal sides for (UInt_t p = brd_Size; p < ref_Right; p += brd_Size) { gVirtualX->CopyArea(bvl_PxMap[7], GetId(), frame_gc_Hnd, 0, 0, brd_Size, brd_Size, p, 0); gVirtualX->CopyArea(bvl_PxMap[3], GetId(), frame_gc_Hnd, 0, 0, brd_Size, brd_Size, p, ref_Bottom); } // Four corners gVirtualX->CopyArea(bvl_PxMap[0], GetId(), frame_gc_Hnd, 0, 0, brd_Size, brd_Size, 0, 0); gVirtualX->CopyArea(bvl_PxMap[2], GetId(), frame_gc_Hnd, 0, 0, brd_Size, brd_Size, 0, ref_Bottom); gVirtualX->CopyArea(bvl_PxMap[4], GetId(), frame_gc_Hnd, 0, 0, brd_Size, brd_Size, ref_Right, ref_Bottom); gVirtualX->CopyArea(bvl_PxMap[6], GetId(), frame_gc_Hnd, 0, 0, brd_Size, brd_Size, ref_Right, 0); } }